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 |
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 >
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 > >
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 --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,
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(+)