* [PATCH 6.18.y] net: Use a dedicated flag to track disabled napi instances
@ 2026-11-13 20:02 Chris J Arges
2026-11-14 17:42 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Chris J Arges @ 2026-11-13 20:02 UTC (permalink / raw)
To: stable, David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Andrew Lunn, Samiullah Khawaja
Cc: netdev, kernel-team, Maxime Chevallier, Jakub Kicinski,
linux-kernel, Daniel Machon, Chris J Arges
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
commit 8dc87fc5d6a0eb337744737008177342a708bf36
("net: Use a dedicated flag to track disabled napi instances") upstream.
Trying to disable the napi threaded state while the napi instance is
disabled will hang forever in napi_stop_kthread(), as it waits for
NAPIF_STATE_SCHED_THREADED to clear.
This won't happen until the next ____napi_schedule() call, which won't
happen as it's disabled.
This happens in 2 instances :
- Drivers that create but don't use napi instances (stmmac's rxtx napi
for AF_XDP for example), here it's a driver bug
- Drivers that create their napi instances in .probe(). Here, setting
threaded off while the interface is down will hang :
ip link set eth0 down
echo 1 > /sys/class/net/eth0/threaded
echo 0 > /sys/class/net/eth0/threaded
-> hang
Checking on netif_running() isn't enough, as napi instances may be
transiently disabled when changing the MTU for example, let's use a
dedicated flag to track if the instance is disabled.
This allows immediately disabling the kthread when the instance is
disabled.
This was tested on mvpp2 (probe-time napi_add) and stmmac.
[ Backport: omit threaded busy-poll state handling, which is not present
in 6.18.y. ]
Fixes: 689883de94dd ("net: stop napi kthreads when THREADED napi is disabled")
Tested-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20261029153130.121204-1-maxime.chevallier@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Chris J Arges <carges@cloudflare.com>
---
Backport upstream commit 8dc87fc5d6a0 ("net: Use a dedicated flag to
track disabled napi instances") to 6.18.y.
The commit fixes a reproducible hang in napi_stop_kthread() when
threaded NAPI is turned off while the NAPI instance is disabled. The
sysfs writer holds the netdev instance lock while waiting, which can
also block device recovery.
The upstream patch does not apply cleanly because 6.18.y does not have
threaded busy-poll support. Keep the 6.18.y state handling while adding
the dedicated disabled-state tracking.
---
include/linux/netdevice.h | 2 ++
net/core/dev.c | 14 ++++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7be5b78b2bff..e272d0006c6b 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -431,6 +431,7 @@ enum {
NAPI_STATE_THREADED, /* The poll is performed inside its own thread*/
NAPI_STATE_SCHED_THREADED, /* Napi is currently scheduled in threaded mode */
NAPI_STATE_HAS_NOTIFIER, /* Napi has an IRQ notifier */
+ NAPI_STATE_DISABLED, /* NAPI is disabled */
};
enum {
@@ -445,6 +446,7 @@ enum {
NAPIF_STATE_THREADED = BIT(NAPI_STATE_THREADED),
NAPIF_STATE_SCHED_THREADED = BIT(NAPI_STATE_SCHED_THREADED),
NAPIF_STATE_HAS_NOTIFIER = BIT(NAPI_STATE_HAS_NOTIFIER),
+ NAPIF_STATE_DISABLED = BIT(NAPI_STATE_DISABLED),
};
enum gro_result {
diff --git a/net/core/dev.c b/net/core/dev.c
index 673223065b95..95126e236079 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7127,6 +7127,12 @@ static void napi_stop_kthread(struct napi_struct *napi)
{
unsigned long val, new;
+ /* Instance is disabled, we can immediately stop the kthread */
+ if (test_bit(NAPI_STATE_DISABLED, &napi->state)) {
+ clear_bit(NAPI_STATE_THREADED, &napi->state);
+ goto stop;
+ }
+
/* Wait until the napi STATE_THREADED is unset. */
while (true) {
val = READ_ONCE(napi->state);
@@ -7156,6 +7162,7 @@ static void napi_stop_kthread(struct napi_struct *napi)
msleep(20);
}
+stop:
kthread_stop(napi->thread);
napi->thread = NULL;
}
@@ -7541,6 +7548,7 @@ void netif_napi_add_weight_locked(struct net_device *dev,
napi->list_owner = -1;
set_bit(NAPI_STATE_SCHED, &napi->state);
set_bit(NAPI_STATE_NPSVC, &napi->state);
+ set_bit(NAPI_STATE_DISABLED, &napi->state);
netif_napi_dev_list_add(dev, napi);
/* default settings from sysfs are applied to all NAPIs. any per-NAPI
@@ -7577,7 +7585,8 @@ void napi_disable_locked(struct napi_struct *n)
val = READ_ONCE(n->state);
}
- new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
+ new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC |
+ NAPIF_STATE_DISABLED;
new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL);
} while (!try_cmpxchg(&n->state, &val, new));
@@ -7620,7 +7629,8 @@ void napi_enable_locked(struct napi_struct *n)
do {
BUG_ON(!test_bit(NAPI_STATE_SCHED, &val));
- new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC);
+ new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC |
+ NAPIF_STATE_DISABLED);
if (n->dev->threaded && n->thread)
new |= NAPIF_STATE_THREADED;
} while (!try_cmpxchg(&n->state, &val, new));
---
base-commit: 1cdda838e8475edf89b73ff0cc952005dd0b1fa7
change-id: 20261113-napi-disabled-backport-6-18-020c3789bc88
Best regards,
--
Chris J Arges <carges@cloudflare.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH 6.18.y] net: Use a dedicated flag to track disabled napi instances
2026-11-13 20:02 [PATCH 6.18.y] net: Use a dedicated flag to track disabled napi instances Chris J Arges
@ 2026-11-14 17:42 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-14 17:42 UTC (permalink / raw)
To: stable, David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Andrew Lunn, Samiullah Khawaja
Cc: Sasha Levin, netdev, kernel-team, Maxime Chevallier,
Jakub Kicinski, linux-kernel, Daniel Machon, Chris J Arges
On 2026-11-13, Chris J Arges <carges@cloudflare.com> wrote:
> commit 8dc87fc5d6a0eb337744737008177342a708bf36
> ("net: Use a dedicated flag to track disabled napi instances") upstream.
Queued for 6.18, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-14 17:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 20:02 [PATCH 6.18.y] net: Use a dedicated flag to track disabled napi instances Chris J Arges
2026-11-14 17:42 ` Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.