Skip to content

Commit f17b15d

Browse files
committed
Merge branch 'eth-fix-calling-napi_enable-in-atomic-context'
Jakub Kicinski says: ==================== eth: fix calling napi_enable() in atomic context Dan has reported that I missed a lot of drivers which call napi_enable() in atomic with the naive coccinelle search for spin locks: https://lore.kernel.org/dcfd56bc-de32-4b11-9e19-d8bd1543745d@stanley.mountain Fix them. Most of the fixes involve taking the netdev_lock() before the spin lock. mt76 is special because we can just move napi_enable() from the BH section. All patches compile tested only. v2: https://lore.kernel.org/20250123004520.806855-1-kuba@kernel.org v1: https://lore.kernel.org/20250121221519.392014-1-kuba@kernel.org ==================== Link: https://patch.msgid.link/20250124031841.1179756-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 964417a + a605586 commit f17b15d

File tree

17 files changed

+132
-65
lines changed

17 files changed

+132
-65
lines changed

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7424,7 +7424,7 @@ static void tg3_napi_enable(struct tg3 *tp)
74247424

74257425
for (i = 0; i < tp->irq_cnt; i++) {
74267426
tnapi = &tp->napi[i];
7427-
napi_enable(&tnapi->napi);
7427+
napi_enable_locked(&tnapi->napi);
74287428
if (tnapi->tx_buffers) {
74297429
netif_queue_set_napi(tp->dev, txq_idx,
74307430
NETDEV_QUEUE_TYPE_TX,
@@ -7445,9 +7445,10 @@ static void tg3_napi_init(struct tg3 *tp)
74457445
int i;
74467446

74477447
for (i = 0; i < tp->irq_cnt; i++) {
7448-
netif_napi_add(tp->dev, &tp->napi[i].napi,
7449-
i ? tg3_poll_msix : tg3_poll);
7450-
netif_napi_set_irq(&tp->napi[i].napi, tp->napi[i].irq_vec);
7448+
netif_napi_add_locked(tp->dev, &tp->napi[i].napi,
7449+
i ? tg3_poll_msix : tg3_poll);
7450+
netif_napi_set_irq_locked(&tp->napi[i].napi,
7451+
tp->napi[i].irq_vec);
74517452
}
74527453
}
74537454

@@ -11259,6 +11260,8 @@ static void tg3_timer_stop(struct tg3 *tp)
1125911260
static int tg3_restart_hw(struct tg3 *tp, bool reset_phy)
1126011261
__releases(tp->lock)
1126111262
__acquires(tp->lock)
11263+
__releases(tp->dev->lock)
11264+
__acquires(tp->dev->lock)
1126211265
{
1126311266
int err;
1126411267

@@ -11271,7 +11274,9 @@ static int tg3_restart_hw(struct tg3 *tp, bool reset_phy)
1127111274
tg3_timer_stop(tp);
1127211275
tp->irq_sync = 0;
1127311276
tg3_napi_enable(tp);
11277+
netdev_unlock(tp->dev);
1127411278
dev_close(tp->dev);
11279+
netdev_lock(tp->dev);
1127511280
tg3_full_lock(tp, 0);
1127611281
}
1127711282
return err;
@@ -11299,6 +11304,7 @@ static void tg3_reset_task(struct work_struct *work)
1129911304

1130011305
tg3_netif_stop(tp);
1130111306

11307+
netdev_lock(tp->dev);
1130211308
tg3_full_lock(tp, 1);
1130311309

1130411310
if (tg3_flag(tp, TX_RECOVERY_PENDING)) {
@@ -11318,12 +11324,14 @@ static void tg3_reset_task(struct work_struct *work)
1131811324
* call cancel_work_sync() and wait forever.
1131911325
*/
1132011326
tg3_flag_clear(tp, RESET_TASK_PENDING);
11327+
netdev_unlock(tp->dev);
1132111328
dev_close(tp->dev);
1132211329
goto out;
1132311330
}
1132411331

1132511332
tg3_netif_start(tp);
1132611333
tg3_full_unlock(tp);
11334+
netdev_unlock(tp->dev);
1132711335
tg3_phy_start(tp);
1132811336
tg3_flag_clear(tp, RESET_TASK_PENDING);
1132911337
out:
@@ -11683,9 +11691,11 @@ static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq,
1168311691
if (err)
1168411692
goto out_ints_fini;
1168511693

11694+
netdev_lock(dev);
1168611695
tg3_napi_init(tp);
1168711696

1168811697
tg3_napi_enable(tp);
11698+
netdev_unlock(dev);
1168911699

1169011700
for (i = 0; i < tp->irq_cnt; i++) {
1169111701
err = tg3_request_irq(tp, i);
@@ -12569,6 +12579,7 @@ static int tg3_set_ringparam(struct net_device *dev,
1256912579
irq_sync = 1;
1257012580
}
1257112581

12582+
netdev_lock(dev);
1257212583
tg3_full_lock(tp, irq_sync);
1257312584

1257412585
tp->rx_pending = ering->rx_pending;
@@ -12597,6 +12608,7 @@ static int tg3_set_ringparam(struct net_device *dev,
1259712608
}
1259812609

1259912610
tg3_full_unlock(tp);
12611+
netdev_unlock(dev);
1260012612

1260112613
if (irq_sync && !err)
1260212614
tg3_phy_start(tp);
@@ -12678,6 +12690,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
1267812690
irq_sync = 1;
1267912691
}
1268012692

12693+
netdev_lock(dev);
1268112694
tg3_full_lock(tp, irq_sync);
1268212695

1268312696
if (epause->autoneg)
@@ -12707,6 +12720,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
1270712720
}
1270812721

1270912722
tg3_full_unlock(tp);
12723+
netdev_unlock(dev);
1271012724
}
1271112725

1271212726
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED;
@@ -13911,6 +13925,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1391113925
data[TG3_INTERRUPT_TEST] = 1;
1391213926
}
1391313927

13928+
netdev_lock(dev);
1391413929
tg3_full_lock(tp, 0);
1391513930

1391613931
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
@@ -13922,6 +13937,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1392213937
}
1392313938

1392413939
tg3_full_unlock(tp);
13940+
netdev_unlock(dev);
1392513941

1392613942
if (irq_sync && !err2)
1392713943
tg3_phy_start(tp);
@@ -14365,6 +14381,7 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
1436514381

1436614382
tg3_set_mtu(dev, tp, new_mtu);
1436714383

14384+
netdev_lock(dev);
1436814385
tg3_full_lock(tp, 1);
1436914386

1437014387
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
@@ -14384,6 +14401,7 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
1438414401
tg3_netif_start(tp);
1438514402

1438614403
tg3_full_unlock(tp);
14404+
netdev_unlock(dev);
1438714405

1438814406
if (!err)
1438914407
tg3_phy_start(tp);
@@ -18164,6 +18182,7 @@ static int tg3_resume(struct device *device)
1816418182

1816518183
netif_device_attach(dev);
1816618184

18185+
netdev_lock(dev);
1816718186
tg3_full_lock(tp, 0);
1816818187

1816918188
tg3_ape_driver_state_change(tp, RESET_KIND_INIT);
@@ -18180,6 +18199,7 @@ static int tg3_resume(struct device *device)
1818018199

1818118200
out:
1818218201
tg3_full_unlock(tp);
18202+
netdev_unlock(dev);
1818318203

1818418204
if (!err)
1818518205
tg3_phy_start(tp);
@@ -18260,7 +18280,9 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
1826018280
done:
1826118281
if (state == pci_channel_io_perm_failure) {
1826218282
if (netdev) {
18283+
netdev_lock(netdev);
1826318284
tg3_napi_enable(tp);
18285+
netdev_unlock(netdev);
1826418286
dev_close(netdev);
1826518287
}
1826618288
err = PCI_ERS_RESULT_DISCONNECT;
@@ -18314,7 +18336,9 @@ static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev)
1831418336

1831518337
done:
1831618338
if (rc != PCI_ERS_RESULT_RECOVERED && netdev && netif_running(netdev)) {
18339+
netdev_lock(netdev);
1831718340
tg3_napi_enable(tp);
18341+
netdev_unlock(netdev);
1831818342
dev_close(netdev);
1831918343
}
1832018344
rtnl_unlock();
@@ -18340,12 +18364,14 @@ static void tg3_io_resume(struct pci_dev *pdev)
1834018364
if (!netdev || !netif_running(netdev))
1834118365
goto done;
1834218366

18367+
netdev_lock(netdev);
1834318368
tg3_full_lock(tp, 0);
1834418369
tg3_ape_driver_state_change(tp, RESET_KIND_INIT);
1834518370
tg3_flag_set(tp, INIT_COMPLETE);
1834618371
err = tg3_restart_hw(tp, true);
1834718372
if (err) {
1834818373
tg3_full_unlock(tp);
18374+
netdev_unlock(netdev);
1834918375
netdev_err(netdev, "Cannot restart hardware after reset.\n");
1835018376
goto done;
1835118377
}
@@ -18357,6 +18383,7 @@ static void tg3_io_resume(struct pci_dev *pdev)
1835718383
tg3_netif_start(tp);
1835818384

1835918385
tg3_full_unlock(tp);
18386+
netdev_unlock(netdev);
1836018387

1836118388
tg3_phy_start(tp);
1836218389

drivers/net/ethernet/nvidia/forcedeth.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,20 +1120,6 @@ static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
11201120
}
11211121
}
11221122

1123-
static void nv_napi_enable(struct net_device *dev)
1124-
{
1125-
struct fe_priv *np = get_nvpriv(dev);
1126-
1127-
napi_enable(&np->napi);
1128-
}
1129-
1130-
static void nv_napi_disable(struct net_device *dev)
1131-
{
1132-
struct fe_priv *np = get_nvpriv(dev);
1133-
1134-
napi_disable(&np->napi);
1135-
}
1136-
11371123
#define MII_READ (-1)
11381124
/* mii_rw: read/write a register on the PHY.
11391125
*
@@ -3114,7 +3100,7 @@ static int nv_change_mtu(struct net_device *dev, int new_mtu)
31143100
* Changing the MTU is a rare event, it shouldn't matter.
31153101
*/
31163102
nv_disable_irq(dev);
3117-
nv_napi_disable(dev);
3103+
napi_disable(&np->napi);
31183104
netif_tx_lock_bh(dev);
31193105
netif_addr_lock(dev);
31203106
spin_lock(&np->lock);
@@ -3143,7 +3129,7 @@ static int nv_change_mtu(struct net_device *dev, int new_mtu)
31433129
spin_unlock(&np->lock);
31443130
netif_addr_unlock(dev);
31453131
netif_tx_unlock_bh(dev);
3146-
nv_napi_enable(dev);
3132+
napi_enable(&np->napi);
31473133
nv_enable_irq(dev);
31483134
}
31493135
return 0;
@@ -4731,7 +4717,7 @@ static int nv_set_ringparam(struct net_device *dev,
47314717

47324718
if (netif_running(dev)) {
47334719
nv_disable_irq(dev);
4734-
nv_napi_disable(dev);
4720+
napi_disable(&np->napi);
47354721
netif_tx_lock_bh(dev);
47364722
netif_addr_lock(dev);
47374723
spin_lock(&np->lock);
@@ -4784,7 +4770,7 @@ static int nv_set_ringparam(struct net_device *dev,
47844770
spin_unlock(&np->lock);
47854771
netif_addr_unlock(dev);
47864772
netif_tx_unlock_bh(dev);
4787-
nv_napi_enable(dev);
4773+
napi_enable(&np->napi);
47884774
nv_enable_irq(dev);
47894775
}
47904776
return 0;
@@ -5277,7 +5263,7 @@ static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64
52775263
if (test->flags & ETH_TEST_FL_OFFLINE) {
52785264
if (netif_running(dev)) {
52795265
netif_stop_queue(dev);
5280-
nv_napi_disable(dev);
5266+
napi_disable(&np->napi);
52815267
netif_tx_lock_bh(dev);
52825268
netif_addr_lock(dev);
52835269
spin_lock_irq(&np->lock);
@@ -5334,7 +5320,7 @@ static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64
53345320
/* restart rx engine */
53355321
nv_start_rxtx(dev);
53365322
netif_start_queue(dev);
5337-
nv_napi_enable(dev);
5323+
napi_enable(&np->napi);
53385324
nv_enable_hw_interrupts(dev, np->irqmask);
53395325
}
53405326
}
@@ -5576,6 +5562,7 @@ static int nv_open(struct net_device *dev)
55765562
/* ask for interrupts */
55775563
nv_enable_hw_interrupts(dev, np->irqmask);
55785564

5565+
netdev_lock(dev);
55795566
spin_lock_irq(&np->lock);
55805567
writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
55815568
writel(0, base + NvRegMulticastAddrB);
@@ -5594,7 +5581,7 @@ static int nv_open(struct net_device *dev)
55945581
ret = nv_update_linkspeed(dev);
55955582
nv_start_rxtx(dev);
55965583
netif_start_queue(dev);
5597-
nv_napi_enable(dev);
5584+
napi_enable_locked(&np->napi);
55985585

55995586
if (ret) {
56005587
netif_carrier_on(dev);
@@ -5611,6 +5598,7 @@ static int nv_open(struct net_device *dev)
56115598
round_jiffies(jiffies + STATS_INTERVAL));
56125599

56135600
spin_unlock_irq(&np->lock);
5601+
netdev_unlock(dev);
56145602

56155603
/* If the loopback feature was set while the device was down, make sure
56165604
* that it's set correctly now.
@@ -5632,7 +5620,7 @@ static int nv_close(struct net_device *dev)
56325620
spin_lock_irq(&np->lock);
56335621
np->in_shutdown = 1;
56345622
spin_unlock_irq(&np->lock);
5635-
nv_napi_disable(dev);
5623+
napi_disable(&np->napi);
56365624
synchronize_irq(np->pci_dev->irq);
56375625

56385626
del_timer_sync(&np->oom_kick);

drivers/net/ethernet/realtek/8139too.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,7 @@ static void rtl8139_tx_timeout_task (struct work_struct *work)
16841684
if (tmp8 & CmdTxEnb)
16851685
RTL_W8 (ChipCmd, CmdRxEnb);
16861686

1687+
netdev_lock(dev);
16871688
spin_lock_bh(&tp->rx_lock);
16881689
/* Disable interrupts by clearing the interrupt mask. */
16891690
RTL_W16 (IntrMask, 0x0000);
@@ -1694,11 +1695,12 @@ static void rtl8139_tx_timeout_task (struct work_struct *work)
16941695
spin_unlock_irq(&tp->lock);
16951696

16961697
/* ...and finally, reset everything */
1697-
napi_enable(&tp->napi);
1698+
napi_enable_locked(&tp->napi);
16981699
rtl8139_hw_start(dev);
16991700
netif_wake_queue(dev);
17001701

17011702
spin_unlock_bh(&tp->rx_lock);
1703+
netdev_unlock(dev);
17021704
}
17031705

17041706
static void rtl8139_tx_timeout(struct net_device *dev, unsigned int txqueue)

drivers/net/ethernet/sun/niu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6086,7 +6086,7 @@ static void niu_enable_napi(struct niu *np)
60866086
int i;
60876087

60886088
for (i = 0; i < np->num_ldg; i++)
6089-
napi_enable(&np->ldg[i].napi);
6089+
napi_enable_locked(&np->ldg[i].napi);
60906090
}
60916091

60926092
static void niu_disable_napi(struct niu *np)
@@ -6116,7 +6116,9 @@ static int niu_open(struct net_device *dev)
61166116
if (err)
61176117
goto out_free_channels;
61186118

6119+
netdev_lock(dev);
61196120
niu_enable_napi(np);
6121+
netdev_unlock(dev);
61206122

61216123
spin_lock_irq(&np->lock);
61226124

@@ -6521,6 +6523,7 @@ static void niu_reset_task(struct work_struct *work)
65216523

65226524
niu_reset_buffers(np);
65236525

6526+
netdev_lock(np->dev);
65246527
spin_lock_irqsave(&np->lock, flags);
65256528

65266529
err = niu_init_hw(np);
@@ -6531,6 +6534,7 @@ static void niu_reset_task(struct work_struct *work)
65316534
}
65326535

65336536
spin_unlock_irqrestore(&np->lock, flags);
6537+
netdev_unlock(np->dev);
65346538
}
65356539

65366540
static void niu_tx_timeout(struct net_device *dev, unsigned int txqueue)
@@ -6761,7 +6765,9 @@ static int niu_change_mtu(struct net_device *dev, int new_mtu)
67616765

67626766
niu_free_channels(np);
67636767

6768+
netdev_lock(dev);
67646769
niu_enable_napi(np);
6770+
netdev_unlock(dev);
67656771

67666772
err = niu_alloc_channels(np);
67676773
if (err)
@@ -9937,6 +9943,7 @@ static int __maybe_unused niu_resume(struct device *dev_d)
99379943

99389944
spin_lock_irqsave(&np->lock, flags);
99399945

9946+
netdev_lock(dev);
99409947
err = niu_init_hw(np);
99419948
if (!err) {
99429949
np->timer.expires = jiffies + HZ;
@@ -9945,6 +9952,7 @@ static int __maybe_unused niu_resume(struct device *dev_d)
99459952
}
99469953

99479954
spin_unlock_irqrestore(&np->lock, flags);
9955+
netdev_unlock(dev);
99489956

99499957
return err;
99509958
}

0 commit comments

Comments
 (0)