Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: joe@dama.to
Cc: netdev@vger.kernel.org, michael.chan@broadcom.com,
	pavan.chebbi@broadcom.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com
Subject: Re: [PATCH net] bnxt_en: Fix NIC lockup caused by stale NQ consumer index
Date: Sat, 05 Dec 2026 20:10:20 +0000	[thread overview]
Message-ID: <179650142046.3148.16138117899076184982@kernel.org> (raw)
In-Reply-To: <20261204200334.2294555-1-joe@dama.to>

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

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

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] bnxt_en: netpoll in bnxt_poll_p5() can disarm P5 NQ interrupts
- [Medium] In bnxt_poll_p5() (drivers/net/ethernet/broadcom/bnxt/bnxt.c,
  line 3433), the new `else if (nq_moved)` branch rings the NQ doorbell,…
- [Low] The new comment in bnxt_poll_p5()
  (drivers/net/ethernet/broadcom/bnxt/bnxt.c, lines 3429-3432) says…

--

bnxt_en: Fix NIC lockup caused by stale NQ consumer index

When napi_complete_done() returns false, for example with hard IRQ
deferral or busy polling, bnxt_poll_p5() now writes the NQ consumer
index without arming the NQ. The write is skipped if the index has not
moved. This addresses a NIC lockup on BCM57504 with some firmware
versions when the NQ consumer index goes stale.

> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> index 85ce4b2e297ec..f5cc273b97a5a 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c

[ ... ]

> @@ -3419,10 +3420,18 @@ static int bnxt_poll_p5(struct napi_struct *napi, int budget)
>  
>  			__bnxt_poll_cqs_done(bp, bnapi, DBR_TYPE_CQ_ARMALL,
>  					     budget);
> +			nq_moved = raw_cons != cpr->cp_raw_cons;
>  			cpr->cp_raw_cons = raw_cons;
> -			if (napi_complete_done(napi, work_done))
> +			if (napi_complete_done(napi, work_done)) {
>  				BNXT_DB_NQ_ARM_P5(&cpr->cp_db,
>  						  cpr->cp_raw_cons);
> +			} else if (nq_moved) {
> +				/* NAPI stays scheduled (IRQ deferral or busy
> +				 * poll) and the NQ is not re-armed, but the
> +				 * HW must still learn how far it was consumed.
> +				 */

[Severity: High]
Does this new branch also run from netpoll? If so, can it leave the NQ
disarmed with nothing left to re-arm it?

poll_one_napi() in net/core/netpoll.c sets NAPI_STATE_NPSVC and calls
napi->poll(napi, 0) for every NAPI on dev->napi_list. That includes
idle ones whose NQ is armed in hardware. It never sets
NAPI_STATE_SCHED, and it does not schedule the NAPI afterwards.

With budget == 0, bnxt_poll_p5() never takes the budget exhaustion
break, and __bnxt_poll_work() does not set has_more_work. Suppose an NQE
is already visible, for example a TX completion for netconsole output
that landed before the MSI-X fired. Then raw_cons advances, nq_moved
is true, the loop falls into the !NQ_CMP_VALID() path, and it calls
napi_complete_done(). That returns false right away because
NAPIF_STATE_NPSVC is set, with no reschedule and no timer.

The new else branch then writes BNXT_DB_NQ_P5(), i.e. DBR_TYPE_NQ.
bnxt_disable_int() and bnxt_queue_stop() use the same doorbell, through
bnxt_db_nq(), to mask the NQ on P5 chips.

When poll_one_napi() clears NPSVC and returns, the NAPI is not
scheduled, no deferral timer is pending, and the NQ is no longer
armed. RX, TX completions and, on ring 0, HWRM async events on that NQ
would then stall until the TX watchdog resets the device.

Before this patch nothing was written on this path, so an armed NQ
stayed armed. The comment above the write also assumes the NAPI stays
scheduled, which is not true for netpoll.

The legacy bnxt_poll() handles this case explicitly: it re-arms with
BNXT_DB_CQ_ARM() when budget is 0. Should bnxt_poll_p5() do something
similar? For example, it could issue BNXT_DB_NQ_ARM_P5() when budget is
0. Or it could avoid calling napi_complete_done() for budget == 0
altogether, as Documentation/networking/napi.rst asks.

[Severity: Low]
Is this comment accurate for the IRQ deferral case?

The reproducer in the commit message sets napi_defer_hard_irqs > 0 and a
non-zero gro_flush_timeout. In that setup, napi_complete_done() clears
NAPIF_STATE_SCHED and starts the hrtimer before it returns false:

net/core/dev.c:napi_complete_done() {
    ...
	if (n->defer_hard_irqs_count > 0) {
		n->defer_hard_irqs_count--;
		timeout = napi_get_gro_flush_timeout(n);
		if (timeout)
			ret = false;
	}
    ...
		new = val & ~(NAPIF_STATE_MISSED | NAPIF_STATE_SCHED |
			      NAPIF_STATE_SCHED_THREADED |
			      NAPIF_STATE_PREFER_BUSY_POLL);
    ...
	if (timeout)
		napi_timer_start(n, timeout);
	return ret;
}

napi_watchdog() later has to set NAPI_STATE_SCHED again with
test_and_set_bit(). So when this doorbell is written, the NAPI is idle
with a pending timer. It is not still scheduled.

The "stays scheduled" wording seems to fit only two cases: the early
return for NAPIF_STATE_IN_BUSY_POLL / NAPIF_STATE_NPSVC, and the
NAPIF_STATE_MISSED path. The comment also does not mention MISSED or
netpoll as reasons for a false return.

Could the comment be reworded so it does not suggest the driver still
owns the NAPI at this point?

> +				BNXT_DB_NQ_P5(&cpr->cp_db, cpr->cp_raw_cons);

[Severity: Medium]
Can this doorbell write race with a busy poller on another CPU in the
deferral case?

In the gro_flush_timeout path, napi_complete_done() has already cleared
NAPIF_STATE_SCHED. That lets __napi_busy_loop() on another CPU claim the
instance:

net/core/dev.c:__napi_busy_loop() {
    ...
		if (cmpxchg(&napi->state, val,
			    val | NAPIF_STATE_IN_BUSY_POLL |
				  NAPIF_STATE_SCHED) != val) {
    ...
}

It can then run bnxt_poll_p5() at the same time. One possible sequence:

CPU1 (bnxt_poll_p5)
    cpr->cp_raw_cons = X;
    napi_complete_done() returns false, SCHED cleared
    <delayed by hardirq, vCPU preemption, or PREEMPT_RT preemption>

CPU2 (busy poll -> bnxt_poll_p5)
    consumes more NQEs
    cpr->cp_raw_cons = X + n;
    BNXT_DB_NQ_P5() with X + n, or BNXT_DB_NQ_ARM_P5() with X + n
    via busy_poll_stop()->napi->poll()

CPU1
    BNXT_DB_NQ_P5(&cpr->cp_db, cpr->cp_raw_cons) re-reads
    cpr->cp_raw_cons, may still see X, and writes DBR_TYPE_NQ | X

Nothing orders the MMIO writes from the two CPUs. The device could get
the older consumer index after the newer one. The commit message says
that a stale NQ index is what locks up this firmware.

If the ring then stays idle, the nq_moved check blocks any further
non-arm writes. The stale index is only corrected when new NQEs arrive,
or when napi_complete_done() finally returns true and the ARM write is
issued.

Re-reading cpr->cp_raw_cons after ownership is dropped is also a plain
data race with the other poller's store.

It is not clear how the hardware handles an index that moves backwards.
It may correct itself on the next NQE or ARM write.

Would it be safer to write the non-arm NQ doorbell before calling
napi_complete_done(), while the NAPI is still owned? Then only the ARM
write would be needed when it returns true.

The existing ARM write in the true branch already writes after
ownership is released. This patch adds a second such write in the
deferral case it is meant to fix.

> +			}
>  			goto poll_done;
>  		}

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204200334.2294555-1-joe%40dama.to

      parent reply	other threads:[~2026-12-05 20:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 20:03 [PATCH net] bnxt_en: Fix NIC lockup caused by stale NQ consumer index Joe Damato
2026-12-04 22:22 ` Michael Chan
2026-12-04 22:58   ` Joe Damato
2026-12-05 15:19     ` Pavan Chebbi
2026-12-05 20:10 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179650142046.3148.16138117899076184982@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=joe@dama.to \
    --cc=kuba@kernel.org \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox