Skip to content

selftests/bpf: Use local types for kfunc declarations

Gregory Bell bpf 2 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 0 repliesApplied 2/2
  2. v12 patches 0 repliesSuperseded

change log from the cover letter

[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

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2selftests/bpf: Use local type for flow_offload_tuple_rhash in xdp_flowtabletools/testing/selftests/bpf/progs/xdp_flowtable.c+5 -20 repliesApplied
2/2selftests/bpf: Use local type for bpf_fou_encap in test_tunnel_kerntools/testing/selftests/bpf/progs/test_tunnel_kern.c+6 -70 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] 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