On 11/29/2018 03:00 PM, Paolo Abeni wrote:
> This header define a bunch of helpers that allow avoiding the
> retpoline overhead when calling builtin functions via function pointers.
> It boils down to explicitly comparing the function pointers to
> known builtin functions and eventually invoke directly the latter.
> 
> The macro defined here implement the boilerplate for the above schema
> and will be used by the next patches.
> 
> Suggested-by: Eric Dumazet <Eric Dumazet <eduma...@google.com>
> Signed-off-by: Paolo Abeni <pab...@redhat.com>
> ---
>  include/linux/indirect_call_wrapper.h | 77 +++++++++++++++++++++++++++
>  1 file changed, 77 insertions(+)
>  create mode 100644 include/linux/indirect_call_wrapper.h
> 
> diff --git a/include/linux/indirect_call_wrapper.h 
> b/include/linux/indirect_call_wrapper.h
> new file mode 100644
> index 000000000000..57e82b4a166d
> --- /dev/null
> +++ b/include/linux/indirect_call_wrapper.h
> @@ -0,0 +1,77 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _LINUX_INDIRECT_CALL_WRAPPER_H
> +#define _LINUX_INDIRECT_CALL_WRAPPER_H
> +
> +#ifdef CONFIG_RETPOLINE
> +
> +/*
> + * INDIRECT_CALL_$NR - wrapper for indirect calls with $NR known builtin
> + *  @f: function pointer
> + *  @name: base name for builtin functions, see INDIRECT_CALLABLE_DECLARE_$NR
> + *  @__VA_ARGS__: arguments for @f
> + *
> + * Avoid retpoline overhead for known builtin, checking @f vs each of them 
> and
> + * eventually invoking directly the builtin function. Fallback to the 
> indirect
> + * call
> + */
> +#define INDIRECT_CALL_1(f, name, ...)                                        
> \
> +     ({                                                              \
> +             f == name ## 1 ? name ## 1(__VA_ARGS__) :               \

              likely(f == name ## 1) ? ...

> +                              f(__VA_ARGS__);                        \
> +     })
> +#define INDIRECT_CALL_2(f, name, ...)                                        
> \
> +     ({                                                              \
> +             f == name ## 2 ? name ## 2(__VA_ARGS__) :               \

             likely(f == name ## 2) ? ...


> +                              INDIRECT_CALL_1(f, name, __VA_ARGS__); \
> +     })
> +
>

Reply via email to