netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx.
@ 2025-05-09 12:19 Mathieu Othacehe
  2025-05-12 11:15 ` Simon Horman
  2025-05-13  1:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Mathieu Othacehe @ 2025-05-09 12:19 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Claudiu Beznea, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel, anton.reding,
	Mathieu Othacehe

There is a situation where after THALT is set high, TGO stays high as
well. Because jiffies are never updated, as we are in a context with
interrupts disabled, we never exit that loop and have a deadlock.

That deadlock was noticed on a sama5d4 device that stayed locked for days.

Use retries instead of jiffies so that the timeout really works and we do
not have a deadlock anymore.

Fixes: e86cd53afc590 ("net/macb: better manage tx errors")

Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
---
v2: Use read_poll_timeout_atomic and add a Fixes tag.

 drivers/net/ethernet/cadence/macb_main.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 1fe8ec37491b1..e1e8bd2ec155b 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -997,22 +997,15 @@ static void macb_update_stats(struct macb *bp)
 
 static int macb_halt_tx(struct macb *bp)
 {
-	unsigned long	halt_time, timeout;
-	u32		status;
+	u32 status;
 
 	macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(THALT));
 
-	timeout = jiffies + usecs_to_jiffies(MACB_HALT_TIMEOUT);
-	do {
-		halt_time = jiffies;
-		status = macb_readl(bp, TSR);
-		if (!(status & MACB_BIT(TGO)))
-			return 0;
-
-		udelay(250);
-	} while (time_before(halt_time, timeout));
-
-	return -ETIMEDOUT;
+	/* Poll TSR until TGO is cleared or timeout. */
+	return read_poll_timeout_atomic(macb_readl, status,
+					!(status & MACB_BIT(TGO)),
+					250, MACB_HALT_TIMEOUT, false,
+					bp, TSR);
 }
 
 static void macb_tx_unmap(struct macb *bp, struct macb_tx_skb *tx_skb, int budget)
-- 
2.49.0


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

* Re: [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx.
  2025-05-09 12:19 [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx Mathieu Othacehe
@ 2025-05-12 11:15 ` Simon Horman
  2025-05-13  1:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2025-05-12 11:15 UTC (permalink / raw)
  To: Mathieu Othacehe
  Cc: Nicolas Ferre, Claudiu Beznea, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	anton.reding

On Fri, May 09, 2025 at 02:19:35PM +0200, Mathieu Othacehe wrote:
> There is a situation where after THALT is set high, TGO stays high as
> well. Because jiffies are never updated, as we are in a context with
> interrupts disabled, we never exit that loop and have a deadlock.
> 
> That deadlock was noticed on a sama5d4 device that stayed locked for days.
> 
> Use retries instead of jiffies so that the timeout really works and we do
> not have a deadlock anymore.
> 
> Fixes: e86cd53afc590 ("net/macb: better manage tx errors")
> 
> Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
> ---
> v2: Use read_poll_timeout_atomic and add a Fixes tag.

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx.
  2025-05-09 12:19 [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx Mathieu Othacehe
  2025-05-12 11:15 ` Simon Horman
@ 2025-05-13  1:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-05-13  1:50 UTC (permalink / raw)
  To: Mathieu Othacehe
  Cc: nicolas.ferre, claudiu.beznea, andrew+netdev, davem, edumazet,
	kuba, pabeni, netdev, linux-kernel, anton.reding

Hello:

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

On Fri,  9 May 2025 14:19:35 +0200 you wrote:
> There is a situation where after THALT is set high, TGO stays high as
> well. Because jiffies are never updated, as we are in a context with
> interrupts disabled, we never exit that loop and have a deadlock.
> 
> That deadlock was noticed on a sama5d4 device that stayed locked for days.
> 
> Use retries instead of jiffies so that the timeout really works and we do
> not have a deadlock anymore.
> 
> [...]

Here is the summary with links:
  - [net,v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx.
    https://git.kernel.org/netdev/net/c/c92d6089d8ad

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:[~2025-05-13  1:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-09 12:19 [PATCH net v2] net: cadence: macb: Fix a possible deadlock in macb_halt_tx Mathieu Othacehe
2025-05-12 11:15 ` Simon Horman
2025-05-13  1:50 ` 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;
as well as URLs for NNTP newsgroup(s).