diff mbox series

[v2,bpf-next,2/2] bpf: Add __bpf_hook_{start,end} macros

Message ID 20231031215625.2343848-2-davemarchevsky@fb.com (mailing list archive)
State Accepted
Commit 15fb6f2b6c4c3c129adc2412ae12ec15e60a6adb
Delegated to: BPF
Headers show
Series [v2,bpf-next,1/2] bpf: Add __bpf_kfunc_{start,end}_defs macros | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2867 this patch: 2867
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
netdev/cc_maintainers warning 24 maintainers not CCed: cgroups@vger.kernel.org pabeni@redhat.com linux-arm-kernel@lists.infradead.org mykolal@fb.com tj@kernel.org sdf@google.com kuba@kernel.org kpsingh@kernel.org song@kernel.org haoluo@google.com alexandre.torgue@foss.st.com lizefan.x@bytedance.com linux-stm32@st-md-mailman.stormreply.com mcoquelin.stm32@gmail.com shuah@kernel.org linux-kselftest@vger.kernel.org netdev@vger.kernel.org martin.lau@linux.dev jolsa@kernel.org john.fastabend@gmail.com davem@davemloft.net yonghong.song@linux.dev edumazet@google.com hannes@cmpxchg.org
netdev/build_clang success Errors and warnings before: 1541 this patch: 1541
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2944 this patch: 2944
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 70 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-16 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-16 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-llvm-16 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-llvm-16 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-5 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-3 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-10 success Logs for set-matrix

Commit Message

Dave Marchevsky Oct. 31, 2023, 9:56 p.m. UTC
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>
---

This patch was added in v2 in response to convo on v1's thread.

 include/linux/btf.h                                   | 2 ++
 kernel/cgroup/rstat.c                                 | 9 +++------
 net/socket.c                                          | 8 ++------
 tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 6 ++----
 4 files changed, 9 insertions(+), 16 deletions(-)

Comments

Jiri Olsa Oct. 31, 2023, 11:03 p.m. UTC | #1
On Tue, Oct 31, 2023 at 02:56:25PM -0700, Dave Marchevsky wrote:
> 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>

jirka

> ---
> 
> This patch was added in v2 in response to convo on v1's thread.
> 
>  include/linux/btf.h                                   | 2 ++
>  kernel/cgroup/rstat.c                                 | 9 +++------
>  net/socket.c                                          | 8 ++------
>  tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 6 ++----
>  4 files changed, 9 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/btf.h b/include/linux/btf.h
> index dc5ce962f600..59d404e22814 100644
> --- a/include/linux/btf.h
> +++ b/include/linux/btf.h
> @@ -92,6 +92,8 @@
>  			  "Global kfuncs as their definitions will be in BTF")
>  
>  #define __bpf_kfunc_end_defs() __diag_pop()
> +#define __bpf_hook_start() __bpf_kfunc_start_defs()
> +#define __bpf_hook_end() __bpf_kfunc_end_defs()
>  
>  /*
>   * Return the name of the passed struct, if exists, or halt the build if for
> diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> index d80d7a608141..c0adb7254b45 100644
> --- a/kernel/cgroup/rstat.c
> +++ b/kernel/cgroup/rstat.c
> @@ -156,19 +156,16 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
>   * optimize away the callsite. Therefore, __weak is needed to ensure that the
>   * call is still emitted, by telling the compiler that we don't know what the
>   * function might eventually be.
> - *
> - * __diag_* below are needed to dismiss the missing prototype warning.
>   */
> -__diag_push();
> -__diag_ignore_all("-Wmissing-prototypes",
> -		  "kfuncs which will be used in BPF programs");
> +
> +__bpf_hook_start();
>  
>  __weak noinline void bpf_rstat_flush(struct cgroup *cgrp,
>  				     struct cgroup *parent, int cpu)
>  {
>  }
>  
> -__diag_pop();
> +__bpf_hook_end();
>  
>  /* see cgroup_rstat_flush() */
>  static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
> diff --git a/net/socket.c b/net/socket.c
> index c4a6f5532955..cd4d9ae2144f 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -1685,20 +1685,16 @@ struct file *__sys_socket_file(int family, int type, int protocol)
>   *	Therefore, __weak is needed to ensure that the call is still
>   *	emitted, by telling the compiler that we don't know what the
>   *	function might eventually be.
> - *
> - *	__diag_* below are needed to dismiss the missing prototype warning.
>   */
>  
> -__diag_push();
> -__diag_ignore_all("-Wmissing-prototypes",
> -		  "A fmod_ret entry point for BPF programs");
> +__bpf_hook_start();
>  
>  __weak noinline int update_socket_protocol(int family, int type, int protocol)
>  {
>  	return protocol;
>  }
>  
> -__diag_pop();
> +__bpf_hook_end();
>  
>  int __sys_socket(int family, int type, int protocol)
>  {
> diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> index a5e246f7b202..91907b321f91 100644
> --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> @@ -39,9 +39,7 @@ struct bpf_testmod_struct_arg_4 {
>  	int b;
>  };
>  
> -__diag_push();
> -__diag_ignore_all("-Wmissing-prototypes",
> -		  "Global functions as their definitions will be in bpf_testmod.ko BTF");
> +__bpf_hook_start();
>  
>  noinline int
>  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)
>  }
>  EXPORT_SYMBOL_GPL(bpf_fentry_shadow_test);
>  
> -__diag_pop();
> +__bpf_hook_end();
>  
>  static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = {
>  	.attr = { .name = "bpf_testmod", .mode = 0666, },
> -- 
> 2.34.1
> 
>
Yafang Shao Nov. 1, 2023, 2:17 a.m. UTC | #2
On Wed, Nov 1, 2023 at 7:03 AM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Tue, Oct 31, 2023 at 02:56:25PM -0700, Dave Marchevsky wrote:
> > 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>

>
> jirka
>
> > ---
> >
> > This patch was added in v2 in response to convo on v1's thread.
> >
> >  include/linux/btf.h                                   | 2 ++
> >  kernel/cgroup/rstat.c                                 | 9 +++------
> >  net/socket.c                                          | 8 ++------
> >  tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 6 ++----
> >  4 files changed, 9 insertions(+), 16 deletions(-)
> >
> > diff --git a/include/linux/btf.h b/include/linux/btf.h
> > index dc5ce962f600..59d404e22814 100644
> > --- a/include/linux/btf.h
> > +++ b/include/linux/btf.h
> > @@ -92,6 +92,8 @@
> >                         "Global kfuncs as their definitions will be in BTF")
> >
> >  #define __bpf_kfunc_end_defs() __diag_pop()
> > +#define __bpf_hook_start() __bpf_kfunc_start_defs()
> > +#define __bpf_hook_end() __bpf_kfunc_end_defs()
> >
> >  /*
> >   * Return the name of the passed struct, if exists, or halt the build if for
> > diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
> > index d80d7a608141..c0adb7254b45 100644
> > --- a/kernel/cgroup/rstat.c
> > +++ b/kernel/cgroup/rstat.c
> > @@ -156,19 +156,16 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
> >   * optimize away the callsite. Therefore, __weak is needed to ensure that the
> >   * call is still emitted, by telling the compiler that we don't know what the
> >   * function might eventually be.
> > - *
> > - * __diag_* below are needed to dismiss the missing prototype warning.
> >   */
> > -__diag_push();
> > -__diag_ignore_all("-Wmissing-prototypes",
> > -               "kfuncs which will be used in BPF programs");
> > +
> > +__bpf_hook_start();
> >
> >  __weak noinline void bpf_rstat_flush(struct cgroup *cgrp,
> >                                    struct cgroup *parent, int cpu)
> >  {
> >  }
> >
> > -__diag_pop();
> > +__bpf_hook_end();
> >
> >  /* see cgroup_rstat_flush() */
> >  static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
> > diff --git a/net/socket.c b/net/socket.c
> > index c4a6f5532955..cd4d9ae2144f 100644
> > --- a/net/socket.c
> > +++ b/net/socket.c
> > @@ -1685,20 +1685,16 @@ struct file *__sys_socket_file(int family, int type, int protocol)
> >   *   Therefore, __weak is needed to ensure that the call is still
> >   *   emitted, by telling the compiler that we don't know what the
> >   *   function might eventually be.
> > - *
> > - *   __diag_* below are needed to dismiss the missing prototype warning.
> >   */
> >
> > -__diag_push();
> > -__diag_ignore_all("-Wmissing-prototypes",
> > -               "A fmod_ret entry point for BPF programs");
> > +__bpf_hook_start();
> >
> >  __weak noinline int update_socket_protocol(int family, int type, int protocol)
> >  {
> >       return protocol;
> >  }
> >
> > -__diag_pop();
> > +__bpf_hook_end();
> >
> >  int __sys_socket(int family, int type, int protocol)
> >  {
> > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > index a5e246f7b202..91907b321f91 100644
> > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
> > @@ -39,9 +39,7 @@ struct bpf_testmod_struct_arg_4 {
> >       int b;
> >  };
> >
> > -__diag_push();
> > -__diag_ignore_all("-Wmissing-prototypes",
> > -               "Global functions as their definitions will be in bpf_testmod.ko BTF");
> > +__bpf_hook_start();
> >
> >  noinline int
> >  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)
> >  }
> >  EXPORT_SYMBOL_GPL(bpf_fentry_shadow_test);
> >
> > -__diag_pop();
> > +__bpf_hook_end();
> >
> >  static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = {
> >       .attr = { .name = "bpf_testmod", .mode = 0666, },
> > --
> > 2.34.1
> >
> >
diff mbox series

Patch

diff --git a/include/linux/btf.h b/include/linux/btf.h
index dc5ce962f600..59d404e22814 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -92,6 +92,8 @@ 
 			  "Global kfuncs as their definitions will be in BTF")
 
 #define __bpf_kfunc_end_defs() __diag_pop()
+#define __bpf_hook_start() __bpf_kfunc_start_defs()
+#define __bpf_hook_end() __bpf_kfunc_end_defs()
 
 /*
  * Return the name of the passed struct, if exists, or halt the build if for
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index d80d7a608141..c0adb7254b45 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -156,19 +156,16 @@  static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
  * optimize away the callsite. Therefore, __weak is needed to ensure that the
  * call is still emitted, by telling the compiler that we don't know what the
  * function might eventually be.
- *
- * __diag_* below are needed to dismiss the missing prototype warning.
  */
-__diag_push();
-__diag_ignore_all("-Wmissing-prototypes",
-		  "kfuncs which will be used in BPF programs");
+
+__bpf_hook_start();
 
 __weak noinline void bpf_rstat_flush(struct cgroup *cgrp,
 				     struct cgroup *parent, int cpu)
 {
 }
 
-__diag_pop();
+__bpf_hook_end();
 
 /* see cgroup_rstat_flush() */
 static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
diff --git a/net/socket.c b/net/socket.c
index c4a6f5532955..cd4d9ae2144f 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1685,20 +1685,16 @@  struct file *__sys_socket_file(int family, int type, int protocol)
  *	Therefore, __weak is needed to ensure that the call is still
  *	emitted, by telling the compiler that we don't know what the
  *	function might eventually be.
- *
- *	__diag_* below are needed to dismiss the missing prototype warning.
  */
 
-__diag_push();
-__diag_ignore_all("-Wmissing-prototypes",
-		  "A fmod_ret entry point for BPF programs");
+__bpf_hook_start();
 
 __weak noinline int update_socket_protocol(int family, int type, int protocol)
 {
 	return protocol;
 }
 
-__diag_pop();
+__bpf_hook_end();
 
 int __sys_socket(int family, int type, int protocol)
 {
diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
index a5e246f7b202..91907b321f91 100644
--- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
@@ -39,9 +39,7 @@  struct bpf_testmod_struct_arg_4 {
 	int b;
 };
 
-__diag_push();
-__diag_ignore_all("-Wmissing-prototypes",
-		  "Global functions as their definitions will be in bpf_testmod.ko BTF");
+__bpf_hook_start();
 
 noinline int
 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)
 }
 EXPORT_SYMBOL_GPL(bpf_fentry_shadow_test);
 
-__diag_pop();
+__bpf_hook_end();
 
 static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = {
 	.attr = { .name = "bpf_testmod", .mode = 0666, },