Netdev List
 help / color / mirror / Atom feed
* [PATCH net 0/4] eth: fbnic: queue stop fixes
@ 2026-11-21  3:32 Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails Dimitri Daskalakis
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2026-11-21  3:32 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Björn Töpel, Bobby Eshleman, Mina Almasry,
	Dimitri Daskalakis, netdev, Dimitri Daskalakis

From: Dimitri Daskalakis <daskald@meta.com>

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

-- 
2.52.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails
  2026-11-21  3:32 [PATCH net 0/4] eth: fbnic: queue stop fixes Dimitri Daskalakis
@ 2026-11-21  3:32 ` Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 2/4] net: add netif_disable_subqueue() Dimitri Daskalakis
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2026-11-21  3:32 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Björn Töpel, Bobby Eshleman, Mina Almasry,
	Dimitri Daskalakis, netdev, Dimitri Daskalakis

From: Dimitri Daskalakis <daskald@meta.com>

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")
Signed-off-by: Dimitri Daskalakis <daskald@meta.com>
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 50 ++++++++++++++++++--
 1 file changed, 47 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
index 381831b7e108..c0fe89425430 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
@@ -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;
 }
-- 
2.52.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/4] net: add netif_disable_subqueue()
  2026-11-21  3:32 [PATCH net 0/4] eth: fbnic: queue stop fixes Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails Dimitri Daskalakis
@ 2026-11-21  3:32 ` Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 3/4] eth: fbnic: wait for in-flight xmit in fbnic_queue_stop() Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 4/4] eth: fbnic: wait for both TWQs of a Tx queue to go idle Dimitri Daskalakis
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2026-11-21  3:32 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Björn Töpel, Bobby Eshleman, Mina Almasry,
	Dimitri Daskalakis, netdev, Dimitri Daskalakis

From: Dimitri Daskalakis <daskald@meta.com>

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.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Dimitri Daskalakis <daskald@meta.com>
---
 include/linux/netdevice.h | 36 +++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 435be7880d7e..e716b98e8b4c 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -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
-- 
2.52.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 3/4] eth: fbnic: wait for in-flight xmit in fbnic_queue_stop()
  2026-11-21  3:32 [PATCH net 0/4] eth: fbnic: queue stop fixes Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 2/4] net: add netif_disable_subqueue() Dimitri Daskalakis
@ 2026-11-21  3:32 ` Dimitri Daskalakis
  2026-11-21  3:32 ` [PATCH net 4/4] eth: fbnic: wait for both TWQs of a Tx queue to go idle Dimitri Daskalakis
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2026-11-21  3:32 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Björn Töpel, Bobby Eshleman, Mina Almasry,
	Dimitri Daskalakis, netdev, Dimitri Daskalakis

From: Dimitri Daskalakis <daskald@meta.com>

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")
Signed-off-by: Dimitri Daskalakis <daskald@meta.com>
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
index c0fe89425430..62b67940c13e 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
@@ -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);
 
-- 
2.52.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 4/4] eth: fbnic: wait for both TWQs of a Tx queue to go idle
  2026-11-21  3:32 [PATCH net 0/4] eth: fbnic: queue stop fixes Dimitri Daskalakis
                   ` (2 preceding siblings ...)
  2026-11-21  3:32 ` [PATCH net 3/4] eth: fbnic: wait for in-flight xmit in fbnic_queue_stop() Dimitri Daskalakis
@ 2026-11-21  3:32 ` Dimitri Daskalakis
  3 siblings, 0 replies; 5+ messages in thread
From: Dimitri Daskalakis @ 2026-11-21  3:32 UTC (permalink / raw)
  To: David S. Miller
  Cc: Alexander Duyck, Jakub Kicinski, kernel-team, Andrew Lunn,
	Eric Dumazet, Paolo Abeni, Willem de Bruijn, Simon Horman,
	Björn Töpel, Bobby Eshleman, Mina Almasry,
	Dimitri Daskalakis, netdev, Dimitri Daskalakis

From: Dimitri Daskalakis <daskald@meta.com>

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")
Signed-off-by: Dimitri Daskalakis <daskald@meta.com>
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
index 62b67940c13e..fe769c33b117 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
@@ -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;
 		}
-- 
2.52.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-21  3:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21  3:32 [PATCH net 0/4] eth: fbnic: queue stop fixes Dimitri Daskalakis
2026-11-21  3:32 ` [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails Dimitri Daskalakis
2026-11-21  3:32 ` [PATCH net 2/4] net: add netif_disable_subqueue() Dimitri Daskalakis
2026-11-21  3:32 ` [PATCH net 3/4] eth: fbnic: wait for in-flight xmit in fbnic_queue_stop() Dimitri Daskalakis
2026-11-21  3:32 ` [PATCH net 4/4] eth: fbnic: wait for both TWQs of a Tx queue to go idle Dimitri Daskalakis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox