* [PATCH] bpf: avoid warning for unused register_bpf_struct_ops()
@ 2025-12-04 9:42 Arnd Bergmann
2025-12-04 19:22 ` Martin KaFai Lau
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2025-12-04 9:42 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Dust Li, D. Wythe
Cc: Arnd Bergmann, Kui-Feng Lee, Martin KaFai Lau, Eduard Zingerman,
Song Liu, Yonghong Song, John Fastabend, KP Singh,
Stanislav Fomichev, Hao Luo, Jiri Olsa, Kumar Kartikeya Dwivedi,
Mykyta Yatsenko, Tao Chen, Anton Protopopov, bpf, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
The macro originally introduced in commit f6be98d19985 ("bpf, net:
switch to dynamic registration") causes a warning in the new smc code
because of the way it evaluates the arguments:
In file included from include/linux/bpf_verifier.h:7,
from net/smc/smc_hs_bpf.c:13:
net/smc/smc_hs_bpf.c: In function 'bpf_smc_hs_ctrl_init':
include/linux/bpf.h:2076:50: error: statement with no effect [-Werror=unused-value]
2076 | #define register_bpf_struct_ops(st_ops, type) ({ (void *)(st_ops); 0; })
| ^~~~~~~~~~~~~~~~
net/smc/smc_hs_bpf.c:139:16: note: in expansion of macro 'register_bpf_struct_ops'
139 | return register_bpf_struct_ops(&bpf_smc_hs_ctrl_ops, smc_hs_ctrl);
| ^~~~~~~~~~~~~~~~~~~~~~~
Work around this using an inline function that takes the argument,
the same way as the normal implementation. Since the second argument to
register_bpf_struct_ops() is a type rather than an object, this still
has to be a macro, but it can call a new inline helper internally like
the normal one does.
Fixes: 15f295f55656 ("net/smc: bpf: Introduce generic hook for handshake flow")
Cc: Kui-Feng Lee <thinker.li@gmail.com>
Cc: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/bpf.h | 2 +-
include/linux/btf.h | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 6498be4c44f8..eca6966d4f87 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2065,7 +2065,7 @@ int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,
void bpf_map_struct_ops_info_fill(struct bpf_map_info *info, struct bpf_map *map);
void bpf_struct_ops_desc_release(struct bpf_struct_ops_desc *st_ops_desc);
#else
-#define register_bpf_struct_ops(st_ops, type) ({ (void *)(st_ops); 0; })
+#define register_bpf_struct_ops(st_ops, type) __register_bpf_struct_ops(st_ops)
static inline bool bpf_try_module_get(const void *data, struct module *owner)
{
return try_module_get(owner);
diff --git a/include/linux/btf.h b/include/linux/btf.h
index f06976ffb63f..799a75209536 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -535,6 +535,11 @@ int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops);
const struct bpf_struct_ops_desc *bpf_struct_ops_find_value(struct btf *btf, u32 value_id);
const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id);
#else
+struct bpf_struct_ops;
+static inline int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)
+{
+ return 0;
+}
static inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id)
{
return NULL;
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bpf: avoid warning for unused register_bpf_struct_ops()
2025-12-04 9:42 [PATCH] bpf: avoid warning for unused register_bpf_struct_ops() Arnd Bergmann
@ 2025-12-04 19:22 ` Martin KaFai Lau
0 siblings, 0 replies; 2+ messages in thread
From: Martin KaFai Lau @ 2025-12-04 19:22 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Dust Li,
D. Wythe, Arnd Bergmann, Kui-Feng Lee, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Kumar Kartikeya Dwivedi, Mykyta Yatsenko, Tao Chen,
Anton Protopopov, bpf, linux-kernel
On 12/4/25 1:42 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> The macro originally introduced in commit f6be98d19985 ("bpf, net:
> switch to dynamic registration") causes a warning in the new smc code
> because of the way it evaluates the arguments:
>
> In file included from include/linux/bpf_verifier.h:7,
> from net/smc/smc_hs_bpf.c:13:
> net/smc/smc_hs_bpf.c: In function 'bpf_smc_hs_ctrl_init':
> include/linux/bpf.h:2076:50: error: statement with no effect [-Werror=unused-value]
> 2076 | #define register_bpf_struct_ops(st_ops, type) ({ (void *)(st_ops); 0; })
> | ^~~~~~~~~~~~~~~~
> net/smc/smc_hs_bpf.c:139:16: note: in expansion of macro 'register_bpf_struct_ops'
> 139 | return register_bpf_struct_ops(&bpf_smc_hs_ctrl_ops, smc_hs_ctrl);
> | ^~~~~~~~~~~~~~~~~~~~~~~
>
> Work around this using an inline function that takes the argument,
> the same way as the normal implementation. Since the second argument to
> register_bpf_struct_ops() is a type rather than an object, this still
> has to be a macro, but it can call a new inline helper internally like
> the normal one does.
Thanks for the patch. This has been fixed in
"https://lore.kernel.org/bpf/988c61e5fea280872d81b3640f1f34d0619cfbbf.1764843951.git.geert@linux-m68k.org/"
to completely remove its usage from smc. The smc usage without
CONFIG_BPF_JIT was an overlook. This empty register_bpf_struct_ops
should be removed from the bpf-next tree as a cleanup.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-04 19:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-04 9:42 [PATCH] bpf: avoid warning for unused register_bpf_struct_ops() Arnd Bergmann
2025-12-04 19:22 ` Martin KaFai Lau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox