Re: [RFC PATCH] watchdog: renesas_wdt: don't sleep in atomic context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 02, 2020 at 05:09:44PM +0200, Wolfram Sang wrote:
> In the restart handler, we hit the following OOPS because rwdt_start()
> schedules because of usleep_range():
> 
> [   16.071855] BUG: scheduling while atomic: init/1184/0x00000002
> ...
> [   16.159955] [<c05b6b3c>] (schedule) from [<c05b9884>] (schedule_hrtimeout_range_clock+0x108/0x15c)
> [   16.168918]  r5:00000003 r4:bd855014
> [   16.172498] [<c05b977c>] (schedule_hrtimeout_range_clock) from [<c05b9904>] (schedule_hrtimeout_range+0x2c/0x34)
> [   16.182679]  r7:ea0edd48 r6:ea0ec000 r5:0000fa00 r4:00000000
> [   16.188343] [<c05b98d8>] (schedule_hrtimeout_range) from [<c05b92dc>] (usleep_range+0x84/0xb8)
> [   16.196973] [<c05b9258>] (usleep_range) from [<c049d4a8>] (rwdt_start+0x58/0xa8)
> 
> Convert usleep_range() to udelay() to avoid the bug. The downside is
> busy looping when the watchdog is started or stopped (64us or 96us in my
> case). However, this happens rarely enough, so it seems acceptable.
> 
> Fixes: b836005b4f95 ("watchdog: renesas_wdt: Add a few cycles delay")
> Signed-off-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx>
> ---
> 
> We could also add a new flag in the watchdog core "IS_RESTARTING" or
> similar and check that in the driver. Depending on the flag, we use
> udelay() or usleep_range(). Not sure, if this is feasible or
> over-engineered, though. Looking forward for comments.

Seems to be neither to me. I don't know if there are many drivers who sleep
in the stop function, but even if there are none (today) it would be a
generic problem.

On a side note, I am quite sure there is a system wide flag indicating
that the system is rebooting. Maybe we can just use that ?

> 
>  drivers/watchdog/renesas_wdt.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c
> index 00662a8e039c..2b0da9b76375 100644
> --- a/drivers/watchdog/renesas_wdt.c
> +++ b/drivers/watchdog/renesas_wdt.c
> @@ -76,8 +76,7 @@ static void rwdt_wait_cycles(struct rwdt_priv *priv, unsigned int cycles)
>  	unsigned int delay;
>  
>  	delay = DIV_ROUND_UP(cycles * 1000000, priv->clk_rate);
> -
> -	usleep_range(delay, 2 * delay);
> +	udelay(delay);

I think there should be a comment such as "we can't sleep here because the
function may be called from the restart handler and thus must not sleep".
Either case, this happens so rarely and the delay is so minor that we
should just apply this patch (with comment added) and bother about the more
generic version if the problem is seen again.

Thanks,
Guenter

>  }
>  
>  static int rwdt_start(struct watchdog_device *wdev)
> -- 
> 2.28.0
> 



[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux