* [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter
@ 2026-08-13 3:48 Zexin Wang
2026-08-13 3:59 ` sashiko-bot
2026-08-13 5:11 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Zexin Wang @ 2026-08-13 3:48 UTC (permalink / raw)
To: Wim Van Sebroeck, Guenter Roeck, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: light.chen, Fred-WY.Chen, Yt.Hsieh, Zexin Wang, linux-watchdog,
linux-kernel, linux-arm-kernel, linux-mediatek
On SBSA platforms using standard UEFI firmware (such as EDK II), the
watchdog timer is often enabled during early boot stages but explicitly
disabled by the firmware before handing over control to the OS (e.g.,
during ExitBootServices). This is done to prevent unintended resets
while the OS is loading, assuming the OS watchdog driver will take over.
However, this leaves a protection gap. If the system hangs between the
firmware handover and the userspace watchdog daemon startup, the hardware
watchdog will not fire to recover the system. For safety-critical systems
that require continuous hardware watchdog protection from the earliest
possible moment, this gap is problematic.
Add an 'early_enable' module parameter to allow the kernel driver to
re-enable the watchdog immediately during probe if it was left disabled
by the firmware. By setting the WDOG_HW_RUNNING status bit, the watchdog
core is instructed that the hardware is active. As a result, the core's
pre-userspace handler (controlled by 'handle_boot_enabled') will
automatically issue periodic keepalives until userspace opens the device.
This bridges the protection gap seamlessly without requiring firmware
modifications and without risking unintended resets during kernel boot.
The parameter defaults to false to preserve the traditional behavior.
Signed-off-by: Zexin Wang <ot_zexin.wang@mediatek.com>
---
.../watchdog/watchdog-parameters.rst | 2 ++
drivers/watchdog/sbsa_gwdt.c | 23 +++++++++++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/Documentation/watchdog/watchdog-parameters.rst b/Documentation/watchdog/watchdog-parameters.rst
index 502cb6adbeda..47867a621ada 100644
--- a/Documentation/watchdog/watchdog-parameters.rst
+++ b/Documentation/watchdog/watchdog-parameters.rst
@@ -515,6 +515,8 @@ sbsa_gwdt:
nowayout:
Watchdog cannot be stopped once started
(default=kernel config parameter)
+ early_enable:
+ Watchdog is started on module insertion (default=0)
-------------------------------------------------
diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index e04d42cc7774..ed913be3d1cb 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -122,6 +122,11 @@ MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+static bool early_enable;
+module_param(early_enable, bool, 0);
+MODULE_PARM_DESC(early_enable,
+ "Watchdog is started on module insertion (default=0)");
+
/*
* Arm Base System Architecture 1.0 introduces watchdog v1 which
* increases the length watchdog offset register to 48 bits.
@@ -296,6 +301,7 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
struct sbsa_gwdt *gwdt;
int ret, irq;
u32 status;
+ bool early_action;
gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL);
if (!gwdt)
@@ -386,14 +392,27 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
*/
sbsa_gwdt_set_timeout(wdd, wdd->timeout);
+ early_action = early_enable && !(status & SBSA_GWDT_WCS_EN);
+ if (early_action) {
+ sbsa_gwdt_start(wdd);
+ set_bit(WDOG_HW_RUNNING, &wdd->status);
+ dev_info(dev, "Watchdog early enabled.\n");
+ }
+
watchdog_stop_on_reboot(wdd);
ret = devm_watchdog_register_device(dev, wdd);
- if (ret)
+ if (ret) {
+ dev_err(dev, "Failed to register watchdog: %d\n", ret);
+ if (early_action) {
+ clear_bit(WDOG_HW_RUNNING, &wdd->status);
+ sbsa_gwdt_stop(wdd);
+ }
return ret;
+ }
dev_info(dev, "Initialized with %ds timeout @ %u Hz, action=%d.%s\n",
wdd->timeout, gwdt->clk, action,
- status & SBSA_GWDT_WCS_EN ? " [enabled]" : "");
+ watchdog_hw_running(wdd) ? " [enabled]" : "");
return 0;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter
2026-08-13 3:48 [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter Zexin Wang
@ 2026-08-13 3:59 ` sashiko-bot
2026-08-13 5:11 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-08-13 3:59 UTC (permalink / raw)
To: Zexin Wang; +Cc: linux-watchdog
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Low] The newly added module parameter `early_enable` is incorrectly indented in the documentation, which will cause it to render as part of the description for the `nowayout` parameter.
Pre-existing issues:
- [High] If the `action=1` (two-stage mode) parameter is requested but the WS0 interrupt is missing, the driver falls back to single-stage mode but fails to recalculate the WS0 race workaround, leaving the device vulnerable to race-induced panics/resets.
--
--- Patch [1]: [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter ---
commit 53d84fbbff2306e50b5e3a377d06b179b96d99f7
Author: Zexin Wang <ot_zexin.wang@mediatek.com>
watchdog: sbsa_gwdt: add early_enable module parameter
This commit adds an early_enable module parameter to the sbsa_gwdt driver.
It allows the watchdog to be re-enabled immediately during probe to prevent
a protection gap between firmware handover and userspace daemon startup.
> diff --git a/Documentation/watchdog/watchdog-parameters.rst b/Documentation/watchdog/watchdog-parameters.rst
> --- a/Documentation/watchdog/watchdog-parameters.rst
> +++ b/Documentation/watchdog/watchdog-parameters.rst
> @@ -515,6 +515,8 @@ sbsa_gwdt:
> nowayout:
> Watchdog cannot be stopped once started
> (default=kernel config parameter)
> + early_enable:
> + Watchdog is started on module insertion (default=0)
[Severity: Low]
This isn't a bug, but will this indentation cause early_enable to render
nested under the nowayout parameter description in the generated Sphinx
documentation? It looks like it uses a tab instead of being aligned with
the other parameter names.
> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
> --- a/drivers/watchdog/sbsa_gwdt.c
> +++ b/drivers/watchdog/sbsa_gwdt.c
[ ... ]
> @@ -386,14 +392,27 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
> */
> sbsa_gwdt_set_timeout(wdd, wdd->timeout);
[Severity: High]
This is a pre-existing issue, but does the driver leave the device vulnerable
to race-induced panics if it falls back to single-stage mode?
Looking at sbsa_gwdt_probe(), the workaround condition for
need_ws0_race_workaround is evaluated early based on the initial action state
during sbsa_gwdt_get_version(wdd). If the WS0 interrupt is missing, the driver
falls back by setting action to 0:
sbsa_gwdt_probe() {
...
if (action) {
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
action = 0;
dev_warn(dev, "unable to get ws0 interrupt.\n");
}
...
}
However, it doesn't recalculate need_ws0_race_workaround after this fallback.
If a system boots with action=1 but fails to find the IRQ, could the
watchdog core schedule keepalives that align with the hardware's WS0
assertion, triggering the known race condition where the ping is ignored?
> + early_action = early_enable && !(status & SBSA_GWDT_WCS_EN);
> + if (early_action) {
> + sbsa_gwdt_start(wdd);
> + set_bit(WDOG_HW_RUNNING, &wdd->status);
> + dev_info(dev, "Watchdog early enabled.\n");
> + }
> +
> watchdog_stop_on_reboot(wdd);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813034900.20235-1-ot_zexin.wang@mediatek.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter
2026-08-13 3:48 [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter Zexin Wang
2026-08-13 3:59 ` sashiko-bot
@ 2026-08-13 5:11 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-08-13 5:11 UTC (permalink / raw)
To: Zexin Wang
Cc: Wim Van Sebroeck, Matthias Brugger, AngeloGioacchino Del Regno,
light.chen, Fred-WY.Chen, Yt.Hsieh, linux-watchdog, linux-kernel,
linux-arm-kernel, linux-mediatek
On Thu, Aug 13, 2026 at 11:48:56AM +0800, Zexin Wang wrote:
> On SBSA platforms using standard UEFI firmware (such as EDK II), the
> watchdog timer is often enabled during early boot stages but explicitly
> disabled by the firmware before handing over control to the OS (e.g.,
> during ExitBootServices). This is done to prevent unintended resets
> while the OS is loading, assuming the OS watchdog driver will take over.
>
> However, this leaves a protection gap. If the system hangs between the
> firmware handover and the userspace watchdog daemon startup, the hardware
> watchdog will not fire to recover the system. For safety-critical systems
> that require continuous hardware watchdog protection from the earliest
> possible moment, this gap is problematic.
>
> Add an 'early_enable' module parameter to allow the kernel driver to
> re-enable the watchdog immediately during probe if it was left disabled
> by the firmware. By setting the WDOG_HW_RUNNING status bit, the watchdog
> core is instructed that the hardware is active. As a result, the core's
> pre-userspace handler (controlled by 'handle_boot_enabled') will
> automatically issue periodic keepalives until userspace opens the device.
>
> This bridges the protection gap seamlessly without requiring firmware
> modifications and without risking unintended resets during kernel boot.
>
> The parameter defaults to false to preserve the traditional behavior.
>
> Signed-off-by: Zexin Wang <ot_zexin.wang@mediatek.com>
> ---
Change log goes here.
> .../watchdog/watchdog-parameters.rst | 2 ++
> drivers/watchdog/sbsa_gwdt.c | 23 +++++++++++++++++--
> 2 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/watchdog/watchdog-parameters.rst b/Documentation/watchdog/watchdog-parameters.rst
> index 502cb6adbeda..47867a621ada 100644
> --- a/Documentation/watchdog/watchdog-parameters.rst
> +++ b/Documentation/watchdog/watchdog-parameters.rst
> @@ -515,6 +515,8 @@ sbsa_gwdt:
> nowayout:
> Watchdog cannot be stopped once started
> (default=kernel config parameter)
> + early_enable:
As pointed out by Sashiko, bad alignment (tab instead of four spaces).
> + Watchdog is started on module insertion (default=0)
>
> -------------------------------------------------
>
> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
> index e04d42cc7774..ed913be3d1cb 100644
> --- a/drivers/watchdog/sbsa_gwdt.c
> +++ b/drivers/watchdog/sbsa_gwdt.c
> @@ -122,6 +122,11 @@ MODULE_PARM_DESC(nowayout,
> "Watchdog cannot be stopped once started (default="
> __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
>
> +static bool early_enable;
> +module_param(early_enable, bool, 0);
> +MODULE_PARM_DESC(early_enable,
> + "Watchdog is started on module insertion (default=0)");
> +
> /*
> * Arm Base System Architecture 1.0 introduces watchdog v1 which
> * increases the length watchdog offset register to 48 bits.
> @@ -296,6 +301,7 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
> struct sbsa_gwdt *gwdt;
> int ret, irq;
> u32 status;
> + bool early_action;
>
> gwdt = devm_kzalloc(dev, sizeof(*gwdt), GFP_KERNEL);
> if (!gwdt)
> @@ -386,14 +392,27 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
> */
> sbsa_gwdt_set_timeout(wdd, wdd->timeout);
>
> + early_action = early_enable && !(status & SBSA_GWDT_WCS_EN);
> + if (early_action) {
> + sbsa_gwdt_start(wdd);
> + set_bit(WDOG_HW_RUNNING, &wdd->status);
> + dev_info(dev, "Watchdog early enabled.\n");
Unnecessary noise (it is also reported below).
> + }
> +
> watchdog_stop_on_reboot(wdd);
> ret = devm_watchdog_register_device(dev, wdd);
> - if (ret)
> + if (ret) {
> + dev_err(dev, "Failed to register watchdog: %d\n", ret);
Unrelated and unnecessary addition.
> + if (early_action) {
> + clear_bit(WDOG_HW_RUNNING, &wdd->status);
Pointless. The watchdog was not registered.
> + sbsa_gwdt_stop(wdd);
> + }
> return ret;
> + }
>
> dev_info(dev, "Initialized with %ds timeout @ %u Hz, action=%d.%s\n",
> wdd->timeout, gwdt->clk, action,
> - status & SBSA_GWDT_WCS_EN ? " [enabled]" : "");
> + watchdog_hw_running(wdd) ? " [enabled]" : "");
>
> return 0;
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-13 5:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-13 3:48 [PATCH v2] watchdog: sbsa_gwdt: add early_enable module parameter Zexin Wang
2026-08-13 3:59 ` sashiko-bot
2026-08-13 5:11 ` Guenter Roeck
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.