Skip to content

Commit 877d94c

Browse files
committed
Merge tag 'linux-watchdog-6.17-rc1' of git://www.linux-watchdog.org/linux-watchdog
Pull watchdog updates from Wim Van Sebroeck: - sbsa: Adjust keepalive timeout to avoid MediaTek WS0 race condition - Various improvements and fixes * tag 'linux-watchdog-6.17-rc1' of git://www.linux-watchdog.org/linux-watchdog: watchdog: sbsa: Adjust keepalive timeout to avoid MediaTek WS0 race condition watchdog: dw_wdt: Fix default timeout watchdog: Don't use "proxy" headers watchdog: it87_wdt: Don't use "proxy" headers watchdog: renesas_wdt: Convert to DEFINE_SIMPLE_DEV_PM_OPS() watchdog: iTCO_wdt: Report error if timeout configuration fails watchdog: rti_wdt: Use of_reserved_mem_region_to_resource() for "memory-region" dt-bindings: watchdog: nxp,pnx4008-wdt: allow clocks property watchdog: ziirave_wdt: check record length in ziirave_firm_verify()
2 parents 196dacf + 48defdf commit 877d94c

File tree

11 files changed

+87
-25
lines changed

11 files changed

+87
-25
lines changed

Documentation/devicetree/bindings/watchdog/nxp,pnx4008-wdt.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ properties:
1919
reg:
2020
maxItems: 1
2121

22+
clocks:
23+
maxItems: 1
24+
2225
required:
2326
- compatible
2427
- reg

drivers/watchdog/dw_wdt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ static int dw_wdt_drv_probe(struct platform_device *pdev)
644644
} else {
645645
wdd->timeout = DW_WDT_DEFAULT_SECONDS;
646646
watchdog_init_timeout(wdd, 0, dev);
647+
/* Limit timeout value to hardware constraints. */
648+
dw_wdt_set_timeout(wdd, wdd->timeout);
647649
}
648650

649651
platform_set_drvdata(pdev, dw_wdt);

drivers/watchdog/iTCO_wdt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,11 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
577577
/* Check that the heartbeat value is within it's range;
578578
if not reset to the default */
579579
if (iTCO_wdt_set_timeout(&p->wddev, heartbeat)) {
580-
iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
580+
ret = iTCO_wdt_set_timeout(&p->wddev, WATCHDOG_TIMEOUT);
581+
if (ret != 0) {
582+
dev_err(dev, "Failed to set watchdog timeout (%d)\n", WATCHDOG_TIMEOUT);
583+
return ret;
584+
}
581585
dev_info(dev, "timeout value out of range, using %d\n",
582586
WATCHDOG_TIMEOUT);
583587
heartbeat = WATCHDOG_TIMEOUT;

drivers/watchdog/it87_wdt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
#include <linux/bits.h>
2424
#include <linux/dmi.h>
25+
#include <linux/errno.h>
2526
#include <linux/init.h>
2627
#include <linux/io.h>
27-
#include <linux/kernel.h>
28+
#include <linux/ioport.h>
2829
#include <linux/module.h>
2930
#include <linux/moduleparam.h>
31+
#include <linux/printk.h>
3032
#include <linux/types.h>
3133
#include <linux/watchdog.h>
3234

drivers/watchdog/renesas_wdt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static void rwdt_remove(struct platform_device *pdev)
300300
pm_runtime_disable(&pdev->dev);
301301
}
302302

303-
static int __maybe_unused rwdt_suspend(struct device *dev)
303+
static int rwdt_suspend(struct device *dev)
304304
{
305305
struct rwdt_priv *priv = dev_get_drvdata(dev);
306306

@@ -310,7 +310,7 @@ static int __maybe_unused rwdt_suspend(struct device *dev)
310310
return 0;
311311
}
312312

313-
static int __maybe_unused rwdt_resume(struct device *dev)
313+
static int rwdt_resume(struct device *dev)
314314
{
315315
struct rwdt_priv *priv = dev_get_drvdata(dev);
316316

@@ -320,7 +320,7 @@ static int __maybe_unused rwdt_resume(struct device *dev)
320320
return 0;
321321
}
322322

323-
static SIMPLE_DEV_PM_OPS(rwdt_pm_ops, rwdt_suspend, rwdt_resume);
323+
static DEFINE_SIMPLE_DEV_PM_OPS(rwdt_pm_ops, rwdt_suspend, rwdt_resume);
324324

325325
static const struct of_device_id rwdt_ids[] = {
326326
{ .compatible = "renesas,rcar-gen2-wdt", },
@@ -334,7 +334,7 @@ static struct platform_driver rwdt_driver = {
334334
.driver = {
335335
.name = "renesas_wdt",
336336
.of_match_table = rwdt_ids,
337-
.pm = &rwdt_pm_ops,
337+
.pm = pm_sleep_ptr(&rwdt_pm_ops),
338338
},
339339
.probe = rwdt_probe,
340340
.remove = rwdt_remove,

drivers/watchdog/rti_wdt.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/module.h>
1616
#include <linux/moduleparam.h>
1717
#include <linux/of.h>
18-
#include <linux/of_address.h>
18+
#include <linux/of_reserved_mem.h>
1919
#include <linux/platform_device.h>
2020
#include <linux/pm_runtime.h>
2121
#include <linux/types.h>
@@ -214,7 +214,6 @@ static int rti_wdt_probe(struct platform_device *pdev)
214214
struct rti_wdt_device *wdt;
215215
struct clk *clk;
216216
u32 last_ping = 0;
217-
struct device_node *node;
218217
u32 reserved_mem_size;
219218
struct resource res;
220219
u32 *vaddr;
@@ -299,15 +298,8 @@ static int rti_wdt_probe(struct platform_device *pdev)
299298
}
300299
}
301300

302-
node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
303-
if (node) {
304-
ret = of_address_to_resource(node, 0, &res);
305-
of_node_put(node);
306-
if (ret) {
307-
dev_err(dev, "No memory address assigned to the region.\n");
308-
goto err_iomap;
309-
}
310-
301+
ret = of_reserved_mem_region_to_resource(pdev->dev.of_node, 0, &res);
302+
if (!ret) {
311303
/*
312304
* If reserved memory is defined for watchdog reset cause.
313305
* Readout the Power-on(PON) reason and pass to bootstatus.

drivers/watchdog/sbsa_gwdt.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,25 @@
7575
#define SBSA_GWDT_VERSION_MASK 0xF
7676
#define SBSA_GWDT_VERSION_SHIFT 16
7777

78+
#define SBSA_GWDT_IMPL_MASK 0x7FF
79+
#define SBSA_GWDT_IMPL_SHIFT 0
80+
#define SBSA_GWDT_IMPL_MEDIATEK 0x426
81+
7882
/**
7983
* struct sbsa_gwdt - Internal representation of the SBSA GWDT
8084
* @wdd: kernel watchdog_device structure
8185
* @clk: store the System Counter clock frequency, in Hz.
8286
* @version: store the architecture version
87+
* @need_ws0_race_workaround:
88+
* indicate whether to adjust wdd->timeout to avoid a race with WS0
8389
* @refresh_base: Virtual address of the watchdog refresh frame
8490
* @control_base: Virtual address of the watchdog control frame
8591
*/
8692
struct sbsa_gwdt {
8793
struct watchdog_device wdd;
8894
u32 clk;
8995
int version;
96+
bool need_ws0_race_workaround;
9097
void __iomem *refresh_base;
9198
void __iomem *control_base;
9299
};
@@ -161,6 +168,31 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
161168
*/
162169
sbsa_gwdt_reg_write(((u64)gwdt->clk / 2) * timeout, gwdt);
163170

171+
/*
172+
* Some watchdog hardware has a race condition where it will ignore
173+
* sbsa_gwdt_keepalive() if it is called at the exact moment that a
174+
* timeout occurs and WS0 is being asserted. Unfortunately, the default
175+
* behavior of the watchdog core is very likely to trigger this race
176+
* when action=0 because it programs WOR to be half of the desired
177+
* timeout, and watchdog_next_keepalive() chooses the exact same time to
178+
* send keepalive pings.
179+
*
180+
* This triggers a race where sbsa_gwdt_keepalive() can be called right
181+
* as WS0 is being asserted, and affected hardware will ignore that
182+
* write and continue to assert WS0. After another (timeout / 2)
183+
* seconds, the same race happens again. If the driver wins then the
184+
* explicit refresh will reset WS0 to false but if the hardware wins,
185+
* then WS1 is asserted and the system resets.
186+
*
187+
* Avoid the problem by scheduling keepalive heartbeats one second later
188+
* than the WOR timeout.
189+
*
190+
* This workaround might not be needed in a future revision of the
191+
* hardware.
192+
*/
193+
if (gwdt->need_ws0_race_workaround)
194+
wdd->min_hw_heartbeat_ms = timeout * 500 + 1000;
195+
164196
return 0;
165197
}
166198

@@ -202,12 +234,15 @@ static int sbsa_gwdt_keepalive(struct watchdog_device *wdd)
202234
static void sbsa_gwdt_get_version(struct watchdog_device *wdd)
203235
{
204236
struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
205-
int ver;
237+
int iidr, ver, impl;
206238

207-
ver = readl(gwdt->control_base + SBSA_GWDT_W_IIDR);
208-
ver = (ver >> SBSA_GWDT_VERSION_SHIFT) & SBSA_GWDT_VERSION_MASK;
239+
iidr = readl(gwdt->control_base + SBSA_GWDT_W_IIDR);
240+
ver = (iidr >> SBSA_GWDT_VERSION_SHIFT) & SBSA_GWDT_VERSION_MASK;
241+
impl = (iidr >> SBSA_GWDT_IMPL_SHIFT) & SBSA_GWDT_IMPL_MASK;
209242

210243
gwdt->version = ver;
244+
gwdt->need_ws0_race_workaround =
245+
!action && (impl == SBSA_GWDT_IMPL_MEDIATEK);
211246
}
212247

213248
static int sbsa_gwdt_start(struct watchdog_device *wdd)
@@ -299,6 +334,15 @@ static int sbsa_gwdt_probe(struct platform_device *pdev)
299334
else
300335
wdd->max_hw_heartbeat_ms = GENMASK_ULL(47, 0) / gwdt->clk * 1000;
301336

337+
if (gwdt->need_ws0_race_workaround) {
338+
/*
339+
* A timeout of 3 seconds means that WOR will be set to 1.5
340+
* seconds and the heartbeat will be scheduled every 2.5
341+
* seconds.
342+
*/
343+
wdd->min_timeout = 3;
344+
}
345+
302346
status = readl(cf_base + SBSA_GWDT_WCS);
303347
if (status & SBSA_GWDT_WCS_WS1) {
304348
dev_warn(dev, "System reset by WDT.\n");

drivers/watchdog/watchdog_core.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424
* This material is provided "AS-IS" and at no charge.
2525
*/
2626

27-
#include <linux/hrtimer.h>
27+
#include <linux/cdev.h>
28+
#include <linux/device.h>
29+
#include <linux/hrtimer_types.h>
30+
#include <linux/init.h>
2831
#include <linux/kthread.h>
32+
#include <linux/mutex_types.h>
33+
#include <linux/types.h>
34+
#include <linux/watchdog.h>
2935

3036
#define MAX_DOGS 32 /* Maximum number of watchdog devices */
3137

drivers/watchdog/watchdog_pretimeout.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/slab.h>
88
#include <linux/spinlock.h>
99
#include <linux/string.h>
10+
#include <linux/sysfs.h>
11+
#include <linux/types.h>
1012
#include <linux/watchdog.h>
1113

1214
#include "watchdog_core.h"

drivers/watchdog/ziirave_wdt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ static int ziirave_firm_verify(struct watchdog_device *wdd,
302302
const u16 len = be16_to_cpu(rec->len);
303303
const u32 addr = be32_to_cpu(rec->addr);
304304

305+
if (len > sizeof(data))
306+
return -EINVAL;
307+
305308
if (ziirave_firm_addr_readonly(addr))
306309
continue;
307310

0 commit comments

Comments
 (0)