Skip to contentSkip to conversation

selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

PATCH Superseded Artem Savkov 7 participants 14 messages Jul 18, 2024 – Jul 23, 2024

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

PATCH 1/1 selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +17 -7
index 3f5abcf3ff136..0913ec384b159 100644
@@ -26,10 +26,20 @@
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8
 
+struct bpf_fou_encap___local {
+       __be16 sport;
+       __be16 dport;
+};
+
+enum bpf_fou_encap_type___local {
+       FOU_BPF_ENCAP_FOU___local,
+       FOU_BPF_ENCAP_GUE___local,
+};
+
 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;
@@ -745,7 +755,7 @@ SEC("tc")
 int ipip_gue_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -769,7 +779,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, &encap, FOU_BPF_ENCAP_GUE);
+	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -782,7 +792,7 @@ SEC("tc")
 int ipip_fou_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -806,7 +816,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, &encap, FOU_BPF_ENCAP_FOU);
+	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -820,7 +830,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 {
 	int ret;
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 
 	ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
 	if (ret < 0) {
Signature · 1 line
2.45.2
maintainer
#1 lore raw

Hi Artem,

Quoted 5 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

This breaks BPF CI, ptal:

https://github.com/kernel-patches/bpf/actions/runs/9999691294/job/27641198557

[...]
CLNG-BPF [test_maps] btf__core_reloc_existence___wrong_field_defs.bpf.o
CLNG-BPF [test_maps] verifier_bswap.bpf.o
CLNG-BPF [test_maps] test_core_reloc_existence.bpf.o
CLNG-BPF [test_maps] test_global_func8.bpf.o
CLNG-BPF [test_maps] verifier_bitfield_write.bpf.o
CLNG-BPF [test_maps] local_storage_bench.bpf.o
CLNG-BPF [test_maps] verifier_runtime_jit.bpf.o
CLNG-BPF [test_maps] test_pkt_access.bpf.o
progs/test_tunnel_kern.c:39:5: error: conflicting types for 'bpf_skb_set_fou_encap'
39 | int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:12: note: previous declaration is here
107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
| ^
progs/test_tunnel_kern.c:41:5: error: conflicting types for 'bpf_skb_get_fou_encap'
41 | int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:12: note: previous declaration is here
107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
| ^
CLNG-BPF [test_maps] verifier_typedef.bpf.o
CLNG-BPF [test_maps] user_ringbuf_fail.bpf.o
CLNG-BPF [test_maps] verifier_map_in_map.bpf.o
progs/test_tunnel_kern.c:782:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]

    782 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
        |                                          ^~~~~~
  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
   107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
          |                                                                                   ^
  progs/test_tunnel_kern.c:819:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
    819 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU___local);
        |                                          ^~~~~~
  /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
   107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
          |                                                                                   ^
  progs/test_tunnel_kern.c:841:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
    841 |         ret = bpf_skb_get_fou_encap(skb, &encap);
        |                                          ^~~~~~

/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:83: note: passing argument to parameter 'encap' here
107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
| ^
5 errors generated.
CLNG-BPF [test_maps] verifier_bounds_deduction.bpf.o
CLNG-BPF [test_maps] test_netfilter_link_attach.bpf.o
CLNG-BPF [test_maps] verifier_jeq_infer_not_null.bpf.o
make: *** [Makefile:654: /tmp/work/bpf/bpf/tools/testing/selftests/bpf/test_tunnel_kern.bpf.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory '/tmp/work/bpf/bpf/tools/testing/selftests/bpf'
Error: Process completed with exit code 2.

#2 lore raw
Quoted 27 lines · Daniel Borkmann

Hi Artem,

Quoted 5 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

This breaks BPF CI, ptal:

https://github.com/kernel-patches/bpf/actions/runs/9999691294/job/27641198557

[...]
CLNG-BPF [test_maps] btf__core_reloc_existence___wrong_field_defs.bpf.o
CLNG-BPF [test_maps] verifier_bswap.bpf.o
CLNG-BPF [test_maps] test_core_reloc_existence.bpf.o
CLNG-BPF [test_maps] test_global_func8.bpf.o
CLNG-BPF [test_maps] verifier_bitfield_write.bpf.o
CLNG-BPF [test_maps] local_storage_bench.bpf.o
CLNG-BPF [test_maps] verifier_runtime_jit.bpf.o
CLNG-BPF [test_maps] test_pkt_access.bpf.o
progs/test_tunnel_kern.c:39:5: error: conflicting types for 'bpf_skb_set_fou_encap'
39 | int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:12: note: previous declaration is here

Quoted 16 lines
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
           |            ^
   progs/test_tunnel_kern.c:41:5: error: conflicting types for 'bpf_skb_get_fou_encap'
      41 | int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
         |     ^
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:12: note: previous declaration is here
    107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
           |            ^
     CLNG-BPF [test_maps] verifier_typedef.bpf.o
     CLNG-BPF [test_maps] user_ringbuf_fail.bpf.o
     CLNG-BPF [test_maps] verifier_map_in_map.bpf.o
   progs/test_tunnel_kern.c:782:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
     782 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
         |                                          ^~~~~~
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;

It's a good idea to introduce struct bpf_fou_encap___local for !FOU builds, but kfunc signature needs to stay and __local variable needs to be type casted to (struct bpf_fou_encap *) when calling kfunc.

#3 lore raw
Quoted 46 lines · Alexei Starovoitov
Quoted 27 lines · Daniel Borkmann

Hi Artem,

Quoted 5 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

This breaks BPF CI, ptal:

https://github.com/kernel-patches/bpf/actions/runs/9999691294/job/27641198557

[...]
CLNG-BPF [test_maps] btf__core_reloc_existence___wrong_field_defs.bpf.o
CLNG-BPF [test_maps] verifier_bswap.bpf.o
CLNG-BPF [test_maps] test_core_reloc_existence.bpf.o
CLNG-BPF [test_maps] test_global_func8.bpf.o
CLNG-BPF [test_maps] verifier_bitfield_write.bpf.o
CLNG-BPF [test_maps] local_storage_bench.bpf.o
CLNG-BPF [test_maps] verifier_runtime_jit.bpf.o
CLNG-BPF [test_maps] test_pkt_access.bpf.o
progs/test_tunnel_kern.c:39:5: error: conflicting types for 'bpf_skb_set_fou_encap'
39 | int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:12: note: previous declaration is here

Quoted 16 lines
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
           |            ^
   progs/test_tunnel_kern.c:41:5: error: conflicting types for 'bpf_skb_get_fou_encap'
      41 | int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
         |     ^
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:12: note: previous declaration is here
    107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
           |            ^
     CLNG-BPF [test_maps] verifier_typedef.bpf.o
     CLNG-BPF [test_maps] user_ringbuf_fail.bpf.o
     CLNG-BPF [test_maps] verifier_map_in_map.bpf.o
   progs/test_tunnel_kern.c:782:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
     782 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
         |                                          ^~~~~~
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
Quoted 4 lines

It's a good idea to introduce struct bpf_fou_encap___local for !FOU builds, but kfunc signature needs to stay and __local variable needs to be type casted to (struct bpf_fou_encap *) when calling kfunc.

Given we specify

CONFIG_NET_FOU=y (not =m)

in selftests/bpf/config, do we really need to work around this? I bet we have a bunch of other missing types if we don't set all the settings as required by selftests/bpf/config.

#4 lore raw
Quoted 53 lines · Andrii Nakryiko
Quoted 46 lines · Alexei Starovoitov
Quoted 27 lines · Daniel Borkmann

Hi Artem,

Quoted 5 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

This breaks BPF CI, ptal:

https://github.com/kernel-patches/bpf/actions/runs/9999691294/job/27641198557

[...]
CLNG-BPF [test_maps] btf__core_reloc_existence___wrong_field_defs.bpf.o
CLNG-BPF [test_maps] verifier_bswap.bpf.o
CLNG-BPF [test_maps] test_core_reloc_existence.bpf.o
CLNG-BPF [test_maps] test_global_func8.bpf.o
CLNG-BPF [test_maps] verifier_bitfield_write.bpf.o
CLNG-BPF [test_maps] local_storage_bench.bpf.o
CLNG-BPF [test_maps] verifier_runtime_jit.bpf.o
CLNG-BPF [test_maps] test_pkt_access.bpf.o
progs/test_tunnel_kern.c:39:5: error: conflicting types for 'bpf_skb_set_fou_encap'
39 | int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:12: note: previous declaration is here

Quoted 16 lines
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
           |            ^
   progs/test_tunnel_kern.c:41:5: error: conflicting types for 'bpf_skb_get_fou_encap'
      41 | int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
         |     ^
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:12: note: previous declaration is here
    107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
           |            ^
     CLNG-BPF [test_maps] verifier_typedef.bpf.o
     CLNG-BPF [test_maps] user_ringbuf_fail.bpf.o
     CLNG-BPF [test_maps] verifier_map_in_map.bpf.o
   progs/test_tunnel_kern.c:782:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
     782 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
         |                                          ^~~~~~
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
Quoted 4 lines

It's a good idea to introduce struct bpf_fou_encap___local for !FOU builds, but kfunc signature needs to stay and __local variable needs to be type casted to (struct bpf_fou_encap *) when calling kfunc.

Quoted 7 lines

Given we specify

CONFIG_NET_FOU=y (not =m)

in selftests/bpf/config, do we really need to work around this? I bet we have a bunch of other missing types if we don't set all the settings as required by selftests/bpf/config.

We do have other missing types and a lot of them (not all) are fixed the same way with ___local versions by interested parties.

Signature · 1 line
 Artem
#5 lore raw
In reply to Alexei Starovoitov
Quoted 45 lines · Alexei Starovoitov
Quoted 27 lines · Daniel Borkmann

Hi Artem,

Quoted 5 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

This breaks BPF CI, ptal:

https://github.com/kernel-patches/bpf/actions/runs/9999691294/job/27641198557

[...]
CLNG-BPF [test_maps] btf__core_reloc_existence___wrong_field_defs.bpf.o
CLNG-BPF [test_maps] verifier_bswap.bpf.o
CLNG-BPF [test_maps] test_core_reloc_existence.bpf.o
CLNG-BPF [test_maps] test_global_func8.bpf.o
CLNG-BPF [test_maps] verifier_bitfield_write.bpf.o
CLNG-BPF [test_maps] local_storage_bench.bpf.o
CLNG-BPF [test_maps] verifier_runtime_jit.bpf.o
CLNG-BPF [test_maps] test_pkt_access.bpf.o
progs/test_tunnel_kern.c:39:5: error: conflicting types for 'bpf_skb_set_fou_encap'
39 | int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:12: note: previous declaration is here

Quoted 16 lines
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
           |            ^
   progs/test_tunnel_kern.c:41:5: error: conflicting types for 'bpf_skb_get_fou_encap'
      41 | int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
         |     ^
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107715:12: note: previous declaration is here
    107715 | extern int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap) __weak __ksym;
           |            ^
     CLNG-BPF [test_maps] verifier_typedef.bpf.o
     CLNG-BPF [test_maps] user_ringbuf_fail.bpf.o
     CLNG-BPF [test_maps] verifier_map_in_map.bpf.o
   progs/test_tunnel_kern.c:782:35: error: incompatible pointer types passing 'struct bpf_fou_encap___local *' to parameter of type 'struct bpf_fou_encap *' [-Werror,-Wincompatible-pointer-types]
     782 |         ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
         |                                          ^~~~~~
   /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:107714:83: note: passing argument to parameter 'encap' here
    107714 | extern int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx, struct bpf_fou_encap *encap, int type) __weak __ksym;
Quoted 4 lines

It's a good idea to introduce struct bpf_fou_encap___local for !FOU builds, but kfunc signature needs to stay and __local variable needs to be type casted to (struct bpf_fou_encap *) when calling kfunc.

Casting won't work as the compiler still have no idea about struct bpf_fou_encap.

I think I'll need to fix this by adding '#define BPF_NO_KDUNC_PROTOTYPES' to the test. Daniel has done this for other cases like this in the series introducing bpftool kfunc prototype dumping (https://lore.kernel.org/all/[email protected]/)

Signature · 1 line
 Artem
#6 lore raw

PATCH v2 1/1 selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

In reply to Daniel Borkmann

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

---
v2: added BPF_NO_KFUNC_PROTOTYPES define to avoid issues when CONFIG_NET_FOU is set.

---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 25 +++++++++++++------
 1 file changed, 18 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +18 -7
index 3f5abcf3ff136..4d526fc73f2bb 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>
@@ -26,10 +27,20 @@
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8
 
+struct bpf_fou_encap___local {
+       __be16 sport;
+       __be16 dport;
+};
+
+enum bpf_fou_encap_type___local {
+       FOU_BPF_ENCAP_FOU___local,
+       FOU_BPF_ENCAP_GUE___local,
+};
+
 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;
@@ -745,7 +756,7 @@ SEC("tc")
 int ipip_gue_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -769,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, &encap, FOU_BPF_ENCAP_GUE);
+	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -782,7 +793,7 @@ SEC("tc")
 int ipip_fou_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -806,7 +817,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, &encap, FOU_BPF_ENCAP_FOU);
+	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -820,7 +831,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 {
 	int ret;
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 
 	ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
 	if (ret < 0) {
Signature · 1 line
2.45.2
#7 lore raw
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [bpf-next,v2] selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=872975&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10042325764

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

#8 lore raw
In reply to Artem Savkov
Quoted 19 lines · Artem Savkov

bpf_xdp_get_xfrm_state(struct xdp_md *ctx, struct bpf_xfrm_state_opts *opts,

                       u32 opts__sz) __ksym;
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +2 -2
@@ -745,7 +756,7 @@ SEC("tc")
 int ipip_gue_set_tunnel(struct __sk_buff *skb)
 {
        struct bpf_tunnel_key key = {};
-       struct bpf_fou_encap encap = {};
+       struct bpf_fou_encap___local encap = {};
        void *data = (void *)(long)skb->data;
        struct iphdr *iph = data;
        void *data_end = (void *)(long)skb->data_end;
@@ -769,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, &encap, FOU_BPF_ENCAP_GUE);
+       ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE___local);
 
Quoted 2 lines

Casting won't work as the compiler still have no idea about struct bpf_fou_encap.

struct bpf_fou_encap;

(struct bpf_fou_encap *)&encap

works just fine.

pw-bot: cr

#9 lore raw

PATCH v3 1/1 selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

---
v3: swith from using BPF_NO_KFUNC_PROTOTYPES to casting to keep kfunc prototype intact.

v2: added BPF_NO_KFUNC_PROTOTYPES define to avoid issues when CONFIG_NET_FOU is set.

---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +20 -6
index 3f5abcf3ff136..fcff3010d8a60 100644
@@ -26,6 +26,18 @@
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8
 
+struct bpf_fou_encap___local {
+       __be16 sport;
+       __be16 dport;
+};
+
+enum bpf_fou_encap_type___local {
+       FOU_BPF_ENCAP_FOU___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;
 int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
@@ -745,7 +757,7 @@ SEC("tc")
 int ipip_gue_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -769,7 +781,8 @@ int ipip_gue_set_tunnel(struct __sk_buff *skb)
 	encap.sport = 0;
 	encap.dport = bpf_htons(5555);
 
-	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE);
+	ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+				    FOU_BPF_ENCAP_GUE___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -782,7 +795,7 @@ SEC("tc")
 int ipip_fou_set_tunnel(struct __sk_buff *skb)
 {
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 	void *data = (void *)(long)skb->data;
 	struct iphdr *iph = data;
 	void *data_end = (void *)(long)skb->data_end;
@@ -806,7 +819,8 @@ int ipip_fou_set_tunnel(struct __sk_buff *skb)
 	encap.sport = 0;
 	encap.dport = bpf_htons(5555);
 
-	ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU);
+	ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+				    FOU_BPF_ENCAP_FOU___local);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
@@ -820,7 +834,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 {
 	int ret;
 	struct bpf_tunnel_key key = {};
-	struct bpf_fou_encap encap = {};
+	struct bpf_fou_encap___local encap = {};
 
 	ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
 	if (ret < 0) {
@@ -828,7 +842,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 		return TC_ACT_SHOT;
 	}
 
-	ret = bpf_skb_get_fou_encap(skb, &encap);
+	ret = bpf_skb_get_fou_encap(skb, (struct bpf_fou_encap *)&encap);
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;
Signature · 1 line
2.45.2
#10 lore raw
CI has tested the following submission:

Dear patch submitter,

CI has tested the following submission:

Status:     SUCCESS
Name:       [bpf-next,v3] selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y
Patchwork:  https://patchwork.kernel.org/project/netdevbpf/list/?series=873153&state=*
Matrix:     https://github.com/kernel-patches/bpf/actions/runs/10054486016

No further action is necessary on your part.

Please note: this email is coming from an unmonitored mailbox. If you have questions or feedback, please reach out to the Meta Kernel CI team at [email protected].

reviewer
#11 lore raw
In reply to Artem Savkov
Quoted 23 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

---
v3: swith from using BPF_NO_KFUNC_PROTOTYPES to casting to keep kfunc prototype intact.

v2: added BPF_NO_KFUNC_PROTOTYPES define to avoid issues when CONFIG_NET_FOU is set.

---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +0 -0
index 3f5abcf3ff136..fcff3010d8a60 100644
@@ -26,6 +26,18 @@
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8

tools/testing/selftests/bpf/progs/test_tunnel_kern.c line 37

Quoted 10 lines
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +9 -0
 
+struct bpf_fou_encap___local {
+       __be16 sport;
+       __be16 dport;
+};
+
+enum bpf_fou_encap_type___local {
+       FOU_BPF_ENCAP_FOU___local,
+       FOU_BPF_ENCAP_GUE___local,
+};

nit: The above use spaces rather than tabs for indentation.

#12 lore raw
In reply to Artem Savkov
Quoted 24 lines · Artem Savkov

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

---
v3: swith from using BPF_NO_KFUNC_PROTOTYPES to casting to keep kfunc prototype intact.

v2: added BPF_NO_KFUNC_PROTOTYPES define to avoid issues when CONFIG_NET_FOU is set.

---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 26 ++++++++++++++-----
 1 file changed, 20 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +0 -0
index 3f5abcf3ff136..fcff3010d8a60 100644
@@ -26,6 +26,18 @@
  */
 #define ASSIGNED_ADDR_VETH1 0xac1001c8

tools/testing/selftests/bpf/progs/test_tunnel_kern.c line 37

Quoted 10 lines
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +9 -0
 
+struct bpf_fou_encap___local {
+       __be16 sport;
+       __be16 dport;
+};
+
+enum bpf_fou_encap_type___local {
+       FOU_BPF_ENCAP_FOU___local,
+       FOU_BPF_ENCAP_GUE___local,
+};

both of the above are internal kernel types (not UAPI ones), so I added preserve_access_index to the struct and ...

Quoted 35 lines
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +7 -3
+
+struct bpf_fou_encap;
+
 int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
                          struct bpf_fou_encap *encap, int type) __ksym;
 int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
@@ -745,7 +757,7 @@ SEC("tc")
 int ipip_gue_set_tunnel(struct __sk_buff *skb)
 {
        struct bpf_tunnel_key key = {};
-       struct bpf_fou_encap encap = {};
+       struct bpf_fou_encap___local encap = {};
        void *data = (void *)(long)skb->data;
        struct iphdr *iph = data;
        void *data_end = (void *)(long)skb->data_end;
@@ -769,7 +781,8 @@ int ipip_gue_set_tunnel(struct __sk_buff *skb)
        encap.sport = 0;
        encap.dport = bpf_htons(5555);
 
-       ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_GUE);
+       ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+                                   FOU_BPF_ENCAP_GUE___local);
        if (ret < 0) {
                log_err(ret);
                return TC_ACT_SHOT;
@@ -782,7 +795,7 @@ SEC("tc")
 int ipip_fou_set_tunnel(struct __sk_buff *skb)
 {
        struct bpf_tunnel_key key = {};
-       struct bpf_fou_encap encap = {};
+       struct bpf_fou_encap___local encap = {};
        void *data = (void *)(long)skb->data;
        struct iphdr *iph = data;
        void *data_end = (void *)(long)skb->data_end;

tools/testing/selftests/bpf/progs/test_tunnel_kern.c int ipip_fou_set_tunnel(struct __sk_buff *skb) · line 823

Quoted 6 lines
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +2 -1
@@ -806,7 +819,8 @@ int ipip_fou_set_tunnel(struct __sk_buff *skb)
        encap.sport = 0;
        encap.dport = bpf_htons(5555);
 
-       ret = bpf_skb_set_fou_encap(skb, &encap, FOU_BPF_ENCAP_FOU);
+       ret = bpf_skb_set_fou_encap(skb, (struct bpf_fou_encap *)&encap,
+                                   FOU_BPF_ENCAP_FOU___local);

use bpf_core_enum_value() here for getting enum value in CO-RE-relocatable way

(also fixed spaces vs tabs issue that were pointed out)

pushed to bpf-next

Quoted 24 lines
tools/testing/selftests/bpf/progs/test_tunnel_kern.c +2 -3
        if (ret < 0) {
                log_err(ret);
                return TC_ACT_SHOT;
@@ -820,7 +834,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
 {
        int ret;
        struct bpf_tunnel_key key = {};
-       struct bpf_fou_encap encap = {};
+       struct bpf_fou_encap___local encap = {};
 
        ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
        if (ret < 0) {
@@ -828,7 +842,7 @@ int ipip_encap_get_tunnel(struct __sk_buff *skb)
                return TC_ACT_SHOT;
        }
 
-       ret = bpf_skb_get_fou_encap(skb, &encap);
+       ret = bpf_skb_get_fou_encap(skb, (struct bpf_fou_encap *)&encap);
        if (ret < 0) {
                log_err(ret);
                return TC_ACT_SHOT;
--

2.45.2

#13 lore raw
In reply to Artem Savkov
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 8 lines · On Tue, 23 Jul 2024 09:10:31 +0200 you wrote:

Without CONFIG_NET_FOU bpf selftests are unable to build because of missing definitions. Add ___local versions of struct bpf_fou_encap and enum bpf_fou_encap_type to fix the issue.

[...]

Here is the summary with links:
- [bpf-next,v3] selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

    https://git.kernel.org/bpf/bpf-next/c/c67b2a6f3b84

You are awesome, thank you!

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