From: Guenter Roeck <linux@roeck-us.net>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: linux-watchdog@vger.kernel.org,
linux-renesas-soc@vger.kernel.org,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Subject: Re: [RFC PATCH] watchdog: renesas_wdt: don't sleep in atomic context
Date: Fri, 2 Oct 2020 09:47:22 -0700 [thread overview]
Message-ID: <20201002164722.GA46009@roeck-us.net> (raw)
In-Reply-To: <20201002150944.9696-1-wsa+renesas@sang-engineering.com>
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@sang-engineering.com>
> ---
>
> 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
>
next prev parent reply other threads:[~2020-10-02 16:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 15:09 [RFC PATCH] watchdog: renesas_wdt: don't sleep in atomic context Wolfram Sang
2020-10-02 15:12 ` Wolfram Sang
2020-10-02 16:47 ` Guenter Roeck [this message]
2020-12-19 17:29 ` Wolfram Sang
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=20201002164722.GA46009@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=yoshihiro.shimoda.uh@renesas.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.