From: Paul Chaignon <paul.chaignon@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Amery Hung <ameryhung@gmail.com>,
bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 5/5] selftests/bpf: Test direct packet access on non-linear skbs
Date: Thu, 9 Oct 2025 15:44:23 +0200 [thread overview]
Message-ID: <aOe8N8IQ_-0ILBVg@mail.gmail.com> (raw)
In-Reply-To: <62e288f3-9917-4218-84f7-01e2eb27130c@linux.dev>
On Tue, Oct 07, 2025 at 11:01:32AM -0700, Martin KaFai Lau wrote:
> On 10/7/25 6:38 AM, Paul Chaignon wrote:
> > +#define access_test_non_linear(name, type, desc, retval, linear_sz, off) \
> > + SEC(type) \
> > + __description("direct packet access: " #name " (non-linear, " type ", " desc ")") \
> > + __success __retval(retval) \
> > + __linear_size(linear_sz) \
> > + __naked void access_non_linear_##name(void) \
> > + { \
> > + asm volatile (" \
> > + r2 = *(u32*)(r1 + %[skb_data]); \
> > + r3 = *(u32*)(r1 + %[skb_data_end]); \
> > + r0 = r2; \
> > + r0 += %[offset]; \
> > + if r0 > r3 goto l0_%=; \
> > + r0 = *(u8*)(r0 - 1); \
> > + r0 = 0; \
> > + exit; \
> > + l0_%=: r0 = 1; \
> > + exit; \
> > + " : \
> > + : __imm_const(skb_data, offsetof(struct __sk_buff, data)), \
> > + __imm_const(skb_data_end, offsetof(struct __sk_buff, data_end)), \
> > + __imm_const(offset, off) \
> > + : __clobber_all); \
> > + }
> > +
> > +access_test_non_linear(test31, "tc", "too short eth", 1, ETH_HLEN, 22);
> > +access_test_non_linear(test32, "tc", "too short 1", 1, 1, 22);
> > +access_test_non_linear(test33, "tc", "long enough", 0, 22, 22);
> > +access_test_non_linear(test34, "cgroup_skb/ingress", "too short eth", 1, ETH_HLEN, 8);
> > +access_test_non_linear(test35, "cgroup_skb/ingress", "too short 1", 1, 1, 8);
> > +access_test_non_linear(test36, "cgroup_skb/ingress", "long enough", 0, 22, 8);
> > +
> > +SEC("tc")
> > +__description("direct packet access: test36 (non-linear, linearized)")
> > +__success __retval(0)
> > +__linear_size(ETH_HLEN)
> > +__naked void access_non_linear_linearized(void)
> > +{
> > + asm volatile (" \
> > + r6 = r1; \
> > + r2 = 22; \
> > + call %[bpf_skb_pull_data]; \
> > + r2 = *(u32*)(r6 + %[skb_data]); \
> > + r3 = *(u32*)(r6 + %[skb_data_end]); \
> > + r0 = r2; \
> > + r0 += 22; \
> > + if r0 > r3 goto l0_%=; \
> > + r0 = *(u8*)(r0 - 1); \
> > + exit; \
> > +l0_%=: r0 = 1; \
> > + exit; \
> > +" :
> > + : __imm(bpf_skb_pull_data),
> > + __imm_const(skb_data, offsetof(struct __sk_buff, data)),
> > + __imm_const(skb_data_end, offsetof(struct __sk_buff, data_end))
> > + : __clobber_all);
> > +}
>
> Does it have to be in asm?
Probably not, but it's easier to write that way. With the added
cgroup_skb test cases, the verifier checks that return codes are either
0 or 1. So we can't do 'return *(ptr - 1);' to force the compiler to
keep the memory access and we'd have to find some other trick.
It's also consistent with the rest of those ctx access tests. It allows
us to see exactly what is verified and the diff between the cases with
and without bpf_skb_pull_data().
prev parent reply other threads:[~2025-10-09 13:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-07 13:36 [PATCH bpf-next v6 0/5] Support non-linear skbs for BPF_PROG_TEST_RUN Paul Chaignon
2025-10-07 13:37 ` [PATCH bpf-next v6 1/5] bpf: Refactor cleanup of bpf_prog_test_run_skb Paul Chaignon
2025-10-07 13:37 ` [PATCH bpf-next v6 2/5] bpf: Reorder bpf_prog_test_run_skb initialization Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 3/5] bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN Paul Chaignon
2025-10-07 17:59 ` Martin KaFai Lau
2025-10-09 13:32 ` Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 4/5] selftests/bpf: Support non-linear flag in test loader Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 5/5] selftests/bpf: Test direct packet access on non-linear skbs Paul Chaignon
2025-10-07 18:01 ` Martin KaFai Lau
2025-10-09 13:44 ` Paul Chaignon [this message]
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=aOe8N8IQ_-0ILBVg@mail.gmail.com \
--to=paul.chaignon@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=martin.lau@linux.dev \
/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