Skip to content

Commit 5689bd3

Browse files
author
CKI KWF Bot
committed
Merge: CNB98: net: use netdev->lock to protect NAPI
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7332 Backport "net: use netdev->lock to protect NAPI" and related fixes. JIRA: https://issues.redhat.com/browse/RHEL-87382 Omitted-fix: 4bc1281 ("virtio-net: disable delayed refill when pausing rx"). Omitted-fix: 1e20324 ("virtio-net: don't re-enable refill work too early when NAPI is disabled"). - Targeted code is not part of the RHEL9 tree. Signed-off-by: Mohammad Heib <mheib@redhat.com> Approved-by: Murphy Zhou <xzhou@redhat.com> Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com> Approved-by: Sabrina Dubroca <sdubroca@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents abbb127 + f7bf6ee commit 5689bd3

File tree

43 files changed

+711
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+711
-253
lines changed

drivers/infiniband/hw/hfi1/netdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct hfi1_netdev_rxq {
4949
* When 0 receive queues will be freed.
5050
*/
5151
struct hfi1_netdev_rx {
52-
struct net_device rx_napi;
52+
struct net_device *rx_napi;
5353
struct hfi1_devdata *dd;
5454
struct hfi1_netdev_rxq *rxq;
5555
int num_rx_q;

drivers/infiniband/hw/hfi1/netdev_rx.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int hfi1_netdev_rxq_init(struct hfi1_netdev_rx *rx)
188188
int i;
189189
int rc;
190190
struct hfi1_devdata *dd = rx->dd;
191-
struct net_device *dev = &rx->rx_napi;
191+
struct net_device *dev = rx->rx_napi;
192192

193193
rx->num_rx_q = dd->num_netdev_contexts;
194194
rx->rxq = kcalloc_node(rx->num_rx_q, sizeof(*rx->rxq),
@@ -360,7 +360,11 @@ int hfi1_alloc_rx(struct hfi1_devdata *dd)
360360
if (!rx)
361361
return -ENOMEM;
362362
rx->dd = dd;
363-
init_dummy_netdev(&rx->rx_napi);
363+
rx->rx_napi = alloc_netdev_dummy(0);
364+
if (!rx->rx_napi) {
365+
kfree(rx);
366+
return -ENOMEM;
367+
}
364368

365369
xa_init(&rx->dev_tbl);
366370
atomic_set(&rx->enabled, 0);
@@ -374,6 +378,7 @@ void hfi1_free_rx(struct hfi1_devdata *dd)
374378
{
375379
if (dd->netdev_rx) {
376380
dd_dev_info(dd, "hfi1 rx freed\n");
381+
free_netdev(dd->netdev_rx->rx_napi);
377382
kfree(dd->netdev_rx);
378383
dd->netdev_rx = NULL;
379384
}

drivers/net/ethernet/amd/pcnet32.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ static void pcnet32_netif_start(struct net_device *dev)
462462
val = lp->a->read_csr(ioaddr, CSR3);
463463
val &= 0x00ff;
464464
lp->a->write_csr(ioaddr, CSR3, val);
465-
napi_enable(&lp->napi);
465+
napi_enable_locked(&lp->napi);
466466
}
467467

468468
/*
@@ -889,6 +889,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
889889
if (netif_running(dev))
890890
pcnet32_netif_stop(dev);
891891

892+
netdev_lock(dev);
892893
spin_lock_irqsave(&lp->lock, flags);
893894
lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
894895

@@ -920,6 +921,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
920921
}
921922

922923
spin_unlock_irqrestore(&lp->lock, flags);
924+
netdev_unlock(dev);
923925

924926
netif_info(lp, drv, dev, "Ring Param Settings: RX: %d, TX: %d\n",
925927
lp->rx_ring_size, lp->tx_ring_size);
@@ -985,6 +987,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
985987
if (netif_running(dev))
986988
pcnet32_netif_stop(dev);
987989

990+
netdev_lock(dev);
988991
spin_lock_irqsave(&lp->lock, flags);
989992
lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
990993

@@ -1122,6 +1125,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
11221125
lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
11231126
}
11241127
spin_unlock_irqrestore(&lp->lock, flags);
1128+
netdev_unlock(dev);
11251129

11261130
return rc;
11271131
} /* end pcnet32_loopback_test */
@@ -2096,6 +2100,7 @@ static int pcnet32_open(struct net_device *dev)
20962100
return -EAGAIN;
20972101
}
20982102

2103+
netdev_lock(dev);
20992104
spin_lock_irqsave(&lp->lock, flags);
21002105
/* Check for a valid station address */
21012106
if (!is_valid_ether_addr(dev->dev_addr)) {
@@ -2261,7 +2266,7 @@ static int pcnet32_open(struct net_device *dev)
22612266
goto err_free_ring;
22622267
}
22632268

2264-
napi_enable(&lp->napi);
2269+
napi_enable_locked(&lp->napi);
22652270

22662271
/* Re-initialize the PCNET32, and start it when done. */
22672272
lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
@@ -2295,6 +2300,7 @@ static int pcnet32_open(struct net_device *dev)
22952300
lp->a->read_csr(ioaddr, CSR0));
22962301

22972302
spin_unlock_irqrestore(&lp->lock, flags);
2303+
netdev_unlock(dev);
22982304

22992305
return 0; /* Always succeed */
23002306

@@ -2310,6 +2316,7 @@ static int pcnet32_open(struct net_device *dev)
23102316

23112317
err_free_irq:
23122318
spin_unlock_irqrestore(&lp->lock, flags);
2319+
netdev_unlock(dev);
23132320
free_irq(dev->irq, dev);
23142321
return rc;
23152322
}

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7407,16 +7407,16 @@ static void tg3_napi_enable(struct tg3 *tp)
74077407
int i;
74087408

74097409
for (i = 0; i < tp->irq_cnt; i++)
7410-
napi_enable(&tp->napi[i].napi);
7410+
napi_enable_locked(&tp->napi[i].napi);
74117411
}
74127412

74137413
static void tg3_napi_init(struct tg3 *tp)
74147414
{
74157415
int i;
74167416

7417-
netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll);
7417+
netif_napi_add_locked(tp->dev, &tp->napi[0].napi, tg3_poll);
74187418
for (i = 1; i < tp->irq_cnt; i++)
7419-
netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix);
7419+
netif_napi_add_locked(tp->dev, &tp->napi[i].napi, tg3_poll_msix);
74207420
}
74217421

74227422
static void tg3_napi_fini(struct tg3 *tp)
@@ -11227,6 +11227,8 @@ static void tg3_timer_stop(struct tg3 *tp)
1122711227
static int tg3_restart_hw(struct tg3 *tp, bool reset_phy)
1122811228
__releases(tp->lock)
1122911229
__acquires(tp->lock)
11230+
__releases(tp->dev->lock)
11231+
__acquires(tp->dev->lock)
1123011232
{
1123111233
int err;
1123211234

@@ -11239,7 +11241,9 @@ static int tg3_restart_hw(struct tg3 *tp, bool reset_phy)
1123911241
tg3_timer_stop(tp);
1124011242
tp->irq_sync = 0;
1124111243
tg3_napi_enable(tp);
11244+
netdev_unlock(tp->dev);
1124211245
dev_close(tp->dev);
11246+
netdev_lock(tp->dev);
1124311247
tg3_full_lock(tp, 0);
1124411248
}
1124511249
return err;
@@ -11267,6 +11271,7 @@ static void tg3_reset_task(struct work_struct *work)
1126711271

1126811272
tg3_netif_stop(tp);
1126911273

11274+
netdev_lock(tp->dev);
1127011275
tg3_full_lock(tp, 1);
1127111276

1127211277
if (tg3_flag(tp, TX_RECOVERY_PENDING)) {
@@ -11286,12 +11291,14 @@ static void tg3_reset_task(struct work_struct *work)
1128611291
* call cancel_work_sync() and wait forever.
1128711292
*/
1128811293
tg3_flag_clear(tp, RESET_TASK_PENDING);
11294+
netdev_unlock(tp->dev);
1128911295
dev_close(tp->dev);
1129011296
goto out;
1129111297
}
1129211298

1129311299
tg3_netif_start(tp);
1129411300
tg3_full_unlock(tp);
11301+
netdev_unlock(tp->dev);
1129511302
tg3_phy_start(tp);
1129611303
tg3_flag_clear(tp, RESET_TASK_PENDING);
1129711304
out:
@@ -11652,9 +11659,11 @@ static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq,
1165211659
if (err)
1165311660
goto out_ints_fini;
1165411661

11662+
netdev_lock(dev);
1165511663
tg3_napi_init(tp);
1165611664

1165711665
tg3_napi_enable(tp);
11666+
netdev_unlock(dev);
1165811667

1165911668
for (i = 0; i < tp->irq_cnt; i++) {
1166011669
err = tg3_request_irq(tp, i);
@@ -12538,6 +12547,7 @@ static int tg3_set_ringparam(struct net_device *dev,
1253812547
irq_sync = 1;
1253912548
}
1254012549

12550+
netdev_lock(dev);
1254112551
tg3_full_lock(tp, irq_sync);
1254212552

1254312553
tp->rx_pending = ering->rx_pending;
@@ -12566,6 +12576,7 @@ static int tg3_set_ringparam(struct net_device *dev,
1256612576
}
1256712577

1256812578
tg3_full_unlock(tp);
12579+
netdev_unlock(dev);
1256912580

1257012581
if (irq_sync && !err)
1257112582
tg3_phy_start(tp);
@@ -12647,6 +12658,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
1264712658
irq_sync = 1;
1264812659
}
1264912660

12661+
netdev_lock(dev);
1265012662
tg3_full_lock(tp, irq_sync);
1265112663

1265212664
if (epause->autoneg)
@@ -12676,6 +12688,7 @@ static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
1267612688
}
1267712689

1267812690
tg3_full_unlock(tp);
12691+
netdev_unlock(dev);
1267912692
}
1268012693

1268112694
tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED;
@@ -13876,6 +13889,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1387613889
data[TG3_INTERRUPT_TEST] = 1;
1387713890
}
1387813891

13892+
netdev_lock(dev);
1387913893
tg3_full_lock(tp, 0);
1388013894

1388113895
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
@@ -13887,6 +13901,7 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
1388713901
}
1388813902

1388913903
tg3_full_unlock(tp);
13904+
netdev_unlock(dev);
1389013905

1389113906
if (irq_sync && !err2)
1389213907
tg3_phy_start(tp);
@@ -14330,6 +14345,7 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
1433014345

1433114346
tg3_set_mtu(dev, tp, new_mtu);
1433214347

14348+
netdev_lock(dev);
1433314349
tg3_full_lock(tp, 1);
1433414350

1433514351
tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
@@ -14349,6 +14365,7 @@ static int tg3_change_mtu(struct net_device *dev, int new_mtu)
1434914365
tg3_netif_start(tp);
1435014366

1435114367
tg3_full_unlock(tp);
14368+
netdev_unlock(dev);
1435214369

1435314370
if (!err)
1435414371
tg3_phy_start(tp);
@@ -18124,6 +18141,7 @@ static int tg3_resume(struct device *device)
1812418141

1812518142
netif_device_attach(dev);
1812618143

18144+
netdev_lock(dev);
1812718145
tg3_full_lock(tp, 0);
1812818146

1812918147
tg3_ape_driver_state_change(tp, RESET_KIND_INIT);
@@ -18140,6 +18158,7 @@ static int tg3_resume(struct device *device)
1814018158

1814118159
out:
1814218160
tg3_full_unlock(tp);
18161+
netdev_unlock(dev);
1814318162

1814418163
if (!err)
1814518164
tg3_phy_start(tp);
@@ -18277,7 +18296,9 @@ static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev,
1827718296
done:
1827818297
if (state == pci_channel_io_perm_failure) {
1827918298
if (netdev) {
18299+
netdev_lock(netdev);
1828018300
tg3_napi_enable(tp);
18301+
netdev_unlock(netdev);
1828118302
dev_close(netdev);
1828218303
}
1828318304
err = PCI_ERS_RESULT_DISCONNECT;
@@ -18331,7 +18352,9 @@ static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev)
1833118352

1833218353
done:
1833318354
if (rc != PCI_ERS_RESULT_RECOVERED && netdev && netif_running(netdev)) {
18355+
netdev_lock(netdev);
1833418356
tg3_napi_enable(tp);
18357+
netdev_unlock(netdev);
1833518358
dev_close(netdev);
1833618359
}
1833718360
rtnl_unlock();
@@ -18357,12 +18380,14 @@ static void tg3_io_resume(struct pci_dev *pdev)
1835718380
if (!netdev || !netif_running(netdev))
1835818381
goto done;
1835918382

18383+
netdev_lock(netdev);
1836018384
tg3_full_lock(tp, 0);
1836118385
tg3_ape_driver_state_change(tp, RESET_KIND_INIT);
1836218386
tg3_flag_set(tp, INIT_COMPLETE);
1836318387
err = tg3_restart_hw(tp, true);
1836418388
if (err) {
1836518389
tg3_full_unlock(tp);
18390+
netdev_unlock(netdev);
1836618391
netdev_err(netdev, "Cannot restart hardware after reset.\n");
1836718392
goto done;
1836818393
}
@@ -18374,6 +18399,7 @@ static void tg3_io_resume(struct pci_dev *pdev)
1837418399
tg3_netif_start(tp);
1837518400

1837618401
tg3_full_unlock(tp);
18402+
netdev_unlock(netdev);
1837718403

1837818404
tg3_phy_start(tp);
1837918405

drivers/net/ethernet/ibm/emac/mal.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,13 @@ static int mal_probe(struct platform_device *ofdev)
603603
INIT_LIST_HEAD(&mal->list);
604604
spin_lock_init(&mal->lock);
605605

606-
init_dummy_netdev(&mal->dummy_dev);
606+
mal->dummy_dev = alloc_netdev_dummy(0);
607+
if (!mal->dummy_dev) {
608+
err = -ENOMEM;
609+
goto fail_unmap;
610+
}
607611

608-
netif_napi_add_weight(&mal->dummy_dev, &mal->napi, mal_poll,
612+
netif_napi_add_weight(mal->dummy_dev, &mal->napi, mal_poll,
609613
CONFIG_IBM_EMAC_POLL_WEIGHT);
610614

611615
/* Load power-on reset defaults */
@@ -635,7 +639,7 @@ static int mal_probe(struct platform_device *ofdev)
635639
GFP_KERNEL);
636640
if (mal->bd_virt == NULL) {
637641
err = -ENOMEM;
638-
goto fail_unmap;
642+
goto fail_dummy;
639643
}
640644

641645
for (i = 0; i < mal->num_tx_chans; ++i)
@@ -701,6 +705,8 @@ static int mal_probe(struct platform_device *ofdev)
701705
free_irq(mal->serr_irq, mal);
702706
fail2:
703707
dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma);
708+
fail_dummy:
709+
free_netdev(mal->dummy_dev);
704710
fail_unmap:
705711
dcr_unmap(mal->dcr_host, 0x100);
706712
fail:
@@ -732,6 +738,8 @@ static int mal_remove(struct platform_device *ofdev)
732738

733739
mal_reset(mal);
734740

741+
free_netdev(mal->dummy_dev);
742+
735743
dma_free_coherent(&ofdev->dev,
736744
sizeof(struct mal_descriptor) *
737745
(NUM_TX_BUFF * mal->num_tx_chans +

drivers/net/ethernet/ibm/emac/mal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct mal_instance {
205205
int index;
206206
spinlock_t lock;
207207

208-
struct net_device dummy_dev;
208+
struct net_device *dummy_dev;
209209

210210
unsigned int features;
211211
};

0 commit comments

Comments
 (0)