Skip to contentSkip to conversation

eth: fbnic: queue stop fixes

PATCH In review Dimitri Daskalakis 2 participants 9 messages Nov 21 – Nov 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover eth: fbnic: queue stop fixes

From: Dimitri Daskalakis <[email protected]>

AI uncovered some pre-existing issues with fbnic's queue stop handling. If the idle wait fails in fbnic_queue_stop(), queues can be reset with in-flight DMAs and completions. fbnic_queue_stop() did not wait for in-flight xmits to complete before tearing down queues. And fbnic_wait_queue_idle() waited on the wrong idle bits for Tx queues.

Patches 1 and 3 were verified on HW, and patch 4 was verified in QEMU.

Dimitri Daskalakis (4):
eth: fbnic: restart queues in place when fbnic_queue_stop() fails
net: add netif_disable_subqueue()
eth: fbnic: wait for in-flight xmit in fbnic_queue_stop()
eth: fbnic: wait for both TWQs of a Tx queue to go idle

 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 84 ++++++++++++++++----
 include/linux/netdevice.h                    | 36 ++++++---
 2 files changed, 91 insertions(+), 29 deletions(-)
Signature · 1 line
2.52.1
#1 lore raw

PATCH 1/4 eth: fbnic: restart queues in place when fbnic_queue_stop() fails

From: Dimitri Daskalakis <[email protected]>

If the idle wait in fbnic_queue_stop() times out, the vector is restarted, which resets head/tail to 0. NAPI then re-walks stale completions and dereferences Tx buffers that were already freed.

We could flush the rings before restarting, but that risks in-flight DMA and completions landing in rings if the HW truly does not stop.

Instead, set the enable bits back without resetting anything, so the HW resumes from where it stopped.

This bug was found by AI and reproduced on HW.

This is not something we expect to hit in production, but we injected idle failures with a test patch to verify the behavior if it ever happened. Devmem was bound to rxq 5 under traffic, with a strict IOMMU:
HW is idled, but waiting for queues to idle fails:

    before: BUG: kernel NULL pointer dereference, address: 000000000000002e
            RIP: 0010:fbnic_clean_twq0+0xa8/0x290
    after:  bind fails with ETIMEDOUT, rxq 5 keeps receiving (5/5)

HW never stops (rings left enabled, and wait skipped):
flush: AMD-Vi: Event logged [IO_PAGE_FAULT ... flags=0x0020] (4/4)
after: no IOMMU faults, rxq 5 keeps receiving (10/10)
25/25 injected runs clean after, across Rx and Tx traffic and non-combined channels.

Fixes da43127a8edc ("eth: fbnic: support queue ops / zero-copy Rx")
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 50 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +47 -3
index 381831b7e108..c0fe89425430 100644
@@ -2326,6 +2326,50 @@ fbnic_nv_disable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)
 	fbnic_wrfl(fbn->fbd);
 }
 
+static void fbnic_reenable_twq(struct fbnic_ring *twq, u32 csr)
+{
+	u32 twq_ctl;
+
+	if (!twq->size_mask)
+		return;
+
+	twq_ctl = fbnic_ring_rd32(twq, csr);
+	fbnic_ring_wr32(twq, csr, twq_ctl | FBNIC_QUEUE_TWQ_CTL_ENABLE);
+}
+
+static void
+fbnic_nv_reenable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)
+{
+	int j, t;
+
+	for (t = 0; t < nv->txt_count; t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+
+		if (qt->cmpl.size_mask) {
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TIM_MASK, 0);
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TCQ_CTL,
+					FBNIC_QUEUE_TCQ_CTL_ENABLE);
+		}
+		fbnic_reenable_twq(&qt->sub1, FBNIC_QUEUE_TWQ1_CTL);
+		fbnic_reenable_twq(&qt->sub0, FBNIC_QUEUE_TWQ0_CTL);
+	}
+
+	for (j = 0; j < nv->rxt_count; j++, t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+		u32 bdq_ctl;
+
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RIM_MASK, 0);
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RCQ_CTL,
+				FBNIC_QUEUE_RCQ_CTL_ENABLE);
+
+		bdq_ctl = fbnic_ring_rd32(&qt->sub0, FBNIC_QUEUE_BDQ_CTL);
+		fbnic_ring_wr32(&qt->sub0, FBNIC_QUEUE_BDQ_CTL,
+				bdq_ctl | FBNIC_QUEUE_BDQ_CTL_ENABLE);
+	}
+
+	fbnic_wrfl(fbn->fbd);
+}
+
 void fbnic_dbg_down(struct fbnic_net *fbn)
 {
 	int i;
@@ -3092,9 +3136,6 @@ static void __fbnic_nv_restart(struct fbnic_net *fbn,
 	struct fbnic_dev *fbd = fbn->fbd;
 	int i;
 
-	fbnic_nv_enable(fbn, nv);
-	fbnic_nv_fill(nv);
-
 	napi_enable_locked(&nv->napi);
 	fbnic_nv_irq_enable(nv);
 	fbnic_wr32(fbd, FBNIC_INTR_SET(nv->v_idx / 32), BIT(nv->v_idx % 32));
@@ -3125,6 +3166,8 @@ static int fbnic_queue_start(struct net_device *dev,
 
 	memcpy(real, qmem, sizeof(*real));
 
+	fbnic_nv_enable(fbn, nv);
+	fbnic_nv_fill(nv);
 	__fbnic_nv_restart(fbn, nv);
 
 	return 0;
@@ -3170,6 +3213,7 @@ static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx)
 	return 0;
 
 err_restart:
+	fbnic_nv_reenable(fbn, nv);
 	__fbnic_nv_restart(fbn, nv);
 	return err;
 }
Signature · 1 line
2.52.1
#2 lore raw

Re: [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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).

- [Medium] fbnic_queue_stop()'s new error path relies on a hardware guarantee that is never written down or checked.

--

eth: fbnic: restart queues in place when fbnic_queue_stop() fails

When the idle wait in fbnic_queue_stop() times out, this patch no longer runs fbnic_nv_enable() and fbnic_nv_fill() on the error path. A new helper, fbnic_nv_reenable(), sets the ring enable bits back without resetting anything, so the hardware and the driver's ring state resume in place. The fbnic_nv_enable()/fbnic_nv_fill() calls move from __fbnic_nv_restart() into fbnic_queue_start().

Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
index 381831b7e1080..c0fe89425430d 100644
@@ -2326,6 +2326,50 @@ fbnic_nv_disable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)

[ ... ]

Quoted 14 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +14 -0
+static void
+fbnic_nv_reenable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)
+{
+	int j, t;
+
+	for (t = 0; t < nv->txt_count; t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+
+		if (qt->cmpl.size_mask) {
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TIM_MASK, 0);
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TCQ_CTL,
+					FBNIC_QUEUE_TCQ_CTL_ENABLE);
+		}
+		fbnic_reenable_twq(&qt->sub1, FBNIC_QUEUE_TWQ1_CTL);

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c fbnic_nv_disable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv) · line 2363

Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10 -0
+		fbnic_reenable_twq(&qt->sub0, FBNIC_QUEUE_TWQ0_CTL);
+	}
+
+	for (j = 0; j < nv->rxt_count; j++, t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+		u32 bdq_ctl;
+
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RIM_MASK, 0);
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RCQ_CTL,
+				FBNIC_QUEUE_RCQ_CTL_ENABLE);

[Severity: Medium]
Does this in-place resume rely on hardware behavior that is not documented or checked anywhere?

The driver keeps all of its ring state across the disable/enable toggle. That includes head/tail, the TCQ deferred_head, the TWQ0 deferred_meta, and the partly built Rx frame in qt->cmpl.pkt.

For that state to stay correct, two things have to be true:

- The device keeps its internal ring pointers and frame-assembly state

    when ENABLE goes 1->0->1 with no RESET.

- Completion writes that were in flight when the CQ was disabled are held back or finished, not dropped.

Nothing on the disable side seems to ensure the second point. __fbnic_nv_disable() turns off the CQs in the same burst as the WQs/BDQs, without waiting for the upstream queue to drain:

fbnic_disable_tcq():

	fbnic_ring_wr32(txr, FBNIC_QUEUE_TCQ_CTL, 0);

fbnic_disable_rcq():

	fbnic_ring_wr32(rxr, FBNIC_QUEUE_RCQ_CTL, 0);

Also, err_restart in fbnic_queue_stop() is only reached when an idle bit did not assert before fbnic_wait_queue_idle() timed out. That is when the device is most likely in the middle of a descriptor or a frame.

On Rx, fbnic_clean_rcq() picks up from pkt = rcq->pkt. Suppose the RDE had written the HDR_AL/PAY_AL completions for a frame, but its META completion was lost while the RCQ was disabled. Would the next frame's PAY_AL frags then be appended to the stale pkt?

The next frame's HDR_AL would also hit this check in fbnic_pkt_prepare():

	WARN_ON_ONCE(pkt->buff.data_hard_start);

pkt would then be overwritten, leaking the old page references.

On Tx, the cumulative head in the TCDs makes this partly self-healing. Even so, could the Tx buffers, DMA mappings and BQL bytes stay stuck until another completion arrives?

The commit message says the HW "resumes from where it stopped". However, fbnic_csr.h only defines RESET and ENABLE for these CTL registers.

The injected tests cover "HW is idled, but waiting for queues to idle fails" and "HW never stops (rings left enabled, and wait skipped)". Neither covers a CQ that was disabled while a completion was actually in flight.

Could this behavior be confirmed against the hardware documentation and described in a comment? If that is not possible, other options would be to disable the CQs only after the WQs/BDQs have gone idle, or to drop the partial qt->cmpl.pkt state before resuming.

The later patches in this series ("net: add netif_disable_subqueue()", "eth: fbnic: wait for in-flight xmit in fbnic_queue_stop()" and "eth:
fbnic: wait for both TWQs of a Tx queue to go idle") do not seem to change fbnic_nv_reenable() or the disable ordering.

Quoted 8 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +8 -0
+
+		bdq_ctl = fbnic_ring_rd32(&qt->sub0, FBNIC_QUEUE_BDQ_CTL);
+		fbnic_ring_wr32(&qt->sub0, FBNIC_QUEUE_BDQ_CTL,
+				bdq_ctl | FBNIC_QUEUE_BDQ_CTL_ENABLE);
+	}
+
+	fbnic_wrfl(fbn->fbd);
+}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121033215.1020506-1-dimitri.daskalakis1%40gmail.com
#3 lore raw

Re: [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails

Quoted 115 lines · On 11/24/26 4:33 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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).

- [Medium] fbnic_queue_stop()'s new error path relies on a hardware guarantee that is never written down or checked.

--

eth: fbnic: restart queues in place when fbnic_queue_stop() fails

When the idle wait in fbnic_queue_stop() times out, this patch no longer runs fbnic_nv_enable() and fbnic_nv_fill() on the error path. A new helper, fbnic_nv_reenable(), sets the ring enable bits back without resetting anything, so the hardware and the driver's ring state resume in place. The fbnic_nv_enable()/fbnic_nv_fill() calls move from __fbnic_nv_restart() into fbnic_queue_start().

Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
index 381831b7e1080..c0fe89425430d 100644
@@ -2326,6 +2326,50 @@ fbnic_nv_disable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)

[ ... ]

Quoted 14 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +14 -0
+static void
+fbnic_nv_reenable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv)
+{
+	int j, t;
+
+	for (t = 0; t < nv->txt_count; t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+
+		if (qt->cmpl.size_mask) {
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TIM_MASK, 0);
+			fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_TCQ_CTL,
+					FBNIC_QUEUE_TCQ_CTL_ENABLE);
+		}
+		fbnic_reenable_twq(&qt->sub1, FBNIC_QUEUE_TWQ1_CTL);

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c fbnic_nv_disable(struct fbnic_net *fbn, struct fbnic_napi_vector *nv) · line 2363

Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10 -0
+		fbnic_reenable_twq(&qt->sub0, FBNIC_QUEUE_TWQ0_CTL);
+	}
+
+	for (j = 0; j < nv->rxt_count; j++, t++) {
+		struct fbnic_q_triad *qt = &nv->qt[t];
+		u32 bdq_ctl;
+
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RIM_MASK, 0);
+		fbnic_ring_wr32(&qt->cmpl, FBNIC_QUEUE_RCQ_CTL,
+				FBNIC_QUEUE_RCQ_CTL_ENABLE);

[Severity: Medium]
Does this in-place resume rely on hardware behavior that is not documented or checked anywhere?

The driver keeps all of its ring state across the disable/enable toggle. That includes head/tail, the TCQ deferred_head, the TWQ0 deferred_meta, and the partly built Rx frame in qt->cmpl.pkt.

For that state to stay correct, two things have to be true:

- The device keeps its internal ring pointers and frame-assembly state

    when ENABLE goes 1->0->1 with no RESET.

- Completion writes that were in flight when the CQ was disabled are held back or finished, not dropped.

Nothing on the disable side seems to ensure the second point. __fbnic_nv_disable() turns off the CQs in the same burst as the WQs/BDQs, without waiting for the upstream queue to drain:

fbnic_disable_tcq():

	fbnic_ring_wr32(txr, FBNIC_QUEUE_TCQ_CTL, 0);

fbnic_disable_rcq():

	fbnic_ring_wr32(rxr, FBNIC_QUEUE_RCQ_CTL, 0);

Also, err_restart in fbnic_queue_stop() is only reached when an idle bit did not assert before fbnic_wait_queue_idle() timed out. That is when the device is most likely in the middle of a descriptor or a frame.

On Rx, fbnic_clean_rcq() picks up from pkt = rcq->pkt. Suppose the RDE had written the HDR_AL/PAY_AL completions for a frame, but its META completion was lost while the RCQ was disabled. Would the next frame's PAY_AL frags then be appended to the stale pkt?

The next frame's HDR_AL would also hit this check in fbnic_pkt_prepare():

	WARN_ON_ONCE(pkt->buff.data_hard_start);

pkt would then be overwritten, leaking the old page references.

On Tx, the cumulative head in the TCDs makes this partly self-healing. Even so, could the Tx buffers, DMA mappings and BQL bytes stay stuck until another completion arrives?

The commit message says the HW "resumes from where it stopped". However, fbnic_csr.h only defines RESET and ENABLE for these CTL registers.

The injected tests cover "HW is idled, but waiting for queues to idle fails" and "HW never stops (rings left enabled, and wait skipped)". Neither covers a CQ that was disabled while a completion was actually in flight.

Could this behavior be confirmed against the hardware documentation and described in a comment? If that is not possible, other options would be to disable the CQs only after the WQs/BDQs have gone idle, or to drop the partial qt->cmpl.pkt state before resuming.

Quoted 5 lines

The later patches in this series ("net: add netif_disable_subqueue()", "eth: fbnic: wait for in-flight xmit in fbnic_queue_stop()" and "eth:
fbnic: wait for both TWQs of a Tx queue to go idle") do not seem to change fbnic_nv_reenable() or the disable ordering.

The device keeps its ring state when we disable the ring. Only a reset clears the device state. The device will finish inflight completions, and when the driver restarts the queue we fire the interrupt which schedules the napi, so Rx/Tx does not get stuck waiting for a new completion.

If for some reason the device truncates an Rx packet, then it will report an error via a metadata descriptor. The driver will purge the pkt data accordingly and move on.

I don't think it's worth a re-spin to document this behavior.

#4 lore raw

PATCH 2/4 net: add netif_disable_subqueue()

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

netif_tx_stop_queue() does not wait for xmit to finish, and with queue API disabling a single queue is becoming more common. Add a helper like netif_tx_disable() (which drivers commonly use when stopping the interface) but for one queue.

---
 include/linux/netdevice.h | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)
include/linux/netdevice.h +23 -13
index 435be7880d7e..e716b98e8b4c 100644
@@ -4980,23 +4980,33 @@ static inline void netif_tx_unlock_bh(struct net_device *dev)
 	}						\
 }
 
+/**
+ * netif_disable_subqueue() - stop subqueue and wait for xmit to finish
+ * @dev: network device
+ * @queue_index: sub queue index
+ *
+ * Stop the subqueue like netif_stop_subqueue(), but also make sure that
+ * ndo_start_xmit() is not running on it once this function returns.
+ * Does not synchronize with xmit of lltx devices.
+ */
+static inline void
+netif_disable_subqueue(struct net_device *dev, u16 queue_index)
+{
+	struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
+
+	__netif_tx_lock_bh(txq);
+	netif_tx_stop_queue(txq);
+	__netif_tx_unlock_bh(txq);
+}
+
 static inline void netif_tx_disable(struct net_device *dev)
 {
 	unsigned int i;
-	int cpu;
 
-	local_bh_disable();
-	cpu = smp_processor_id();
-	spin_lock(&dev->tx_global_lock);
-	for (i = 0; i < dev->num_tx_queues; i++) {
-		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
-
-		__netif_tx_lock(txq, cpu);
-		netif_tx_stop_queue(txq);
-		__netif_tx_unlock(txq);
-	}
-	spin_unlock(&dev->tx_global_lock);
-	local_bh_enable();
+	spin_lock_bh(&dev->tx_global_lock);
+	for (i = 0; i < dev->num_tx_queues; i++)
+		netif_disable_subqueue(dev, i);
+	spin_unlock_bh(&dev->tx_global_lock);
 }
 
 #ifndef CONFIG_PREEMPT_RT
Signature · 1 line
2.52.1
#5 lore raw

Re: [PATCH net 2/4] net: add netif_disable_subqueue()

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…

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] The commit message for "net: add netif_disable_subqueue()" describes the patch as only adding a new helper ("Add a helper like…

--

net: add netif_disable_subqueue()

This commit adds netif_disable_subqueue(). The helper stops a single TX subqueue while holding that queue's xmit lock, so ndo_start_xmit() is no longer running on it when the helper returns. The commit also rewrites netif_tx_disable() so that it calls the new helper for each queue.

Quoted 4 lines
include/linux/netdevice.h +0 -0
index 435be7880d7e5..e716b98e8b4c8 100644

[ ... ]

Quoted 12 lines

static inline void netif_tx_disable(struct net_device *dev) {

include/linux/netdevice.h +0 -8
 	unsigned int i;
-	int cpu;
 
-	local_bh_disable();
-	cpu = smp_processor_id();
-	spin_lock(&dev->tx_global_lock);
-	for (i = 0; i < dev->num_tx_queues; i++) {
-		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
-
-		__netif_tx_lock(txq, cpu);

include/linux/netdevice.h static inline void netif_tx_unlock_bh(struct net_device *dev) · line 5010

Quoted 10 lines
include/linux/netdevice.h +4 -5
-		netif_tx_stop_queue(txq);
-		__netif_tx_unlock(txq);
-	}
-	spin_unlock(&dev->tx_global_lock);
-	local_bh_enable();
+	spin_lock_bh(&dev->tx_global_lock);
+	for (i = 0; i < dev->num_tx_queues; i++)
+		netif_disable_subqueue(dev, i);
+	spin_unlock_bh(&dev->tx_global_lock);
 }

[Severity: Low]
This isn't a bug, but the commit message only talks about adding a new helper:

Add a helper like netif_tx_disable() (which drivers commonly use when stopping the interface) but for one queue.

It doesn't say that netif_tx_disable() itself is rewritten here.

The old body disabled BH once, read smp_processor_id() once, and used __netif_tx_lock(txq, cpu) for each queue. The new body uses spin_lock_bh(&dev->tx_global_lock) and calls netif_disable_subqueue() for each queue. That helper does its own nested __netif_tx_lock_bh()/__netif_tx_unlock_bh(), and it takes the queue index as u16 rather than the unsigned int loop counter.

As far as I can tell the behavior is unchanged. Still, every driver calling netif_tx_disable() on its stop path picks up this change.

Could the commit log mention the conversion? Something like "Convert netif_tx_disable() to use the new helper, no functional change intended." would be enough.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121033215.1020506-1-dimitri.daskalakis1%40gmail.com
#6 lore raw

Re: [PATCH net 2/4] net: add netif_disable_subqueue()

Quoted 64 lines · On 11/24/26 4:33 AM, [email protected] wrote:

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] The commit message for "net: add netif_disable_subqueue()" describes the patch as only adding a new helper ("Add a helper like…

--

net: add netif_disable_subqueue()

This commit adds netif_disable_subqueue(). The helper stops a single TX subqueue while holding that queue's xmit lock, so ndo_start_xmit() is no longer running on it when the helper returns. The commit also rewrites netif_tx_disable() so that it calls the new helper for each queue.

Quoted 4 lines
include/linux/netdevice.h +0 -0
index 435be7880d7e5..e716b98e8b4c8 100644

[ ... ]

Quoted 12 lines

static inline void netif_tx_disable(struct net_device *dev) {

include/linux/netdevice.h +0 -8
 	unsigned int i;
-	int cpu;
 
-	local_bh_disable();
-	cpu = smp_processor_id();
-	spin_lock(&dev->tx_global_lock);
-	for (i = 0; i < dev->num_tx_queues; i++) {
-		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
-
-		__netif_tx_lock(txq, cpu);

include/linux/netdevice.h static inline void netif_tx_unlock_bh(struct net_device *dev) · line 5010

Quoted 10 lines
include/linux/netdevice.h +4 -5
-		netif_tx_stop_queue(txq);
-		__netif_tx_unlock(txq);
-	}
-	spin_unlock(&dev->tx_global_lock);
-	local_bh_enable();
+	spin_lock_bh(&dev->tx_global_lock);
+	for (i = 0; i < dev->num_tx_queues; i++)
+		netif_disable_subqueue(dev, i);
+	spin_unlock_bh(&dev->tx_global_lock);
 }

[Severity: Low]
This isn't a bug, but the commit message only talks about adding a new helper:

Add a helper like netif_tx_disable() (which drivers commonly use when stopping the interface) but for one queue.

It doesn't say that netif_tx_disable() itself is rewritten here.

The old body disabled BH once, read smp_processor_id() once, and used __netif_tx_lock(txq, cpu) for each queue. The new body uses spin_lock_bh(&dev->tx_global_lock) and calls netif_disable_subqueue() for each queue. That helper does its own nested __netif_tx_lock_bh()/__netif_tx_unlock_bh(), and it takes the queue index as u16 rather than the unsigned int loop counter.

Quoted 7 lines

As far as I can tell the behavior is unchanged. Still, every driver calling netif_tx_disable() on its stop path picks up this change.

Could the commit log mention the conversion? Something like "Convert netif_tx_disable() to use the new helper, no functional change intended." would be enough.

If this series needs a re-spin, I'll address the change in the commit msg.

#7 lore raw

PATCH 3/4 eth: fbnic: wait for in-flight xmit in fbnic_queue_stop()

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

fbnic_queue_stop() stops the vector's Tx queues with netif_stop_subqueue(), which only sets the stop bit. This races with senders who are already in fbnic_xmit_frame().

Use the new netif_disable_subqueue() helper prevent freeing rings while senders are still in xmit.

This bug was found by AI and verified on HW.

Forced by adding a 20ms delay in fbnic_tx_map() on Tx queue 5, binding devmem to rxq 5 under traffic:
before: BUG: kernel NULL pointer dereference, address: 000000000000002e

          RIP: 0010:fbnic_clean_twq0+0xa8/0x290
  after:  fbnic_queue_stop() waits for the in-flight xmit, no crash (10/10)
Fixes da43127a8edc ("eth: fbnic: support queue ops / zero-copy Rx")
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +1 -1
index c0fe89425430..62b67940c13e 100644
@@ -3191,7 +3191,7 @@ static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx)
 	for (i = 0; i < nv->txt_count; i++) {
 		if (nv->qt[i].sub0.flags & FBNIC_RING_F_DISABLED)
 			continue;
-		netif_stop_subqueue(dev, nv->qt[i].sub0.q_idx);
+		netif_disable_subqueue(dev, nv->qt[i].sub0.q_idx);
 	}
 	fbnic_nv_disable(fbn, nv);
 
Signature · 1 line
2.52.1
#8 lore raw

PATCH 4/4 eth: fbnic: wait for both TWQs of a Tx queue to go idle

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

TWQ_IDLE, TQS_IDLE and TDE_IDLE have a bit per Tx work queue. Bit 2q is for TWQ0, and bit 2q+1 is for TWQ1. fbnic_wait_queue_idle() only tests bit q, which belongs to queue q/2. Thus, the wait covers a TWQ of the wrong queue (except when q = 0).

Test both of the queue's TWQ bits in those registers.

This bug was found by AI and verified in QEMU.

Forced TWQ1 of Tx queue 3 to never read idle in QEMU, with rx 2 tx 2 (queue 3 is the XDP Tx queue of rxq 1's vector), and bound devmem to rxq 1:
before: bind succeeds
after: bind fails with ETIMEDOUT:

    wait for queue Tx3 idle failed 0x0800(0): ffffff7f (mask: 000000c0)
Fixes da43127a8edc ("eth: fbnic: support queue ops / zero-copy Rx")
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +20 -12
index 62b67940c13e..fe769c33b117 100644
@@ -2532,36 +2532,44 @@ int fbnic_wait_all_queues_idle(struct fbnic_dev *fbd, bool may_fail)
 	return err;
 }
 
+struct fbnic_queue_idle_reg {
+	u32 reg;
+	u8 bits_per_q;
+};
+
 static int
 fbnic_wait_queue_idle(struct fbnic_net *fbn, bool rx, unsigned int idx)
 {
-	static const unsigned int tx_regs[] = {
-		FBNIC_QM_TWQ_IDLE(0), FBNIC_QM_TQS_IDLE(0),
-		FBNIC_QM_TDE_IDLE(0), FBNIC_QM_TCQ_IDLE(0),
+	static const struct fbnic_queue_idle_reg tx_regs[] = {
+		{ FBNIC_QM_TWQ_IDLE(0), 2 }, { FBNIC_QM_TQS_IDLE(0), 2 },
+		{ FBNIC_QM_TDE_IDLE(0), 2 }, { FBNIC_QM_TCQ_IDLE(0), 1 },
 	}, rx_regs[] = {
-		FBNIC_QM_HPQ_IDLE(0), FBNIC_QM_PPQ_IDLE(0),
-		FBNIC_QM_RCQ_IDLE(0),
+		{ FBNIC_QM_HPQ_IDLE(0), 1 }, { FBNIC_QM_PPQ_IDLE(0), 1 },
+		{ FBNIC_QM_RCQ_IDLE(0), 1 },
 	};
+	const struct fbnic_queue_idle_reg *regs;
 	struct fbnic_dev *fbd = fbn->fbd;
 	unsigned int val, mask, off;
-	const unsigned int *regs;
 	unsigned int reg_cnt;
 	int i, err;
 
 	regs = rx ? rx_regs : tx_regs;
 	reg_cnt = rx ? ARRAY_SIZE(rx_regs) : ARRAY_SIZE(tx_regs);
 
-	off = idx / 32;
-	mask = BIT(idx % 32);
-
 	for (i = 0; i < reg_cnt; i++) {
-		err = read_poll_timeout_atomic(fbnic_rd32, val, val & mask,
+		unsigned int bit = idx * regs[i].bits_per_q;
+
+		off = bit / 32;
+		mask = GENMASK(regs[i].bits_per_q - 1, 0) << (bit % 32);
+
+		err = read_poll_timeout_atomic(fbnic_rd32, val,
+					       (val & mask) == mask,
 					       2, 500000, false,
-					       fbd, regs[i] + off);
+					       fbd, regs[i].reg + off);
 		if (err) {
 			netdev_err(fbd->netdev,
 				   "wait for queue %s%d idle failed 0x%04x(%d): %08x (mask: %08x)\n",
-				   rx ? "Rx" : "Tx", idx, regs[i] + off, i,
+				   rx ? "Rx" : "Tx", idx, regs[i].reg + off, i,
 				   val, mask);
 			return err;
 		}
Signature · 1 line
2.52.1