* [PATCH] watchdog: da9063: wake up parent ahead of reboot
@ 2020-09-01 16:17 Ulrich Hecht
2020-09-01 16:48 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Hecht @ 2020-09-01 16:17 UTC (permalink / raw)
To: linux-renesas-soc; +Cc: wsa, geert, linux-i2c, linux-watchdog, Ulrich Hecht
This patch ensures our parent is awake before a reboot takes place. This
prevents situations in which the I2C host has been suspended and cannot
be safely woken up anymore when it needs to talk to us.
Signed-off-by: Ulrich Hecht <uli+renesas@fpond.eu>
---
Hi!
This is supposed to resolve the issue that came up in the review of
"[PATCH v2] i2c: sh_mobile: implement atomic transfers" that the parent
controller may be suspended when the restart method is called. See
https://www.spinics.net/lists/linux-i2c/msg46367.html for details.
CU
Uli
drivers/watchdog/da9063_wdt.c | 21 +++++++++++++++++++++
include/linux/mfd/da9063/core.h | 2 ++
2 files changed, 23 insertions(+)
diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c
index 423584252606..89718733491e 100644
--- a/drivers/watchdog/da9063_wdt.c
+++ b/drivers/watchdog/da9063_wdt.c
@@ -18,6 +18,8 @@
#include <linux/mfd/da9063/registers.h>
#include <linux/mfd/da9063/core.h>
#include <linux/regmap.h>
+#include <linux/pm_runtime.h>
+#include <linux/reboot.h>
/*
* Watchdog selector to timeout in seconds.
@@ -158,6 +160,21 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd,
return ret;
}
+static int da9063_reboot_notifier(struct notifier_block *nb,
+ unsigned long code, void *unused)
+{
+ struct da9063 *da9063 = container_of(nb, struct da9063, reboot_nb);
+
+ /*
+ * Make sure parent device is running. This cannot be done in the
+ * restart handler because it is no longer safe to do runtime PM
+ * there.
+ */
+ pm_runtime_get_sync(da9063->dev->parent);
+
+ return NOTIFY_DONE;
+}
+
static int da9063_wdt_restart(struct watchdog_device *wdd, unsigned long action,
void *data)
{
@@ -233,6 +250,10 @@ static int da9063_wdt_probe(struct platform_device *pdev)
set_bit(WDOG_HW_RUNNING, &wdd->status);
}
+ /* Get early notification of reboot so we can wake up the parent. */
+ da9063->reboot_nb.notifier_call = da9063_reboot_notifier;
+ devm_register_reboot_notifier(dev, &da9063->reboot_nb);
+
return devm_watchdog_register_device(dev, wdd);
}
diff --git a/include/linux/mfd/da9063/core.h b/include/linux/mfd/da9063/core.h
index fa7a43f02f27..9a3283d488b7 100644
--- a/include/linux/mfd/da9063/core.h
+++ b/include/linux/mfd/da9063/core.h
@@ -85,6 +85,8 @@ struct da9063 {
int chip_irq;
unsigned int irq_base;
struct regmap_irq_chip_data *regmap_irq;
+
+ struct notifier_block reboot_nb;
};
int da9063_device_init(struct da9063 *da9063, unsigned int irq);
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] watchdog: da9063: wake up parent ahead of reboot
2020-09-01 16:17 [PATCH] watchdog: da9063: wake up parent ahead of reboot Ulrich Hecht
@ 2020-09-01 16:48 ` Guenter Roeck
2020-09-07 21:19 ` Ulrich Hecht
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2020-09-01 16:48 UTC (permalink / raw)
To: Ulrich Hecht, linux-renesas-soc; +Cc: wsa, geert, linux-i2c, linux-watchdog
On 9/1/20 9:17 AM, Ulrich Hecht wrote:
> This patch ensures our parent is awake before a reboot takes place. This
> prevents situations in which the I2C host has been suspended and cannot
> be safely woken up anymore when it needs to talk to us.
>
Why not call pm_runtime_get_sync() in da9063_wdt_restart() ? What
guarantees that the local notifier is called before the watchdog core's
restart notifier ? And what is the point of using the watchdog core's
reboot handler if it is bypassed anyway ?
Also, why is it not necessary to call pm functions when the watchdog is
started, when it is stopped, and during suspend/resume ?
Thanks,
Guenter
> Signed-off-by: Ulrich Hecht <uli+renesas@fpond.eu>
> ---
>
> Hi!
>
> This is supposed to resolve the issue that came up in the review of
> "[PATCH v2] i2c: sh_mobile: implement atomic transfers" that the parent
> controller may be suspended when the restart method is called. See
> https://www.spinics.net/lists/linux-i2c/msg46367.html for details.
>
> CU
> Uli
>
>
> drivers/watchdog/da9063_wdt.c | 21 +++++++++++++++++++++
> include/linux/mfd/da9063/core.h | 2 ++
> 2 files changed, 23 insertions(+)
>
> diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c
> index 423584252606..89718733491e 100644
> --- a/drivers/watchdog/da9063_wdt.c
> +++ b/drivers/watchdog/da9063_wdt.c
> @@ -18,6 +18,8 @@
> #include <linux/mfd/da9063/registers.h>
> #include <linux/mfd/da9063/core.h>
> #include <linux/regmap.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/reboot.h>
>
> /*
> * Watchdog selector to timeout in seconds.
> @@ -158,6 +160,21 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd,
> return ret;
> }
>
> +static int da9063_reboot_notifier(struct notifier_block *nb,
> + unsigned long code, void *unused)
> +{
> + struct da9063 *da9063 = container_of(nb, struct da9063, reboot_nb);
> +
> + /*
> + * Make sure parent device is running. This cannot be done in the
> + * restart handler because it is no longer safe to do runtime PM
> + * there.
> + */
> + pm_runtime_get_sync(da9063->dev->parent);
> +
> + return NOTIFY_DONE;
> +}
> +
> static int da9063_wdt_restart(struct watchdog_device *wdd, unsigned long action,
> void *data)
> {
> @@ -233,6 +250,10 @@ static int da9063_wdt_probe(struct platform_device *pdev)
> set_bit(WDOG_HW_RUNNING, &wdd->status);
> }
>
> + /* Get early notification of reboot so we can wake up the parent. */
> + da9063->reboot_nb.notifier_call = da9063_reboot_notifier;
> + devm_register_reboot_notifier(dev, &da9063->reboot_nb);
> +
> return devm_watchdog_register_device(dev, wdd);
> }
>
> diff --git a/include/linux/mfd/da9063/core.h b/include/linux/mfd/da9063/core.h
> index fa7a43f02f27..9a3283d488b7 100644
> --- a/include/linux/mfd/da9063/core.h
> +++ b/include/linux/mfd/da9063/core.h
> @@ -85,6 +85,8 @@ struct da9063 {
> int chip_irq;
> unsigned int irq_base;
> struct regmap_irq_chip_data *regmap_irq;
> +
> + struct notifier_block reboot_nb;
> };
>
> int da9063_device_init(struct da9063 *da9063, unsigned int irq);
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] watchdog: da9063: wake up parent ahead of reboot
2020-09-01 16:48 ` Guenter Roeck
@ 2020-09-07 21:19 ` Ulrich Hecht
0 siblings, 0 replies; 3+ messages in thread
From: Ulrich Hecht @ 2020-09-07 21:19 UTC (permalink / raw)
To: Guenter Roeck, Ulrich Hecht, linux-renesas-soc
Cc: wsa, geert, linux-i2c, linux-watchdog
> On 09/01/2020 6:48 PM Guenter Roeck <linux@roeck-us.net> wrote:
>
>
> On 9/1/20 9:17 AM, Ulrich Hecht wrote:
> > This patch ensures our parent is awake before a reboot takes place. This
> > prevents situations in which the I2C host has been suspended and cannot
> > be safely woken up anymore when it needs to talk to us.
> >
>
> Why not call pm_runtime_get_sync() in da9063_wdt_restart() ?
It's no longer safe to do so at that point because the restart handler runs in atomic context. The unpleasant details can be found at https://www.spinics.net/lists/linux-i2c/msg46367.html
> What
> guarantees that the local notifier is called before the watchdog core's
> restart notifier ?
It would seem to me that a reboot notifier that triggers after the restart notifier (which, if successfully handled, does not return) would be rather pointless.
> And what is the point of using the watchdog core's
> reboot handler if it is bypassed anyway ?
I don't think it's bypassed, it should be possible to register several reboot notifiers per device.
It would also be possible to do this stuff in the core's reboot handler, but I have chosen not to do so because the core seems to avoid dealing with PM, which I assume is a design decision. Also, it would affect all other drivers with a restart handler, with (to me) unforeseeable effects. What do you think?
> Also, why is it not necessary to call pm functions when the watchdog is
> started, when it is stopped, and during suspend/resume ?
These cases are handled automatically, AFAIK.
CU
Uli
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-07 21:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 16:17 [PATCH] watchdog: da9063: wake up parent ahead of reboot Ulrich Hecht
2020-09-01 16:48 ` Guenter Roeck
2020-09-07 21:19 ` Ulrich Hecht
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).