mirror of
https://github.com/torvalds/linux.git
synced 2025-08-15 14:11:42 +02:00
net: prevent deadlocks when enabling NAPIs with mixed kthread config
The following order of calls currently deadlocks if:
- device has threaded=1; and
- NAPI has persistent config with threaded=0.
netif_napi_add_weight_config()
dev->threaded == 1
napi_kthread_create()
napi_enable()
napi_restore_config()
napi_set_threaded(0)
napi_stop_kthread()
while (NAPIF_STATE_SCHED)
msleep(20)
We deadlock because disabled NAPI has STATE_SCHED set.
Creating a thread in netif_napi_add() just to destroy it in
napi_disable() is fairly ugly in the first place. Let's read
both the device config and the NAPI config in netif_napi_add().
Fixes: e6d7626881
("net: Update threaded state in napi config in netif_set_threaded")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Joe Damato <joe@dama.to>
Link: https://patch.msgid.link/20250809001205.1147153-4-kuba@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
ccba9f6baa
commit
b3fc08ab9a
2 changed files with 11 additions and 2 deletions
|
@ -7357,7 +7357,8 @@ void netif_napi_add_weight_locked(struct net_device *dev,
|
|||
* Clear dev->threaded if kthread creation failed so that
|
||||
* threaded mode will not be enabled in napi_enable().
|
||||
*/
|
||||
if (dev->threaded && napi_kthread_create(napi))
|
||||
if (napi_get_threaded_config(dev, napi))
|
||||
if (napi_kthread_create(napi))
|
||||
dev->threaded = NETDEV_NAPI_THREADED_DISABLED;
|
||||
netif_napi_set_irq_locked(napi, -1);
|
||||
}
|
||||
|
|
|
@ -323,6 +323,14 @@ static inline enum netdev_napi_threaded napi_get_threaded(struct napi_struct *n)
|
|||
return NETDEV_NAPI_THREADED_DISABLED;
|
||||
}
|
||||
|
||||
static inline enum netdev_napi_threaded
|
||||
napi_get_threaded_config(struct net_device *dev, struct napi_struct *n)
|
||||
{
|
||||
if (n->config)
|
||||
return n->config->threaded;
|
||||
return dev->threaded;
|
||||
}
|
||||
|
||||
int napi_set_threaded(struct napi_struct *n,
|
||||
enum netdev_napi_threaded threaded);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue