Skip to contentSkip to conversation

watchdog: realtek-otto: Make use of regmap API

PATCH In review Rustam Adilov 3 participants 5 messages Jul 10 – Jul 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover watchdog: realtek-otto: Make use of regmap API

This patch series changes the driver to use regmap API for all of the register access stuff instead of the ioread32 and iowrite32 with __iomem. That makes the watchdog operable when SWAP_IO_SPACE config is enabled just by adding big-endian property to the device tree node.

Also, there was a comment by sashiko which got addressed by Sander in [2] with possibility of it being false positive so i left it at that.

---
Changelog in v3:
- reworded the commit message to make the main reasoning clear.
- rebased the branch.
- Link v2: https://lore.kernel.org/linux-watchdog/[email protected]/

Changelog in v2:
- removed patches 2 and 3 that add rtl9607c device.
- included driver changes made by Sander in [1].
- added disable_locking to regmap_config and set it to true.
- Link to v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/linux-watchdog/[email protected]/

Rustam Adilov (1):
watchdog: realtek-otto: Change to use regmap API

 drivers/watchdog/Kconfig            |  1 +
 drivers/watchdog/realtek_otto_wdt.c | 74 +++++++++++++++--------------
 2 files changed, 39 insertions(+), 36 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v3 1/1 watchdog: realtek-otto: Change to use regmap API

To make the realtek watchdog driver functional when SWAP_IO_SPACE config is enabled, change all of the register access to be done by regmap API which helps us to tweak endianness with big-endian or little-endian property from within the device tree node.

Add the REGMAP_MMIO as a select to REALTEK_OTTO_WDT now that the regmap is used.

---
 drivers/watchdog/Kconfig            |  1 +
 drivers/watchdog/realtek_otto_wdt.c | 74 +++++++++++++++--------------
 2 files changed, 39 insertions(+), 36 deletions(-)
drivers/watchdog/Kconfig +1 -0
index 08cb8612d41f..e0ef0b339abd 100644
@@ -1076,6 +1076,7 @@ config REALTEK_OTTO_WDT
 	depends on MACH_REALTEK_RTL || COMPILE_TEST
 	depends on COMMON_CLK
 	select WATCHDOG_CORE
+	select REGMAP_MMIO
 	default MACH_REALTEK_RTL
 	help
 	  Say Y here to include support for the watchdog timer on Realtek
drivers/watchdog/realtek_otto_wdt.c +38 -36

162 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v3 1/1] watchdog: realtek-otto: Change to use regmap API

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Calling disable_irq() in the restart handler causes a scheduling while atomic bug and a deadlock when triggered by a pretimeout panic.
- [High] The watchdog timeout setup logic does not clamp user timeouts to hardware limits, breaking the watchdog core's software-extended timeout feature. --

--- Patch [1]: [PATCH v3 1/1] watchdog: realtek-otto: Change to use regmap API --- commit df79c826fd293fb9a9e926fad614d84ecc05598a
Author: Rustam Adilov <[email protected]>

watchdog: realtek-otto: Change to use regmap API

To make the realtek watchdog driver functional when SWAP_IO_SPACE config is enabled, change all of the register access to be done by regmap API which helps us to tweak endianness with big-endian or little-endian property from within the device tree node.

Add the REGMAP_MMIO as a select to REALTEK_OTTO_WDT now that the regmap is used.

Quoted 4 lines
drivers/watchdog/realtek_otto_wdt.c +0 -0
index 9094f2189f555..5c48ffba70a20 100644

[ ... ]

Quoted 10 lines
drivers/watchdog/realtek_otto_wdt.c +0 -6
@@ -141,14 +134,11 @@ static int otto_wdt_determine_timeouts(struct watchdog_device *wdev, unsigned in
 	} while (phase1_ticks > OTTO_WDT_PHASE_TICKS_MAX
 		|| phase2_ticks > OTTO_WDT_PHASE_TICKS_MAX);
 
-	v = ioread32(ctrl->base + OTTO_WDT_REG_CTRL);
-
-	v &= ~(OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 | OTTO_WDT_CTRL_PHASE2);
-	v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
-	v |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
-	v |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);

drivers/watchdog/realtek_otto_wdt.c static int otto_wdt_determine_timeouts(struct watchdog_device *wdev, unsigned in · line 144

Quoted 10 lines
drivers/watchdog/realtek_otto_wdt.c +5 -2
-
-	iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+	mask = OTTO_WDT_CTRL_PRESCALE | OTTO_WDT_CTRL_PHASE1 | OTTO_WDT_CTRL_PHASE2;
+	val = FIELD_PREP(OTTO_WDT_CTRL_PHASE1, phase1_ticks - 1);
+	val |= FIELD_PREP(OTTO_WDT_CTRL_PHASE2, phase2_ticks - 1);
+	val |= FIELD_PREP(OTTO_WDT_CTRL_PRESCALE, prescale);
+	regmap_update_bits(ctrl->regmap, OTTO_WDT_REG_CTRL, mask, val);
 
 	timeout_ms = total_ticks * tick_ms;
 	ctrl->wdev.timeout = timeout_ms / 1000;

[Severity: High]
This is a pre-existing issue, but does otto_wdt_determine_timeouts() break the watchdog core's software heartbeat extension?

When a user requests a timeout larger than the hardware's maximum capability, the prescale calculation loop earlier in this function exceeds OTTO_WDT_PRESCALE_MAX and returns -EINVAL.

It seems the driver fails to clamp the requested timeout to its hardware capability before programming the registers, and overwrites wdev.timeout with the calculated hardware ticks. This prevents the core from maintaining the full user-requested timeout via periodic pings.

[ ... ]

drivers/watchdog/realtek_otto_wdt.c static int otto_wdt_restart(struct watchdog_device *wdev, unsigned long reboot_m · line 185

Quoted 6 lines
drivers/watchdog/realtek_otto_wdt.c +1 -1
@@ -192,7 +182,7 @@ static int otto_wdt_restart(struct watchdog_device *wdev, unsigned long reboot_m
 
 	/* Configure for shortest timeout and wait for reset to occur */
 	v = FIELD_PREP(OTTO_WDT_CTRL_RST_MODE, reset_mode) | OTTO_WDT_CTRL_ENABLE;
-	iowrite32(v, ctrl->base + OTTO_WDT_REG_CTRL);
+	regmap_write(ctrl->regmap, OTTO_WDT_REG_CTRL, v);

[Severity: High]
This isn't a bug introduced by this patch, but can the call to disable_irq() earlier in otto_wdt_restart() cause a deadlock during a pretimeout panic?

If the pretimeout governor is set to panic, otto_wdt_phase1_isr() calls watchdog_notify_pretimeout() which triggers a kernel panic. The panic routine disables local interrupts and calls machine_restart(), which invokes otto_wdt_restart().

Because otto_wdt_restart() calls disable_irq(), it internally calls synchronize_irq() which will spin waiting for the currently active interrupt handler (otto_wdt_phase1_isr) to complete.

Since we are already inside that handler, this will hang indefinitely during reboot. Additionally, calling disable_irq() in an atomic context with interrupts disabled could trigger a scheduling while atomic bug.

Quoted 2 lines
drivers/watchdog/realtek_otto_wdt.c +0 -0
 	mdelay(3 * otto_wdt_tick_ms(ctrl, 0));
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw
In reply to Rustam Adilov
Quoted 23 lines · Rustam Adilov

This patch series changes the driver to use regmap API for all of the register access stuff instead of the ioread32 and iowrite32 with __iomem. That makes the watchdog operable when SWAP_IO_SPACE config is enabled just by adding big-endian property to the device tree node.

Also, there was a comment by sashiko which got addressed by Sander in [2] with possibility of it being false positive so i left it at that.

---
Changelog in v3:
- reworded the commit message to make the main reasoning clear.
- rebased the branch.
- Link v2: https://lore.kernel.org/linux-watchdog/[email protected]/

Changelog in v2:
- removed patches 2 and 3 that add rtl9607c device.
- included driver changes made by Sander in [1].
- added disable_locking to regmap_config and set it to true.
- Link to v1: https://lore.kernel.org/all/[email protected]/

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/linux-watchdog/[email protected]/

Quoted 6 lines

Rustam Adilov (1):
watchdog: realtek-otto: Change to use regmap API

 drivers/watchdog/Kconfig            |  1 +
 drivers/watchdog/realtek_otto_wdt.c | 74 +++++++++++++++--------------
 2 files changed, 39 insertions(+), 36 deletions(-)

Hmm, there is a real possibility that Guenter Roeck didn't receive my patches because I've received a message "Undelivered Mail Returned to Sender" indicating mail host roeck-us.net has rejected them.

I don't know if that's gonna be a problem but i hope not. At the very least it is visible on linux-watchdog mailing list.

maintainer
#3 lore raw

Re: [PATCH v3 1/1] watchdog: realtek-otto: Change to use regmap API

In reply to Rustam Adilov
Quoted 9 lines · Rustam Adilov

To make the realtek watchdog driver functional when SWAP_IO_SPACE config is enabled, change all of the register access to be done by regmap API which helps us to tweak endianness with big-endian or little-endian property from within the device tree node.

Add the REGMAP_MMIO as a select to REALTEK_OTTO_WDT now that the regmap is used.

The issues reported by Sashiko are pre-existing, so I am going to apply this patch.

Thanks,
Guenter