[-next] watchdog: sbsa: Test WDOG_HW_RUNNING bit in suspend and resume

Message ID 20230301113702.76437-1-wangwensheng4@huawei.com
State New
Headers
Series [-next] watchdog: sbsa: Test WDOG_HW_RUNNING bit in suspend and resume |

Commit Message

Wang Wensheng March 1, 2023, 11:37 a.m. UTC
  If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit
and keep it alive before anyone else would open it. When system suspend,
the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then
the sbsa_gwdt would reach timeout since no one touch it during system
suspend.

To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the
sbsa_gwdt if the bit is set, then reopen it accordingly in resume
process.

Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
---
 drivers/watchdog/sbsa_gwdt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Guenter Roeck March 4, 2023, 2:54 p.m. UTC | #1
On 3/1/23 03:37, Wang Wensheng wrote:
> If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit
> and keep it alive before anyone else would open it. When system suspend,
> the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then
> the sbsa_gwdt would reach timeout since no one touch it during system
> suspend.
> 
> To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the
> sbsa_gwdt if the bit is set, then reopen it accordingly in resume
> process.
> 
> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
> ---
>   drivers/watchdog/sbsa_gwdt.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
> index 9791c74aebd4..60875a710e43 100644
> --- a/drivers/watchdog/sbsa_gwdt.c
> +++ b/drivers/watchdog/sbsa_gwdt.c
> @@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
>   {
>   	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>   
> -	if (watchdog_active(&gwdt->wdd))
> +	if (watchdog_hw_running(&gwdt->wdd))
>   		sbsa_gwdt_stop(&gwdt->wdd);

That will not stop the watchdog if it is currently open (active)
and if it wasn't running when the module was loaded.

Guenter

>   
>   	return 0;
> @@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
>   {
>   	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>   
> -	if (watchdog_active(&gwdt->wdd))
> +	if (watchdog_hw_running(&gwdt->wdd))
>   		sbsa_gwdt_start(&gwdt->wdd);
>   
>   	return 0;
  
Guenter Roeck March 4, 2023, 4:16 p.m. UTC | #2
On 3/4/23 06:54, Guenter Roeck wrote:
> On 3/1/23 03:37, Wang Wensheng wrote:
>> If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit
>> and keep it alive before anyone else would open it. When system suspend,
>> the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then
>> the sbsa_gwdt would reach timeout since no one touch it during system
>> suspend.
>>
>> To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the
>> sbsa_gwdt if the bit is set, then reopen it accordingly in resume
>> process.
>>
>> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>
>> ---
>>   drivers/watchdog/sbsa_gwdt.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
>> index 9791c74aebd4..60875a710e43 100644
>> --- a/drivers/watchdog/sbsa_gwdt.c
>> +++ b/drivers/watchdog/sbsa_gwdt.c
>> @@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
>>   {
>>       struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>> -    if (watchdog_active(&gwdt->wdd))
>> +    if (watchdog_hw_running(&gwdt->wdd))
>>           sbsa_gwdt_stop(&gwdt->wdd);
> 
> That will not stop the watchdog if it is currently open (active)
> and if it wasn't running when the module was loaded.
> 

I just sent a patch which fixes the problem in the watchdog core.

Guenter

> Guenter
> 
>>       return 0;
>> @@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
>>   {
>>       struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>> -    if (watchdog_active(&gwdt->wdd))
>> +    if (watchdog_hw_running(&gwdt->wdd))
>>           sbsa_gwdt_start(&gwdt->wdd);
>>       return 0;
>
  
Guenter Roeck March 4, 2023, 4:24 p.m. UTC | #3
On 3/1/23 03:37, Wang Wensheng wrote:
> If the sbsa_gwdt is enabled by BIOS, the kernel set WDOG_HW_RUNNING bit
> and keep it alive before anyone else would open it. When system suspend,
> the sbsa_gwdt would not be disabled because WDOG_ACTIVE is not set. Then
> the sbsa_gwdt would reach timeout since no one touch it during system
> suspend.
> 
> To solve this, just test WDOG_HW_RUNNING bit in suspend and disable the
> sbsa_gwdt if the bit is set, then reopen it accordingly in resume
> process.
> 
> Signed-off-by: Wang Wensheng <wangwensheng4@huawei.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Prerequisite: "watchdog: core: Always set WDOG_HW_RUNNING when starting watchdog"

Guenter

> ---
>   drivers/watchdog/sbsa_gwdt.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
> index 9791c74aebd4..60875a710e43 100644
> --- a/drivers/watchdog/sbsa_gwdt.c
> +++ b/drivers/watchdog/sbsa_gwdt.c
> @@ -360,7 +360,7 @@ static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
>   {
>   	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>   
> -	if (watchdog_active(&gwdt->wdd))
> +	if (watchdog_hw_running(&gwdt->wdd))
>   		sbsa_gwdt_stop(&gwdt->wdd);
>   
>   	return 0;
> @@ -371,7 +371,7 @@ static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
>   {
>   	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
>   
> -	if (watchdog_active(&gwdt->wdd))
> +	if (watchdog_hw_running(&gwdt->wdd))
>   		sbsa_gwdt_start(&gwdt->wdd);
>   
>   	return 0;
  

Patch

diff --git a/drivers/watchdog/sbsa_gwdt.c b/drivers/watchdog/sbsa_gwdt.c
index 9791c74aebd4..60875a710e43 100644
--- a/drivers/watchdog/sbsa_gwdt.c
+++ b/drivers/watchdog/sbsa_gwdt.c
@@ -360,7 +360,7 @@  static int __maybe_unused sbsa_gwdt_suspend(struct device *dev)
 {
 	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
 		sbsa_gwdt_stop(&gwdt->wdd);
 
 	return 0;
@@ -371,7 +371,7 @@  static int __maybe_unused sbsa_gwdt_resume(struct device *dev)
 {
 	struct sbsa_gwdt *gwdt = dev_get_drvdata(dev);
 
-	if (watchdog_active(&gwdt->wdd))
+	if (watchdog_hw_running(&gwdt->wdd))
 		sbsa_gwdt_start(&gwdt->wdd);
 
 	return 0;