diff mbox series

[bpf-next] samples: bpf: avoid name collision with kernel enum values

Message ID 20210926125605.1101605-1-memxor@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] samples: bpf: avoid name collision with kernel enum values | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers fail 1 blamed authors not CCed: ast@kernel.org; 12 maintainers not CCed: andrii@kernel.org ast@kernel.org hawk@kernel.org kuba@kernel.org kpsingh@kernel.org kafai@fb.com netdev@vger.kernel.org john.fastabend@gmail.com davem@davemloft.net daniel@iogearbox.net yhs@fb.com songliubraving@fb.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
bpf/vmtest-bpf-next success VM_Test

Commit Message

Kumar Kartikeya Dwivedi Sept. 26, 2021, 12:56 p.m. UTC
In xdp_redirect_map_multi.bpf.c, on newer kernels samples compilation
fails when vmlinux.h is generated from a kernel supporting broadcast for
devmap. Hence, avoid naming collisions to prevent build failure.

Fixes: a29b3ca17ee6 (samples: bpf: Convert xdp_redirect_map_multi_kern.o to XDP samples helper)
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 samples/bpf/xdp_redirect_map_multi.bpf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--
2.33.0

Comments

Toke Høiland-Jørgensen Sept. 27, 2021, 12:37 p.m. UTC | #1
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:

> In xdp_redirect_map_multi.bpf.c, on newer kernels samples compilation
> fails when vmlinux.h is generated from a kernel supporting broadcast for
> devmap. Hence, avoid naming collisions to prevent build failure.

Hmm, shouldn't the sample just be getting the value from the kernel in
the first place instead of re-defining it?

-Toke
Kumar Kartikeya Dwivedi Sept. 27, 2021, 1:46 p.m. UTC | #2
On Mon, Sep 27, 2021 at 06:07:30PM IST, Toke Høiland-Jørgensen wrote:
> Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
>
> > In xdp_redirect_map_multi.bpf.c, on newer kernels samples compilation
> > fails when vmlinux.h is generated from a kernel supporting broadcast for
> > devmap. Hence, avoid naming collisions to prevent build failure.
>
> Hmm, shouldn't the sample just be getting the value from the kernel in
> the first place instead of re-defining it?
>

True, but in general my assumption was that it could be built with a older
kernel's vmlinux.h, but be ran on a newer one. If that's not strictly needed, I
can just drop it.

This can also be the case if you haven't built the kernel in the tree (just did
a make headers_install), it then falls back to generating the vmlinux.h from the
running kernel.

> -Toke
>

--
Kartikeya
Toke Høiland-Jørgensen Sept. 27, 2021, 4:01 p.m. UTC | #3
Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:

> On Mon, Sep 27, 2021 at 06:07:30PM IST, Toke Høiland-Jørgensen wrote:
>> Kumar Kartikeya Dwivedi <memxor@gmail.com> writes:
>>
>> > In xdp_redirect_map_multi.bpf.c, on newer kernels samples compilation
>> > fails when vmlinux.h is generated from a kernel supporting broadcast for
>> > devmap. Hence, avoid naming collisions to prevent build failure.
>>
>> Hmm, shouldn't the sample just be getting the value from the kernel in
>> the first place instead of re-defining it?
>>
>
> True, but in general my assumption was that it could be built with a older
> kernel's vmlinux.h, but be ran on a newer one. If that's not strictly needed, I
> can just drop it.

But the code is still making assumptions about the contents of
vmlinux.h, isn't it? Like the size (and existence) of struct
bpf_devmap_val.

> This can also be the case if you haven't built the kernel in the tree
> (just did a make headers_install), it then falls back to generating
> the vmlinux.h from the running kernel.

This seems a bit brittle. Given that the samples are distributed with
the kernel sources, I would expect them to always correspond to the
kernel version in the source tree they're in and not randomly break if
the running kernel is different...

-Toke
diff mbox series

Patch

diff --git a/samples/bpf/xdp_redirect_map_multi.bpf.c b/samples/bpf/xdp_redirect_map_multi.bpf.c
index 8f59d430cb64..c6361e70c829 100644
--- a/samples/bpf/xdp_redirect_map_multi.bpf.c
+++ b/samples/bpf/xdp_redirect_map_multi.bpf.c
@@ -6,8 +6,8 @@ 
 #include "xdp_sample_shared.h"

 enum {
-	BPF_F_BROADCAST		= (1ULL << 3),
-	BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
+	__BPF_F_BROADCAST	= (1ULL << 3),
+	__BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
 };

 struct {
@@ -43,7 +43,8 @@  static int xdp_redirect_map(struct xdp_md *ctx, void *forward_map)
 	NO_TEAR_INC(rec->processed);

 	return bpf_redirect_map(forward_map, 0,
-				BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS);
+				__BPF_F_BROADCAST |
+				__BPF_F_EXCLUDE_INGRESS);
 }

 SEC("xdp")