Skip to contentSkip to conversation

selftests/bpf: Use local types for kfunc declarations

PATCH Applied Gregory Bell 3 participants 5 messages Apr 17 – Apr 27

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover selftests/bpf: Use local types for kfunc declarations

The xdp_flowtable and test_tunnel_kern selftests were previously rewritten to compile with CONFIG_NF_FLOW_TABLE=m and CONFIG_NET_FOU=m. While the compilation issues were resolved, the tests fail at runtime. In test_tunnel_kern.c, struct bpf_fou_encap___local is defined with the correct fields but the kfunc declarations still reference the forward-declared struct bpf_fou_encap. Similarly, xdp_flowtable.c uses a forward-declared struct flow_offload_tuple_rhash as the return type for bpf_xdp_flow_lookup(). Clang emits these forward declarations as BTF FWD types, which fail to resolve against the module-defined STRUCT types at run time:

libbpf: extern (func ksym) 'bpf_xdp_flow_lookup': func_proto [51] incompatible with nf_flow_table [128640]
libbpf: extern (func ksym) 'bpf_skb_get_fou_encap': func_proto [79] incompatible with fou [135045]

This patch updates both selftests to use ___local type suffixes for kernel struct type, replacing the forward declarations.

struct flow_offload_tuple_rhash___local is defined without fields because the test only uses the returned pointer for a null check. This avoids needing to locally define its nested types, struct rhash_head and struct flow_offload_tuple.

I understand that fixing selftests for specific config options is generally not a priority, but since these tests were already rewritten to support these configs, they should work correctly with them.

Fixes d17f9b370df6 ("selftests/bpf: Fix compilation failure when CONFIG_NET_FOU!=y")
Fixes eeb23b54e447 ("selftests/bpf: fix compilation failure when CONFIG_NF_FLOW_TABLE=m")

change log:
[0] https://lore.kernel.org/all/[email protected]/
- Add BPF_NO_KFUNC_PROTOTYPES macro to test_tunnel_kern.c so the test compiles when CONFIG_NET_FOU=y. Without it the function prototypes conflict with vmlinux.h

Gregory Bell (2):
selftests/bpf: Use local type for flow_offload_tuple_rhash in
xdp_flowtable
selftests/bpf: Use local type for bpf_fou_encap in test_tunnel_kern

 .../testing/selftests/bpf/progs/test_tunnel_kern.c  | 13 ++++++-------
 tools/testing/selftests/bpf/progs/xdp_flowtable.c   |  7 +++++--
 2 files changed, 11 insertions(+), 9 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/2 selftests/bpf: Use local type for flow_offload_tuple_rhash in xdp_flowtable

Define flow_offload_tuple_rhash___local and use it in place of the forward-declared kernel type for the bpf_xdp_flow_lookup kfunc return type and tuplehash variable. This is consistent with how bpf_flowtable_opts___local is already handled in the same file and avoids relying on a forward declaration of the struct.

Fixes eeb23b54e447 ("selftests/bpf: fix compilation failure when CONFIG_NF_FLOW_TABLE=m")
---
 tools/testing/selftests/bpf/progs/xdp_flowtable.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/xdp_flowtable.c +5 -2
index 7fdc7b23ee74..e67daa02749d 100644
@@ -15,7 +15,10 @@ struct bpf_flowtable_opts___local {
 	s32 error;
 };
 
-struct flow_offload_tuple_rhash *
+struct flow_offload_tuple_rhash___local {
+};
+
+struct flow_offload_tuple_rhash___local *
 bpf_xdp_flow_lookup(struct xdp_md *, struct bpf_fib_lookup *,
 		    struct bpf_flowtable_opts___local *, u32) __ksym;
 
@@ -67,7 +70,7 @@ int xdp_flowtable_do_lookup(struct xdp_md *ctx)
 {
 	void *data_end = (void *)(long)ctx->data_end;
 	struct bpf_flowtable_opts___local opts = {};
-	struct flow_offload_tuple_rhash *tuplehash;
+	struct flow_offload_tuple_rhash___local *tuplehash;
 	struct bpf_fib_lookup tuple = {
 		.ifindex = ctx->ingress_ifindex,
 	};
Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH v2 1/2] selftests/bpf: Use local type for flow_offload_tuple_rhash in xdp_flowtable

Should this Fixes tag reference c77e572d3a8c instead? That commit originally introduced the forward declaration of flow_offload_tuple_rhash that this patch is now fixing. Commit eeb23b54e447…
Quoted 1 line
Fixes eeb23b54e447 ("selftests/bpf: fix compilation failure when CONFIG_NF_FLOW_TABLE=m")

Should this Fixes tag reference c77e572d3a8c instead? That commit originally introduced the forward declaration of flow_offload_tuple_rhash that this patch is now fixing. Commit eeb23b54e447 partially addressed the same issue by fixing flow_ports but left flow_offload_tuple_rhash unfixed.

Quoted 17 lines
tools/testing/selftests/bpf/progs/xdp_flowtable.c +4 -1
index 7fdc7b23ee74..e67daa02749d 100644
@@ -15,7 +15,10 @@ struct bpf_flowtable_opts___local {
 	s32 error;
 };
 
-struct flow_offload_tuple_rhash *
+struct flow_offload_tuple_rhash___local {
+};
+
+struct flow_offload_tuple_rhash___local *
 bpf_xdp_flow_lookup(struct xdp_md *, struct bpf_fib_lookup *,
 		    struct bpf_flowtable_opts___local *, u32) __ksym;
 

tools/testing/selftests/bpf/progs/xdp_flowtable.c int xdp_flowtable_do_lookup(struct xdp_md *ctx) · line 76

Quoted 8 lines
tools/testing/selftests/bpf/progs/xdp_flowtable.c +1 -1
@@ -67,7 +70,7 @@ int xdp_flowtable_do_lookup(struct xdp_md *ctx)
 {
 	void *data_end = (void *)(long)ctx->data_end;
 	struct bpf_flowtable_opts___local opts = {};
-	struct flow_offload_tuple_rhash *tuplehash;
+	struct flow_offload_tuple_rhash___local *tuplehash;
 	struct bpf_fib_lookup tuple = {
 		.ifindex = ctx->ingress_ifindex,
 	};

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/24574259813

#3 lore raw

PATCH v2 2/2 selftests/bpf: Use local type for bpf_fou_encap in test_tunnel_kern

In reply to Gregory Bell

Replace the forward-declared struct bpf_fou_encap with the existing bpf_fou_encap___local type in the bpf_skb_set_fou_encap and bpf_skb_get_fou_encap declarations. This removes the need for the forward declaration and the explicit casts at each call.

Fixes d17f9b370df6 ("selftests/bpf: Fix compilation failure when CONFIG_NET_FOU!=y")
---
 .../testing/selftests/bpf/progs/test_tunnel_kern.c  | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +6 -7
index 32127f1cd687..30f1de458669 100644
@@ -6,6 +6,7 @@
  * modify it under the terms of version 2 of the GNU General Public
  * License as published by the Free Software Foundation.
  */
+#define BPF_NO_KFUNC_PROTOTYPES
 #include "vmlinux.h"
 #include <bpf/bpf_core_read.h>
 #include <bpf/bpf_helpers.h>
@@ -36,12 +37,10 @@ enum bpf_fou_encap_type___local {
 	FOU_BPF_ENCAP_GUE___local,
 };
 
-struct bpf_fou_encap;
-
 int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
-			  struct bpf_fou_encap *encap, int type) __ksym;
+			  struct bpf_fou_encap___local *encap, int type) __ksym;
 int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
-			  struct bpf_fou_encap *encap) __ksym;
+			  struct bpf_fou_encap___local *encap) __ksym;
 struct xfrm_state *
 bpf_xdp_get_xfrm_state(struct xdp_md *ctx, struct bpf_xfrm_state_opts *opts,
 		       u32 opts__sz) __ksym;
@@ -781,7 +780,7 @@ int ipip_gue_set_tunnel(struct __sk_buff *skb)
 	encap.sport = 0;
 	encap.dport = bpf_htons(5555);
 
-	ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+	ret = bpf_skb_set_fou_encap(skb, &encap,
 				    bpf_core_enum_value(enum bpf_fou_encap_type___local,
 							FOU_BPF_ENCAP_GUE___local));
 	if (ret < 0) {
@@ -820,7 +819,7 @@ int ipip_fou_set_tunnel(struct __sk_buff *skb)
 	encap.sport = 0;
 	encap.dport = bpf_htons(5555);
 
-	ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+	ret = bpf_skb_set_fou_encap(skb, &encap,
 				    FOU_BPF_ENCAP_FOU___local);
 	if (ret < 0) {
 		log_err(ret);
@@ -843,7 +842,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 		return TC_ACT_SHOT;
 	}
 
-	ret = bpf_skb_get_fou_encap(skb, (struct bpf_fou_encap *)&encap);
+	ret = bpf_skb_get_fou_encap(skb, &encap);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
Signature · 1 line
2.52.0
#4 lore raw
In reply to Gregory Bell
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Fri, 17 Apr 2026 11:41:20 -0400 you wrote:

The xdp_flowtable and test_tunnel_kern selftests were previously rewritten to compile with CONFIG_NF_FLOW_TABLE=m and CONFIG_NET_FOU=m. While the compilation issues were resolved, the tests fail at runtime. In test_tunnel_kern.c, struct bpf_fou_encap___local is defined with the correct fields but the kfunc declarations still reference the forward-declared struct bpf_fou_encap. Similarly, xdp_flowtable.c uses a forward-declared struct flow_offload_tuple_rhash as the return type for bpf_xdp_flow_lookup(). Clang emits these forward declarations as BTF FWD types, which fail to resolve against the module-defined STRUCT types at run time:

Quoted 1 line

[...]

Here is the summary with links:
- [v2,1/2] selftests/bpf: Use local type for flow_offload_tuple_rhash in xdp_flowtable

    https://git.kernel.org/bpf/bpf-next/c/ac985e7bf840
  - [v2,2/2] selftests/bpf: Use local type for bpf_fou_encap in test_tunnel_kern
    https://git.kernel.org/bpf/bpf-next/c/afb0450be061

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html