From: sashiko-bot@kernel.org
To: "Prajwal N" <prajwal.n@oss.qualcomm.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [RFC PATCH v4 2/2] drivers/watchdog: Add RISC-V SBI watchdog driver
Date: Tue, 24 Nov 2026 13:37:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-231227@kernel.org> (raw)
In-Reply-To: <20261124131542.613271-3-prajwal.n@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] watchdog: riscv_sbi_wdt: unclamped timeout bounds in
sbiwdt_init_attributes()
- [Medium] watchdog: riscv_sbi_wdt: stale firmware pretimeout in
sbiwdt_init_attributes()
- [Medium] watchdog: riscv_sbi_wdt: missing running state check in
sbiwdt_probe()
- [Medium] watchdog: riscv_sbi_wdt: probe fails in sbiwdt_probe()
without S-mode IMSIC
--
commit 7154e44eab330baa1ded9a131b702c04ae8a2530
Author: Prajwal N <prajwal.n@oss.qualcomm.com>
drivers/watchdog: Add RISC-V SBI watchdog driver
This commit adds a Linux watchdog driver for the RISC-V SBI watchdog
extension, including MSI-based pretimeout notification support.
> diff --git a/drivers/watchdog/riscv_sbi_wdt.c b/drivers/watchdog/riscv_sbi_wdt.c
> new file mode 100644
> index 0000000000000..8e3db98547882
> --- /dev/null
> +++ b/drivers/watchdog/riscv_sbi_wdt.c
[ ... ]
> +/* Initialize the watchdog attributes */
> +static int sbiwdt_init_attributes(struct sbiwdt *wdt)
> +{
> + int ret;
> + u32 attr_val;
> + u32 timeout_usec;
> +
> + /* Read watchdog capability from firmware */
> + ret = sbiwdt_read_attribute(SBI_WATCHDOG_CAPABILITY, &attr_val);
> + if (ret)
> + return ret;
> +
> + wdt->attrs.wdt_capability = attr_val;
[Severity: Medium]
As reported by Guenter Roeck on RFC v3 [1], should sbiwdt_init_attributes()
check SBI_WATCHDOG_STATE and either stop an active watchdog or set
WDOG_HW_RUNNING on wdt->wdd.status?
wdt_state is declared in struct sbiwdt_attributes, but SBI_WATCHDOG_STATE is
never read. If the bootloader, firmware, or a pre-kexec kernel leaves the
watchdog running, writing SBI_WATCHDOG_PERIOD below can fail in firmware, or
watchdog_register_device() will not start the kernel keepalive worker before
userspace opens /dev/watchdog.
> +
> + /*
> + * Read watchdog min period supported in firmware
> + * The firmware ensures the MIN_PERIOD is in valid range
> + */
> + ret = sbiwdt_read_attribute(SBI_WATCHDOG_MIN_PERIOD, &attr_val);
> + if (ret)
> + return ret;
> +
> + if (!attr_val)
> + attr_val = 1;
> +
> + wdt->attrs.wdt_min_period = attr_val;
> + wdt->wdd.min_timeout = usec_to_sec_ceil(wdt->attrs.wdt_min_period);
> +
> + /* Initialize the watchdog timeout to default value */
> + timeout_usec = sec_to_usec(SBI_WATCHDOG_DEFAULT_TIMEOUT);
> + ret = sbiwdt_write_attribute(SBI_WATCHDOG_PERIOD, timeout_usec);
> + if (ret)
> + return ret;
> +
> + wdt->attrs.wdt_period = timeout_usec;
> + wdt->wdd.timeout = SBI_WATCHDOG_DEFAULT_TIMEOUT;
> + wdt->wdd.max_timeout = U32_MAX / USEC_PER_SEC;
[Severity: Medium]
As reported by Guenter Roeck on RFC v3 [2], what happens if firmware reports
SBI_WATCHDOG_MIN_PERIOD greater than 60 seconds, or near U32_MAX?
Writing an unclamped 60-second SBI_WATCHDOG_DEFAULT_TIMEOUT to
SBI_WATCHDOG_PERIOD will be rejected by firmware when wdt_min_period exceeds
60,000,000 us, failing probe. Also, if wdt_min_period is between
4,294,000,001 and U32_MAX, usec_to_sec_ceil() rounds min_timeout up to 4295
seconds while max_timeout is 4294 seconds, causing
watchdog_check_min_max_timeout() to reset both bounds to 0 and allowing
userspace timeouts that overflow u32 in sec_to_usec().
> +
> + /*
> + * Initialize the pretimeout to default value
> + * The firmware ensures the pretimeout init value is 0
> + */
> + wdt->attrs.wdt_notif_time = 0;
> + wdt->wdd.pretimeout = 0;
> +
> + return 0;
> +}
[Severity: Medium]
Does sbiwdt_init_attributes() leave a stale SBI_WATCHDOG_NOTIF_TIME programmed
in firmware across module reload, driver rebind, or kexec?
Neither sbiwdt_stop() nor driver teardown clears SBI_WATCHDOG_NOTIF_TIME in
firmware, and sbiwdt_init_attributes() only zeroes wdt->wdd.pretimeout in
memory after writing SBI_WATCHDOG_PERIOD. If a previous instance configured a
pretimeout of 60 seconds or more, writing the 60-second default period fails
probe; if it configured 1 to 59 seconds, firmware keeps firing unexpected
pretimeout MSIs and rejects later sbiwdt_set_timeout() calls at or below the
stale firmware pretimeout. Writing 0 to SBI_WATCHDOG_NOTIF_TIME before
programming SBI_WATCHDOG_PERIOD would keep software and firmware in sync.
[ ... ]
> +static int sbiwdt_probe(struct platform_device *pdev)
> +{
[ ... ]
> + /* Setup MSI if the capability is available */
> + if (wdt->attrs.wdt_capability & SBI_WATCHDOG_CAP_MSI_SUPPORT_MASK) {
> + imsic_global = imsic_get_global_config();
> + if (!imsic_global)
> + return dev_err_probe(dev, -ENODEV, "IMSIC firmware node is unavailable\n");
> +
> + msi_domain = irq_find_matching_fwnode(imsic_global->fwnode,
> + DOMAIN_BUS_PLATFORM_MSI);
> +
> + if (!msi_domain)
> + return dev_err_probe(dev, -ENODEV,
> + "IMSIC platform MSI domain is unavailable\n");
[Severity: Medium]
Should a missing S-mode IMSIC or platform MSI domain abort the entire watchdog
probe when firmware sets SBI_WATCHDOG_CAP_MSI_SUPPORT_MASK?
On platforms or guests without an S-mode IMSIC platform MSI domain (such as
systems using PLIC or wired APLIC), returning -ENODEV here prevents basic
watchdog registration instead of falling back to non-pretimeout operation with
sbiwdt_info.
[1] https://lore.kernel.org/r/23c02c91-0f92-46aa-86e7-5d9692d9ba8a@roeck-us.net
[2] https://lore.kernel.org/r/23c02c91-0f92-46aa-86e7-5d9692d9ba8a@roeck-us.net
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124131542.613271-1-prajwal.n@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-11-24 13:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 13:15 [RFC PATCH v4 0/2] Add RISC-V SBI watchdog driver Prajwal N
2026-11-24 13:15 ` Prajwal N
2026-11-24 13:15 ` [RFC PATCH v4 1/2] RISC-V: Add defines for the RISC-V SBI watchdog extension Prajwal N
2026-11-24 13:15 ` Prajwal N
2026-11-24 13:21 ` sashiko-bot
2026-11-24 13:15 ` [RFC PATCH v4 2/2] drivers/watchdog: Add RISC-V SBI watchdog driver Prajwal N
2026-11-24 13:15 ` Prajwal N
2026-11-24 13:37 ` sashiko-bot [this message]
2026-11-24 16:12 ` Guenter Roeck
2026-11-26 6:06 ` Prajwal N
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=sashiko-outbox-231227@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=prajwal.n@oss.qualcomm.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.