* [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c
@ 2024-01-23 20:17 Jose E. Marchesi
2024-01-23 21:06 ` Yonghong Song
2024-01-24 0:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jose E. Marchesi @ 2024-01-23 20:17 UTC (permalink / raw)
To: bpf
Cc: Jose E . Marchesi, Yonghong Song, Eduard Zingerman, david.faust,
cupertino.miranda
VLAs are not supported by either the BPF port of clang nor GCC. The
selftest test_xdp_dynptr.c contains the following code:
const size_t tcphdr_sz = sizeof(struct tcphdr);
const size_t udphdr_sz = sizeof(struct udphdr);
const size_t ethhdr_sz = sizeof(struct ethhdr);
const size_t iphdr_sz = sizeof(struct iphdr);
const size_t ipv6hdr_sz = sizeof(struct ipv6hdr);
[...]
static __always_inline int handle_ipv4(struct xdp_md *xdp, struct bpf_dynptr *xdp_ptr)
{
__u8 eth_buffer[ethhdr_sz + iphdr_sz + ethhdr_sz];
__u8 iph_buffer_tcp[iphdr_sz + tcphdr_sz];
__u8 iph_buffer_udp[iphdr_sz + udphdr_sz];
[...]
}
The eth_buffer, iph_buffer_tcp and other automatics are fixed size
only if the compiler optimizes away the constant global variables.
clang does this, but GCC does not, turning these automatics into
variable length arrays.
This patch removes the global variables and turns these values into
preprocessor constants. This makes the selftest to build properly
with GCC.
Tested in bpf-next master.
No regressions.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Cc: Yonghong Song <yhs@meta.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: david.faust@oracle.com
Cc: cupertino.miranda@oracle.com
---
tools/testing/selftests/bpf/progs/test_xdp_dynptr.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/test_xdp_dynptr.c b/tools/testing/selftests/bpf/progs/test_xdp_dynptr.c
index 78c368e71797..67a77944ef29 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp_dynptr.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp_dynptr.c
@@ -18,11 +18,11 @@
#include "test_iptunnel_common.h"
#include "bpf_kfuncs.h"
-const size_t tcphdr_sz = sizeof(struct tcphdr);
-const size_t udphdr_sz = sizeof(struct udphdr);
-const size_t ethhdr_sz = sizeof(struct ethhdr);
-const size_t iphdr_sz = sizeof(struct iphdr);
-const size_t ipv6hdr_sz = sizeof(struct ipv6hdr);
+#define tcphdr_sz sizeof(struct tcphdr)
+#define udphdr_sz sizeof(struct udphdr)
+#define ethhdr_sz sizeof(struct ethhdr)
+#define iphdr_sz sizeof(struct iphdr)
+#define ipv6hdr_sz sizeof(struct ipv6hdr)
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c
2024-01-23 20:17 [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c Jose E. Marchesi
@ 2024-01-23 21:06 ` Yonghong Song
2024-01-24 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Yonghong Song @ 2024-01-23 21:06 UTC (permalink / raw)
To: Jose E. Marchesi, bpf
Cc: Yonghong Song, Eduard Zingerman, david.faust, cupertino.miranda
On 1/23/24 12:17 PM, Jose E. Marchesi wrote:
> VLAs are not supported by either the BPF port of clang nor GCC. The
> selftest test_xdp_dynptr.c contains the following code:
>
> const size_t tcphdr_sz = sizeof(struct tcphdr);
> const size_t udphdr_sz = sizeof(struct udphdr);
> const size_t ethhdr_sz = sizeof(struct ethhdr);
> const size_t iphdr_sz = sizeof(struct iphdr);
> const size_t ipv6hdr_sz = sizeof(struct ipv6hdr);
>
> [...]
>
> static __always_inline int handle_ipv4(struct xdp_md *xdp, struct bpf_dynptr *xdp_ptr)
> {
> __u8 eth_buffer[ethhdr_sz + iphdr_sz + ethhdr_sz];
> __u8 iph_buffer_tcp[iphdr_sz + tcphdr_sz];
> __u8 iph_buffer_udp[iphdr_sz + udphdr_sz];
> [...]
> }
>
> The eth_buffer, iph_buffer_tcp and other automatics are fixed size
> only if the compiler optimizes away the constant global variables.
> clang does this, but GCC does not, turning these automatics into
> variable length arrays.
>
> This patch removes the global variables and turns these values into
> preprocessor constants. This makes the selftest to build properly
> with GCC.
>
> Tested in bpf-next master.
> No regressions.
>
> Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
> Cc: Yonghong Song <yhs@meta.com>
> Cc: Eduard Zingerman <eddyz87@gmail.com>
> Cc: david.faust@oracle.com
> Cc: cupertino.miranda@oracle.com
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c
2024-01-23 20:17 [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c Jose E. Marchesi
2024-01-23 21:06 ` Yonghong Song
@ 2024-01-24 0:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-24 0:00 UTC (permalink / raw)
To: Jose E. Marchesi; +Cc: bpf, yhs, eddyz87, david.faust, cupertino.miranda
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Tue, 23 Jan 2024 21:17:29 +0100 you wrote:
> VLAs are not supported by either the BPF port of clang nor GCC. The
> selftest test_xdp_dynptr.c contains the following code:
>
> const size_t tcphdr_sz = sizeof(struct tcphdr);
> const size_t udphdr_sz = sizeof(struct udphdr);
> const size_t ethhdr_sz = sizeof(struct ethhdr);
> const size_t iphdr_sz = sizeof(struct iphdr);
> const size_t ipv6hdr_sz = sizeof(struct ipv6hdr);
>
> [...]
Here is the summary with links:
- bpf: avoid VLAs in progs/test_xdp_dynptr.c
https://git.kernel.org/bpf/bpf-next/c/edb799035dd7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-24 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-23 20:17 [PATCH] bpf: avoid VLAs in progs/test_xdp_dynptr.c Jose E. Marchesi
2024-01-23 21:06 ` Yonghong Song
2024-01-24 0:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox