public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Larysa Zaremba <larysa.zaremba@intel.com>
To: Vladimir Oltean <vladimir.oltean@nxp.com>,
	Jakub Kicinski <kuba@kernel.org>
Cc: bpf@vger.kernel.org, "Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Wei Fang" <wei.fang@nxp.com>,
	"Clark Wang" <xiaoning.wang@nxp.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Tony Nguyen" <anthony.l.nguyen@intel.com>,
	"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
	"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>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"KP Singh" <kpsingh@kernel.org>, "Hao Luo" <haoluo@google.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Simon Horman" <horms@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"Alexander Lobakin" <aleksander.lobakin@intel.com>,
	"Maciej Fijalkowski" <maciej.fijalkowski@intel.com>,
	"Bastien Curutchet (eBPF Foundation)"
	<bastien.curutchet@bootlin.com>,
	"Tushar Vyavahare" <tushar.vyavahare@intel.com>,
	"Jason Xing" <kernelxing@tencent.com>,
	"Ricardo B. Marlière" <rbm@suse.com>,
	"Eelco Chaudron" <echaudro@redhat.com>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>,
	"Toke Hoiland-Jorgensen" <toke@redhat.com>,
	imx@lists.linux.dev, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
	linux-kselftest@vger.kernel.org,
	"Aleksandr Loktionov" <aleksandr.loktionov@intel.com>
Subject: Re: [PATCH bpf 6/6] net: enetc: use truesize as XDP RxQ info frag_size
Date: Thu, 5 Feb 2026 14:23:15 +0100	[thread overview]
Message-ID: <aYSZw4wbd-nvLTuD@soc-5CG4396X81.clients.intel.com> (raw)
In-Reply-To: <20260205124638.hxzvjiocephzlrk3@skbuf>

On Thu, Feb 05, 2026 at 02:46:38PM +0200, Vladimir Oltean wrote:
> On Thu, Feb 05, 2026 at 01:41:03PM +0100, Larysa Zaremba wrote:
> > On Thu, Feb 05, 2026 at 02:29:53PM +0200, Vladimir Oltean wrote:
> > > On Wed, Feb 04, 2026 at 05:34:01PM -0800, Jakub Kicinski wrote:
> > > > On Thu, 5 Feb 2026 02:59:01 +0200 Vladimir Oltean wrote:
> > > > > Thanks! This is an extremely subtle corner case. I appreciate the patch
> > > > > and explanation.
> > > > > 
> > > > > I did run tests on the blamed commit (which I still have), but to catch
> > > > > a real issue in a meaningful way it would have been required to have a
> > > > > program which calls bpf_xdp_adjust_tail() with a very large offset.
> > > > > I'm noting that I'm seeing the WARN_ON() much easier after your fix, but
> > > > > before, it was mostly inconsequential for practical cases.
> > > > > 
> > > > > Namely, the ENETC truesize is 2048, and XDP_PACKET_HEADROOM is 256.
> > > > > First buffers also contain the skb_shared_info (320 bytes), while
> > > > > subsequent buffers don't.
> > > > 
> > > > I can't wrap my head around this series, hope you can tell me where I'm
> > > > going wrong. AFAICT enetc splits the page into two halves for small MTU.
> > > > 
> > > > So we have 
> > > > 
> > > >  |                 2k          |             2k              |
> > > >   ----------------------------- ----------------------------- 
> > > >  | hroom | data | troom/shinfo | hroom | data | troom/shinfo |
> > > >   ----------------------------- ----------------------------- 
> > > > 
> > > > If we attach the second chunk as frag well have:
> > > >   offset = 2k + hroom
> > > >   size = data.len
> > > > But we use
> > > >   truesize / frag_size = 2k
> > > > so
> > > >   tailroom = rxq->frag_size - skb_frag_size(frag) - skb_frag_off(frag);
> > > >   tailroom = 2k - data.len - 2k
> > > >   tailroom = -data.len
> > > >   WARN(tailroom < 0) -> yes
> > > > 
> > > > The frag_size thing is unusable for any driver that doesn't hand out
> > > > full pages to frags?
> > > 
> > > This is an excellent question.
> > > 
> > > Yes, you're right, bpf_xdp_frags_increase_tail() only has a 50% chance
> > > of working - the paged data has to be in the first half of the page,
> > > otherwise the tailroom calculations are not correct due to rxq->frag_size,
> > > and the WARN_ON() will trigger.
> > > 
> > > The reason why I didn't notice this during my testing is stupid. I was
> > > attaching the BPF program to the interface and then detaching it after
> > > each test, and each test was sending less than the RX ring size (2048)
> > > worth of packets. So all multi-buffer frames were using buffers which
> > > were fresh out of enetc_setup_rxbdr() -> ... -> enetc_new_page() (first
> > > halves) and never out of flipped pages (enetc_bulk_flip_buff()).
> > > 
> > > This seems to be a good reason to convert this driver to use page pool,
> > > which I can look into. I'm not sure that there's anything that can be
> > > done to make the rxq->frag_size mechanism compatible with the current
> > > buffer allocation scheme.
> > 
> > I was just about to send an answer.
> > 
> > Seems like my mistake here. I actually think adjusting the tail should work, if 
> > we set rxq->frag_size to PAGE_SIZE in enetc and i40e_rx_pg_size() in i40e, and 
> > not to (PAGE_SIZE / 2), as I did at first, but in such case naming this 
> > frag_size is just utterly wrong. Glad Jakub has pointed this out.
> 
> I mean, it should "work" given the caveat that calling bpf_xdp_adjust_tail()
> on a first-half page buffer with a large offset risks leaking into the
> second half, which may also be in use, and this will go undetected, right?
> Although the practical chances of that happening are low, the requested
> offset needs to be in the order of hundreds still.

Oh, I did get carried away there...
Well, one thing is shared page memory model in enetc and i40e, another thing is
xsk_buff_pool, where chunk size can be between 2K and PAGE_SIZE. What about

tailroom = rxq->frag_size - skb_frag_size(frag) -
           (skb_frag_off(frag) % rxq->frag_size);

When frag_size is set to 2K, headroom is let's say 256, so aligned DMA write
size is 1420.
last frag at the start of the page: offset=256, size<=1420
    tailroom >= 2K - 1420 - 256 = 372
last frag in the middle of the page: offset=256+2K, size<=1420
    tailroom >= 2K - 1420 - ((256 + 2K) % 2K) = 372

And for drivers that do not fragment pages for multi-buffer packets, nothing
changes, since offset is always less than rxq->frag_size.

This brings us back to rxq->frag_size being half of a page for enetc and i40e,
and seems like in ZC mode it should be pool->chunk_size to work properly.

> 
> > ice and idpf are fine, since they use libeth for Rx buffers, so mbuf packets
> > always reside in 3K+ buffers. But for xsk_buff_pool seems like all drivers 
> > should have PAGE_SIZE as frag_size? I will let the discussion go on for at least
> > a day and then will send v2 with patches reordered and those sizes corrected, 
> > maybe add ZC fixes on top.

  reply	other threads:[~2026-02-05 13:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03 10:53 [PATCH bpf 0/6] Address XDP frags having negative tailroom Larysa Zaremba
2026-02-03 10:53 ` [PATCH bpf 1/6] xdp: produce a warning when calculated tailroom is negative Larysa Zaremba
2026-02-03 12:26   ` Toke Høiland-Jørgensen
2026-02-03 12:31     ` Larysa Zaremba
2026-02-03 12:38       ` Toke Høiland-Jørgensen
2026-02-03 12:54         ` Larysa Zaremba
2026-02-03 13:37           ` Toke Høiland-Jørgensen
2026-02-04 22:52   ` Martin KaFai Lau
2026-02-03 10:53 ` [PATCH bpf 2/6] ice: fix rxq info registering in mbuf packets Larysa Zaremba
2026-02-03 10:53 ` [PATCH bpf 3/6] ice: change XDP RxQ frag_size from DMA write length to truesize Larysa Zaremba
2026-02-03 10:53 ` [PATCH bpf 4/6] i40e: use truesize as XDP RxQ info frag_size Larysa Zaremba
2026-02-03 10:53 ` [PATCH bpf 5/6] idpf: " Larysa Zaremba
2026-02-03 10:53 ` [PATCH bpf 6/6] net: enetc: " Larysa Zaremba
2026-02-05  0:59   ` Vladimir Oltean
2026-02-05  1:34     ` Jakub Kicinski
2026-02-05 12:29       ` Vladimir Oltean
2026-02-05 12:41         ` Larysa Zaremba
2026-02-05 12:46           ` Vladimir Oltean
2026-02-05 13:23             ` Larysa Zaremba [this message]
2026-02-05 13:40               ` Vladimir Oltean
2026-02-06  1:54                 ` Jakub Kicinski
2026-02-06  8:36                   ` Larysa Zaremba
2026-02-07  2:57                     ` Jakub Kicinski
2026-02-09  9:46                       ` Larysa Zaremba
2026-02-08 12:59                   ` Vladimir Oltean
2026-02-10 17:27                     ` Dragos Tatulea
2026-02-04 22:57 ` [PATCH bpf 0/6] Address XDP frags having negative tailroom Martin KaFai Lau
2026-02-05  1:23   ` Jakub Kicinski
2026-02-05  1:26 ` 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=aYSZw4wbd-nvLTuD@soc-5CG4396X81.clients.intel.com \
    --to=larysa.zaremba@intel.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrii@kernel.org \
    --cc=anthony.l.nguyen@intel.com \
    --cc=ast@kernel.org \
    --cc=bastien.curutchet@bootlin.com \
    --cc=bpf@vger.kernel.org \
    --cc=claudiu.manoil@nxp.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=echaudro@redhat.com \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kernelxing@tencent.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=maciej.fijalkowski@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rbm@suse.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=toke@redhat.com \
    --cc=tushar.vyavahare@intel.com \
    --cc=vladimir.oltean@nxp.com \
    --cc=wei.fang@nxp.com \
    --cc=xiaoning.wang@nxp.com \
    --cc=yonghong.song@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