🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Dimitri Daskalakis Sat, 21 Nov 2026 03:32
[PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails
#20077
Author: Dimitri Daskalakis
Date: Sat, 21 Nov 2026 03:32
118 lines
15122 bytes
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
Re: [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails
#21753
Author: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 12:33
134 lines
13085 bytes
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().

> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
> index 381831b7e1080..c0fe89425430d 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)

[ ... ]

> +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);

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

> +
> +		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);
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121033215.1020506-1-dimitri.daskalakis1%40gmail.com
Re: [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails
#21992
Author: Dimitri Daskalakis
Date: Tue, 24 Nov 2026 17:42
134 lines
17088 bytes
On 11/24/26 4:33 AM, netdev-bot+sashiko@kernel.org 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().
> 
>> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c
>> index 381831b7e1080..c0fe89425430d 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)
> 
> [ ... ]
> 
>> +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);
> 
> [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.
> 

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.
Re: [PATCH net 1/4] eth: fbnic: restart queues in place when fbnic_queue_stop() fails
#25236
Author: Simon Horman
Date: Tue, 01 Dec 2026 12:38
38 lines
9554 bytes
On Tue, Nov 24, 2026 at 09:42:09AM -0800, Dimitri Daskalakis wrote:
> On 11/24/26 4:33 AM, netdev-bot+sashiko@kernel.org wrote:

...

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

Reviewed-by: Simon Horman <horms@kernel.org>
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