Skip to contentSkip to conversation

arch/powerpc/44x/fsp2: wdt tcr update instead of whole rewrite

PATCH Applied Ivan Mikhaylov 4 participants 7 messages May 15, 2017 – May 30, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 arch/powerpc/44x/fsp2: wdt tcr update instead of whole rewrite

Prevent a kernel panic caused by unintentionally clearing TCR watchdog bits. At this point in the kernel boot, the watchdog has already been enabled by u-boot. The original code's attempt to write to the TCR register results in an inadvertent clearing of the watchdog configuration bits, causing the 476 to reset. Panic happens in case of error as silently reboot without any outputs on serial.

---
 arch/powerpc/kernel/time.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
arch/powerpc/kernel/time.c +16 -0
index 2b33cfa..f75e512 100644
@@ -738,12 +738,28 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
 
 static void start_cpu_decrementer(void)
 {
+	unsigned int tcr;
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
 
+#ifdef CONFIG_FSP2
+	/*
+	 * Prevent a kernel panic caused by unintentionally clearing TCR
+	 * watchdog bits.  At this point in the kernel boot, the watchdog has
+	 * already been enabled by u-boot.  The original code's attempt to
+	 * write to the TCR register results in an inadvertent clearing of the
+	 * watchdog configuration bits, causing the 440 to reset.
+	 */
+	tcr = mfspr(SPRN_TCR);
+	tcr &= TCR_WP_MASK; /* clear all bits except for TCR[WP] */
+	tcr |= TCR_DIE; /* enable decrementer */
+	mtspr(SPRN_TCR, tcr);
+#else
 	/* Enable decrementer interrupt */
 	mtspr(SPRN_TCR, TCR_DIE);
+#endif
+
 #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */
 }
 
Signature · 1 line
1.7.1
#1 lore raw

Hi Ivan,

Quoted 7 lines · Ivan Mikhaylov

Prevent a kernel panic caused by unintentionally clearing TCR watchdog bits. At this point in the kernel boot, the watchdog has already been enabled by u-boot. The original code's attempt to write to the TCR register results in an inadvertent clearing of the watchdog configuration bits, causing the 476 to reset. Panic happens in case of error as silently reboot without any outputs on serial.

That sounds reasonable.

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, u=

Quoted 5 lines
arch/powerpc/kernel/time.c +0 -0
index 2b33cfa..f75e512 100644
@@ -738,12 +738,28 @@ static int __init get_freq(char *name, int cells, u=

nsigned long *val)

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, unsigned long *val) · line 750

Quoted 13 lines

=20=20
static void start_cpu_decrementer(void)
{

arch/powerpc/kernel/time.c +1 -0
+	unsigned int tcr;
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);

=20=20

arch/powerpc/kernel/time.c +5 -0
+#ifdef CONFIG_FSP2
+	/*
+	 * Prevent a kernel panic caused by unintentionally clearing TCR
+	 * watchdog bits.  At this point in the kernel boot, the watchdog has
+	 * already been enabled by u-boot.  The original code's attempt to

Don't refer to "the original code", as it doesn't exist anymore now that we've patched it. Just say something like ".. so we must not clear the watchdog configuration bits".

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, unsigned long *val) · line 763

Quoted 13 lines
arch/powerpc/kernel/time.c +10 -0
+	 * write to the TCR register results in an inadvertent clearing of the
+	 * watchdog configuration bits, causing the 440 to reset.
+	 */
+	tcr =3D mfspr(SPRN_TCR);
+	tcr &=3D TCR_WP_MASK; /* clear all bits except for TCR[WP] */
+	tcr |=3D TCR_DIE; /* enable decrementer */
+	mtspr(SPRN_TCR, tcr);
+#else
 	/* Enable decrementer interrupt */
 	mtspr(SPRN_TCR, TCR_DIE);
+#endif
+
 #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */

That breaks the build for other platforms:

arch/powerpc/kernel/time.c: In function =E2=80=98start_cpu_decrementer=E2=
=80=99:
arch/powerpc/kernel/time.c:741:15: error: unused variable =E2=80=98tcr=E2=
=80=99 [-Werror=3Dunused-variable]

You can just do something like:

  #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
  	unsigned int tcr;

  #ifdef CONFIG_FSP2
  	tcr =3D mfspr(SPRN_TCR);
  	tcr &=3D TCR_WP_MASK; /* clear all bits except for TCR[WP] */
  #else
  	tcr =3D 0;
  #endif
  	tcr |=3D TCR_DIE; /* enable decrementer */
  	mtspr(SPRN_TCR, TCR_DIE);
  #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */

Or you could possibly just always leave TCR[WP], is there any case where it would be correct to clear that?

cheers

#2 lore raw

Hi Michael,

Quoted 5 lines

arch/powerpc/kernel/time.c static int =5F=5Finit get=5Ffreq(char *name, int c=

Quoted 5 lines
arch/powerpc/kernel/time.c +0 -0
index 2b33cfa..f75e512 100644
@@ -738,12 +738,28 @@ static int =5F=5Finit get=5Ffreq(char *name, int c=

ells, unsigned long *val)

Quoted 9 lines
Quoted 9 lines

=20
static void start=5Fcpu=5Fdecrementer(void)
{

arch/powerpc/kernel/time.c +1 -0
+	unsigned int tcr;
 #if defined(CONFIG=5FBOOKE) || defined(CONFIG=5F40x)
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN=5FTSR, TSR=5FENW | TSR=5FWIS | TSR=5FDIS | TSR=5FFIS);

=20
+#ifdef CONFIG=5FFSP2

Quoted 8 lines

arch/powerpc/kernel/time.c

Quoted 4 lines
arch/powerpc/kernel/time.c +4 -0
+	/*
+	 * Prevent a kernel panic caused by unintentionally clearing TCR
+	 * watchdog bits.  At this point in the kernel boot, the watchdog has
+	 * already been enabled by u-boot.  The original code's attempt to

Don't refer to "the original code", as it doesn't exist anymore now that we've patched it. Just say something like ".. so we must not clear the watchdog configuration bits".

Ok, got it.

Quoted 3 lines

That breaks the build for other platforms:

arch/powerpc/kernel/time.c: In function =E2=80=98start=5Fcpu=5Fdecremente=

r=E2=80=99:

Quoted 1 line

arch/powerpc/kernel/time.c:741:15: error: unused variable =E2=80=98tcr=E2=

=80=99 [-Werror=3Dunused-variable]

Quoted 1 line

Oops, didn't notice, my fault.=20

Quoted 6 lines

Or you could possibly just always leave TCR[WP], is there any case where it would be correct to clear that?

cheers

From my point of view it's possible. I've checked docu and on idea

it should be possible cause WP is only affecting watchdog ping time. Which in case of '00' is very small, around ~5 ms.=20
Ben also in next message said about get rid of ifdef for FSP2.

And now patch looks like this, What do you think Michael, Ben?

 arch/powerpc/kernel/time.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
arch/powerpc/kernel/time.c +0 -0
index bc2e08d..2411c49 100644
@@ -718,11 +718,22 @@ static int =5F=5Finit get=5Ffreq(char *name, int cell=

s, unsigned long *val)
static void start=5Fcpu=5Fdecrementer(void)
{
#if defined(CONFIG=5FBOOKE) || defined(CONFIG=5F40x)
+ unsigned int tcr;
/* Clear any pending timer interrupts */ mtspr(SPRN=5FTSR, TSR=5FENW | TSR=5FWIS | TSR=5FDIS | TSR=5FFIS);
=20
- /* Enable decrementer interrupt */
- mtspr(SPRN=5FTCR, TCR=5FDIE);
+ tcr =3D mfspr(SPRN=5FTCR);
+ /*
+ * At this point in the kernel boot, the watchdog has already
+ * been enabled by u-boot. If we set it this to '00' it may
+ * trigger watchdog earlier than needed which will cause
+ * inattentional kernel panic. In this case we leaving TCR[WP]
+ * bit setting from uboot/bootstrap.
+ */
+ tcr &=3D TCR=5FWP=5FMASK; /* clear all bits except for TCR[WP] */
+ tcr |=3D TCR=5FDIE; /* enable decrementer */
+ mtspr(SPRN=5FTCR, tcr);
+
#endif /* defined(CONFIG=5FBOOKE) || defined(CONFIG=5F40x) */ }
=20
--=20
1.7.1

#3 lore raw
Quoted 3 lines · Ivan Mikhaylov

From my point of view it's possible. I've checked docu and on idea it should be possible cause WP is only affecting watchdog ping time.

The question is, is there any chance that leaving those bits set on another platform will cause a problem?

ie. on existing machines we always clear those bits, is it OK that we will now start leaving those bits with whatever value they had.

cheers

#4 lore raw
Quoted 10 lines · Michael Ellerman
Quoted 3 lines · Ivan Mikhaylov

From my point of view it's possible. I've checked docu and on idea it should be possible cause WP is only affecting watchdog ping time.

The question is, is there any chance that leaving those bits set on another platform will cause a problem?

ie. on existing machines we always clear those bits, is it OK that we will now start leaving those bits with whatever value they had.

I came up with the patch below (more or less your v2), if it breaks something we can always fix it.

cheers

commit c80409358a9c91e1f6b18353dad939b851bb3522

Author: Ivan Mikhaylov <[email protected]>
Date:   Fri May 19 18:47:05 2017 +0300

powerpc/[booke|4xx]: Don't clobber TCR[WP] when setting TCR[DIE]

Prevent a kernel panic caused by unintentionally clearing TCR watchdog bits. At this point in the kernel boot, the watchdog may have already been enabled by u-boot. The original code's attempt to write to the TCR register results in an inadvertent clearing of the watchdog configuration bits, causing the 476 to reset.

arch/powerpc/kernel/time.c +11 -3
index 2b33cfaac7b8..60714b8c9a2f 100644
@@ -739,12 +739,20 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
 static void start_cpu_decrementer(void)
 {
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
+	unsigned int tcr;
+
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
 
-	/* Enable decrementer interrupt */
-	mtspr(SPRN_TCR, TCR_DIE);
-#endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */
+	tcr = mfspr(SPRN_TCR);
+	/*
+	 * The watchdog may have already been enabled by u-boot. So leave
+	 * TRC[WP] (Watchdog Period) alone.
+	 */
+	tcr &= TCR_WP_MASK;	/* Clear all bits except for TCR[WP] */
+	tcr |= TCR_DIE;		/* Enable decrementer */
+	mtspr(SPRN_TCR, tcr);
+#endif
 }
 
 void __init generic_calibrate_decr(void)
#5 lore raw
In reply to Ivan Mikhaylov
Quoted 67 lines · Ivan Mikhaylov

Hi Michael,

Quoted 13 lines
Quoted 13 lines
arch/powerpc/kernel/time.c +1 -0
index 2b33cfa..f75e512 100644
@@ -738,12 +738,28 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
 
 static void start_cpu_decrementer(void)
 {
+	unsigned int tcr;
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
 
Quoted 9 lines

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, unsigned long *val) · line 750

Quoted 5 lines
arch/powerpc/kernel/time.c +5 -0
+#ifdef CONFIG_FSP2
+	/*
+	 * Prevent a kernel panic caused by unintentionally clearing TCR
+	 * watchdog bits.  At this point in the kernel boot, the watchdog has
+	 * already been enabled by u-boot.  The original code's attempt to

Don't refer to "the original code", as it doesn't exist anymore now that we've patched it. Just say something like ".. so we must not clear the watchdog configuration bits".

Ok, got it.

Quoted 5 lines

That breaks the build for other platforms:

arch/powerpc/kernel/time.c: In function ‘start_cpu_decrementer’:
arch/powerpc/kernel/time.c:741:15: error: unused variable ‘tcr’ [-Werror=unused-variable]

Oops, didn't notice, my fault.

Quoted 6 lines

Or you could possibly just always leave TCR[WP], is there any case where it would be correct to clear that?

cheers

From my point of view it's possible. I've checked docu and on idea

it should be possible cause WP is only affecting watchdog ping time. Which in case of '00' is very small, around ~5 ms.
Ben also in next message said about get rid of ifdef for FSP2.

And now patch looks like this, What do you think Michael, Ben?

 arch/powerpc/kernel/time.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
arch/powerpc/kernel/time.c +6 -2
index bc2e08d..2411c49 100644
@@ -718,11 +718,22 @@ static int __init get_freq(char *name, int cells, unsigned long *val)
 static void start_cpu_decrementer(void)
 {
 #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
+	unsigned int tcr;
 	/* Clear any pending timer interrupts */
 	mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
 
-	/* Enable decrementer interrupt */
-	mtspr(SPRN_TCR, TCR_DIE);
+	tcr = mfspr(SPRN_TCR);
+	/*
+	 * At this point in the kernel boot, the watchdog has already
+	 * been enabled by u-boot. If we set it this to '00' it may
+	 * trigger watchdog earlier than needed which will cause

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, unsigned long *val) · line 739

Quoted 10 lines
arch/powerpc/kernel/time.c +7 -0
+	 * inattentional kernel panic. In this case we leaving TCR[WP]
+	 * bit setting from uboot/bootstrap.
+	 */
+	tcr &= TCR_WP_MASK; /* clear all bits except for TCR[WP] */
+	tcr |= TCR_DIE; /* enable decrementer */
+	mtspr(SPRN_TCR, tcr);
+
 #endif /* defined(CONFIG_BOOKE) || defined(CONFIG_40x) */
 }
 

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/6e2f03e292ef46eed2b31b0a344a91

cheers

#6 lore raw
In reply to Ivan Mikhaylov

arch/powerpc/kernel/time.c static int __init get_freq(char *name, int cells, unsigned long *val) · line 758

Quoted 13 lines · Ivan Mikhaylov
arch/powerpc/kernel/time.c +13 -0
+#ifdef CONFIG_FSP2
+       /*
+        * Prevent a kernel panic caused by unintentionally clearing TCR
+        * watchdog bits.  At this point in the kernel boot, the watchdog has
+        * already been enabled by u-boot.  The original code's attempt to
+        * write to the TCR register results in an inadvertent clearing of the
+        * watchdog configuration bits, causing the 440 to reset.
+        */
+       tcr = mfspr(SPRN_TCR);
+       tcr &= TCR_WP_MASK; /* clear all bits except for TCR[WP] */
+       tcr |= TCR_DIE; /* enable decrementer */
+       mtspr(SPRN_TCR, tcr);
+#else

This should be a runtime test, not a compile time option.

Cheers,
Ben.