bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values
@ 2021-09-26 12:56 Kumar Kartikeya Dwivedi
  2021-09-27 12:37 ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-09-26 12:56 UTC (permalink / raw)
  To: bpf

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

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")
--
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values
  2021-09-26 12:56 [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values Kumar Kartikeya Dwivedi
@ 2021-09-27 12:37 ` Toke Høiland-Jørgensen
  2021-09-27 13:46   ` Kumar Kartikeya Dwivedi
  0 siblings, 1 reply; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-09-27 12:37 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi, bpf

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values
  2021-09-27 12:37 ` Toke Høiland-Jørgensen
@ 2021-09-27 13:46   ` Kumar Kartikeya Dwivedi
  2021-09-27 16:01     ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2021-09-27 13:46 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen; +Cc: bpf

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values
  2021-09-27 13:46   ` Kumar Kartikeya Dwivedi
@ 2021-09-27 16:01     ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-09-27 16:01 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi; +Cc: bpf

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-27 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-26 12:56 [PATCH bpf-next] samples: bpf: avoid name collision with kernel enum values Kumar Kartikeya Dwivedi
2021-09-27 12:37 ` Toke Høiland-Jørgensen
2021-09-27 13:46   ` Kumar Kartikeya Dwivedi
2021-09-27 16:01     ` Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).