Skip to content

Commit 15fb6f2

Browse files
davemarchevskyAlexei Starovoitov
authored andcommitted
bpf: Add __bpf_hook_{start,end} macros
Not all uses of __diag_ignore_all(...) in BPF-related code in order to suppress warnings are wrapping kfunc definitions. Some "hook point" definitions - small functions meant to be used as attach points for fentry and similar BPF progs - need to suppress -Wmissing-declarations. We could use __bpf_kfunc_{start,end}_defs added in the previous patch in such cases, but this might be confusing to someone unfamiliar with BPF internals. Instead, this patch adds __bpf_hook_{start,end} macros, currently having the same effect as __bpf_kfunc_{start,end}_defs, then uses them to suppress warnings for two hook points in the kernel itself and some bpf_testmod hook points as well. Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com> Cc: Yafang Shao <laoar.shao@gmail.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Acked-by: Yafang Shao <laoar.shao@gmail.com> Link: https://lore.kernel.org/r/20231031215625.2343848-2-davemarchevsky@fb.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 391145b commit 15fb6f2

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

include/linux/btf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
"Global kfuncs as their definitions will be in BTF")
9393

9494
#define __bpf_kfunc_end_defs() __diag_pop()
95+
#define __bpf_hook_start() __bpf_kfunc_start_defs()
96+
#define __bpf_hook_end() __bpf_kfunc_end_defs()
9597

9698
/*
9799
* Return the name of the passed struct, if exists, or halt the build if for

kernel/cgroup/rstat.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,16 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
156156
* optimize away the callsite. Therefore, __weak is needed to ensure that the
157157
* call is still emitted, by telling the compiler that we don't know what the
158158
* function might eventually be.
159-
*
160-
* __diag_* below are needed to dismiss the missing prototype warning.
161159
*/
162-
__diag_push();
163-
__diag_ignore_all("-Wmissing-prototypes",
164-
"kfuncs which will be used in BPF programs");
160+
161+
__bpf_hook_start();
165162

166163
__weak noinline void bpf_rstat_flush(struct cgroup *cgrp,
167164
struct cgroup *parent, int cpu)
168165
{
169166
}
170167

171-
__diag_pop();
168+
__bpf_hook_end();
172169

173170
/* see cgroup_rstat_flush() */
174171
static void cgroup_rstat_flush_locked(struct cgroup *cgrp)

net/socket.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,20 +1685,16 @@ struct file *__sys_socket_file(int family, int type, int protocol)
16851685
* Therefore, __weak is needed to ensure that the call is still
16861686
* emitted, by telling the compiler that we don't know what the
16871687
* function might eventually be.
1688-
*
1689-
* __diag_* below are needed to dismiss the missing prototype warning.
16901688
*/
16911689

1692-
__diag_push();
1693-
__diag_ignore_all("-Wmissing-prototypes",
1694-
"A fmod_ret entry point for BPF programs");
1690+
__bpf_hook_start();
16951691

16961692
__weak noinline int update_socket_protocol(int family, int type, int protocol)
16971693
{
16981694
return protocol;
16991695
}
17001696

1701-
__diag_pop();
1697+
__bpf_hook_end();
17021698

17031699
int __sys_socket(int family, int type, int protocol)
17041700
{

tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ struct bpf_testmod_struct_arg_4 {
3939
int b;
4040
};
4141

42-
__diag_push();
43-
__diag_ignore_all("-Wmissing-prototypes",
44-
"Global functions as their definitions will be in bpf_testmod.ko BTF");
42+
__bpf_hook_start();
4543

4644
noinline int
4745
bpf_testmod_test_struct_arg_1(struct bpf_testmod_struct_arg_2 a, int b, int c) {
@@ -335,7 +333,7 @@ noinline int bpf_fentry_shadow_test(int a)
335333
}
336334
EXPORT_SYMBOL_GPL(bpf_fentry_shadow_test);
337335

338-
__diag_pop();
336+
__bpf_hook_end();
339337

340338
static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = {
341339
.attr = { .name = "bpf_testmod", .mode = 0666, },

0 commit comments

Comments
 (0)