2023-02-08 08:38:18

by George Cherian

[permalink] [raw]
Subject: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

Make sure to honour the max_hw_heartbeat_ms while programming the timeout
value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to
make sure the programmed value is within the permissible range.

Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")

Signed-off-by: George Cherian <[email protected]>
---
drivers/watchdog/sbsa_gwdt.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index 9791c74aebd4..ee1039a652f1 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
{
struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);

+ timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000);
wdd->timeout = timeout;

if (action)
--
2.34.1



2023-02-08 15:11:08

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

On 2/8/23 00:37, George Cherian wrote:
> Make sure to honour the max_hw_heartbeat_ms while programming the timeout
> value to WOR. Clamp the timeout passed to sbsa_gwdt_set_timeout() to
> make sure the programmed value is within the permissible range.
>
> Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
>
> Signed-off-by: George Cherian <[email protected]>
> ---
> drivers/watchdog/sbsa_gwdt.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
> index 9791c74aebd4..ee1039a652f1 100644
> --- a/drivers/watchdog/sbsa_gwdt.c
> +++ b/drivers/watchdog/sbsa_gwdt.c
> @@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct watchdog_device *wdd,
> {
> struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
>
> + timeout = clamp_t(unsigned int, timeout, 1, wdd->max_hw_heartbeat_ms / 1000);
> wdd->timeout = timeout;
>

Wrong order. wdd->timeout should still contain the requested timeout.

Guenter


2023-02-08 17:21:12

by George Cherian

[permalink] [raw]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits



> -----Original Message-----
> From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> Sent: Wednesday, February 8, 2023 8:41 PM
> To: George Cherian <[email protected]>; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]
> Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout
> programming is within the limits
>
>
> ----------------------------------------------------------------------
> On 2/8/23 00:37, George Cherian wrote:
> > Make sure to honour the max_hw_heartbeat_ms while programming the
> > timeout value to WOR. Clamp the timeout passed to
> > sbsa_gwdt_set_timeout() to make sure the programmed value is within
> the permissible range.
> >
> > Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
> >
> > Signed-off-by: George Cherian <[email protected]>
> > ---
> > drivers/watchdog/sbsa_gwdt.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/watchdog/sbsa_gwdt.c
> > b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1
> 100644
> > --- a/drivers/watchdog/sbsa_gwdt.c
> > +++ b/drivers/watchdog/sbsa_gwdt.c
> > @@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct
> watchdog_device *wdd,
> > {
> > struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
> >
> > + timeout = clamp_t(unsigned int, timeout, 1, wdd-
> >max_hw_heartbeat_ms
> > +/ 1000);
> > wdd->timeout = timeout;
> >
>
> Wrong order. wdd->timeout should still contain the requested timeout.
But then the requested timeout is not being set in HW.
Isn't that a disconnect?

>
> Guenter

2023-02-08 17:55:53

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits

On Wed, Feb 08, 2023 at 05:20:34PM +0000, George Cherian wrote:
>
>
> > -----Original Message-----
> > From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> > Sent: Wednesday, February 8, 2023 8:41 PM
> > To: George Cherian <[email protected]>; [email protected];
> > [email protected]
> > Cc: [email protected]; [email protected]
> > Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout
> > programming is within the limits
> >
> >
> > ----------------------------------------------------------------------
> > On 2/8/23 00:37, George Cherian wrote:
> > > Make sure to honour the max_hw_heartbeat_ms while programming the
> > > timeout value to WOR. Clamp the timeout passed to
> > > sbsa_gwdt_set_timeout() to make sure the programmed value is within
> > the permissible range.
> > >
> > > Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version 1")
> > >
> > > Signed-off-by: George Cherian <[email protected]>
> > > ---
> > > drivers/watchdog/sbsa_gwdt.c | 1 +
> > > 1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/watchdog/sbsa_gwdt.c
> > > b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1
> > 100644
> > > --- a/drivers/watchdog/sbsa_gwdt.c
> > > +++ b/drivers/watchdog/sbsa_gwdt.c
> > > @@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct
> > watchdog_device *wdd,
> > > {
> > > struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
> > >
> > > + timeout = clamp_t(unsigned int, timeout, 1, wdd-
> > >max_hw_heartbeat_ms
> > > +/ 1000);
> > > wdd->timeout = timeout;
> > >
> >
> > Wrong order. wdd->timeout should still contain the requested timeout.
> But then the requested timeout is not being set in HW.
> Isn't that a disconnect?

No. The driver is supposed to set a timeout no larger than
max_hw_heartbeat_ms. The watchdog core then takes care of
differences between ->timeout (as seen by the user) and
max_hw_heartbeat_ms and pings the watchdog as needed.

Guenter

2023-02-09 02:10:03

by George Cherian

[permalink] [raw]
Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits



> -----Original Message-----
> From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
> Sent: Wednesday, February 8, 2023 11:26 PM
> To: George Cherian <[email protected]>
> Cc: [email protected]; [email protected]; linux-
> [email protected]; [email protected]
> Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout
> programming is within the limits
>
> ----------------------------------------------------------------------
> On Wed, Feb 08, 2023 at 05:20:34PM +0000, George Cherian wrote:
> >
> >
> > > -----Original Message-----
> > > From: Guenter Roeck <[email protected]> On Behalf Of Guenter
> Roeck
> > > Sent: Wednesday, February 8, 2023 8:41 PM
> > > To: George Cherian <[email protected]>; [email protected];
> > > [email protected]
> > > Cc: [email protected]; [email protected]
> > > Subject: Re: [PATCH v2] watchdog: sbsa_wdog: Make sure the timeout
> > > programming is within the limits
> > >
> > >
> > > --------------------------------------------------------------------
> > > -- On 2/8/23 00:37, George Cherian wrote:
> > > > Make sure to honour the max_hw_heartbeat_ms while programming
> the
> > > > timeout value to WOR. Clamp the timeout passed to
> > > > sbsa_gwdt_set_timeout() to make sure the programmed value is
> > > > within
> > > the permissible range.
> > > >
> > > > Fixes: abd3ac7902fb ("watchdog: sbsa: Support architecture version
> > > > 1")
> > > >
> > > > Signed-off-by: George Cherian <[email protected]>
> > > > ---
> > > > drivers/watchdog/sbsa_gwdt.c | 1 +
> > > > 1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/drivers/watchdog/sbsa_gwdt.c
> > > > b/drivers/watchdog/sbsa_gwdt.c index 9791c74aebd4..ee1039a652f1
> > > 100644
> > > > --- a/drivers/watchdog/sbsa_gwdt.c
> > > > +++ b/drivers/watchdog/sbsa_gwdt.c
> > > > @@ -149,6 +149,7 @@ static int sbsa_gwdt_set_timeout(struct
> > > watchdog_device *wdd,
> > > > {
> > > > struct sbsa_gwdt *gwdt = watchdog_get_drvdata(wdd);
> > > >
> > > > + timeout = clamp_t(unsigned int, timeout, 1, wdd-
> > > >max_hw_heartbeat_ms
> > > > +/ 1000);
> > > > wdd->timeout = timeout;
> > > >
> > >
> > > Wrong order. wdd->timeout should still contain the requested timeout.
> > But then the requested timeout is not being set in HW.
> > Isn't that a disconnect?
>
> No. The driver is supposed to set a timeout no larger than
> max_hw_heartbeat_ms. The watchdog core then takes care of differences
> between ->timeout (as seen by the user) and max_hw_heartbeat_ms and
> pings the watchdog as needed.
Thanks for the explanation. Will post v3.

-George
>
> Guenter