Skip to content

Commit 3f9183b

Browse files
committed
net: Make napi_hash_lock irq safe
JIRA: https://issues.redhat.com/browse/RHEL-77816 Upstream Status: net.git commit cecc155 commit cecc155 Author: Joe Damato <jdamato@fastly.com> Date: Mon Dec 2 18:21:02 2024 +0000 net: Make napi_hash_lock irq safe Make napi_hash_lock IRQ safe. It is used during the control path, and is taken and released in napi_hash_add and napi_hash_del, which will typically be called by calls to napi_enable and napi_disable. This change avoids a deadlock in pcnet32 (and other any other drivers which follow the same pattern): CPU 0: pcnet32_open spin_lock_irqsave(&lp->lock, ...) napi_enable napi_hash_add <- before this executes, CPU 1 proceeds spin_lock(napi_hash_lock) [...] spin_unlock_irqrestore(&lp->lock, flags); CPU 1: pcnet32_close napi_disable napi_hash_del spin_lock(napi_hash_lock) < INTERRUPT > pcnet32_interrupt spin_lock(lp->lock) <- DEADLOCK Changing the napi_hash_lock to be IRQ safe prevents the IRQ from firing on CPU 1 until napi_hash_lock is released, preventing the deadlock. Cc: stable@vger.kernel.org Fixes: 86e25f4 ("net: napi: Add napi_config") Reported-by: Guenter Roeck <linux@roeck-us.net> Closes: https://lore.kernel.org/netdev/85dd4590-ea6b-427d-876a-1d8559c7ad82@roeck-us.net/ Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Joe Damato <jdamato@fastly.com> Tested-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20241202182103.363038-1-jdamato@fastly.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Davide Caratti <dcaratti@redhat.com>
1 parent 3a2c083 commit 3f9183b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

net/core/dev.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6457,18 +6457,22 @@ static void __napi_hash_add_with_id(struct napi_struct *napi,
64576457
static void napi_hash_add_with_id(struct napi_struct *napi,
64586458
unsigned int napi_id)
64596459
{
6460-
spin_lock(&napi_hash_lock);
6460+
unsigned long flags;
6461+
6462+
spin_lock_irqsave(&napi_hash_lock, flags);
64616463
WARN_ON_ONCE(napi_by_id(napi_id));
64626464
__napi_hash_add_with_id(napi, napi_id);
6463-
spin_unlock(&napi_hash_lock);
6465+
spin_unlock_irqrestore(&napi_hash_lock, flags);
64646466
}
64656467

64666468
static void napi_hash_add(struct napi_struct *napi)
64676469
{
6470+
unsigned long flags;
6471+
64686472
if (test_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state))
64696473
return;
64706474

6471-
spin_lock(&napi_hash_lock);
6475+
spin_lock_irqsave(&napi_hash_lock, flags);
64726476

64736477
/* 0..NR_CPUS range is reserved for sender_cpu use */
64746478
do {
@@ -6478,19 +6482,21 @@ static void napi_hash_add(struct napi_struct *napi)
64786482

64796483
__napi_hash_add_with_id(napi, napi_gen_id);
64806484

6481-
spin_unlock(&napi_hash_lock);
6485+
spin_unlock_irqrestore(&napi_hash_lock, flags);
64826486
}
64836487

64846488
/* Warning : caller is responsible to make sure rcu grace period
64856489
* is respected before freeing memory containing @napi
64866490
*/
64876491
static void napi_hash_del(struct napi_struct *napi)
64886492
{
6489-
spin_lock(&napi_hash_lock);
6493+
unsigned long flags;
6494+
6495+
spin_lock_irqsave(&napi_hash_lock, flags);
64906496

64916497
hlist_del_init_rcu(&napi->napi_hash_node);
64926498

6493-
spin_unlock(&napi_hash_lock);
6499+
spin_unlock_irqrestore(&napi_hash_lock, flags);
64946500
}
64956501

64966502
static enum hrtimer_restart napi_watchdog(struct hrtimer *timer)

0 commit comments

Comments
 (0)