public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops
@ 2026-04-14 23:10 Stanislav Fomichev
  2026-04-16  7:34 ` Maxime Chevallier
  2026-04-17  2:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2026-04-14 23:10 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, andrew, olteanv, horms, sdf,
	linux-kernel, Maxime Chevallier

DSA replaces the conduit (master) device's ethtool_ops with its own
wrappers that aggregate stats from both the conduit and DSA switch
ports. Taking the lock again inside the DSA wrappers causes a deadlock.

Stumbled upon this when booting qemu with fbnic and CONFIG_NET_DSA_LOOP=y
(which looks like some kind of testing device that auto-populates the ports
of eth0). `ethtool -i` is enough to deadlock. This means we have basically zero
coverage for DSA stuff with real ops locked devs.

Remove the redundant netdev_lock_ops()/netdev_unlock_ops() calls from
the DSA conduit ethtool wrappers.

Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>
Fixes: 2bcf4772e45a ("net: ethtool: try to protect all callback with netdev instance lock")
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
(cherry picked from commit 1538c00ab3212273240112bd53692d54d95f2dd5)
---
 net/dsa/conduit.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/net/dsa/conduit.c b/net/dsa/conduit.c
index a1b044467bd6..8398d72d7e4d 100644
--- a/net/dsa/conduit.c
+++ b/net/dsa/conduit.c
@@ -27,9 +27,7 @@ static int dsa_conduit_get_regs_len(struct net_device *dev)
 	int len;
 
 	if (ops && ops->get_regs_len) {
-		netdev_lock_ops(dev);
 		len = ops->get_regs_len(dev);
-		netdev_unlock_ops(dev);
 		if (len < 0)
 			return len;
 		ret += len;
@@ -60,15 +58,11 @@ static void dsa_conduit_get_regs(struct net_device *dev,
 	int len;
 
 	if (ops && ops->get_regs_len && ops->get_regs) {
-		netdev_lock_ops(dev);
 		len = ops->get_regs_len(dev);
-		if (len < 0) {
-			netdev_unlock_ops(dev);
+		if (len < 0)
 			return;
-		}
 		regs->len = len;
 		ops->get_regs(dev, regs, data);
-		netdev_unlock_ops(dev);
 		data += regs->len;
 	}
 
@@ -115,10 +109,8 @@ static void dsa_conduit_get_ethtool_stats(struct net_device *dev,
 	int count, mcount = 0;
 
 	if (ops && ops->get_sset_count && ops->get_ethtool_stats) {
-		netdev_lock_ops(dev);
 		mcount = ops->get_sset_count(dev, ETH_SS_STATS);
 		ops->get_ethtool_stats(dev, stats, data);
-		netdev_unlock_ops(dev);
 	}
 
 	list_for_each_entry(dp, &dst->ports, list) {
@@ -149,10 +141,8 @@ static void dsa_conduit_get_ethtool_phy_stats(struct net_device *dev,
 		if (count >= 0)
 			phy_ethtool_get_stats(dev->phydev, stats, data);
 	} else if (ops && ops->get_sset_count && ops->get_ethtool_phy_stats) {
-		netdev_lock_ops(dev);
 		count = ops->get_sset_count(dev, ETH_SS_PHY_STATS);
 		ops->get_ethtool_phy_stats(dev, stats, data);
-		netdev_unlock_ops(dev);
 	}
 
 	if (count < 0)
@@ -176,13 +166,11 @@ static int dsa_conduit_get_sset_count(struct net_device *dev, int sset)
 	struct dsa_switch_tree *dst = cpu_dp->dst;
 	int count = 0;
 
-	netdev_lock_ops(dev);
 	if (sset == ETH_SS_PHY_STATS && dev->phydev &&
 	    (!ops || !ops->get_ethtool_phy_stats))
 		count = phy_ethtool_get_sset_count(dev->phydev);
 	else if (ops && ops->get_sset_count)
 		count = ops->get_sset_count(dev, sset);
-	netdev_unlock_ops(dev);
 
 	if (count < 0)
 		count = 0;
@@ -239,7 +227,6 @@ static void dsa_conduit_get_strings(struct net_device *dev, u32 stringset,
 	struct dsa_switch_tree *dst = cpu_dp->dst;
 	int count, mcount = 0;
 
-	netdev_lock_ops(dev);
 	if (stringset == ETH_SS_PHY_STATS && dev->phydev &&
 	    !ops->get_ethtool_phy_stats) {
 		mcount = phy_ethtool_get_sset_count(dev->phydev);
@@ -253,7 +240,6 @@ static void dsa_conduit_get_strings(struct net_device *dev, u32 stringset,
 			mcount = 0;
 		ops->get_strings(dev, stringset, data);
 	}
-	netdev_unlock_ops(dev);
 
 	list_for_each_entry(dp, &dst->ports, list) {
 		if (!dsa_port_is_dsa(dp) && !dsa_port_is_cpu(dp))
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops
  2026-04-14 23:10 [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops Stanislav Fomichev
@ 2026-04-16  7:34 ` Maxime Chevallier
  2026-04-17  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Chevallier @ 2026-04-16  7:34 UTC (permalink / raw)
  To: Stanislav Fomichev, netdev
  Cc: davem, edumazet, kuba, pabeni, andrew, olteanv, horms, sdf,
	linux-kernel

Hi Stanislav,

On 15/04/2026 01:10, Stanislav Fomichev wrote:
> DSA replaces the conduit (master) device's ethtool_ops with its own
> wrappers that aggregate stats from both the conduit and DSA switch
> ports. Taking the lock again inside the DSA wrappers causes a deadlock.
> 
> Stumbled upon this when booting qemu with fbnic and CONFIG_NET_DSA_LOOP=y
> (which looks like some kind of testing device that auto-populates the ports
> of eth0). `ethtool -i` is enough to deadlock. This means we have basically zero
> coverage for DSA stuff with real ops locked devs.

True, indeed I don't have physical devices here with locked ops, looking
at the current devices that use it (fbnic, bnxt, gve, mlx5, bnge) that's
not too surprising, I don't think these are often used with DSA.

> 
> Remove the redundant netdev_lock_ops()/netdev_unlock_ops() calls from
> the DSA conduit ethtool wrappers.
> 
> Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>
> Fixes: 2bcf4772e45a ("net: ethtool: try to protect all callback with netdev instance lock")
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> (cherry picked from commit 1538c00ab3212273240112bd53692d54d95f2dd5)

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Maxime
> ---
>  net/dsa/conduit.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
> 
> diff --git a/net/dsa/conduit.c b/net/dsa/conduit.c
> index a1b044467bd6..8398d72d7e4d 100644
> --- a/net/dsa/conduit.c
> +++ b/net/dsa/conduit.c
> @@ -27,9 +27,7 @@ static int dsa_conduit_get_regs_len(struct net_device *dev)
>  	int len;
>  
>  	if (ops && ops->get_regs_len) {
> -		netdev_lock_ops(dev);
>  		len = ops->get_regs_len(dev);
> -		netdev_unlock_ops(dev);
>  		if (len < 0)
>  			return len;
>  		ret += len;
> @@ -60,15 +58,11 @@ static void dsa_conduit_get_regs(struct net_device *dev,
>  	int len;
>  
>  	if (ops && ops->get_regs_len && ops->get_regs) {
> -		netdev_lock_ops(dev);
>  		len = ops->get_regs_len(dev);
> -		if (len < 0) {
> -			netdev_unlock_ops(dev);
> +		if (len < 0)
>  			return;
> -		}
>  		regs->len = len;
>  		ops->get_regs(dev, regs, data);
> -		netdev_unlock_ops(dev);
>  		data += regs->len;
>  	}
>  
> @@ -115,10 +109,8 @@ static void dsa_conduit_get_ethtool_stats(struct net_device *dev,
>  	int count, mcount = 0;
>  
>  	if (ops && ops->get_sset_count && ops->get_ethtool_stats) {
> -		netdev_lock_ops(dev);
>  		mcount = ops->get_sset_count(dev, ETH_SS_STATS);
>  		ops->get_ethtool_stats(dev, stats, data);
> -		netdev_unlock_ops(dev);
>  	}
>  
>  	list_for_each_entry(dp, &dst->ports, list) {
> @@ -149,10 +141,8 @@ static void dsa_conduit_get_ethtool_phy_stats(struct net_device *dev,
>  		if (count >= 0)
>  			phy_ethtool_get_stats(dev->phydev, stats, data);
>  	} else if (ops && ops->get_sset_count && ops->get_ethtool_phy_stats) {
> -		netdev_lock_ops(dev);
>  		count = ops->get_sset_count(dev, ETH_SS_PHY_STATS);
>  		ops->get_ethtool_phy_stats(dev, stats, data);
> -		netdev_unlock_ops(dev);
>  	}
>  
>  	if (count < 0)
> @@ -176,13 +166,11 @@ static int dsa_conduit_get_sset_count(struct net_device *dev, int sset)
>  	struct dsa_switch_tree *dst = cpu_dp->dst;
>  	int count = 0;
>  
> -	netdev_lock_ops(dev);
>  	if (sset == ETH_SS_PHY_STATS && dev->phydev &&
>  	    (!ops || !ops->get_ethtool_phy_stats))
>  		count = phy_ethtool_get_sset_count(dev->phydev);
>  	else if (ops && ops->get_sset_count)
>  		count = ops->get_sset_count(dev, sset);
> -	netdev_unlock_ops(dev);
>  
>  	if (count < 0)
>  		count = 0;
> @@ -239,7 +227,6 @@ static void dsa_conduit_get_strings(struct net_device *dev, u32 stringset,
>  	struct dsa_switch_tree *dst = cpu_dp->dst;
>  	int count, mcount = 0;
>  
> -	netdev_lock_ops(dev);
>  	if (stringset == ETH_SS_PHY_STATS && dev->phydev &&
>  	    !ops->get_ethtool_phy_stats) {
>  		mcount = phy_ethtool_get_sset_count(dev->phydev);
> @@ -253,7 +240,6 @@ static void dsa_conduit_get_strings(struct net_device *dev, u32 stringset,
>  			mcount = 0;
>  		ops->get_strings(dev, stringset, data);
>  	}
> -	netdev_unlock_ops(dev);
>  
>  	list_for_each_entry(dp, &dst->ports, list) {
>  		if (!dsa_port_is_dsa(dp) && !dsa_port_is_cpu(dp))


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops
  2026-04-14 23:10 [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops Stanislav Fomichev
  2026-04-16  7:34 ` Maxime Chevallier
@ 2026-04-17  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-17  2:40 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: netdev, davem, edumazet, kuba, pabeni, andrew, olteanv, horms,
	sdf, linux-kernel, maxime.chevallier

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 14 Apr 2026 16:10:35 -0700 you wrote:
> DSA replaces the conduit (master) device's ethtool_ops with its own
> wrappers that aggregate stats from both the conduit and DSA switch
> ports. Taking the lock again inside the DSA wrappers causes a deadlock.
> 
> Stumbled upon this when booting qemu with fbnic and CONFIG_NET_DSA_LOOP=y
> (which looks like some kind of testing device that auto-populates the ports
> of eth0). `ethtool -i` is enough to deadlock. This means we have basically zero
> coverage for DSA stuff with real ops locked devs.
> 
> [...]

Here is the summary with links:
  - [net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops
    https://git.kernel.org/netdev/net/c/0f99e0c3e19b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-17  2:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 23:10 [PATCH net] net: dsa: remove redundant netdev_lock_ops() from conduit ethtool ops Stanislav Fomichev
2026-04-16  7:34 ` Maxime Chevallier
2026-04-17  2:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox