Skip to content

Commit cecc155

Browse files
jdamato-fslykuba-moo
authored andcommitted
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: [email protected] Fixes: 86e25f4 ("net: napi: Add napi_config") Reported-by: Guenter Roeck <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Joe Damato <[email protected]> Tested-by: Guenter Roeck <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent af8edae commit cecc155

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
@@ -6557,18 +6557,22 @@ static void __napi_hash_add_with_id(struct napi_struct *napi,
65576557
static void napi_hash_add_with_id(struct napi_struct *napi,
65586558
unsigned int napi_id)
65596559
{
6560-
spin_lock(&napi_hash_lock);
6560+
unsigned long flags;
6561+
6562+
spin_lock_irqsave(&napi_hash_lock, flags);
65616563
WARN_ON_ONCE(napi_by_id(napi_id));
65626564
__napi_hash_add_with_id(napi, napi_id);
6563-
spin_unlock(&napi_hash_lock);
6565+
spin_unlock_irqrestore(&napi_hash_lock, flags);
65646566
}
65656567

65666568
static void napi_hash_add(struct napi_struct *napi)
65676569
{
6570+
unsigned long flags;
6571+
65686572
if (test_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state))
65696573
return;
65706574

6571-
spin_lock(&napi_hash_lock);
6575+
spin_lock_irqsave(&napi_hash_lock, flags);
65726576

65736577
/* 0..NR_CPUS range is reserved for sender_cpu use */
65746578
do {
@@ -6578,19 +6582,21 @@ static void napi_hash_add(struct napi_struct *napi)
65786582

65796583
__napi_hash_add_with_id(napi, napi_gen_id);
65806584

6581-
spin_unlock(&napi_hash_lock);
6585+
spin_unlock_irqrestore(&napi_hash_lock, flags);
65826586
}
65836587

65846588
/* Warning : caller is responsible to make sure rcu grace period
65856589
* is respected before freeing memory containing @napi
65866590
*/
65876591
static void napi_hash_del(struct napi_struct *napi)
65886592
{
6589-
spin_lock(&napi_hash_lock);
6593+
unsigned long flags;
6594+
6595+
spin_lock_irqsave(&napi_hash_lock, flags);
65906596

65916597
hlist_del_init_rcu(&napi->napi_hash_node);
65926598

6593-
spin_unlock(&napi_hash_lock);
6599+
spin_unlock_irqrestore(&napi_hash_lock, flags);
65946600
}
65956601

65966602
static enum hrtimer_restart napi_watchdog(struct hrtimer *timer)

0 commit comments

Comments
 (0)