Skip to content

Commit 0b8c878

Browse files
haokexinkuba-moo
authored andcommitted
net: cpsw: Execute ndo_set_rx_mode callback in a work queue
Commit 1767bb2 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.") removed the RTNL lock for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP operations. However, this change triggered the following call trace on my BeagleBone Black board: WARNING: net/8021q/vlan_core.c:236 at vlan_for_each+0x120/0x124, CPU#0: rpcbind/481 RTNL: assertion failed at net/8021q/vlan_core.c (236) Modules linked in: CPU: 0 UID: 997 PID: 481 Comm: rpcbind Not tainted 6.19.0-rc7-next-20260130-yocto-standard+ #35 PREEMPT Hardware name: Generic AM33XX (Flattened Device Tree) Call trace: unwind_backtrace from show_stack+0x28/0x2c show_stack from dump_stack_lvl+0x30/0x38 dump_stack_lvl from __warn+0xb8/0x11c __warn from warn_slowpath_fmt+0x130/0x194 warn_slowpath_fmt from vlan_for_each+0x120/0x124 vlan_for_each from cpsw_add_mc_addr+0x54/0x98 cpsw_add_mc_addr from __hw_addr_ref_sync_dev+0xc4/0xec __hw_addr_ref_sync_dev from __dev_mc_add+0x78/0x88 __dev_mc_add from igmp6_group_added+0x84/0xec igmp6_group_added from __ipv6_dev_mc_inc+0x1fc/0x2f0 __ipv6_dev_mc_inc from __ipv6_sock_mc_join+0x124/0x1b4 __ipv6_sock_mc_join from do_ipv6_setsockopt+0x84c/0x1168 do_ipv6_setsockopt from ipv6_setsockopt+0x88/0xc8 ipv6_setsockopt from do_sock_setsockopt+0xe8/0x19c do_sock_setsockopt from __sys_setsockopt+0x84/0xac __sys_setsockopt from ret_fast_syscall+0x0/0x54 This trace occurs because vlan_for_each() is called within cpsw_ndo_set_rx_mode(), which expects the RTNL lock to be held. Since modifying vlan_for_each() to operate without the RTNL lock is not straightforward, and because ndo_set_rx_mode() is invoked both with and without the RTNL lock across different code paths, simply adding rtnl_lock() in cpsw_ndo_set_rx_mode() is not a viable solution. To resolve this issue, we opt to execute the actual processing within a work queue, following the approach used by the icssg-prueth driver. Please note: To reproduce this issue, I manually reverted the changes to am335x-bone-common.dtsi from commit c477358 ("ARM: dts: am335x-bone: switch to new cpsw switch drv") in order to revert to the legacy cpsw driver. Fixes: 1767bb2 ("ipv6: mcast: Don't hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.") Signed-off-by: Kevin Hao <haokexin@gmail.com> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260203-bbb-v5-2-ea0ea217a85c@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c0b5dc7 commit 0b8c878

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

drivers/net/ethernet/ti/cpsw.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,20 +305,27 @@ static int cpsw_purge_all_mc(struct net_device *ndev, const u8 *addr, int num)
305305
return 0;
306306
}
307307

308-
static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
308+
static void cpsw_ndo_set_rx_mode_work(struct work_struct *work)
309309
{
310-
struct cpsw_priv *priv = netdev_priv(ndev);
310+
struct cpsw_priv *priv = container_of(work, struct cpsw_priv, rx_mode_work);
311311
struct cpsw_common *cpsw = priv->cpsw;
312+
struct net_device *ndev = priv->ndev;
312313
int slave_port = -1;
313314

315+
rtnl_lock();
316+
if (!netif_running(ndev))
317+
goto unlock_rtnl;
318+
319+
netif_addr_lock_bh(ndev);
320+
314321
if (cpsw->data.dual_emac)
315322
slave_port = priv->emac_port + 1;
316323

317324
if (ndev->flags & IFF_PROMISC) {
318325
/* Enable promiscuous mode */
319326
cpsw_set_promiscious(ndev, true);
320327
cpsw_ale_set_allmulti(cpsw->ale, IFF_ALLMULTI, slave_port);
321-
return;
328+
goto unlock_addr;
322329
} else {
323330
/* Disable promiscuous mode */
324331
cpsw_set_promiscious(ndev, false);
@@ -331,6 +338,18 @@ static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
331338
/* add/remove mcast address either for real netdev or for vlan */
332339
__hw_addr_ref_sync_dev(&ndev->mc, ndev, cpsw_add_mc_addr,
333340
cpsw_del_mc_addr);
341+
342+
unlock_addr:
343+
netif_addr_unlock_bh(ndev);
344+
unlock_rtnl:
345+
rtnl_unlock();
346+
}
347+
348+
static void cpsw_ndo_set_rx_mode(struct net_device *ndev)
349+
{
350+
struct cpsw_priv *priv = netdev_priv(ndev);
351+
352+
schedule_work(&priv->rx_mode_work);
334353
}
335354

336355
static unsigned int cpsw_rxbuf_total_len(unsigned int len)
@@ -1472,6 +1491,7 @@ static int cpsw_probe_dual_emac(struct cpsw_priv *priv)
14721491
priv_sl2->ndev = ndev;
14731492
priv_sl2->dev = &ndev->dev;
14741493
priv_sl2->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
1494+
INIT_WORK(&priv_sl2->rx_mode_work, cpsw_ndo_set_rx_mode_work);
14751495

14761496
if (is_valid_ether_addr(data->slave_data[1].mac_addr)) {
14771497
memcpy(priv_sl2->mac_addr, data->slave_data[1].mac_addr,
@@ -1653,6 +1673,7 @@ static int cpsw_probe(struct platform_device *pdev)
16531673
priv->dev = dev;
16541674
priv->msg_enable = netif_msg_init(debug_level, CPSW_DEBUG);
16551675
priv->emac_port = 0;
1676+
INIT_WORK(&priv->rx_mode_work, cpsw_ndo_set_rx_mode_work);
16561677

16571678
if (is_valid_ether_addr(data->slave_data[0].mac_addr)) {
16581679
memcpy(priv->mac_addr, data->slave_data[0].mac_addr, ETH_ALEN);
@@ -1758,6 +1779,8 @@ static int cpsw_probe(struct platform_device *pdev)
17581779
static void cpsw_remove(struct platform_device *pdev)
17591780
{
17601781
struct cpsw_common *cpsw = platform_get_drvdata(pdev);
1782+
struct net_device *ndev;
1783+
struct cpsw_priv *priv;
17611784
int i, ret;
17621785

17631786
ret = pm_runtime_resume_and_get(&pdev->dev);
@@ -1770,9 +1793,15 @@ static void cpsw_remove(struct platform_device *pdev)
17701793
return;
17711794
}
17721795

1773-
for (i = 0; i < cpsw->data.slaves; i++)
1774-
if (cpsw->slaves[i].ndev)
1775-
unregister_netdev(cpsw->slaves[i].ndev);
1796+
for (i = 0; i < cpsw->data.slaves; i++) {
1797+
ndev = cpsw->slaves[i].ndev;
1798+
if (!ndev)
1799+
continue;
1800+
1801+
priv = netdev_priv(ndev);
1802+
unregister_netdev(ndev);
1803+
disable_work_sync(&priv->rx_mode_work);
1804+
}
17761805

17771806
cpts_release(cpsw->cpts);
17781807
cpdma_ctlr_destroy(cpsw->dma);

0 commit comments

Comments
 (0)