๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Antonio Quartulli Tue, 24 Nov 2026 23:57
[PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
#22188
Author: Antonio Quartulli
Date: Tue, 24 Nov 2026 23:57
84 lines
12692 bytes
When igb lowers its queue counts by itself, after a fallback from MSI-X
to MSI on resume or when enabling VFs, xsk_get_pool_from_qid() doesn't
find the pool of a socket bound to a removed queue anymore. Disabling
it then fails ("Failed to disable zero-copy!") and the pool's DMA
mappings are never unmapped.

ethtool refuses to remove a queue that still has an XSK pool, but igb
can't refuse a VF enable or a resume fallback. Keep the real Rx queue
count up to the highest queue that still has an XSK pool instead, so
that the pool can still be disabled, and lower it at the next open. The
Tx count follows the device: an XSK pool is always bound to both an Rx
and a Tx queue, and the lookup finds it through the Rx one.

Tested with the 82576 emulated by QEMU and a zero-copy AF_XDP socket,
bound to queue 2 when enabling a VF, and to queue 1 across a runtime
resume forced to use MSI with a single queue (with a test hook): closing
it warned and leaked before, not anymore.

Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
Cc: stable@vger.kernel.org # 6.14+
Reported-by: Janis Edvarts Lacis <janislacis06@gmail.com>
Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
v5: new patch (Janis)

 drivers/net/ethernet/intel/igb/igb_main.c | 27 ++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 2f51edc..6961646 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -4126,6 +4126,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
 	return 0;
 }
 
+/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
+ * refuse when it lowers its queue counts by itself, so keep the stack's Rx
+ * queue instead, or the pool couldn't be disabled anymore: lower the count
+ * once it's gone, at the next open.
+ */
+static int igb_set_real_num_queues(struct igb_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	unsigned int rxq = adapter->num_rx_queues;
+	unsigned int i;
+
+	for (i = netdev->real_num_rx_queues; i > rxq; i--)
+		if (xsk_get_pool_from_qid(netdev, i - 1)) {
+			rxq = i;
+			break;
+		}
+
+	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
+}
+
 /* Some settings need RTNL, which isn't held when resuming from runtime
  * suspend: apply them from here instead, if the device is still up.
  */
@@ -4137,9 +4157,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
 	rtnl_lock();
 	if (!test_bit(__IGB_DOWN, &adapter->state) &&
 	    netif_running(adapter->netdev)) {
-		if (netif_set_real_num_queues(adapter->netdev,
-					      adapter->num_tx_queues,
-					      adapter->num_rx_queues))
+		if (igb_set_real_num_queues(adapter))
 			netdev_err(adapter->netdev,
 				   "error setting real queue count\n");
 	}
@@ -4208,8 +4226,7 @@ static int __igb_open(struct net_device *netdev, bool resuming,
 	 * runtime resume igb_rtnl_resume_task() does it.
 	 */
 	if (rtnl_held) {
-		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
-						adapter->num_rx_queues);
+		err = igb_set_real_num_queues(adapter);
 		if (err)
 			goto err_set_queues;
 	}
-- 
2.56.1
Re: [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
#23878
Author: Janis Edvarts Lacis
Date: Sat, 28 Nov 2026 13:37
87 lines
15003 bytes
On 25 Nov 00:57, Antonio Quartulli wrote:
>When igb lowers its queue counts by itself, after a fallback from MSI-X
>to MSI on resume or when enabling VFs, xsk_get_pool_from_qid() doesn't
>find the pool of a socket bound to a removed queue anymore. Disabling
>it then fails ("Failed to disable zero-copy!") and the pool's DMA
>mappings are never unmapped.
>
>ethtool refuses to remove a queue that still has an XSK pool, but igb
>can't refuse a VF enable or a resume fallback. Keep the real Rx queue
>count up to the highest queue that still has an XSK pool instead, so
>that the pool can still be disabled, and lower it at the next open. The
>Tx count follows the device: an XSK pool is always bound to both an Rx
>and a Tx queue, and the lookup finds it through the Rx one.
>
>Tested with the 82576 emulated by QEMU and a zero-copy AF_XDP socket,
>bound to queue 2 when enabling a VF, and to queue 1 across a runtime
>resume forced to use MSI with a single queue (with a test hook): closing
>it warned and leaked before, not anymore.
>
>Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers")
>Cc: stable@vger.kernel.org # 6.14+
>Reported-by: Janis Edvarts Lacis <janislacis06@gmail.com>
>Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/
>Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
>---
>v5: new patch (Janis)
>
> drivers/net/ethernet/intel/igb/igb_main.c | 27 ++++++++++++++++++-----
> 1 file changed, 22 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
>index 2f51edc..6961646 100644
>--- a/drivers/net/ethernet/intel/igb/igb_main.c
>+++ b/drivers/net/ethernet/intel/igb/igb_main.c
>@@ -4126,6 +4126,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
> 	return 0;
> }
>
>+/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
>+ * refuse when it lowers its queue counts by itself, so keep the stack's Rx
>+ * queue instead, or the pool couldn't be disabled anymore: lower the count
>+ * once it's gone, at the next open.
>+ */
>+static int igb_set_real_num_queues(struct igb_adapter *adapter)
>+{
>+	struct net_device *netdev = adapter->netdev;
>+	unsigned int rxq = adapter->num_rx_queues;
>+	unsigned int i;
>+
>+	for (i = netdev->real_num_rx_queues; i > rxq; i--)
>+		if (xsk_get_pool_from_qid(netdev, i - 1)) {
>+			rxq = i;
>+			break;
>+		}
>+
>+	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
>+}
>+
> /* Some settings need RTNL, which isn't held when resuming from runtime
>  * suspend: apply them from here instead, if the device is still up.
>  */
>@@ -4137,9 +4157,7 @@ static void igb_rtnl_resume_task(struct work_struct *work)
> 	rtnl_lock();
> 	if (!test_bit(__IGB_DOWN, &adapter->state) &&
> 	    netif_running(adapter->netdev)) {
>-		if (netif_set_real_num_queues(adapter->netdev,
>-					      adapter->num_tx_queues,
>-					      adapter->num_rx_queues))
>+		if (igb_set_real_num_queues(adapter))
> 			netdev_err(adapter->netdev,
> 				   "error setting real queue count\n");
> 	}
>@@ -4208,8 +4226,7 @@ static int __igb_open(struct net_device *netdev, bool resuming,
> 	 * runtime resume igb_rtnl_resume_task() does it.
> 	 */
> 	if (rtnl_held) {
>-		err = netif_set_real_num_queues(netdev, adapter->num_tx_queues,
>-						adapter->num_rx_queues);
>+		err = igb_set_real_num_queues(adapter);
> 		if (err)
> 			goto err_set_queues;
> 	}
>-- 
>2.56.1
>
Reviewed-by: Janis Edvarts Lacis <janislacis06@gmail.com>
Re: [PATCH net v5 3/6] igb: keep the stack's Rx queues that still have an XSK pool
#24027
Author: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 00:37
99 lines
11684 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] igb_set_real_num_queues()
  (drivers/net/ethernet/intel/igb/igb_main.c) keepsโ€ฆ

--

igb: keep the stack's Rx queues that still have an XSK pool

When igb lowers its own queue counts (an MSI fallback on resume, or a VF
enable), this patch keeps netdev->real_num_rx_queues up to the highest
queue that still has an XSK pool. That way the pool can still be found
and disabled. The count is lowered again at the next open.

Closes: https://lore.kernel.org/netdev/xupy6jbpnziq2qji54zjbvm7neggrwkxg3sfrhlolmrd6ysifl@zptk6ynkbu5f/

> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
> index 6b299a1429a8e..47a92447aab27 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -4125,6 +4125,26 @@ static int igb_sw_init(struct igb_adapter *adapter)
>  	return 0;
>  }
>  
> +/* ethtool refuses to remove a queue that still has an XSK pool. igb can't
> + * refuse when it lowers its queue counts by itself, so keep the stack's Rx
> + * queue instead, or the pool couldn't be disabled anymore: lower the count
> + * once it's gone, at the next open.
> + */
> +static int igb_set_real_num_queues(struct igb_adapter *adapter)
> +{
> +	struct net_device *netdev = adapter->netdev;
> +	unsigned int rxq = adapter->num_rx_queues;
> +	unsigned int i;
> +
> +	for (i = netdev->real_num_rx_queues; i > rxq; i--)
> +		if (xsk_get_pool_from_qid(netdev, i - 1)) {
> +			rxq = i;
> +			break;
> +		}

[Severity: Low]
Should this loop only keep queues whose pool is in zero-copy mode?

As written, any registered pool keeps the count up, including copy-mode
(XDP_COPY) pools. The comment above gives one reason for keeping the
queue: otherwise the pool couldn't be disabled. That reason only seems to
apply to zero-copy pools:

net/xdp/xsk_buff_pool.c:xp_disable_drv_zc() {
    ...
	if (pool->umem->zc) {
		bpf.command = XDP_SETUP_XSK_POOL;
    ...
}

A copy-mode pool on a removed queue is cleared by
__xsk_clear_pool_at_qid(). That function walks dev->_rx[] and dev->_tx[]
up to the allocated num_rx_queues and num_tx_queues, so the extra queues
were not needed for that case before this patch.

This case also looks easy to reach. igb only sets the real queue counts
through this helper, so before the first open real_num_rx_queues is still
16 from alloc_etherdev_mq(..., IGB_MAX_TX_QUEUES) in igb_probe(). While
the device is down, xsk_reg_pool_at_qid() accepts any qid below 16.

igb_xsk_pool_enable() rejects a zero-copy bind on such a queue:

	if (qid >= adapter->num_rx_queues)
		return -EINVAL;

If neither XDP_ZEROCOPY nor XDP_COPY is requested, xp_assign_dev() falls
back to copy mode and leaves the pool registered at that qid. An explicit
XDP_COPY bind skips the driver entirely.

On the next __igb_open(), or after a VF enable or MSI fallback with only a
copy-mode socket on a removed queue, this loop finds that pool and calls
netif_set_real_num_queues(netdev, num_tx_queues, qid + 1). The stack would
then report RX queues that have no hardware ring (rx-N sysfs entries and
netdev-genl queue dumps) until the socket is closed and the device is
reopened.

Would checking pool->umem->zc here limit the behavior to the case
described in the commit message and the comment?

> +
> +	return netif_set_real_num_queues(netdev, adapter->num_tx_queues, rxq);
> +}
> +

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124235723.1135808-1-antonio%40mandelbit.com
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