All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Prajwal N" <prajwal.n@oss.qualcomm.com>
Cc: linux-watchdog@vger.kernel.org
Subject: Re: [RFC PATCH v3 2/2] drivers/watchdog: Add RISC-V SBI watchdog driver
Date: Wed, 18 Nov 2026 09:51:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-220630@kernel.org> (raw)
In-Reply-To: <20261118092147.2017658-3-prajwal.n@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] watchdog: riscv_sbi_wdt: stale firmware pretimeout in
  sbiwdt_init_attributes()
- [Medium] watchdog: riscv_sbi_wdt: unclamped default timeout in
  sbiwdt_init_attributes()
--

commit b565a37dea556ad8d64b1011abd4a164f5ec1f54
Author: Prajwal N <prajwal.n@oss.qualcomm.com>

drivers/watchdog: Add RISC-V SBI watchdog driver

This commit adds a watchdog driver for the RISC-V SBI watchdog extension
with support for MSI pretimeout notifications.

> diff --git a/drivers/watchdog/riscv_sbi_wdt.c b/drivers/watchdog/riscv_sbi_wdt.c
> new file mode 100644
> index 0000000000000..026579a3c5cfd
> --- /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;
> +
> +	/* Read watchdog min period supported in firmware */
> +	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]
What happens if firmware reports SBI_WATCHDOG_MIN_PERIOD greater than
SBI_WATCHDOG_DEFAULT_TIMEOUT (60 seconds)?  Writing the unclamped 60-second
default to SBI_WATCHDOG_PERIOD will fail in firmware and abort probe, or
leave wdt->wdd.timeout smaller than wdt->wdd.min_timeout.

In addition, if wdt_min_period is in (4294000000, U32_MAX],
usec_to_sec_ceil() rounds wdt->wdd.min_timeout up to 4295 seconds while
wdt->wdd.max_timeout is 4294 seconds, which causes
watchdog_check_min_max_timeout() during watchdog_register_device() to reset
both min_timeout and max_timeout to 0 and allows sbiwdt_set_timeout() to
receive timeouts that overflow u32 in sec_to_usec().

> +
> +	/* Initialize the pretimeout to default value */
> +	wdt->attrs.wdt_notif_time = 0;
> +	wdt->wdd.pretimeout = 0;

[Severity: Medium]
Should sbiwdt_init_attributes() also write 0 to SBI_WATCHDOG_NOTIF_TIME in
firmware before setting SBI_WATCHDOG_PERIOD?

If a non-zero pretimeout was configured in firmware before a module reload,
driver rebind, or kexec, leaving SBI_WATCHDOG_NOTIF_TIME untouched in
firmware causes the 60-second SBI_WATCHDOG_PERIOD write above to fail with
-EINVAL when the prior pretimeout is >= 60 seconds.  When the prior
pretimeout is < 60 seconds, firmware keeps the stale pretimeout active while
wdt->wdd.pretimeout is reset to 0 in software, triggering unexpected
pretimeout interrupts and allowing sbiwdt_set_timeout() to pass timeouts at
or below the active firmware pretimeout that firmware then rejects.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118092147.2017658-1-prajwal.n@oss.qualcomm.com?part=2

      reply	other threads:[~2026-11-18  9:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  9:21 [RFC PATCH v3 0/2] Add RISC-V SBI watchdog driver Prajwal N
2026-11-18  9:21 ` Prajwal N
2026-11-18  9:21 ` [RFC PATCH v3 1/2] RISC-V: Add defines for the RISC-V SBI watchdog extension Prajwal N
2026-11-18  9:21   ` Prajwal N
2026-11-18  9:28   ` sashiko-bot
2026-11-18  9:21 ` [RFC PATCH v3 2/2] drivers/watchdog: Add RISC-V SBI watchdog driver Prajwal N
2026-11-18  9:21   ` Prajwal N
2026-11-18  9:51   ` sashiko-bot [this message]

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-220630@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.