Commit 6a64037d authored by Björn Töpel's avatar Björn Töpel Committed by Alexei Starovoitov

bpf: Add bpf_trampoline_ name prefix for DECLARE_BPF_DISPATCHER

Adding bpf_trampoline_ name prefix for DECLARE_BPF_DISPATCHER,
so all the dispatchers have the common name prefix.

And also a small '_' cleanup for bpf_dispatcher_nopfunc function
name.
Signed-off-by: default avatarBjörn Töpel <bjorn.topel@intel.com>
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200312195610.346362-3-jolsa@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent b56cd05c
...@@ -522,7 +522,7 @@ struct bpf_dispatcher { ...@@ -522,7 +522,7 @@ struct bpf_dispatcher {
u32 image_off; u32 image_off;
}; };
static __always_inline unsigned int bpf_dispatcher_nopfunc( static __always_inline unsigned int bpf_dispatcher_nop_func(
const void *ctx, const void *ctx,
const struct bpf_insn *insnsi, const struct bpf_insn *insnsi,
unsigned int (*bpf_func)(const void *, unsigned int (*bpf_func)(const void *,
...@@ -537,7 +537,7 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog); ...@@ -537,7 +537,7 @@ int bpf_trampoline_unlink_prog(struct bpf_prog *prog);
void bpf_trampoline_put(struct bpf_trampoline *tr); void bpf_trampoline_put(struct bpf_trampoline *tr);
#define BPF_DISPATCHER_INIT(name) { \ #define BPF_DISPATCHER_INIT(name) { \
.mutex = __MUTEX_INITIALIZER(name.mutex), \ .mutex = __MUTEX_INITIALIZER(name.mutex), \
.func = &name##func, \ .func = &name##_func, \
.progs = {}, \ .progs = {}, \
.num_progs = 0, \ .num_progs = 0, \
.image = NULL, \ .image = NULL, \
...@@ -545,7 +545,7 @@ void bpf_trampoline_put(struct bpf_trampoline *tr); ...@@ -545,7 +545,7 @@ void bpf_trampoline_put(struct bpf_trampoline *tr);
} }
#define DEFINE_BPF_DISPATCHER(name) \ #define DEFINE_BPF_DISPATCHER(name) \
noinline unsigned int name##func( \ noinline unsigned int bpf_dispatcher_##name##_func( \
const void *ctx, \ const void *ctx, \
const struct bpf_insn *insnsi, \ const struct bpf_insn *insnsi, \
unsigned int (*bpf_func)(const void *, \ unsigned int (*bpf_func)(const void *, \
...@@ -553,17 +553,18 @@ void bpf_trampoline_put(struct bpf_trampoline *tr); ...@@ -553,17 +553,18 @@ void bpf_trampoline_put(struct bpf_trampoline *tr);
{ \ { \
return bpf_func(ctx, insnsi); \ return bpf_func(ctx, insnsi); \
} \ } \
EXPORT_SYMBOL(name##func); \ EXPORT_SYMBOL(bpf_dispatcher_##name##_func); \
struct bpf_dispatcher name = BPF_DISPATCHER_INIT(name); struct bpf_dispatcher bpf_dispatcher_##name = \
BPF_DISPATCHER_INIT(bpf_dispatcher_##name);
#define DECLARE_BPF_DISPATCHER(name) \ #define DECLARE_BPF_DISPATCHER(name) \
unsigned int name##func( \ unsigned int bpf_dispatcher_##name##_func( \
const void *ctx, \ const void *ctx, \
const struct bpf_insn *insnsi, \ const struct bpf_insn *insnsi, \
unsigned int (*bpf_func)(const void *, \ unsigned int (*bpf_func)(const void *, \
const struct bpf_insn *)); \ const struct bpf_insn *)); \
extern struct bpf_dispatcher name; extern struct bpf_dispatcher bpf_dispatcher_##name;
#define BPF_DISPATCHER_FUNC(name) name##func #define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_##name##_func
#define BPF_DISPATCHER_PTR(name) (&name) #define BPF_DISPATCHER_PTR(name) (&bpf_dispatcher_##name)
void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from, void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, struct bpf_prog *from,
struct bpf_prog *to); struct bpf_prog *to);
struct bpf_image { struct bpf_image {
...@@ -589,7 +590,7 @@ static inline int bpf_trampoline_unlink_prog(struct bpf_prog *prog) ...@@ -589,7 +590,7 @@ static inline int bpf_trampoline_unlink_prog(struct bpf_prog *prog)
static inline void bpf_trampoline_put(struct bpf_trampoline *tr) {} static inline void bpf_trampoline_put(struct bpf_trampoline *tr) {}
#define DEFINE_BPF_DISPATCHER(name) #define DEFINE_BPF_DISPATCHER(name)
#define DECLARE_BPF_DISPATCHER(name) #define DECLARE_BPF_DISPATCHER(name)
#define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_nopfunc #define BPF_DISPATCHER_FUNC(name) bpf_dispatcher_nop_func
#define BPF_DISPATCHER_PTR(name) NULL #define BPF_DISPATCHER_PTR(name) NULL
static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d, static inline void bpf_dispatcher_change_prog(struct bpf_dispatcher *d,
struct bpf_prog *from, struct bpf_prog *from,
......
...@@ -577,7 +577,7 @@ DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key); ...@@ -577,7 +577,7 @@ DECLARE_STATIC_KEY_FALSE(bpf_stats_enabled_key);
ret; }) ret; })
#define BPF_PROG_RUN(prog, ctx) \ #define BPF_PROG_RUN(prog, ctx) \
__BPF_PROG_RUN(prog, ctx, bpf_dispatcher_nopfunc) __BPF_PROG_RUN(prog, ctx, bpf_dispatcher_nop_func)
/* /*
* Use in preemptible and therefore migratable context to make sure that * Use in preemptible and therefore migratable context to make sure that
...@@ -596,7 +596,7 @@ static inline u32 bpf_prog_run_pin_on_cpu(const struct bpf_prog *prog, ...@@ -596,7 +596,7 @@ static inline u32 bpf_prog_run_pin_on_cpu(const struct bpf_prog *prog,
u32 ret; u32 ret;
migrate_disable(); migrate_disable();
ret = __BPF_PROG_RUN(prog, ctx, bpf_dispatcher_nopfunc); ret = __BPF_PROG_RUN(prog, ctx, bpf_dispatcher_nop_func);
migrate_enable(); migrate_enable();
return ret; return ret;
} }
...@@ -722,7 +722,7 @@ static inline u32 bpf_prog_run_clear_cb(const struct bpf_prog *prog, ...@@ -722,7 +722,7 @@ static inline u32 bpf_prog_run_clear_cb(const struct bpf_prog *prog,
return res; return res;
} }
DECLARE_BPF_DISPATCHER(bpf_dispatcher_xdp) DECLARE_BPF_DISPATCHER(xdp)
static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog, static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
struct xdp_buff *xdp) struct xdp_buff *xdp)
...@@ -733,8 +733,7 @@ static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog, ...@@ -733,8 +733,7 @@ static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
* already takes rcu_read_lock() when fetching the program, so * already takes rcu_read_lock() when fetching the program, so
* it's not necessary here anymore. * it's not necessary here anymore.
*/ */
return __BPF_PROG_RUN(prog, xdp, return __BPF_PROG_RUN(prog, xdp, BPF_DISPATCHER_FUNC(xdp));
BPF_DISPATCHER_FUNC(bpf_dispatcher_xdp));
} }
void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog); void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog);
......
...@@ -8859,10 +8859,9 @@ const struct bpf_prog_ops sk_reuseport_prog_ops = { ...@@ -8859,10 +8859,9 @@ const struct bpf_prog_ops sk_reuseport_prog_ops = {
}; };
#endif /* CONFIG_INET */ #endif /* CONFIG_INET */
DEFINE_BPF_DISPATCHER(bpf_dispatcher_xdp) DEFINE_BPF_DISPATCHER(xdp)
void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog) void bpf_prog_change_xdp(struct bpf_prog *prev_prog, struct bpf_prog *prog)
{ {
bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(bpf_dispatcher_xdp), bpf_dispatcher_change_prog(BPF_DISPATCHER_PTR(xdp), prev_prog, prog);
prev_prog, prog);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment