From: Nimrod Oren <noren@nvidia.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Shuah Khan <shuah@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Mohsin Bashir <mohsin.bashr@gmail.com>
Cc: Dragos Tatulea <dtatulea@nvidia.com>,
Tariq Toukan <tariqt@nvidia.com>,
Carolina Jubran <cjubran@nvidia.com>, <netdev@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<bpf@vger.kernel.org>, Nimrod Oren <noren@nvidia.com>
Subject: [PATCH RFC net-next 4/5] selftests: drv-net: Adjust XDP header data with bpf_dynptr
Date: Tue, 9 Sep 2025 11:52:35 +0300 [thread overview]
Message-ID: <20250909085236.2234306-5-noren@nvidia.com> (raw)
In-Reply-To: <20250909085236.2234306-1-noren@nvidia.com>
Update update_pkt to use bpf_dynptr_slice_rdwr instead of accessing the
packet data directly.
This makes the test viable for drivers that do not store any
packet data in the linear part when in multi-buffer mode.
Signed-off-by: Nimrod Oren <noren@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
.../selftests/net/lib/xdp_native.bpf.c | 35 ++++++++++---------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/tools/testing/selftests/net/lib/xdp_native.bpf.c b/tools/testing/selftests/net/lib/xdp_native.bpf.c
index 71172d32c529..ff63f572552b 100644
--- a/tools/testing/selftests/net/lib/xdp_native.bpf.c
+++ b/tools/testing/selftests/net/lib/xdp_native.bpf.c
@@ -208,38 +208,41 @@ static int xdp_mode_tx_handler(struct xdp_md *ctx, __u16 port)
static void *update_pkt(struct xdp_md *ctx, __s16 offset, __u32 *udp_csum)
{
- void *data_end = (void *)(long)ctx->data_end;
- void *data = (void *)(long)ctx->data;
struct udphdr *udph = NULL;
- struct ethhdr *eth = data;
+ struct ethhdr *eth = NULL;
+ struct bpf_dynptr ptr;
__u32 len, len_new;
- if (data + sizeof(*eth) > data_end)
+ bpf_dynptr_from_xdp(ctx, 0, &ptr);
+ eth = bpf_dynptr_slice(&ptr, 0, NULL, sizeof(*eth));
+ if (!eth)
return NULL;
if (eth->h_proto == bpf_htons(ETH_P_IP)) {
- struct iphdr *iph = data + sizeof(*eth);
- __u16 total_len;
-
- if (iph + 1 > (struct iphdr *)data_end)
+ struct iphdr *iph = bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth),
+ NULL, sizeof(*iph));
+ if (!iph)
return NULL;
iph->tot_len = bpf_htons(bpf_ntohs(iph->tot_len) + offset);
- udph = (void *)eth + sizeof(*iph) + sizeof(*eth);
- if (!udph || udph + 1 > (struct udphdr *)data_end)
+ udph = bpf_dynptr_slice_rdwr(&ptr, sizeof(*iph) + sizeof(*eth),
+ NULL, sizeof(*udph));
+ if (!udph)
return NULL;
len_new = bpf_htons(bpf_ntohs(udph->len) + offset);
} else if (eth->h_proto == bpf_htons(ETH_P_IPV6)) {
- struct ipv6hdr *ipv6h = data + sizeof(*eth);
- __u16 payload_len;
-
- if (ipv6h + 1 > (struct ipv6hdr *)data_end)
+ struct ipv6hdr *ipv6h =
+ bpf_dynptr_slice_rdwr(&ptr, sizeof(*eth),
+ NULL, sizeof(*ipv6h));
+ if (!ipv6h)
return NULL;
- udph = (void *)eth + sizeof(*ipv6h) + sizeof(*eth);
- if (!udph || udph + 1 > (struct udphdr *)data_end)
+ udph = bpf_dynptr_slice_rdwr(&ptr,
+ sizeof(*ipv6h) + sizeof(*eth),
+ NULL, sizeof(*udph));
+ if (!udph)
return NULL;
*udp_csum = ~((__u32)udph->check);
--
2.45.0
next prev parent reply other threads:[~2025-09-09 8:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 8:52 [PATCH RFC net-next 0/5] selftests: drv-net: Convert XDP program to bpf_dynptr Nimrod Oren
2025-09-09 8:52 ` [PATCH RFC net-next 1/5] selftests: drv-net: Test XDP_TX with bpf_dynptr Nimrod Oren
2025-09-09 8:52 ` [PATCH RFC net-next 2/5] selftests: drv-net: Test XDP tail adjustment " Nimrod Oren
2025-09-09 8:52 ` [PATCH RFC net-next 3/5] selftests: drv-net: Test XDP head " Nimrod Oren
2025-09-09 17:26 ` Martin KaFai Lau
2025-09-09 8:52 ` Nimrod Oren [this message]
2025-09-09 8:52 ` [PATCH RFC net-next 5/5] selftests: drv-net: Check XDP header data " Nimrod Oren
2025-09-09 21:12 ` [PATCH RFC net-next 0/5] selftests: drv-net: Convert XDP program to bpf_dynptr Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250909085236.2234306-5-noren@nvidia.com \
--to=noren@nvidia.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cjubran@nvidia.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox