diff mbox series

[bpf,2/2] selftests/bpf: Add local definition of enum nf_nat_manip_type to bpf_nf test

Message ID 20221130144240.603803-2-toke@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf,1/2] bpf: Add dummy type reference to nf_conn___init to fix type deduplication | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain }}
bpf/vmtest-bpf-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-3 fail Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-4 fail Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-5 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-6 fail Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-7 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-8 success Logs for llvm-toolchain
bpf/vmtest-bpf-VM_Test-9 success Logs for set-matrix
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: dxu@dxuuu.xyz linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Toke Høiland-Jørgensen Nov. 30, 2022, 2:42 p.m. UTC
The bpf_nf selftest calls the bpf_ct_set_nat_info() kfunc, which takes a
parameter of type enum nf_nat_manip_type. However, if the nf_nat code is
compiled as a module, that enum is not defined in vmlinux BTF, and
compilation of the selftest fails.

A previous patch suggested just hard-coding the enum values:

https://lore.kernel.org/r/tencent_4C0B445E0305A18FACA04B4A959B57835107@qq.com

However, this doesn't work as the compiler then complains about an
incomplete type definition in the function prototype. Instead, just add a
local definition of the enum to the selftest code.

Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/progs/test_bpf_nf.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Andrii Nakryiko Dec. 1, 2022, 1:18 a.m. UTC | #1
On Wed, Nov 30, 2022 at 6:42 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> The bpf_nf selftest calls the bpf_ct_set_nat_info() kfunc, which takes a
> parameter of type enum nf_nat_manip_type. However, if the nf_nat code is
> compiled as a module, that enum is not defined in vmlinux BTF, and
> compilation of the selftest fails.
>
> A previous patch suggested just hard-coding the enum values:
>
> https://lore.kernel.org/r/tencent_4C0B445E0305A18FACA04B4A959B57835107@qq.com
>
> However, this doesn't work as the compiler then complains about an
> incomplete type definition in the function prototype. Instead, just add a
> local definition of the enum to the selftest code.
>
> Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc")
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
>  tools/testing/selftests/bpf/progs/test_bpf_nf.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> index 227e85e85dda..6350d11ec6f6 100644
> --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> @@ -43,6 +43,11 @@ struct bpf_ct_opts___local {
>         u8 reserved[3];
>  } __attribute__((preserve_access_index));
>
> +enum nf_nat_manip_type {
> +       NF_NAT_MANIP_SRC,
> +       NF_NAT_MANIP_DST
> +};
> +

and enum redefinition error if vmlinux.h already defines it?...

>  struct nf_conn *bpf_xdp_ct_alloc(struct xdp_md *, struct bpf_sock_tuple *, u32,
>                                  struct bpf_ct_opts___local *, u32) __ksym;
>  struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *, struct bpf_sock_tuple *, u32,
> --
> 2.38.1
>
Andrii Nakryiko Dec. 1, 2022, 1:19 a.m. UTC | #2
On Wed, Nov 30, 2022 at 5:18 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Nov 30, 2022 at 6:42 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
> >
> > The bpf_nf selftest calls the bpf_ct_set_nat_info() kfunc, which takes a
> > parameter of type enum nf_nat_manip_type. However, if the nf_nat code is
> > compiled as a module, that enum is not defined in vmlinux BTF, and
> > compilation of the selftest fails.
> >
> > A previous patch suggested just hard-coding the enum values:
> >
> > https://lore.kernel.org/r/tencent_4C0B445E0305A18FACA04B4A959B57835107@qq.com
> >
> > However, this doesn't work as the compiler then complains about an
> > incomplete type definition in the function prototype. Instead, just add a
> > local definition of the enum to the selftest code.
> >
> > Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc")
> > Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> > ---
> >  tools/testing/selftests/bpf/progs/test_bpf_nf.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> > index 227e85e85dda..6350d11ec6f6 100644
> > --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> > +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
> > @@ -43,6 +43,11 @@ struct bpf_ct_opts___local {
> >         u8 reserved[3];
> >  } __attribute__((preserve_access_index));
> >
> > +enum nf_nat_manip_type {
> > +       NF_NAT_MANIP_SRC,
> > +       NF_NAT_MANIP_DST
> > +};
> > +
>
> and enum redefinition error if vmlinux.h already defines it?...


... which is apparently proven by our CI already:

  [0] https://github.com/kernel-patches/bpf/actions/runs/3584446939/jobs/6031141757

>
> >  struct nf_conn *bpf_xdp_ct_alloc(struct xdp_md *, struct bpf_sock_tuple *, u32,
> >                                  struct bpf_ct_opts___local *, u32) __ksym;
> >  struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *, struct bpf_sock_tuple *, u32,
> > --
> > 2.38.1
> >
Toke Høiland-Jørgensen Dec. 1, 2022, 11:09 a.m. UTC | #3
Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:

> On Wed, Nov 30, 2022 at 5:18 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Wed, Nov 30, 2022 at 6:42 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>> >
>> > The bpf_nf selftest calls the bpf_ct_set_nat_info() kfunc, which takes a
>> > parameter of type enum nf_nat_manip_type. However, if the nf_nat code is
>> > compiled as a module, that enum is not defined in vmlinux BTF, and
>> > compilation of the selftest fails.
>> >
>> > A previous patch suggested just hard-coding the enum values:
>> >
>> > https://lore.kernel.org/r/tencent_4C0B445E0305A18FACA04B4A959B57835107@qq.com
>> >
>> > However, this doesn't work as the compiler then complains about an
>> > incomplete type definition in the function prototype. Instead, just add a
>> > local definition of the enum to the selftest code.
>> >
>> > Fixes: b06b45e82b59 ("selftests/bpf: add tests for bpf_ct_set_nat_info kfunc")
>> > Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> > ---
>> >  tools/testing/selftests/bpf/progs/test_bpf_nf.c | 5 +++++
>> >  1 file changed, 5 insertions(+)
>> >
>> > diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
>> > index 227e85e85dda..6350d11ec6f6 100644
>> > --- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
>> > +++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
>> > @@ -43,6 +43,11 @@ struct bpf_ct_opts___local {
>> >         u8 reserved[3];
>> >  } __attribute__((preserve_access_index));
>> >
>> > +enum nf_nat_manip_type {
>> > +       NF_NAT_MANIP_SRC,
>> > +       NF_NAT_MANIP_DST
>> > +};
>> > +
>>
>> and enum redefinition error if vmlinux.h already defines it?...
>
>
> ... which is apparently proven by our CI already:
>
>   [0] https://github.com/kernel-patches/bpf/actions/runs/3584446939/jobs/6031141757

Doh *facepalm*! Will fix...

-Toke
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/test_bpf_nf.c b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
index 227e85e85dda..6350d11ec6f6 100644
--- a/tools/testing/selftests/bpf/progs/test_bpf_nf.c
+++ b/tools/testing/selftests/bpf/progs/test_bpf_nf.c
@@ -43,6 +43,11 @@  struct bpf_ct_opts___local {
 	u8 reserved[3];
 } __attribute__((preserve_access_index));
 
+enum nf_nat_manip_type {
+	NF_NAT_MANIP_SRC,
+	NF_NAT_MANIP_DST
+};
+
 struct nf_conn *bpf_xdp_ct_alloc(struct xdp_md *, struct bpf_sock_tuple *, u32,
 				 struct bpf_ct_opts___local *, u32) __ksym;
 struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *, struct bpf_sock_tuple *, u32,