diff mbox series

[bpf-next] selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y

Message ID 20240718143122.2230780-1-asavkov@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: fix compilation failure when CONFIG_NET_FOU!=y | 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/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 14 maintainers not CCed: kpsingh@kernel.org shuah@kernel.org haoluo@google.com dxu@dxuuu.xyz john.fastabend@gmail.com jolsa@kernel.org antony.antony@secunet.com linux-kselftest@vger.kernel.org yonghong.song@linux.dev martin.lau@linux.dev mykolal@fb.com song@kernel.org eddyz87@gmail.com sdf@fomichev.me
netdev/build_clang success Errors and warnings before: 7 this patch: 7
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: 7 this patch: 7
netdev/checkpatch warning WARNING: please, no spaces at the start of a line
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-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-8 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-16 fail Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-17 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / test
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-20 fail Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-llvm-17 / test
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-24 fail Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-25 fail Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-llvm-18 / test
bpf/vmtest-bpf-next-VM_Test-10 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps 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-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
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

Commit Message

Artem Savkov July 18, 2024, 2:31 p.m. UTC
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.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 .../selftests/bpf/progs/test_tunnel_kern.c    | 24 +++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)

Comments

Daniel Borkmann July 19, 2024, 3:45 p.m. UTC | #1
Hi Artem,

On 7/18/24 4:31 PM, Artem Savkov 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.
> 
> Signed-off-by: Artem Savkov <asavkov@redhat.com>

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.
Alexei Starovoitov July 19, 2024, 5:09 p.m. UTC | #2
On Fri, Jul 19, 2024 at 8:45 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
>
> Hi Artem,
>
> On 7/18/24 4:31 PM, Artem Savkov 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.
> >
> > Signed-off-by: Artem Savkov <asavkov@redhat.com>
>
> 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;

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.
Andrii Nakryiko July 19, 2024, 6:44 p.m. UTC | #3
On Fri, Jul 19, 2024 at 10:09 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> On Fri, Jul 19, 2024 at 8:45 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> >
> > Hi Artem,
> >
> > On 7/18/24 4:31 PM, Artem Savkov 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.
> > >
> > > Signed-off-by: Artem Savkov <asavkov@redhat.com>
> >
> > 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;
>
> 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.
Artem Savkov July 22, 2024, 6:56 a.m. UTC | #4
On Fri, Jul 19, 2024 at 11:44:34AM -0700, Andrii Nakryiko wrote:
> On Fri, Jul 19, 2024 at 10:09 AM Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> >
> > On Fri, Jul 19, 2024 at 8:45 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> > >
> > > Hi Artem,
> > >
> > > On 7/18/24 4:31 PM, Artem Savkov 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.
> > > >
> > > > Signed-off-by: Artem Savkov <asavkov@redhat.com>
> > >
> > > 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;
> >
> > 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.

We do have other missing types and a lot of them (not all) are fixed
the same way with ___local versions by interested parties.
Artem Savkov July 22, 2024, 12:03 p.m. UTC | #5
On Fri, Jul 19, 2024 at 10:09:35AM -0700, Alexei Starovoitov wrote:
> On Fri, Jul 19, 2024 at 8:45 AM Daniel Borkmann <daniel@iogearbox.net> wrote:
> >
> > Hi Artem,
> >
> > On 7/18/24 4:31 PM, Artem Savkov 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.
> > >
> > > Signed-off-by: Artem Savkov <asavkov@redhat.com>
> >
> > 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;
> 
> 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/cover.1718207789.git.dxu@dxuuu.xyz/)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
index 3f5abcf3ff136..0913ec384b159 100644
--- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
@@ -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) {