From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
Jakub Kicinski <kuba@kernel.org>,
davem@davemloft.net, Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Russell King <linux@armlinux.org.uk>,
Kuniyuki Iwashima <kuniyu@google.com>,
Stanislav Fomichev <sdf.kernel@gmail.com>
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
thomas.petazzoni@bootlin.com,
"Alexis Lothoré" <alexis.lothore@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v2] net: Don't allow disabling napi kthread mode while napi instances are disabled
Date: Tue, 6 Oct 2026 16:11:18 +0200 [thread overview]
Message-ID: <20261006141119.85562-1-maxime.chevallier@bootlin.com> (raw)
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, so let's check
the NAPIF_STATE_NPSVC flag instead, that's clear when the napi instance
is enabled.
This fix only addresses the second case. For the first case where
drivers have unused napi instances, the "threaded" mode can't be
switched off once enabled, these drivers will need fixing. As this
hasn't been seen before on said drivers, I guess it's OK as it used to
just freeze the system.
This was tested on mvpp2 (probe-time napi_add) and stmmac.
Fixes: 689883de94dd ("net: stop napi kthreads when THREADED napi is disabled")
Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
V2:
- Different approach as per Jakub's review, just don't allow setting
the napi threaded mode while interface is down.
I'm unsure about the correctness of this, to me it seems that the
NAPI_STATE_NPSVC flag indicates the condition we're interested in (is
napi instance enabled or not ?), but I may be missing something
obvious :(
V1:
https://lore.kernel.org/r/20260926194714.648819-1-maxime.chevallier@bootlin.com
net/core/dev.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/core/dev.c b/net/core/dev.c
index f660fccfc0db..fcf18c9eedb8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7315,6 +7315,12 @@ int netif_set_threaded(struct net_device *dev,
}
}
}
+ } else {
+ list_for_each_entry(napi, &dev->napi_list, dev_list) {
+ if (napi->thread &&
+ test_bit(NAPI_STATE_NPSVC, &napi->state))
+ return -EBUSY;
+ }
}
WRITE_ONCE(dev->threaded, threaded);
--
2.55.0
next reply other threads:[~2026-10-06 14:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 14:11 Maxime Chevallier [this message]
2026-10-08 2:11 ` netdev-bot+sashiko
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=20261006141119.85562-1-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=alexis.lothore@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=thomas.petazzoni@bootlin.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
all inboxes | Powered by JetHome®