Linux Watchdog driver development
 help / color / mirror / Atom feed
* [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS
@ 2026-08-04  9:23 Renê de Souza Pinto
  2026-08-04  9:40 ` sashiko-bot
  2026-08-04 10:39 ` [PATCH v2] " Renê de Souza Pinto
  0 siblings, 2 replies; 4+ messages in thread
From: Renê de Souza Pinto @ 2026-08-04  9:23 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck,
	open list:WATCHDOG DEVICE DRIVERS, open list
  Cc: Renê de Souza Pinto

Some firmwares describe WDAT registers inside memory ranges marked as
ACPI NVS in the E820 map, failing with -EBUSY during probe, leaving the
hardware watchdog unserviced and triggering periodic system resets.

This issue was observed on a OnLogic Karbon 524 device (when watchdog is
enabled in BIOS):

wdat_wdt wdat_wdt: error -EBUSY: can't request region for resource [mem 0x63df7a98]
wdat_wdt wdat_wdt: probe with driver wdat_wdt failed with error -16

This commit fixes this issue by falling back to devm_memremap() when
devm_ioremap_resource() fails with -EBUSY on an ACPI NVS region.

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
---
 drivers/watchdog/wdat_wdt.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c
index dd3c2d69c9df..a56224cf8d22 100644
--- a/drivers/watchdog/wdat_wdt.c
+++ b/drivers/watchdog/wdat_wdt.c
@@ -7,7 +7,9 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
@@ -309,6 +311,33 @@ static struct watchdog_ops wdat_wdt_ops = {
 	.set_timeout = wdat_wdt_set_timeout,
 };
 
+static void __iomem *wdat_wdt_map_mem(struct device *dev, struct resource *res)
+{
+	resource_size_t size = resource_size(res);
+	void __iomem *reg;
+	void *addr;
+
+	/* Try standard reservation + ioremap first */
+	reg = devm_ioremap_resource(dev, res);
+	if (!IS_ERR(reg) || PTR_ERR(reg) != -EBUSY)
+		return reg;
+
+	/* If busy, check if conflict is due to ACPI NVS memory */
+	if (region_intersects(res->start, size, IORESOURCE_MEM,
+			      IORES_DESC_ACPI_NV_STORAGE) != REGION_INTERSECTS)
+		return reg; /* Real conflict, return -EBUSY */
+
+	dev_warn(dev, "%pR is inside ACPI NVS, mapping without reservation\n", res);
+
+	addr = devm_memremap(dev, res->start, size, MEMREMAP_WB);
+	if (IS_ERR(addr)) {
+		dev_err(dev, "failed to map resource %pR\n", res);
+		return IOMEM_ERR_PTR(PTR_ERR(addr));
+	}
+
+	return (void __iomem __force *)addr;
+}
+
 static int wdat_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -362,7 +391,7 @@ static int wdat_wdt_probe(struct platform_device *pdev)
 
 		res = &pdev->resource[i];
 		if (resource_type(res) == IORESOURCE_MEM) {
-			reg = devm_ioremap_resource(dev, res);
+			reg = wdat_wdt_map_mem(dev, res);
 			if (IS_ERR(reg)) {
 				ret = PTR_ERR(reg);
 				goto out_put_table;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS
  2026-08-04  9:23 [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS Renê de Souza Pinto
@ 2026-08-04  9:40 ` sashiko-bot
  2026-08-04 10:39 ` [PATCH v2] " Renê de Souza Pinto
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-08-04  9:40 UTC (permalink / raw)
  To: Renê de Souza Pinto; +Cc: linux-watchdog

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Calling `devm_ioremap_resource()` triggers an unconditional `dev_err()` when it fails with `-EBUSY`, causing confusing and spurious errors in the kernel log on systems with ACPI NVS.
--

--- Patch [1]: [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS ---
commit fe186a236b35b9dc11c6a76632ffa54de7cc01ba
Author: Renê de Souza Pinto <rene@renesp.com.br>

watchdog: wdat_wdt: map registers that fall inside ACPI NVS

This commit fixes an issue where the WDAT watchdog fails to probe on systems 
where its registers reside in ACPI NVS memory (like the OnLogic Karbon 524)
by falling back to devm_memremap() when devm_ioremap_resource() returns -EBUSY.

> diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c
> index dd3c2d69c9df1..a56224cf8d22d 100644
> --- a/drivers/watchdog/wdat_wdt.c
> +++ b/drivers/watchdog/wdat_wdt.c

[ ... ]

> @@ -309,6 +311,33 @@ static struct watchdog_ops wdat_wdt_ops = {
>  	.set_timeout = wdat_wdt_set_timeout,
>  };
>  
> +static void __iomem *wdat_wdt_map_mem(struct device *dev, struct resource *res)
> +{
> +	resource_size_t size = resource_size(res);
> +	void __iomem *reg;
> +	void *addr;
> +
> +	/* Try standard reservation + ioremap first */
> +	reg = devm_ioremap_resource(dev, res);
> +	if (!IS_ERR(reg) || PTR_ERR(reg) != -EBUSY)
> +		return reg;

[Severity: Medium]
Since devm_ioremap_resource() internally calls dev_err() when it fails,
will this unconditional call log a spurious error before the driver has
a chance to execute the expected ACPI NVS fallback?

Could this be avoided by checking region_intersects() for 
IORES_DESC_ACPI_NV_STORAGE before attempting the reservation, rather than
relying on devm_ioremap_resource() to fail first?

> +
> +	/* If busy, check if conflict is due to ACPI NVS memory */
> +	if (region_intersects(res->start, size, IORESOURCE_MEM,
> +			      IORES_DESC_ACPI_NV_STORAGE) != REGION_INTERSECTS)
> +		return reg; /* Real conflict, return -EBUSY */
> +
> +	dev_warn(dev, "%pR is inside ACPI NVS, mapping without reservation\n", res);
> +
> +	addr = devm_memremap(dev, res->start, size, MEMREMAP_WB);
> +	if (IS_ERR(addr)) {
> +		dev_err(dev, "failed to map resource %pR\n", res);
> +		return IOMEM_ERR_PTR(PTR_ERR(addr));
> +	}
> +
> +	return (void __iomem __force *)addr;
> +}
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804092337.3556947-1-rene@renesp.com.br?part=1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] watchdog: wdat_wdt: map registers that fall inside ACPI NVS
  2026-08-04  9:23 [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS Renê de Souza Pinto
  2026-08-04  9:40 ` sashiko-bot
@ 2026-08-04 10:39 ` Renê de Souza Pinto
  2026-08-06 21:27   ` Guenter Roeck
  1 sibling, 1 reply; 4+ messages in thread
From: Renê de Souza Pinto @ 2026-08-04 10:39 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck,
	open list:WATCHDOG DEVICE DRIVERS, open list
  Cc: Renê de Souza Pinto

Some firmwares describe WDAT registers inside memory ranges marked as
ACPI NVS in the E820 map, failing with -EBUSY during probe, leaving the
hardware watchdog unserviced and triggering periodic system resets.

This issue was observed on a OnLogic Karbon 524 device (when watchdog is
enabled in BIOS):

wdat_wdt wdat_wdt: error -EBUSY: can't request region for resource [mem 0x63df7a98]
wdat_wdt wdat_wdt: probe with driver wdat_wdt failed with error -16

Check whether the region falls inside ACPI NVS before requesting it and,
if so, map it without reservation.

Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>
---
 drivers/watchdog/wdat_wdt.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/wdat_wdt.c b/drivers/watchdog/wdat_wdt.c
index dd3c2d69c9df..55ea16e73652 100644
--- a/drivers/watchdog/wdat_wdt.c
+++ b/drivers/watchdog/wdat_wdt.c
@@ -7,7 +7,9 @@
  */
 
 #include <linux/acpi.h>
+#include <linux/io.h>
 #include <linux/ioport.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
@@ -309,6 +311,29 @@ static struct watchdog_ops wdat_wdt_ops = {
 	.set_timeout = wdat_wdt_set_timeout,
 };
 
+static void __iomem *wdat_wdt_map_mem(struct device *dev, struct resource *res)
+{
+	resource_size_t size = resource_size(res);
+	void *addr;
+
+	/* Map memory region without reserving it if it falls inside ACPI NVS */
+	if (region_intersects(res->start, size, IORESOURCE_MEM,
+			      IORES_DESC_ACPI_NV_STORAGE) == REGION_INTERSECTS) {
+		dev_warn(dev, "%pR is inside ACPI NVS, mapping without reservation\n",
+			 res);
+
+		addr = devm_memremap(dev, res->start, size, MEMREMAP_WB);
+		if (IS_ERR(addr)) {
+			dev_err(dev, "failed to map resource %pR\n", res);
+			return IOMEM_ERR_PTR(PTR_ERR(addr));
+		}
+
+		return (void __iomem __force *)addr;
+	}
+
+	return devm_ioremap_resource(dev, res);
+}
+
 static int wdat_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -362,7 +387,7 @@ static int wdat_wdt_probe(struct platform_device *pdev)
 
 		res = &pdev->resource[i];
 		if (resource_type(res) == IORESOURCE_MEM) {
-			reg = devm_ioremap_resource(dev, res);
+			reg = wdat_wdt_map_mem(dev, res);
 			if (IS_ERR(reg)) {
 				ret = PTR_ERR(reg);
 				goto out_put_table;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] watchdog: wdat_wdt: map registers that fall inside ACPI NVS
  2026-08-04 10:39 ` [PATCH v2] " Renê de Souza Pinto
@ 2026-08-06 21:27   ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2026-08-06 21:27 UTC (permalink / raw)
  To: Renê de Souza Pinto
  Cc: Wim Van Sebroeck, open list:WATCHDOG DEVICE DRIVERS, open list

On Tue, Aug 04, 2026 at 12:39:57PM +0200, Renê de Souza Pinto wrote:
> Some firmwares describe WDAT registers inside memory ranges marked as
> ACPI NVS in the E820 map, failing with -EBUSY during probe, leaving the
> hardware watchdog unserviced and triggering periodic system resets.
> 
> This issue was observed on a OnLogic Karbon 524 device (when watchdog is
> enabled in BIOS):
> 
> wdat_wdt wdat_wdt: error -EBUSY: can't request region for resource [mem 0x63df7a98]
> wdat_wdt wdat_wdt: probe with driver wdat_wdt failed with error -16
> 
> Check whether the region falls inside ACPI NVS before requesting it and,
> if so, map it without reservation.
> 
> Signed-off-by: Renê de Souza Pinto <rene@renesp.com.br>

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-06 21:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-04  9:23 [PATCH] watchdog: wdat_wdt: map registers that fall inside ACPI NVS Renê de Souza Pinto
2026-08-04  9:40 ` sashiko-bot
2026-08-04 10:39 ` [PATCH v2] " Renê de Souza Pinto
2026-08-06 21:27   ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox