[PATCH net 1/1] net: stmmac: use plain TX queue lock in the NAPI poll
Luke Dashjr
luke at dashjr.org
Wed Dec 2 16:03:53 PST 2026
Netpoll may run a device NAPI ->poll() callback with hard IRQs disabled
while it holds that NAPI's poll owner. netconsole takes this path: when
a transmit does not complete immediately, __netpoll_send_skb() retries
through netpoll_poll_dev(), which claims napi->poll_owner and runs the
driver poll callback with a zero budget.
stmmac_tx_clean() serializes against the TX queue with the BH-enabling
__netif_tx_lock_bh()/__netif_tx_unlock_bh() pair. The unlock ends in
local_bh_enable(), which services pending softirqs inline. Because
irqs_disabled() does not imply in_interrupt(), a pending NET_RX_SOFTIRQ
can run net_rx_action() -> napi_poll() -> netpoll_poll_lock() on the
same CPU, and netpoll_poll_lock() then spins forever on the
napi->poll_owner that this CPU still holds. The CPU hangs, which defeats
the no-UART recovery path that relies on early netconsole.
stmmac_tx_clean() is only called from the two NAPI poll callbacks,
stmmac_napi_poll_tx() and stmmac_napi_poll_rxtx(). A poll callback always
runs with bottom halves already disabled: softirq context, the
threaded-NAPI kthread (which takes local_bh_disable() around ->poll()), or
netpoll with hard IRQs disabled. The BH-enabling lock is therefore
redundant in the first two and harmful in the last. Use the plain
__netif_tx_lock()/__netif_tx_unlock() pair, as the core transmit path
(HARD_TX_LOCK) and the other poll callbacks already do; the queue lock
and its ownership accounting are unchanged.
The same class of bug was fixed the same way in the USB CDC drivers:
cdc_ncm in commit 108ca34cf4b4 ("net: usb: cdc_ncm: don't enable BHs in
tx_fixup under netpoll"), and cdc_mbim the same way. There too a _bh
unlock reached by netpoll with IRQs off ran softirqs inside the
netpoll-held section, and the plain lock was used because every caller
already has BHs or IRQs off.
The bug was first observed on a downstream 6.12.112-based kernel with
out-of-tree iMAPx910 support, where an unpatched image hung in about 2-3
of 12 boots during the netconsole printk-backlog replay.
Validation and testing were on mainline 7.4.0-rc5. The natural
reproduction did not modify the kernel: it needed only a local, test-only
tweak to QEMU's npcm_gmac model that defers the TX-completion interrupt to
emulate DMA latency. The deterministic case additionally built a local
test module (removed for submission) that drives netpoll_poll_dev() with
IRQs disabled. Booting the emulated npcm845-evb with the console on the
extended netconsole, the unpatched kernel hung in netpoll_poll_lock() in
17 of 20 boots, while all 20 boots reached /init with this change. No
physical hardware was available, so the testing is emulation only; no QEMU
code is part of this submission. No kernel selftest exercises this path.
AI-assistance disclosure: the bug was found by an AI code review assistant
(GPT-6.2-Sol, high reasoning effort); its guardrails refused a follow-up
request to help prepare the report, so a second AI assistant, DeepSeek
V4.1 Flash (high reasoning), was used for the source analysis, the
reproduction, the testing and this changelog.
Fixes: 8fce33317023 ("net: stmmac: Rework coalesce timer and fix
multi-queue races")
Cc: <stable at vger.kernel.org> # 6.1.y
Signed-off-by: Luke Dashjr <luke-jr+git at utopios.org>
---
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index a685ce4..a13ee14 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2862,7 +2862,7 @@ static int stmmac_tx_clean(struct stmmac_priv
*priv, int budget, u32 queue,
unsigned int entry, xmits = 0, count = 0;
u32 tx_packets = 0, tx_errors = 0;
-__netif_tx_lock_bh(netdev_get_tx_queue(priv->dev, queue));
+__netif_tx_lock(netdev_get_tx_queue(priv->dev, queue), smp_processor_id());
tx_q->xsk_frames_done = 0;
@@ -3032,7 +3032,7 @@ static int stmmac_tx_clean(struct stmmac_priv
*priv, int budget, u32 queue,
priv->xstats.tx_errors += tx_errors;
-__netif_tx_unlock_bh(netdev_get_tx_queue(priv->dev, queue));
+__netif_tx_unlock(netdev_get_tx_queue(priv->dev, queue));
/* Combine decisions from TX clean and XSK TX */
return max(count, xmits);
--
2.43.0
More information about the linux-arm-kernel
mailing list