diff mbox series

[v3] iTCO_wdt: mask NMI_NOW bit for update_no_reboot_bit() call

Message ID 20240913191403.2560805-1-oocheret@cisco.com (mailing list archive)
State New
Headers show
Series [v3] iTCO_wdt: mask NMI_NOW bit for update_no_reboot_bit() call | expand

Commit Message

Oleksandr Ocheretnyi Sept. 13, 2024, 7:14 p.m. UTC
Commit da23b6faa8bf ("watchdog: iTCO: Add support for Cannon Lake
PCH iTCO") does not mask NMI_NOW bit during TCO1_CNT register's
value comparison for update_no_reboot_bit() call causing following
failure:

   ...
   iTCO_vendor_support: vendor-support=0
   iTCO_wdt iTCO_wdt: unable to reset NO_REBOOT flag, device
                                    disabled by hardware/BIOS
   ...

and this can lead to unexpected NMIs later during regular
crashkernel's workflow because of watchdog probe call failures.

This change masks NMI_NOW bit for TCO1_CNT register values to
avoid unexpected NMI_NOW bit inversions.

Fixes: da23b6faa8bf ("watchdog: iTCO: Add support for Cannon Lake PCH iTCO")
Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>
---
 V2 -> V3: Removed not necessary variable 'mask', updated multi-line comments
 V1 -> V2: Provided comments and macro define with bit description

 drivers/watchdog/iTCO_wdt.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Comments

Guenter Roeck Sept. 17, 2024, 1:09 a.m. UTC | #1
On 9/13/24 12:14, Oleksandr Ocheretnyi wrote:
> Commit da23b6faa8bf ("watchdog: iTCO: Add support for Cannon Lake
> PCH iTCO") does not mask NMI_NOW bit during TCO1_CNT register's
> value comparison for update_no_reboot_bit() call causing following
> failure:
> 
>     ...
>     iTCO_vendor_support: vendor-support=0
>     iTCO_wdt iTCO_wdt: unable to reset NO_REBOOT flag, device
>                                      disabled by hardware/BIOS
>     ...
> 
> and this can lead to unexpected NMIs later during regular
> crashkernel's workflow because of watchdog probe call failures.
> 
> This change masks NMI_NOW bit for TCO1_CNT register values to
> avoid unexpected NMI_NOW bit inversions.
> 
> Fixes: da23b6faa8bf ("watchdog: iTCO: Add support for Cannon Lake PCH iTCO")
> Signed-off-by: Oleksandr Ocheretnyi <oocheret@cisco.com>

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

> ---
>   V2 -> V3: Removed not necessary variable 'mask', updated multi-line comments
>   V1 -> V2: Provided comments and macro define with bit description
> 
>   drivers/watchdog/iTCO_wdt.c | 21 +++++++++++++++++++--
>   1 file changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
> index 264857d314da..dd297dcd524c 100644
> --- a/drivers/watchdog/iTCO_wdt.c
> +++ b/drivers/watchdog/iTCO_wdt.c
> @@ -82,6 +82,13 @@
>   #define TCO2_CNT(p)	(TCOBASE(p) + 0x0a) /* TCO2 Control Register	*/
>   #define TCOv2_TMR(p)	(TCOBASE(p) + 0x12) /* TCOv2 Timer Initial Value*/
>   
> +/*
> + * NMI_NOW is bit 8 of TCO1_CNT register
> + * Read/Write
> + * This bit is implemented as RW but has no effect on HW.
> + */
> +#define NMI_NOW		BIT(8)
> +
>   /* internal variables */
>   struct iTCO_wdt_private {
>   	struct watchdog_device wddev;
> @@ -219,13 +226,23 @@ static int update_no_reboot_bit_cnt(void *priv, bool set)
>   	struct iTCO_wdt_private *p = priv;
>   	u16 val, newval;
>   
> -	val = inw(TCO1_CNT(p));
> +	/*
> +	 * writing back 1b1 to NMI_NOW of TCO1_CNT register
> +	 * causes NMI_NOW bit inversion what consequently does
> +	 * not allow to perform the register's value comparison
> +	 * properly.
> +	 *
> +	 * NMI_NOW bit masking for TCO1_CNT register values
> +	 * helps to avoid possible NMI_NOW bit inversions on
> +	 * following write operation.
> +	 */
> +	val = inw(TCO1_CNT(p)) & ~NMI_NOW;
>   	if (set)
>   		val |= BIT(0);
>   	else
>   		val &= ~BIT(0);
>   	outw(val, TCO1_CNT(p));
> -	newval = inw(TCO1_CNT(p));
> +	newval = inw(TCO1_CNT(p)) & ~NMI_NOW;
>   
>   	/* make sure the update is successful */
>   	return val != newval ? -EIO : 0;
Oleksandr Ocheretnyi Oct. 7, 2024, 3:57 p.m. UTC | #2
Hello Mika,

> I suggest adding some #define for the magical number 8 so that it is
> easier for anyone looking at this driver to figure out what it is doing.

Are the changes with #define NMI_NOW bit fine for you?

Best regards,
Oleksandr
Mika Westerberg Oct. 8, 2024, 4:33 p.m. UTC | #3
On Mon, Oct 07, 2024 at 08:57:02AM -0700, Oleksandr Ocheretnyi wrote:
> Hello Mika,
> 
> > I suggest adding some #define for the magical number 8 so that it is
> > easier for anyone looking at this driver to figure out what it is doing.
> 
> Are the changes with #define NMI_NOW bit fine for you?

Sure,

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index 264857d314da..dd297dcd524c 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -82,6 +82,13 @@ 
 #define TCO2_CNT(p)	(TCOBASE(p) + 0x0a) /* TCO2 Control Register	*/
 #define TCOv2_TMR(p)	(TCOBASE(p) + 0x12) /* TCOv2 Timer Initial Value*/
 
+/*
+ * NMI_NOW is bit 8 of TCO1_CNT register
+ * Read/Write
+ * This bit is implemented as RW but has no effect on HW.
+ */
+#define NMI_NOW		BIT(8)
+
 /* internal variables */
 struct iTCO_wdt_private {
 	struct watchdog_device wddev;
@@ -219,13 +226,23 @@  static int update_no_reboot_bit_cnt(void *priv, bool set)
 	struct iTCO_wdt_private *p = priv;
 	u16 val, newval;
 
-	val = inw(TCO1_CNT(p));
+	/*
+	 * writing back 1b1 to NMI_NOW of TCO1_CNT register
+	 * causes NMI_NOW bit inversion what consequently does
+	 * not allow to perform the register's value comparison
+	 * properly.
+	 *
+	 * NMI_NOW bit masking for TCO1_CNT register values
+	 * helps to avoid possible NMI_NOW bit inversions on
+	 * following write operation.
+	 */
+	val = inw(TCO1_CNT(p)) & ~NMI_NOW;
 	if (set)
 		val |= BIT(0);
 	else
 		val &= ~BIT(0);
 	outw(val, TCO1_CNT(p));
-	newval = inw(TCO1_CNT(p));
+	newval = inw(TCO1_CNT(p)) & ~NMI_NOW;
 
 	/* make sure the update is successful */
 	return val != newval ? -EIO : 0;