Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Tjerk Kusters via B4 Relay
Wed, 11 Nov 2026 06:51
[PATCH net v6 0/3] igb: only strip the Rx timestamp header from the first buffer of a frame
Author: Tjerk Kusters via B4 Relay
Date: Wed, 11 Nov 2026 06:51
Date: Wed, 11 Nov 2026 06:51
216 lines
22224 bytes
22224 bytes
With Rx hardware timestamping enabled (e.g. by ptp4l), igb strips the
16-byte inline timestamp header from every Rx buffer of a frame instead
of only from the first one. A continuation buffer that starts with 8
zero bytes loses 16 bytes, so jumbo frames with zero payload arrive
short and are dropped.
v3 used skb == NULL to find the first buffer of a frame. The Sashiko
AI review pointed out that this does not hold when an XDP program
consumes the first buffer of a frame that spans several buffers, so v3
was sent back for rework.
The same question came up for igc. There, Maciej suggested not to track
frame boundaries in the data path, but to make sure that frames never
span several buffers while XDP is attached [1]. Paul Moses' igc v3 does
that [2]. This version follows the same approach for igb:
1/3 limits the receive length (RLPML, or the PF pool's VMOLR with VFs)
to the configured frame size while XDP is attached, and leaves
room for the timestamp header in the XDP buffer size checks for
3 KiB, legacy-rx and PAGE_SIZE >= 8192 buffers. It also refuses
XDP with rx-all and legacy-rx changes while XDP is attached, as
both would break the limit. The limit is now set from
igb_configure() instead of igb_set_rx_mode(). With VFs, the PF
pool limit is also written on i354.
2/3 is v3, unchanged in code, with a note that it relies on 1/3.
The Reviewed-by and Tested-by tags of v3 are kept for that reason.
3/3 gives AF_XDP zero-copy rings a 2 KiB or 3 KiB hardware buffer
instead of rounding the XSK frame size down to 1 KiB. It refuses
XSK pools that cannot hold the current maximum frame plus the
timestamp header, and MTU changes that would no longer fit a bound
pool. Unlike the igc patch in [2], which checks against the
largest XDP MTU, this checks the current MTU, as igb allows XDP up
to MTU 3030 and a fixed check would rule out 2 KiB chunks.
Enabling VFs, which takes queues from the PF, is refused with
-EBUSY while an XSK pool is bound to a queue the PF would lose; the
core refuses ethtool -L in the same case. A pool on a queue hidden
in another way, for example after a fallback to MSI, is checked
again when its ring is set up.
As in igc, 1/3 moves the RLPML programming out of igb_set_rx_mode(),
which can run without RTNL, into igb_configure(), which runs when the
interface is (re)configured, before Rx is enabled. This includes the PF
pool limit in VMOLR, which igb_set_rx_mode() now leaves as it is.
Attaching or removing XDP on a running interface goes through
igb_close() and igb_open(), and an MTU change through igb_down() and
igb_up(), so the limit is updated before Rx is enabled again.
The Sashiko reviews of v4 and v5 also point out three older issues
that this series does not change:
- On 2 KiB build_skb rings, igb_skb_pad() leaves exactly
IGB_MAX_FRAME_BUILD_SKB bytes before skb_shared_info, with no room for
the 16-byte timestamp header. With Rx timestamping on, frame and
header can overlap skb_shared_info by up to 12 bytes, or 2 bytes at
the XDP limit at MTU 1500. This dates from 9cbc948b5a20 ("igb: add XDP
support"). I left it out of this series: it is a separate problem from
the one fixed here, and a fix changes the buffer layout and the XDP
headroom for all igb users, so it needs its own review and testing.
- igb_set_vf_rlpml() let a VF set other VMOLR bits of its own pool. That
is fixed separately: https://lore.kernel.org/all/20261104-igb-vf-rlpml-v1-1-729621b60eee@aweta.nl/
- igb_alloc_rx_buffers_zc() does not clear the length of the next
descriptor after a partial refill at the end of the ring, so
igb_clean_rx_irq_zc() can read a stale descriptor. igc clears it in
that case. This is a separate zero-copy problem as well.
How to reproduce
----------------
Receiver with igb (eth0), peer with MTU 8228. hwstamp_ctl turns on Rx
timestamping with filter ALL, no ptp4l needed; this ping method is
taken from Paul's igc report. One host with two ports also works if
the sending port is moved into its own network namespace.
1) Truncated jumbo frames (patch 2)
receiver: ip link set eth0 mtu 8228
hwstamp_ctl -i eth0 -r 1
peer: ping -c 5 -M do -s 8200 -p 00 <receiver>
Without the series there are no replies, and IpExtInTruncatedPkts
goes up by one per frame. With the series all requests are answered.
2) XDP consumes the first buffer (patch 1)
receiver: ip link set eth0 mtu 3000
hwstamp_ctl -i eth0 -r 1
xdp-filter load -m native eth0
xdp-filter ip <peer> -m src
tcpdump -nn -e -i eth0 'ether src 00:00:00:00:00:00'
peer: ping -c 3 -M do -s 8200 -p 00 <receiver>
At MTU 3000 XDP can attach, but without patch 1 the MAC still accepts
the 8242-byte frames, which then span three Rx buffers. xdp-filter
drops the first one, and the rest reaches the stack as a separate
frame with all-zero MAC addresses:
without the series 5154 bytes (header stripped twice)
v3 alone 5170 bytes (stripped once)
this series no frame; rx_long_length_errors +1 per frame
3) AF_XDP zero-copy with 2 KiB chunks (patch 3)
receiver: ip link set eth0 mtu 1500
ethtool -L eth0 combined 1
hwstamp_ctl -i eth0 -r 1
xdpsock -i eth0 -q 0 -r -z -N -f 2048
peer: ping -c 50 -i 0.02 -s 1472 <receiver>
xdpsock is from xdp-project/bpf-examples (AF_XDP-example). It also
takes ARP, so the peer needs a fresh ARP entry before it starts.
Compare rx_packets (MAC) with rx_queue_0_packets in ethtool -S:
without the series 68 frames, 118 descriptors
this series 64 frames, 64 descriptors
At MTU 3000, -f 4096 receives 3014-byte frames in one buffer. Binding
with -f 2048 at MTU 3000 was refused with EOPNOTSUPP by the new check
on the 6.14.9 test kernel; current kernels refuse it earlier, in
xp_assign_dev(), with EINVAL.
Tested on an I350 with these patches applied to the igb driver of
kernel 6.14.9 (the series itself is against v7.1-rc7), with the steps
above: results as listed. The v3 line is from an earlier run with an
XDP program dropping ICMP. Also checked: XDP attach at MTU 1500 and
3030 works, at MTU 3046 it is refused, as is an MTU change to 3046
with XDP attached. With two VFs allocated (booted with pci=realloc),
step 2 gives the same picture: three leftover frames without the
series, none with it, as the PF pool limit in VMOLR drops the frames.
In step 3, 98-byte frames and 4 KiB chunks take one descriptor per
frame with and without the series. With XDP attached, rx-all stays off
and legacy-rx cannot be changed, and XDP attach is refused with rx-all
on, or with legacy-rx on at MTU 3000, also when it was set while the
interface was down. RLPML and the PF pool's VMOLR limit read back as
expected with and without XDP and VFs. In repeated runs of about 200 MTU
changes each with XDP and two VFs, the limit was right after every
change, except for one read in one run, where the value was not logged;
eight reruns showed no mismatch.
The steps above were repeated on kernel 7.3.1 with the series applied
to the v7.3 igb driver, with the same results, including step 2 with
VFs. There, enabling two VFs while xdpsock was bound to queue 1 was
refused with EBUSY; with the socket on queue 0 it worked. With the
driver built so that the I350 keeps two Rx queues with VFs, as an 82576
does, the VF enable with the socket on queue 1 was refused as well. The
i354 path was checked with the driver built so that the I350 takes the
i354 branches for VMOLR: with two VFs and XDP attached, the PF pool
limit kept its old value of 9728 with v5, which skipped i354, and read
back as 3026 at MTU 3000 and 1526 at MTU 1500 with v6. Only the
registers were checked; I have no i354 to test on.
Not tested: PAGE_SIZE >= 8192.
The patches, their descriptions and this cover letter were prepared
with the help of an AI coding assistant (Claude). I reviewed them and
ran the tests above on my test bench.
[1] https://lore.kernel.org/all/20261025065154.2037149-1-p@1g4.org/
[2] https://lore.kernel.org/all/20261028083344.3047350-1-p@1g4.org/
Changes in v6:
- Patch 1: with VFs, also write the PF pool limit on i354 (Sashiko).
- Patch 3: refuse to enable VFs with -EBUSY while an XSK pool is bound
to a queue the PF would lose (Maciej). Restore the DMA coalescing flag
on that error. Keep the frame size check in igb_xsk_pool() only for
queues hidden in another way, such as a fallback to MSI.
- Patch 4 dropped: with patch 3 the hardware does not split frames in
zero-copy mode, so it only added dead code to the hot path (Maciej).
- Link to v5: https://patch.msgid.link/20261104-igb-rx-ts-fix-v5-0-bf4b4367129a@aweta.nl
Changes in v5:
- Patch 1: v4 also subtracted the timestamp header from the build_skb
frame limit, so XDP no longer attached at MTU 1495-1510 on x86
(1493-1508 where NET_IP_ALIGN is 2), including the default MTU 1500.
Only subtract the header where the limit is the hardware buffer size,
and compute it from the adapter state instead of the ring flags. Skip
the check when XDP is removed, so a program can always be detached.
- Patch 1: refuse XDP with rx-all and legacy-rx changes with XDP
attached, and turn rx-all back on after XDP removal if it was
requested meanwhile. Program RLPML and the PF pool limit from
igb_configure() instead of igb_set_rx_mode(). With XDP attached, an
MTU change can now move from 2 KiB to 3 KiB buffers. Added
Suggested-by: Maciej.
- Patch 1: the issues above were also reported by the Sashiko review
of v4.
- Patch 2: no code change. Commit message: igc is fixed by Paul's
series, not by this patch; the loss is per continuation buffer, not
only at the tail; the possible size wrap is described (Sashiko).
- New patch 3: AF_XDP zero-copy Rx buffer size, as asked by Maciej.
- New patch 4: drop zero-copy frames that span several descriptors;
depends on patch 3.
- Link to v4: https://patch.msgid.link/20261102-igb-rx-ts-fix-v4-0-8785124c5d23@aweta.nl
Changes in v4:
- New patch 1: limit the receive length while XDP is attached, so that
skb == NULL reliably marks the first buffer (Sashiko review), as
done for igc.
- Patch 2: no code change; added a note that it relies on patch 1.
- Link to v3: https://patch.msgid.link/20260625-igb-rx-ts-fix-v3-1-99b3efa08dca@aweta.nl
---
Tjerk Kusters (3):
igb: do not let XDP frames span more than one Rx buffer
igb: only strip Rx timestamp header on the first buffer of a frame
igb: do not split AF_XDP zero-copy frames over several Rx buffers
drivers/net/ethernet/intel/igb/igb.h | 9 ++
drivers/net/ethernet/intel/igb/igb_ethtool.c | 9 ++
drivers/net/ethernet/intel/igb/igb_main.c | 207 +++++++++++++++++++++------
drivers/net/ethernet/intel/igb/igb_xsk.c | 20 ++-
4 files changed, 197 insertions(+), 48 deletions(-)
---
base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
change-id: 20260619-igb-rx-ts-fix-cd70585ee316
Best regards,
--
Tjerk Kusters <tkusters@aweta.nl>
[PATCH net v6 3/3] igb: do not split AF_XDP zero-copy frames over several Rx buffers
Author: Tjerk Kusters via B4 Relay
Date: Wed, 11 Nov 2026 06:51
Date: Wed, 11 Nov 2026 06:51
234 lines
20520 bytes
20520 bytes
From: Tjerk Kusters <tkusters@aweta.nl>
SRRCTL.BSIZEPKT has a granularity of 1 KiB. For AF_XDP zero-copy rings,
igb_setup_srrctl() programs xsk_pool_get_rx_frame_size(), which is
rounded down. With 2 KiB UMEM chunks and the default headroom this is
1792 bytes, so the hardware buffer becomes 1 KiB and a full-size frame
spans two Rx buffers. igb_clean_rx_irq_zc() handles every descriptor as
a complete frame, so the AF_XDP socket gets such a frame as two
packets, the second one without headers. With Rx timestamping enabled,
the timestamp header is also stripped from the second buffer, and a
short final buffer makes the size wrap.
Program the same buffer size as for the other rings, 2 KiB or 3 KiB.
This depends on "igb: do not let XDP frames span more than one Rx
buffer": the receive length limit set there while XDP is attached keeps
the hardware from writing more than the frame plus the timestamp header
into the larger buffer. Without it, the hardware can write past the XSK
frame.
Refuse an XSK pool whose frame size cannot hold that, and an MTU change
that would no longer fit a bound pool, also while no XDP program is
attached. The current MTU is checked rather than the largest XDP MTU,
as igb allows XDP up to MTU 3030 and that would rule out 2 KiB chunks.
With VFs, the PF keeps a single Tx queue, and one Rx queue on i350 or
two on 82576. A pool bound to a queue above that would lose its Rx
queue, which the MTU check then no longer sees, or its Tx queue, which
breaks the socket. The core refuses ethtool -L in that case (with
-EINVAL). Likewise, refuse to enable VFs with -EBUSY while an XSK pool
is bound to a queue the PF would lose. On that error, igb_enable_sriov()
also restores the DMA coalescing flag it cleared. The MAC filter
entries it reserved for the VFs before the check stay reserved until
the next reset.
A queue can also be hidden without such a request, for example when the
driver falls back from MSI-X to MSI and keeps one queue. The MTU check
does not see a pool on that queue, so igb_xsk_pool() checks the frame
size again when the ring is set up, and does not use zero-copy if the
frame does not fit. The socket then receives through the copy path,
and its Tx wakeup fails with EINVAL, until the ring is set up again
with an MTU that fits. This path was not tested.
This is the igb counterpart of the igc XSK buffer change.
Tested on an I350 with xdpsock from bpf-examples in rxdrop zero-copy
mode on one queue, Rx timestamping on and 1514-byte frames from the
peer. With 2 KiB chunks, the receive descriptors went from about two
per frame to one per frame; 98-byte frames and 4 KiB chunks were one
per frame with and without this patch. At MTU 3000, 4 KiB chunks
receive 3014-byte frames in one buffer. A 2 KiB chunk pool at MTU 3000
was refused by the new check on the 6.14.9 test kernel; current kernels
already refuse it in xp_assign_dev(). There, with 2 KiB chunks and the
default headroom, the new check refuses MTU 1751 to 1766, which the core
accepts.
On 7.3.1, with xdpsock bound to queue 1 of an I350, enabling two VFs is
now refused with EBUSY and the socket keeps its queue; with the socket on
queue 0, which the PF keeps, the VFs are enabled. The 82576 case, with
two Rx queues and one Tx queue for the PF, was checked with the driver
built so that the I350 keeps two Rx queues with VFs: with the socket on
queue 1, the VF enable is refused as well. Only the refusal was checked.
Link: https://lore.kernel.org/all/20261028083344.3047350-3-p@1g4.org/
Fixes: 2c6196013f84 ("igb: Add AF_XDP zero-copy Rx support")
Cc: stable@vger.kernel.org
Suggested-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Tjerk Kusters <tkusters@aweta.nl>
---
drivers/net/ethernet/intel/igb/igb.h | 9 ++++++
drivers/net/ethernet/intel/igb/igb_main.c | 51 +++++++++++++++++++++++++++++--
drivers/net/ethernet/intel/igb/igb_xsk.c | 20 +++++++++++-
3 files changed, 76 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 0fff1df81b7b..0495c02544d6 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -856,6 +856,15 @@ int igb_add_mac_steering_filter(struct igb_adapter *adapter,
int igb_del_mac_steering_filter(struct igb_adapter *adapter,
const u8 *addr, u8 queue, u8 flags);
+/* XDP does not support frames that span more than one Rx buffer, so a
+ * frame plus the inline Rx timestamp header must fit in one XSK buffer.
+ */
+static inline bool igb_xsk_frame_fits(struct xsk_buff_pool *pool,
+ int max_frame)
+{
+ return max_frame + IGB_TS_HDR_LEN <= xsk_pool_get_rx_frame_size(pool);
+}
+
struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,
struct igb_ring *ring);
int igb_xsk_pool_setup(struct igb_adapter *adapter,
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index e787095d3cdb..c9351a8c4f5e 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -3777,9 +3777,29 @@ static int igb_sriov_reinit(struct pci_dev *dev)
struct net_device *netdev = pci_get_drvdata(dev);
struct igb_adapter *adapter = netdev_priv(netdev);
struct pci_dev *pdev = adapter->pdev;
+ unsigned int i, rxq, txq, end;
rtnl_lock();
+ /* With VFs the PF gets fewer Rx queues and a single Tx queue, see
+ * igb_set_interrupt_capability(). Refuse that while an XSK pool is
+ * bound to a queue the PF would lose; the core refuses ethtool -L in
+ * the same case.
+ */
+ rxq = min_t(unsigned int, igb_get_max_rss_queues(adapter),
+ num_online_cpus());
+ txq = adapter->vfs_allocated_count ? 1 : rxq;
+ end = max(netdev->real_num_rx_queues, netdev->real_num_tx_queues);
+ for (i = min(rxq, txq); i < end; i++) {
+ if (xsk_get_pool_from_qid(netdev, i)) {
+ rtnl_unlock();
+ dev_err(&pdev->dev,
+ "Cannot change the number of queues, an AF_XDP socket is bound to queue %u\n",
+ i);
+ return -EBUSY;
+ }
+ }
+
if (netif_running(netdev))
igb_close(netdev);
else
@@ -3844,6 +3864,7 @@ static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs, bool reinit)
{
struct net_device *netdev = pci_get_drvdata(pdev);
struct igb_adapter *adapter = netdev_priv(netdev);
+ bool dmac = adapter->flags & IGB_FLAG_DMAC;
int old_vfs = pci_num_vf(pdev);
struct vf_mac_filter *mac_list;
int err = 0;
@@ -3933,6 +3954,8 @@ static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs, bool reinit)
kfree(adapter->vf_data);
adapter->vf_data = NULL;
adapter->vfs_allocated_count = 0;
+ if (dmac)
+ adapter->flags |= IGB_FLAG_DMAC;
out:
return err;
}
@@ -4836,9 +4859,13 @@ void igb_setup_srrctl(struct igb_adapter *adapter, struct igb_ring *ring)
u32 srrctl = 0;
u32 buf_size;
- if (ring->xsk_pool)
- buf_size = xsk_pool_get_rx_frame_size(ring->xsk_pool);
- else if (ring_uses_large_buffer(ring))
+ /* SRRCTL.BSIZEPKT has a 1 KiB granularity, so programming the XSK
+ * frame size would round it down and split frames over several
+ * buffers. XSK rings use the same buffer size as the other rings.
+ * While XDP is attached, the receive length limit keeps frames
+ * within the XSK frame, see igb_xsk_frame_fits().
+ */
+ if (ring_uses_large_buffer(ring))
buf_size = IGB_RXBUFFER_3072;
else
buf_size = IGB_RXBUFFER_2048;
@@ -6778,6 +6805,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)
{
struct igb_adapter *adapter = netdev_priv(netdev);
int max_frame = new_mtu + IGB_ETH_PKT_HDR_PAD;
+ int i;
if (igb_xdp_is_enabled(adapter) &&
!igb_xdp_frame_fits(adapter, max_frame)) {
@@ -6791,6 +6819,23 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)
if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
max_frame = ETH_FRAME_LEN + ETH_FCS_LEN;
+ /* the frame must fit the buffers of a bound XSK pool, also while no
+ * XDP program is attached, as attaching one does not check it again
+ */
+ for (i = 0; i < adapter->num_rx_queues; i++) {
+ struct xsk_buff_pool *pool = xsk_get_pool_from_qid(netdev, i);
+
+ if (!pool || !pool->dev)
+ continue;
+
+ if (!igb_xsk_frame_fits(pool, max_frame)) {
+ netdev_warn(adapter->netdev,
+ "Requested MTU size is not supported with AF_XDP. Frame size is %d\n",
+ max_frame);
+ return -EINVAL;
+ }
+ }
+
while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
usleep_range(1000, 2000);
diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
index ce4a7b58cad2..7f99e834c1ed 100644
--- a/drivers/net/ethernet/intel/igb/igb_xsk.c
+++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
@@ -91,7 +91,21 @@ struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,
if (!igb_xdp_is_enabled(adapter))
return NULL;
- return (pool && pool->dev) ? pool : NULL;
+ if (!pool || !pool->dev)
+ return NULL;
+
+ /* igb_change_mtu() does not see a pool on a queue that is hidden, for
+ * example after a fallback from MSI-X to MSI. The hardware buffer can
+ * be larger than the XSK frame, so check again when the ring is set up.
+ */
+ if (!igb_xsk_frame_fits(pool, adapter->max_frame_size)) {
+ netdev_warn_once(adapter->netdev,
+ "XSK frame size is too small for the MTU, queue %d is not used in zero-copy mode\n",
+ qid);
+ return NULL;
+ }
+
+ return pool;
}
static int igb_xsk_pool_enable(struct igb_adapter *adapter,
@@ -110,6 +124,10 @@ static int igb_xsk_pool_enable(struct igb_adapter *adapter,
qid >= netdev->real_num_tx_queues)
return -EINVAL;
+ /* checked again on MTU changes and when the ring is set up */
+ if (!igb_xsk_frame_fits(pool, adapter->max_frame_size))
+ return -EOPNOTSUPP;
+
err = xsk_pool_dma_map(pool, &adapter->pdev->dev, IGB_RX_DMA_ATTR);
if (err)
return err;
--
2.27.0
Re: [PATCH net v6 3/3] igb: do not split AF_XDP zero-copy frames over several Rx buffers
Author: netdev-bot+sashiko
Date: Sun, 15 Nov 2026 09:39
Date: Sun, 15 Nov 2026 09:39
302 lines
19960 bytes
19960 bytes
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 (1) · Low: 3
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new XSK queue check sits in igb_sriov_reinit(), and that
function is shared by the SR-IOV enable and disable paths.
- [Medium] The new -EBUSY return from igb_sriov_reinit() gives userspace
a deterministic way into igb_enable_sriov()'s err_out path while the…
- [Low] This patch raises the XSK ring hardware buffer in
igb_setup_srrctl() to 2 KiB or 3 KiB, while the XSK frame can be as…
- [Low] The new -EBUSY refusal in igb_sriov_reinit() runs after
igb_enable_sriov() has already called igb_vf_configure() for each VF.
- [Low] The new restore `if (dmac) adapter->flags |= IGB_FLAG_DMAC;` in
igb_enable_sriov() err_out is a non-atomic read-modify-write of…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it sits in
igb_xsk_pool(), which the patch edits.
- [Medium] This problem wasn't introduced by this patch.
--
igb: do not split AF_XDP zero-copy frames over several Rx buffers
AF_XDP zero-copy Rx rings now get the same 2 KiB or 3 KiB SRRCTL buffer
size as the other rings, so frames are no longer split over two
buffers. The patch adds checks that refuse an XSK pool, an MTU change,
or VF enablement when a bound pool's frame size or queue would no
longer fit. When the frame does not fit at ring setup, igb_xsk_pool()
falls back to copy mode.
Link: https://lore.kernel.org/all/20261028083344.3047350-3-p@1g4.org/
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index e787095d3cdbe..c9351a8c4f5e5 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -3777,9 +3777,29 @@ static int igb_sriov_reinit(struct pci_dev *dev)
> struct net_device *netdev = pci_get_drvdata(dev);
> struct igb_adapter *adapter = netdev_priv(netdev);
> struct pci_dev *pdev = adapter->pdev;
> + unsigned int i, rxq, txq, end;
>
> rtnl_lock();
>
> + /* With VFs the PF gets fewer Rx queues and a single Tx queue, see
> + * igb_set_interrupt_capability(). Refuse that while an XSK pool is
> + * bound to a queue the PF would lose; the core refuses ethtool -L in
> + * the same case.
> + */
> + rxq = min_t(unsigned int, igb_get_max_rss_queues(adapter),
> + num_online_cpus());
> + txq = adapter->vfs_allocated_count ? 1 : rxq;
> + end = max(netdev->real_num_rx_queues, netdev->real_num_tx_queues);
> + for (i = min(rxq, txq); i < end; i++) {
> + if (xsk_get_pool_from_qid(netdev, i)) {
> + rtnl_unlock();
> + dev_err(&pdev->dev,
> + "Cannot change the number of queues, an AF_XDP socket is bound to queue %u\n",
> + i);
> + return -EBUSY;
> + }
> + }
[Severity: High]
igb_sriov_reinit() is shared by igb_enable_sriov() and
igb_disable_sriov(). Can this check also fire on the disable path? The
commit message only describes refusing the enable case.
igb_disable_sriov() calls igb_sriov_reinit() only after the VFs have
already been torn down:
igb_disable_sriov() {
...
pci_disable_sriov(pdev);
...
kfree(adapter->vf_data);
adapter->vf_data = NULL;
adapter->vfs_allocated_count = 0;
...
wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
...
return reinit ? igb_sriov_reinit(pdev) : 0;
}
One possible path is an i350 with the interface down.
real_num_rx_queues and real_num_tx_queues stay at 8 from
alloc_etherdev_mq(). Enable VFs, then bind a copy-mode XSK to queue 5.
The loop doesn't check pool->dev, so copy-mode pools count too. On a
host with fewer than 8 CPUs, writing 0 to sriov_numvfs then lands queue
5 inside [min(rxq, txq), end) and returns -EBUSY, even though the VFs
are already gone. On 82576, ethtool -L combined 2 on a 1-CPU host, or
offlining a CPU, gives a similar range.
The -EBUSY return skips igb_clear_interrupt_scheme(),
igb_init_queue_configuration() and igb_init_interrupt_scheme(). The PF
keeps a single Tx queue. The rings also keep the reg_idx offset that
igb_cache_ring_register() computed from the old vfs_allocated_count,
while vfs_allocated_count is now 0.
Would the next igb_configure() then program non-VT MRQC that steers to
hardware queue 0, while the only PF Rx ring sits at the old register
index, so PF Rx stops?
Could this check run only on the enable path, ideally at the start of
igb_enable_sriov() before any VF state is set up?
[ ... ]
> @@ -3933,6 +3954,8 @@ static int igb_enable_sriov(struct pci_dev *pdev, int num_vfs, bool reinit)
> kfree(adapter->vf_data);
> adapter->vf_data = NULL;
> adapter->vfs_allocated_count = 0;
[Severity: Medium]
The new -EBUSY return lets userspace reliably reach this err_out
teardown while the PF is still up. The check runs before igb_close(),
so the watchdog and rx_mode keep running. Here rtnl has already been
dropped inside igb_sriov_reinit(), and vfs_lock is not taken.
Some readers walk vf_data without either lock, for example
igb_watchdog_task()->igb_ping_all_vfs():
for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
ping = E1000_PF_CONTROL_MSG;
if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
igb_set_rx_mode()->igb_restore_vf_multicasts() does the same under
addr_list_lock only. rtnl-only VF ops such as igb_ndo_set_vf_mac() also
write vf_data[vf].
vf_data is set to NULL before vfs_allocated_count is cleared. Can a
concurrent reader see a non-zero count and either use the freed
vf_data or dereference NULL plus an offset?
This unsynchronized reader pattern also exists against
igb_disable_sriov(), but this patch adds a user-triggerable way into
it. Moving the XSK check before vfs_allocated_count and vf_data are
published would avoid that.
[Severity: Low]
The commit message says the MAC filter entries reserved for the VFs
stay reserved until the next reset. They come from
igb_vf_configure()->igb_set_vf_mac(), which runs before
igb_sriov_reinit():
adapter->mac_table[rar_entry].queue = vf;
adapter->mac_table[rar_entry].state |= IGB_MAC_STATE_IN_USE;
igb_rar_set_index(adapter, rar_entry);
err_out does not release them. With vfs_allocated_count back at 0, the
PF loses up to num_vfs - 1 unicast filter slots.
If the check ran at the top of igb_enable_sriov() (the PF queue limit
can be derived from num_vfs), would this leak and the disable-path
problem above both go away?
[Severity: Medium]
This isn't a bug introduced by this patch, but when igb_sriov_reinit()
succeeds and pci_enable_sriov() then fails:
if (!old_vfs) {
err = pci_enable_sriov(pdev, adapter->vfs_allocated_count);
if (err)
goto err_out;
}
err_out clears vfs_allocated_count without running igb_sriov_reinit()
again. The interrupt scheme, the ring reg_idx offsets and the VT
register programming all stay in VF mode while software believes there
are no VFs.
The new DMAC restore matches the intended no-VF state and does not
make this worse. Should err_out redo the reinit in this case?
> + if (dmac)
> + adapter->flags |= IGB_FLAG_DMAC;
[Severity: Low]
This is a non-atomic read-modify-write of adapter->flags from sysfs
context, and the interface is still up after the -EBUSY return.
igb_watchdog_task() updates the same word
(IGB_FLAG_NEED_LINK_UPDATE, IGB_FLAG_MEDIA_RESET, IGB_FLAG_EEE), and so
does igb_set_rx_mode() (IGB_FLAG_VLAN_PROMISC) under addr_list_lock.
Can an overlapping update lose either the DMAC bit or the other
context's bit? The earlier "adapter->flags &= ~IGB_FLAG_DMAC" in this
function already follows the same pattern.
> out:
> return err;
> }
[ ... ]
> @@ -4836,9 +4859,13 @@ void igb_setup_srrctl(struct igb_adapter *adapter, struct igb_ring *ring)
> u32 srrctl = 0;
> u32 buf_size;
>
> - if (ring->xsk_pool)
> - buf_size = xsk_pool_get_rx_frame_size(ring->xsk_pool);
> - else if (ring_uses_large_buffer(ring))
> + /* SRRCTL.BSIZEPKT has a 1 KiB granularity, so programming the XSK
> + * frame size would round it down and split frames over several
> + * buffers. XSK rings use the same buffer size as the other rings.
> + * While XDP is attached, the receive length limit keeps frames
> + * within the XSK frame, see igb_xsk_frame_fits().
> + */
> + if (ring_uses_large_buffer(ring))
> buf_size = IGB_RXBUFFER_3072;
> else
> buf_size = IGB_RXBUFFER_2048;
[Severity: Low]
This is only safe together with the receive length limit from the
earlier patch. The commit message says:
This depends on "igb: do not let XDP frames span more than one Rx
buffer" ... Without it, the hardware can write past the XSK frame.
The two patches carry different Fixes: tags (9cbc948b5a20 and
2c6196013f84), and the Cc: stable tag here has no prerequisite note. If
a stable tree takes this patch without the prerequisite, could the NIC
DMA up to 2 KiB or 3 KiB into a 1792-byte XSK frame and overrun the
next UMEM chunk?
Would a stable prerequisite annotation on the Cc: stable line make the
dependency explicit?
> diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c
> index ce4a7b58cad2f..7f99e834c1edb 100644
> --- a/drivers/net/ethernet/intel/igb/igb_xsk.c
> +++ b/drivers/net/ethernet/intel/igb/igb_xsk.c
> @@ -91,7 +91,21 @@ struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,
> if (!igb_xdp_is_enabled(adapter))
> return NULL;
>
> - return (pool && pool->dev) ? pool : NULL;
> + if (!pool || !pool->dev)
> + return NULL;
> +
> + /* igb_change_mtu() does not see a pool on a queue that is hidden, for
> + * example after a fallback from MSI-X to MSI. The hardware buffer can
> + * be larger than the XSK frame, so check again when the ring is set up.
> + */
> + if (!igb_xsk_frame_fits(pool, adapter->max_frame_size)) {
> + netdev_warn_once(adapter->netdev,
> + "XSK frame size is too small for the MTU, queue %d is not used in zero-copy mode\n",
> + qid);
> + return NULL;
> + }
> +
> + return pool;
> }
[Severity: High]
This is a pre-existing issue that was not introduced by this patch.
igb_xsk_pool() picks the pool from ring->queue_index alone.
igb_setup_desc_rings() in igb_ethtool.c never sets
test_rx_ring.queue_index, so it stays 0. It then calls
igb_configure_rx_ring(), which sets ring->xsk_pool from
igb_xsk_pool().
Suppose XDP is attached and a zero-copy pool is bound to queue 0. Then
ethtool -t ethX offline takes this path:
igb_diag_test()
igb_loopback_test()
igb_setup_desc_rings()
igb_configure_rx_ring() test ring gets the queue 0 pool
igb_alloc_rx_buffers() fills igb_rx_buffer page entries
...
igb_free_desc_rings()
igb_free_rx_resources()
igb_clean_rx_ring()
igb_clean_rx_ring_zc()
igb_clean_rx_ring_zc() then does:
struct xdp_buff *xdp = rx_ring->rx_buffer_info_zc[ntc];
xsk_buff_free(xdp);
Can this call xsk_buff_free() on words of the igb_rx_buffer array (DMA
addresses, struct page pointers) as if they were struct xdp_buff
pointers?
The test's pages would also leak and stay DMA-mapped. The live pool's
rxq info also gets pointed at the test ring's xdp_rxq. The new
netdev_warn_once() above can also fire for this test ring.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-igb-rx-ts-fix-v6-0-ba5b9903859c%40aweta.nl
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads