Re: [PATCH v2] powerpc/powermac: Fix low_sleep_handler with CONFIG_VMAP_STACK

2020-12-15 Thread Michael Ellerman
On Tue, 8 Dec 2020 05:24:19 + (UTC), Christophe Leroy wrote:
> low_sleep_handler() can't restore the context from standard
> stack because the stack can hardly be accessed with MMU OFF.
> 
> Store everything in a global storage area instead of storing
> a pointer to the stack in that global storage area.
> 
> To avoid a complete churn of the function, still use r1 as
> the pointer to the storage area during restore.

Applied to powerpc/next.

[1/1] powerpc/powermac: Fix low_sleep_handler with CONFIG_VMAP_STACK
  https://git.kernel.org/powerpc/c/db972a3787d12b1ce9ba7a31ec376d8a79e04c47

cheers


Re: [PATCH v2] powerpc/powermac: Fix low_sleep_handler with CONFIG_VMAP_STACK

2020-12-08 Thread Giuseppe Sacco
Hello Christophe,

Il giorno mar, 08/12/2020 alle 05.24 +, Christophe Leroy ha
scritto:
> low_sleep_handler() can't restore the context from standard
> stack because the stack can hardly be accessed with MMU OFF.
> 
> Store everything in a global storage area instead of storing
> a pointer to the stack in that global storage area.
> 
> To avoid a complete churn of the function, still use r1 as
> the pointer to the storage area during restore.
> 
> Reported-by: Giuseppe Sacco 
> Fixes: cd08f109e262 ("powerpc/32s: Enable CONFIG_VMAP_STACK")
> Signed-off-by: Christophe Leroy 
> ---
> This is only build tested. Giuseppe can you test it ? Thanks.
> 
> v2: Changed an erroneous 'addis' to 'addi' ; Using bss instead of
> data section
> Signed-off-by: Christophe Leroy 
> ---
>  arch/powerpc/platforms/Kconfig.cputype  |   2 +-
>  arch/powerpc/platforms/powermac/sleep.S | 132 +++---
> --
>  2 files changed, 60 insertions(+), 74 deletions(-)
[...]

I just tested the v2 patch against latest kernel. Please note that
yesterday patch was on a kernel named 5.10.0-rc6+, while today's patch
is on a kernel named 5.10.0-rc7+. Even with the latest kernel updates,
the patch apply correctly and machine boots normally, fixing the
problem.

$ uname -a
Linux titanium4 5.10.0-rc7+ #3 Tue Dec 8 09:11:20 CET 2020 ppc GNU/Linux
$ grep VMAP /boot/config-5.10.0-rc7+
CONFIG_HAVE_ARCH_VMAP_STACK=y
CONFIG_VMAP_STACK=y

Thank you again.

Bye,
Giuseppe




[PATCH v2] powerpc/powermac: Fix low_sleep_handler with CONFIG_VMAP_STACK

2020-12-07 Thread Christophe Leroy
low_sleep_handler() can't restore the context from standard
stack because the stack can hardly be accessed with MMU OFF.

Store everything in a global storage area instead of storing
a pointer to the stack in that global storage area.

To avoid a complete churn of the function, still use r1 as
the pointer to the storage area during restore.

Reported-by: Giuseppe Sacco 
Fixes: cd08f109e262 ("powerpc/32s: Enable CONFIG_VMAP_STACK")
Signed-off-by: Christophe Leroy 
---
This is only build tested. Giuseppe can you test it ? Thanks.

v2: Changed an erroneous 'addis' to 'addi' ; Using bss instead of data section
Signed-off-by: Christophe Leroy 
---
 arch/powerpc/platforms/Kconfig.cputype  |   2 +-
 arch/powerpc/platforms/powermac/sleep.S | 132 +++-
 2 files changed, 60 insertions(+), 74 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig.cputype 
b/arch/powerpc/platforms/Kconfig.cputype
index c194c4ae8bc7..32a9c4c09b98 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -36,7 +36,7 @@ config PPC_BOOK3S_6xx
select PPC_HAVE_PMU_SUPPORT
select PPC_HAVE_KUEP
select PPC_HAVE_KUAP
-   select HAVE_ARCH_VMAP_STACK if !ADB_PMU
+   select HAVE_ARCH_VMAP_STACK
 
 config PPC_85xx
bool "Freescale 85xx"
diff --git a/arch/powerpc/platforms/powermac/sleep.S 
b/arch/powerpc/platforms/powermac/sleep.S
index 7e0f8ba6e54a..d497a60003d2 100644
--- a/arch/powerpc/platforms/powermac/sleep.S
+++ b/arch/powerpc/platforms/powermac/sleep.S
@@ -44,7 +44,8 @@
 #define SL_TB  0xa0
 #define SL_R2  0xa8
 #define SL_CR  0xac
-#define SL_R12 0xb0/* r12 to r31 */
+#define SL_LR  0xb0
+#define SL_R12 0xb4/* r12 to r31 */
 #define SL_SIZE(SL_R12 + 80)
 
.section .text
@@ -63,105 +64,107 @@ _GLOBAL(low_sleep_handler)
blr
 #else
mflrr0
-   stw r0,4(r1)
-   stwur1,-SL_SIZE(r1)
+   lis r11,sleep_storage@ha
+   addir11,r11,sleep_storage@l
+   stw r0,SL_LR(r11)
mfcrr0
-   stw r0,SL_CR(r1)
-   stw r2,SL_R2(r1)
-   stmwr12,SL_R12(r1)
+   stw r0,SL_CR(r11)
+   stw r1,SL_SP(r11)
+   stw r2,SL_R2(r11)
+   stmwr12,SL_R12(r11)
 
/* Save MSR & SDR1 */
mfmsr   r4
-   stw r4,SL_MSR(r1)
+   stw r4,SL_MSR(r11)
mfsdr1  r4
-   stw r4,SL_SDR1(r1)
+   stw r4,SL_SDR1(r11)
 
/* Get a stable timebase and save it */
 1: mftbu   r4
-   stw r4,SL_TB(r1)
+   stw r4,SL_TB(r11)
mftbr5
-   stw r5,SL_TB+4(r1)
+   stw r5,SL_TB+4(r11)
mftbu   r3
cmpwr3,r4
bne 1b
 
/* Save SPRGs */
mfsprg  r4,0
-   stw r4,SL_SPRG0(r1)
+   stw r4,SL_SPRG0(r11)
mfsprg  r4,1
-   stw r4,SL_SPRG0+4(r1)
+   stw r4,SL_SPRG0+4(r11)
mfsprg  r4,2
-   stw r4,SL_SPRG0+8(r1)
+   stw r4,SL_SPRG0+8(r11)
mfsprg  r4,3
-   stw r4,SL_SPRG0+12(r1)
+   stw r4,SL_SPRG0+12(r11)
 
/* Save BATs */
mfdbatu r4,0
-   stw r4,SL_DBAT0(r1)
+   stw r4,SL_DBAT0(r11)
mfdbatl r4,0
-   stw r4,SL_DBAT0+4(r1)
+   stw r4,SL_DBAT0+4(r11)
mfdbatu r4,1
-   stw r4,SL_DBAT1(r1)
+   stw r4,SL_DBAT1(r11)
mfdbatl r4,1
-   stw r4,SL_DBAT1+4(r1)
+   stw r4,SL_DBAT1+4(r11)
mfdbatu r4,2
-   stw r4,SL_DBAT2(r1)
+   stw r4,SL_DBAT2(r11)
mfdbatl r4,2
-   stw r4,SL_DBAT2+4(r1)
+   stw r4,SL_DBAT2+4(r11)
mfdbatu r4,3
-   stw r4,SL_DBAT3(r1)
+   stw r4,SL_DBAT3(r11)
mfdbatl r4,3
-   stw r4,SL_DBAT3+4(r1)
+   stw r4,SL_DBAT3+4(r11)
mfibatu r4,0
-   stw r4,SL_IBAT0(r1)
+   stw r4,SL_IBAT0(r11)
mfibatl r4,0
-   stw r4,SL_IBAT0+4(r1)
+   stw r4,SL_IBAT0+4(r11)
mfibatu r4,1
-   stw r4,SL_IBAT1(r1)
+   stw r4,SL_IBAT1(r11)
mfibatl r4,1
-   stw r4,SL_IBAT1+4(r1)
+   stw r4,SL_IBAT1+4(r11)
mfibatu r4,2
-   stw r4,SL_IBAT2(r1)
+   stw r4,SL_IBAT2(r11)
mfibatl r4,2
-   stw r4,SL_IBAT2+4(r1)
+   stw r4,SL_IBAT2+4(r11)
mfibatu r4,3
-   stw r4,SL_IBAT3(r1)
+   stw r4,SL_IBAT3(r11)
mfibatl r4,3
-   stw r4,SL_IBAT3+4(r1)
+   stw r4,SL_IBAT3+4(r11)
 
 BEGIN_MMU_FTR_SECTION
mfspr   r4,SPRN_DBAT4U
-   stw r4,SL_DBAT4(r1)
+   stw r4,SL_DBAT4(r11)
mfspr   r4,SPRN_DBAT4L
-   stw r4,SL_DBAT4+4(r1)
+   stw r4,SL_DBAT4+4(r11)
mfspr   r4,SPRN_DBAT5U
-   stw r4,SL_DBAT5(r1)
+   stw r4,SL_DBAT5(r11)
mfspr   r4,SPRN_DBAT5L
-   stw r4,SL_DBAT5+4(r1)
+