public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Chaignon <paul.chaignon@gmail.com>
To: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf@vger.kernel.org, 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>
Subject: Re: [PATCH bpf-next v6 3/5] bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN
Date: Thu, 9 Oct 2025 15:32:37 +0200	[thread overview]
Message-ID: <aOe5dZ4cYjz6B02o@mail.gmail.com> (raw)
In-Reply-To: <a7a12dcc-4fc4-4c1a-aceb-bb4ce2815a36@linux.dev>

On Tue, Oct 07, 2025 at 10:59:32AM -0700, Martin KaFai Lau wrote:
> On 10/7/25 6:38 AM, Paul Chaignon wrote:
> > This patch adds support for crafting non-linear skbs in BPF test runs
> > for tc programs. The size of the linear area is given by ctx->data_end,
> > with a minimum of ETH_HLEN always pulled in the linear area. If ctx or
> > ctx->data_end are null, a linear skb is used.
> > 
> > This is particularly useful to test support for non-linear skbs in large
> > codebases such as Cilium. We've had multiple bugs in the past few years
> > where we were missing calls to bpf_skb_pull_data(). This support in
> > BPF_PROG_TEST_RUN would allow us to automatically cover this case in our
> > BPF tests.
> > 
> > In addition to the selftests introduced later in the series, this patch
> > was tested by setting enabling non-linear skbs for all tc selftests
> > programs and checking test failures were expected.
> > 

[...]

> >   	skb->sk = sk;
> >   	data = NULL; /* data released via kfree_skb */
> >   	skb_reserve(skb, NET_SKB_PAD + NET_IP_ALIGN);
> > -	__skb_put(skb, size);
> > +	__skb_put(skb, linear_sz);
> > +
> > +	if (unlikely(kattr->test.data_size_in > linear_sz)) {
> > +		void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
> > +		struct skb_shared_info *sinfo = skb_shinfo(skb);
> > +
> > +		size = linear_sz;
> 
> nit. I find the "size" variable confusing to follow. The "size" is
> overloaded with different meanings in this function.
> 
> Define a "u32 copied = linear_sz;" for this purpose (number of bytes copied
> so far) here.

Thanks for the review! I implemented this and all above suggestions.

[...]

> > -	/* bpf program can never convert linear skb to non-linear */
> > -	if (WARN_ON_ONCE(skb_is_nonlinear(skb)))
> > +	if (skb_is_nonlinear(skb)) {
> > +		/* bpf program can never convert linear skb to non-linear */
> > +		WARN_ON_ONCE(linear_sz == size);
> I don't think I understand this WARN. Do you mean "WARN_ON_ONCE(linear_sz ==
> kattr->test.data_size_in)" instead?

Yes. At that point in the code, size should be equal to
kattr->test.data_size_in, but using kattr->test.data_size_in directly is
clearer.

[...]

> > +	}
> >   	ret = bpf_test_finish(kattr, uattr, skb->data, NULL, size, retval,
> 
> What does it take to have bpf_test_finish support the skb's shinfo instead
> of passing NULL?

Not much actually. I've implemented it in the next iteration.

[...]


  reply	other threads:[~2025-10-09 13:32 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 [this message]
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

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=aOe5dZ4cYjz6B02o@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