The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Mathieu Othacehe <othacehe@gnu.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	anton.reding@landisgyr.com
Subject: Re: [PATCH] net: cadence: macb: Fix a possible deadlock in macb_halt_tx.
Date: Thu, 8 May 2025 12:41:45 +0200	[thread overview]
Message-ID: <14c78296-97a0-46b4-b2aa-0ac8fa026d59@redhat.com> (raw)
In-Reply-To: <20250507101231.12578-1-othacehe@gnu.org>

On 5/7/25 12:12 PM, 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.
> 
> Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>

This looks like a fix that should target the net tree and include a
fixes tag, see Documentation/process/maintainer-netdev.rst

> ---
>  drivers/net/ethernet/cadence/macb_main.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 1fe8ec37491b1..ffcf569c14f6a 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -997,20 +997,19 @@ static void macb_update_stats(struct macb *bp)
>  
>  static int macb_halt_tx(struct macb *bp)
>  {
> -	unsigned long	halt_time, timeout;
> -	u32		status;
> +	unsigned int delay_us = 250;
> +	unsigned int retries = MACB_HALT_TIMEOUT / delay_us;
> +	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));
> +		udelay(delay_us);
> +	} while (retries-- > 0);

I think it would be better to use read_poll_timeout_atomic() instead of
sort-of open-codying it.

Thanks,

Paolo


      reply	other threads:[~2025-05-08 10:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 10:12 [PATCH] net: cadence: macb: Fix a possible deadlock in macb_halt_tx Mathieu Othacehe
2025-05-08 10:41 ` Paolo Abeni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14c78296-97a0-46b4-b2aa-0ac8fa026d59@redhat.com \
    --to=pabeni@redhat.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anton.reding@landisgyr.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=othacehe@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox