mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
net: ethernet: mtk_eth_soc: allocate dummy netdev sooner
The RX rings and the shared NAPI are carried by an internal "dummy" netdev
(eth->dummy_dev). mtk_probe() creates that dummy device, and adds the
shared tx/rx NAPI to it, only after the MAC netdevs have been registered.
That order has been there since the MT7623 support was added and leaves a
window in which the netdevs are visible to the network core before the
shared NAPI and the dummy device exist.
If anything brings the first netdev up during that window (e.g. netifd
opening the WAN link the instant the interface is registered), the
first-open path runs without them. On NETSYS v2 and later SoCs
mtk_rx_alloc() -> __xdp_rxq_info_reg() then dereferences eth->dummy_dev ==
NULL:
WARNING: CPU: ... Missing net_device from driver
in net/core/xdp.c and mtk_open() fails with -ENODEV. On NETSYS v1 SoCs
(MT7621/MT7622/MT7623/MT7629) there is no page pool, so the same open
instead calls napi_enable() on a napi_struct that netif_napi_add() has not
initialised yet and dereferences a NULL napi->dev.
Allocate the dummy netdev and add the shared tx/rx NAPI to it before the
register_netdev() loop. Both the dummy-allocation failure and a
register_netdev() failure now unwind through mtk_unreg_dev(), which
unregisters the net_device notifiers and the netdevs registered so far,
stopping a concurrently-opened netdev (ndo_stop) and its NAPI before the
dummy carrier is freed.
A netdev that opened during the window can also have queued the
frame-engine reset worker (via the tx watchdog or phylink), so the probe
error path now cancels eth->pending_work before freeing the shared state,
as mtk_cleanup() already does on remove.
Fixes: 656e705243 ("net-next: mediatek: add support for MT7623 ethernet")
Signed-off-by: Sandeep Haemoon <sandeeph@loljews.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/patch-e52c13380b0768fec63af04c80e4b487@loljews.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
5f0764cb1c
commit
6f0c2c4f5e
|
|
@ -5341,6 +5341,22 @@ static int mtk_probe(struct platform_device *pdev)
|
|||
}
|
||||
}
|
||||
|
||||
/* we run 2 devices on the same DMA ring so we need a dummy device
|
||||
* for NAPI to work. Allocate it before registering the netdevs so a
|
||||
* concurrent ndo_open (e.g. netifd bringing the first netdev up the
|
||||
* instant it is registered) never observes eth->dummy_dev == NULL in
|
||||
* mtk_dma_init() -> mtk_rx_alloc() -> __xdp_rxq_info_reg() (net/core/xdp.c
|
||||
* "Missing net_device from driver") and fails the first open.
|
||||
*/
|
||||
eth->dummy_dev = alloc_netdev_dummy(0);
|
||||
if (!eth->dummy_dev) {
|
||||
err = -ENOMEM;
|
||||
dev_err(eth->dev, "failed to allocated dummy device\n");
|
||||
goto err_unreg_netdev;
|
||||
}
|
||||
netif_napi_add(eth->dummy_dev, ð->tx_napi, mtk_napi_tx);
|
||||
netif_napi_add(eth->dummy_dev, ð->rx_napi, mtk_napi_rx);
|
||||
|
||||
for (i = 0; i < MTK_MAX_DEVS; i++) {
|
||||
if (!eth->netdev[i])
|
||||
continue;
|
||||
|
|
@ -5355,18 +5371,6 @@ static int mtk_probe(struct platform_device *pdev)
|
|||
eth->netdev[i]->base_addr, eth->irq[MTK_FE_IRQ_SHARED]);
|
||||
}
|
||||
|
||||
/* we run 2 devices on the same DMA ring so we need a dummy device
|
||||
* for NAPI to work
|
||||
*/
|
||||
eth->dummy_dev = alloc_netdev_dummy(0);
|
||||
if (!eth->dummy_dev) {
|
||||
err = -ENOMEM;
|
||||
dev_err(eth->dev, "failed to allocated dummy device\n");
|
||||
goto err_unreg_netdev;
|
||||
}
|
||||
netif_napi_add(eth->dummy_dev, ð->tx_napi, mtk_napi_tx);
|
||||
netif_napi_add(eth->dummy_dev, ð->rx_napi, mtk_napi_rx);
|
||||
|
||||
platform_set_drvdata(pdev, eth);
|
||||
schedule_delayed_work(ð->reset.monitor_work,
|
||||
MTK_DMA_MONITOR_TIMEOUT);
|
||||
|
|
@ -5376,6 +5380,16 @@ static int mtk_probe(struct platform_device *pdev)
|
|||
err_unreg_netdev:
|
||||
mtk_unreg_dev(eth);
|
||||
err_deinit_ppe:
|
||||
/* A netdev opened while probe was still registering can have queued
|
||||
* the frame-engine reset worker, which takes rtnl and drives the
|
||||
* hardware; cancel it before anything below is torn down.
|
||||
*/
|
||||
cancel_work_sync(ð->pending_work);
|
||||
if (eth->dummy_dev) {
|
||||
netif_napi_del(ð->tx_napi);
|
||||
netif_napi_del(ð->rx_napi);
|
||||
free_netdev(eth->dummy_dev);
|
||||
}
|
||||
mtk_ppe_deinit(eth);
|
||||
mtk_mdio_cleanup(eth);
|
||||
err_free_dev:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user