public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit()
@ 2026-01-30  2:12 Ziyi Guo
  2026-01-31  1:39 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Ziyi Guo @ 2026-01-30  2:12 UTC (permalink / raw)
  To: Vladimir Oltean, Claudiu Manoil, Alexandre Belloni
  Cc: UNGLinuxDriver, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, Ziyi Guo

ocelot_port_xmit() calls ocelot_can_inject() and ocelot_port_inject_frame()
without holding ocelot->inj_lock. However, both functions have
lockdep_assert_held(&ocelot->inj_lock) indicating that callers must hold
this lock.

The correct caller felix_port_deferred_xmit() properly acquires the lock
using ocelot_lock_inj_grp() before calling these functions.

Add ocelot_lock_inj_grp()/ocelot_unlock_inj_grp() around the injection
code path in ocelot_port_xmit() to fix the missing lock protection.

Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
---
 drivers/net/ethernet/mscc/ocelot_net.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c
index 469784d3a1a6..da8579abea1e 100644
--- a/drivers/net/ethernet/mscc/ocelot_net.c
+++ b/drivers/net/ethernet/mscc/ocelot_net.c
@@ -559,15 +559,22 @@ static netdev_tx_t ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
 	int port = priv->port.index;
 	u32 rew_op = 0;
 
-	if (!static_branch_unlikely(&ocelot_fdma_enabled) &&
-	    !ocelot_can_inject(ocelot, 0))
-		return NETDEV_TX_BUSY;
+	if (!static_branch_unlikely(&ocelot_fdma_enabled)) {
+		ocelot_lock_inj_grp(ocelot, 0);
+
+		if (!ocelot_can_inject(ocelot, 0)) {
+			ocelot_unlock_inj_grp(ocelot, 0);
+			return NETDEV_TX_BUSY;
+		}
+	}
 
 	/* Check if timestamping is needed */
 	if (ocelot->ptp && (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
 		struct sk_buff *clone = NULL;
 
 		if (ocelot_port_txtstamp_request(ocelot, port, skb, &clone)) {
+			if (!static_branch_unlikely(&ocelot_fdma_enabled))
+				ocelot_unlock_inj_grp(ocelot, 0);
 			kfree_skb(skb);
 			return NETDEV_TX_OK;
 		}
@@ -582,6 +589,7 @@ static netdev_tx_t ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
 		ocelot_fdma_inject_frame(ocelot, port, rew_op, skb, dev);
 	} else {
 		ocelot_port_inject_frame(ocelot, port, 0, rew_op, skb);
+		ocelot_unlock_inj_grp(ocelot, 0);
 
 		consume_skb(skb);
 	}
-- 
2.34.1


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

* Re: [PATCH] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit()
  2026-01-30  2:12 [PATCH] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit() Ziyi Guo
@ 2026-01-31  1:39 ` Jakub Kicinski
  2026-01-31  4:50   ` Ziyi Guo
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2026-01-31  1:39 UTC (permalink / raw)
  To: Ziyi Guo
  Cc: Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver, Andrew Lunn, David S . Miller, Eric Dumazet,
	Paolo Abeni, netdev, linux-kernel

On Fri, 30 Jan 2026 02:12:58 +0000 Ziyi Guo wrote:
> ocelot_port_xmit() calls ocelot_can_inject() and ocelot_port_inject_frame()
> without holding ocelot->inj_lock. However, both functions have
> lockdep_assert_held(&ocelot->inj_lock) indicating that callers must hold
> this lock.
> 
> The correct caller felix_port_deferred_xmit() properly acquires the lock
> using ocelot_lock_inj_grp() before calling these functions.
> 
> Add ocelot_lock_inj_grp()/ocelot_unlock_inj_grp() around the injection
> code path in ocelot_port_xmit() to fix the missing lock protection.

Please add an appropriate Fixes tag and repost.
-- 
pw-bot: cr

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

* Re: [PATCH] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit()
  2026-01-31  1:39 ` Jakub Kicinski
@ 2026-01-31  4:50   ` Ziyi Guo
  0 siblings, 0 replies; 3+ messages in thread
From: Ziyi Guo @ 2026-01-31  4:50 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Vladimir Oltean, Claudiu Manoil, Alexandre Belloni,
	UNGLinuxDriver, Andrew Lunn, David S . Miller, Eric Dumazet,
	Paolo Abeni, netdev, linux-kernel

On Fri, Jan 30, 2026 at 8:39 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> Please add an appropriate Fixes tag and repost.

Thank you for your time, I've added the Fixes tag and sent a v2 patch.

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

end of thread, other threads:[~2026-01-31  4:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-30  2:12 [PATCH] net: mscc: ocelot: add missing lock protection in ocelot_port_xmit() Ziyi Guo
2026-01-31  1:39 ` Jakub Kicinski
2026-01-31  4:50   ` Ziyi Guo

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