* [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32
@ 2019-08-31 10:18 Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 01/10] powerpc/32: replace MTMSRD() by mtmsr Christophe Leroy
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
The purpose of this serie is to enable CONFIG_VMAP_STACK on PPC32.
For the time being we have something working on 8xx.
Further work I'm working on:
- Fix stack overflow detection (doesn't work all the time yet, with the LKDTM STACK_EXHAUST test it hang).
- Add support to powerpc 603
- Add support to all book3s32
v2: added stack overflow detection.
Christophe Leroy (10):
powerpc/32: replace MTMSRD() by mtmsr
powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h
powerpc/32: prepare for CONFIG_VMAP_STACK
powerpc/8xx: Use alternative scratch registers in DTLB miss handler
powerpc/8xx: drop exception entries for non-existing exceptions
powerpc/8xx: move DataStoreTLBMiss perf handler
powerpc/8xx: split breakpoint exception
powerpc/8xx: Enable CONFIG_VMAP_STACK
powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK
powerpc/32: Add stack overflow detection with VMAP stack.
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/processor.h | 5 ++
arch/powerpc/include/asm/thread_info.h | 18 ++++
arch/powerpc/kernel/asm-offsets.c | 5 ++
arch/powerpc/kernel/entry_32.S | 37 +++++++--
arch/powerpc/kernel/head_32.S | 4 +-
arch/powerpc/kernel/head_32.h | 98 ++++++++++++++++++++--
arch/powerpc/kernel/head_8xx.S | 145 ++++++++++++++++++---------------
arch/powerpc/kernel/setup_32.c | 2 +-
arch/powerpc/kernel/setup_64.c | 2 +-
arch/powerpc/kernel/vmlinux.lds.S | 2 +-
arch/powerpc/perf/8xx-pmu.c | 12 ++-
12 files changed, 240 insertions(+), 91 deletions(-)
--
2.13.3
^ permalink raw reply [flat|nested] 11+ messages in thread
* [RFC PATCH v2 01/10] powerpc/32: replace MTMSRD() by mtmsr
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 02/10] powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h Christophe Leroy
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
On PPC32, MTMSRD() is simply defined as mtmsr.
Replace MTMSRD(reg) by mtmsr reg in files dedicated to PPC32,
this makes the code less obscure.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/entry_32.S | 18 +++++++++---------
arch/powerpc/kernel/head_32.h | 4 ++--
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 972b05504a0a..44716157c918 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -397,7 +397,7 @@ ret_from_syscall:
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL) /* doesn't include MSR_EE */
/* Note: We don't bother telling lockdep about it */
SYNC
- MTMSRD(r10)
+ mtmsr r10
lwz r9,TI_FLAGS(r2)
li r8,-MAX_ERRNO
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
@@ -554,7 +554,7 @@ syscall_exit_work:
*/
ori r10,r10,MSR_EE
SYNC
- MTMSRD(r10)
+ mtmsr r10
/* Save NVGPRS if they're not saved already */
lwz r4,_TRAP(r1)
@@ -697,7 +697,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_SPE)
and. r0,r0,r11 /* FP or altivec or SPE enabled? */
beq+ 1f
andc r11,r11,r0
- MTMSRD(r11)
+ mtmsr r11
isync
1: stw r11,_MSR(r1)
mfcr r10
@@ -826,7 +826,7 @@ ret_from_except:
/* Note: We don't bother telling lockdep about it */
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
SYNC /* Some chip revs have problems here... */
- MTMSRD(r10) /* disable interrupts */
+ mtmsr r10 /* disable interrupts */
lwz r3,_MSR(r1) /* Returning to user mode? */
andi. r0,r3,MSR_PR
@@ -993,7 +993,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
*/
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL & ~MSR_RI)
SYNC
- MTMSRD(r10) /* clear the RI bit */
+ mtmsr r10 /* clear the RI bit */
.globl exc_exit_restart
exc_exit_restart:
lwz r12,_NIP(r1)
@@ -1229,7 +1229,7 @@ do_resched: /* r10 contains MSR_KERNEL here */
#endif
ori r10,r10,MSR_EE
SYNC
- MTMSRD(r10) /* hard-enable interrupts */
+ mtmsr r10 /* hard-enable interrupts */
bl schedule
recheck:
/* Note: And we don't tell it we are disabling them again
@@ -1238,7 +1238,7 @@ recheck:
*/
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL)
SYNC
- MTMSRD(r10) /* disable interrupts */
+ mtmsr r10 /* disable interrupts */
lwz r9,TI_FLAGS(r2)
andi. r0,r9,_TIF_NEED_RESCHED
bne- do_resched
@@ -1247,7 +1247,7 @@ recheck:
do_user_signal: /* r10 contains MSR_KERNEL here */
ori r10,r10,MSR_EE
SYNC
- MTMSRD(r10) /* hard-enable interrupts */
+ mtmsr r10 /* hard-enable interrupts */
/* save r13-r31 in the exception frame, if not already done */
lwz r3,_TRAP(r1)
andi. r0,r3,1
@@ -1331,7 +1331,7 @@ _GLOBAL(enter_rtas)
stw r9,8(r1)
LOAD_REG_IMMEDIATE(r0,MSR_KERNEL)
SYNC /* disable interrupts so SRR0/1 */
- MTMSRD(r0) /* don't get trashed */
+ mtmsr r0 /* don't get trashed */
li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
mtlr r6
stw r7, THREAD + RTAS_SP(r2)
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 8abc7783dbe5..b2ca8c9ffd8b 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -50,7 +50,7 @@
rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */
#else
li r10,MSR_KERNEL & ~(MSR_IR|MSR_DR) /* can take exceptions */
- MTMSRD(r10) /* (except for mach check in rtas) */
+ mtmsr r10 /* (except for mach check in rtas) */
#endif
stw r0,GPR0(r11)
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
@@ -80,7 +80,7 @@
rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */
#else
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL & ~(MSR_IR|MSR_DR)) /* can take exceptions */
- MTMSRD(r10) /* (except for mach check in rtas) */
+ mtmsr r10 /* (except for mach check in rtas) */
#endif
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
stw r2,GPR2(r11)
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 02/10] powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 01/10] powerpc/32: replace MTMSRD() by mtmsr Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 03/10] powerpc/32: prepare for CONFIG_VMAP_STACK Christophe Leroy
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
This patch creates a macro for the very first part of
exception prolog, this will help when implementing
CONFIG_VMAP_STACK
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/head_32.S | 4 +---
arch/powerpc/kernel/head_32.h | 9 ++++++---
arch/powerpc/kernel/head_8xx.S | 9 ++-------
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index 9e6f01abb31e..53a9dab024c7 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -264,9 +264,7 @@ __secondary_hold_acknowledge:
*/
. = 0x200
DO_KVM 0x200
- mtspr SPRN_SPRG_SCRATCH0,r10
- mtspr SPRN_SPRG_SCRATCH1,r11
- mfcr r10
+ EXCEPTION_PROLOG_0
#ifdef CONFIG_PPC_CHRP
mfspr r11, SPRN_SPRG_THREAD
lwz r11, RTAS_SP(r11)
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index b2ca8c9ffd8b..8e345f8d4b0e 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -10,13 +10,16 @@
* We assume sprg3 has the physical address of the current
* task's thread_struct.
*/
-
.macro EXCEPTION_PROLOG
+ EXCEPTION_PROLOG_0
+ EXCEPTION_PROLOG_1
+ EXCEPTION_PROLOG_2
+.endm
+
+.macro EXCEPTION_PROLOG_0
mtspr SPRN_SPRG_SCRATCH0,r10
mtspr SPRN_SPRG_SCRATCH1,r11
mfcr r10
- EXCEPTION_PROLOG_1
- EXCEPTION_PROLOG_2
.endm
.macro EXCEPTION_PROLOG_1
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 5ab9178c2347..16d68c8575ca 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -493,10 +493,7 @@ InstructionTLBError:
*/
. = 0x1400
DataTLBError:
- mtspr SPRN_SPRG_SCRATCH0, r10
- mtspr SPRN_SPRG_SCRATCH1, r11
- mfcr r10
-
+ EXCEPTION_PROLOG_0
mfspr r11, SPRN_DAR
cmpwi cr0, r11, RPN_PATTERN
beq- FixupDAR /* must be a buggy dcbX, icbi insn. */
@@ -529,9 +526,7 @@ DARFixed:/* Return from dcbx instruction bug workaround */
*/
. = 0x1c00
DataBreakpoint:
- mtspr SPRN_SPRG_SCRATCH0, r10
- mtspr SPRN_SPRG_SCRATCH1, r11
- mfcr r10
+ EXCEPTION_PROLOG_0
mfspr r11, SPRN_SRR0
cmplwi cr0, r11, (.Ldtlbie - PAGE_OFFSET)@l
cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 03/10] powerpc/32: prepare for CONFIG_VMAP_STACK
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 01/10] powerpc/32: replace MTMSRD() by mtmsr Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 02/10] powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 04/10] powerpc/8xx: Use alternative scratch registers in DTLB miss handler Christophe Leroy
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
To support CONFIG_VMAP_STACK, the kernel has to activate Data MMU
Translation for accessing the stack. Before doing that it must save
SRR0, SRR1 and DAR in order to not loose them in case there is a
Data TLB Miss once the translation is reactivated.
This patch defines fields in the thread struct for saving those
registers. It prepares entry_32.S to handle exception entry with
Data MMU Translation enabled and alters EXCEPTION_PROLOG macros to
save SRR0, SRR1 and DAR and reenable Data MMU.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/include/asm/processor.h | 5 +++
arch/powerpc/include/asm/thread_info.h | 5 +++
arch/powerpc/kernel/asm-offsets.c | 5 +++
arch/powerpc/kernel/entry_32.S | 7 +++
arch/powerpc/kernel/head_32.h | 82 ++++++++++++++++++++++++++++++++--
5 files changed, 101 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h
index a9993e7a443b..867a4e761d7a 100644
--- a/arch/powerpc/include/asm/processor.h
+++ b/arch/powerpc/include/asm/processor.h
@@ -163,6 +163,11 @@ struct thread_struct {
#if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
unsigned long kuap; /* opened segments for user access */
#endif
+#ifdef CONFIG_VMAP_STACK
+ unsigned long dar;
+ unsigned long srr0;
+ unsigned long srr1;
+#endif
/* Debug Registers */
struct debug_reg debug;
struct thread_fp_state fp_state;
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 8e1d0195ac36..488d5c4670ff 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -10,10 +10,15 @@
#define _ASM_POWERPC_THREAD_INFO_H
#include <asm/asm-const.h>
+#include <asm/page.h>
#ifdef __KERNEL__
+#if defined(CONFIG_VMAP_STACK) && CONFIG_THREAD_SHIFT < PAGE_SHIFT
+#define THREAD_SHIFT PAGE_SHIFT
+#else
#define THREAD_SHIFT CONFIG_THREAD_SHIFT
+#endif
#define THREAD_SIZE (1 << THREAD_SHIFT)
diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 4ccb6b3a7fbd..a2194fe8f890 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -127,6 +127,11 @@ int main(void)
OFFSET(KSP_VSID, thread_struct, ksp_vsid);
#else /* CONFIG_PPC64 */
OFFSET(PGDIR, thread_struct, pgdir);
+#ifdef CONFIG_VMAP_STACK
+ OFFSET(SRR0, thread_struct, srr0);
+ OFFSET(SRR1, thread_struct, srr1);
+ OFFSET(DAR, thread_struct, dar);
+#endif
#ifdef CONFIG_SPE
OFFSET(THREAD_EVR0, thread_struct, evr[0]);
OFFSET(THREAD_ACC, thread_struct, acc);
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 44716157c918..ef296572a513 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -140,6 +140,9 @@ transfer_to_handler:
stw r12,_CTR(r11)
stw r2,_XER(r11)
mfspr r12,SPRN_SPRG_THREAD
+#ifdef CONFIG_VMAP_STACK
+ tovirt(r12, r12)
+#endif
beq 2f /* if from user, fix up THREAD.regs */
addi r2, r12, -THREAD
addi r11,r1,STACK_FRAME_OVERHEAD
@@ -195,7 +198,11 @@ transfer_to_handler:
transfer_to_handler_cont:
3:
mflr r9
+#ifdef CONFIG_VMAP_STACK
+ tovirt(r9, r9)
+#else
tovirt(r2, r2) /* set r2 to current */
+#endif
lwz r11,0(r9) /* virtual address of handler */
lwz r9,4(r9) /* where to go when done */
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 8e345f8d4b0e..4980babde59e 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -19,19 +19,42 @@
.macro EXCEPTION_PROLOG_0
mtspr SPRN_SPRG_SCRATCH0,r10
mtspr SPRN_SPRG_SCRATCH1,r11
+#ifdef CONFIG_VMAP_STACK
+ mfspr r10, SPRN_SPRG_THREAD
+ mfspr r11, SPRN_SRR0
+ stw r11, SRR0(r10)
+ mfspr r11, SPRN_DAR
+ stw r11, DAR(r10)
+ mfspr r11,SPRN_SRR1 /* check whether user or kernel */
+ stw r11, SRR1(r10)
+#endif
mfcr r10
.endm
.macro EXCEPTION_PROLOG_1
+#ifndef CONFIG_VMAP_STACK
mfspr r11,SPRN_SRR1 /* check whether user or kernel */
+#endif
andi. r11,r11,MSR_PR
+#ifdef CONFIG_VMAP_STACK
+ li r11, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */
+ mtmsr r11
+ subi r11, r1, INT_FRAME_SIZE /* use r1 if kernel */
+#else
tophys(r11,r1) /* use tophys(r1) if kernel */
+ subi r11, r11, INT_FRAME_SIZE /* alloc exc. frame */
+#endif
beq 1f
mfspr r11,SPRN_SPRG_THREAD
+#ifdef CONFIG_VMAP_STACK
+ tovirt(r11, r11)
+#endif
lwz r11,TASK_STACK-THREAD(r11)
- addi r11,r11,THREAD_SIZE
+ addi r11, r11, THREAD_SIZE - INT_FRAME_SIZE
+#ifndef CONFIG_VMAP_STACK
tophys(r11,r11)
-1: subi r11,r11,INT_FRAME_SIZE /* alloc exc. frame */
+#endif
+1:
.endm
.macro EXCEPTION_PROLOG_2
@@ -42,17 +65,36 @@
stw r10,GPR10(r11)
mfspr r12,SPRN_SPRG_SCRATCH1
stw r12,GPR11(r11)
+#ifdef CONFIG_VMAP_STACK
+ mfspr r12, SPRN_SPRG_THREAD
+ tovirt(r12, r12)
+#endif
mflr r10
stw r10,_LINK(r11)
+#ifdef CONFIG_VMAP_STACK
+ lwz r10, DAR(r12)
+ stw r10, _DAR(r11)
+ lwz r9, SRR1(r12)
+ lwz r12, SRR0(r12)
+#else
mfspr r12,SPRN_SRR0
mfspr r9,SPRN_SRR1
+#endif
stw r1,GPR1(r11)
stw r1,0(r11)
+#ifdef CONFIG_VMAP_STACK
+ mr r1, r11 /* set new kernel sp */
+#else
tovirt(r1,r11) /* set new kernel sp */
+#endif
#ifdef CONFIG_40x
rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */
#else
+#ifdef CONFIG_VMAP_STACK
+ li r10,MSR_KERNEL & ~MSR_IR /* can take exceptions */
+#else
li r10,MSR_KERNEL & ~(MSR_IR|MSR_DR) /* can take exceptions */
+#endif
mtmsr r10 /* (except for mach check in rtas) */
#endif
stw r0,GPR0(r11)
@@ -65,24 +107,56 @@
.macro SYSCALL_ENTRY trapno
mfspr r12,SPRN_SPRG_THREAD
+#ifdef CONFIG_VMAP_STACK
+ mfspr r9, SPRN_SRR0
+ mfspr r10, SPRN_DAR
+ mfspr r11,SPRN_SRR1 /* check whether user or kernel */
+ stw r9, SRR0(r12)
+ stw r10, DAR(r12)
+ stw r11, SRR1(r12)
+#endif
mfcr r10
lwz r11,TASK_STACK-THREAD(r12)
- mflr r9
addi r11,r11,THREAD_SIZE - INT_FRAME_SIZE
rlwinm r10,r10,0,4,2 /* Clear SO bit in CR */
+#ifdef CONFIG_VMAP_STACK
+ li r9, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */
+ mtmsr r9 /* (except for mach check in rtas) */
+ tovirt(r12, r12)
+#else
tophys(r11,r11)
+#endif
+ mflr r9
stw r10,_CCR(r11) /* save registers */
+#ifdef CONFIG_VMAP_STACK
+ lwz r10, DAR(r12)
+ stw r10, _DAR(r11)
+ lwz r10, SRR0(r12)
+#else
mfspr r10,SPRN_SRR0
+#endif
stw r9,_LINK(r11)
+#ifdef CONFIG_VMAP_STACK
+ lwz r9, SRR1(r12)
+#else
mfspr r9,SPRN_SRR1
+#endif
stw r1,GPR1(r11)
stw r1,0(r11)
+#ifdef CONFIG_VMAP_STACK
+ mr r1, r11
+#else
tovirt(r1,r11) /* set new kernel sp */
+#endif
stw r10,_NIP(r11)
#ifdef CONFIG_40x
rlwinm r9,r9,0,14,12 /* clear MSR_WE (necessary?) */
#else
+#ifdef CONFIG_VMAP_STACK
+ LOAD_REG_IMMEDIATE(r10, MSR_KERNEL & ~MSR_IR) /* can take exceptions */
+#else
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL & ~(MSR_IR|MSR_DR)) /* can take exceptions */
+#endif
mtmsr r10 /* (except for mach check in rtas) */
#endif
lis r10,STACK_FRAME_REGS_MARKER@ha /* exception frame marker */
@@ -121,7 +195,9 @@
#endif
3:
+#ifndef CONFIG_VMAP_STACK
tovirt(r2, r2) /* set r2 to current */
+#endif
lis r11, transfer_to_syscall@h
ori r11, r11, transfer_to_syscall@l
#ifdef CONFIG_TRACE_IRQFLAGS
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 04/10] powerpc/8xx: Use alternative scratch registers in DTLB miss handler
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (2 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 03/10] powerpc/32: prepare for CONFIG_VMAP_STACK Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 05/10] powerpc/8xx: drop exception entries for non-existing exceptions Christophe Leroy
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
In preparation of handling CONFIG_VMAP_STACK, we need DTLB miss handler
to use different scratch registers than other exception handlers in
order to not jeopardise exception entry on stack DTLB misses.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/head_8xx.S | 28 +++++++++++++++-------------
arch/powerpc/perf/8xx-pmu.c | 12 ++++++++----
2 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 16d68c8575ca..b9e520e52498 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -198,11 +198,13 @@ SystemCall:
0: lwz r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
addi r10, r10, 1
stw r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
- mfspr r10, SPRN_SPRG_SCRATCH0
- mfspr r11, SPRN_SPRG_SCRATCH1
+ mfspr r10, SPRN_DAR
+ mtspr SPRN_DAR, r11 /* Tag DAR */
+ mfspr r11, SPRN_M_TW
rfi
#endif
+
. = 0x1100
/*
* For the MPC8xx, this is a software tablewalk to load the instruction
@@ -342,8 +344,8 @@ ITLBMissLinear:
. = 0x1200
DataStoreTLBMiss:
- mtspr SPRN_SPRG_SCRATCH0, r10
- mtspr SPRN_SPRG_SCRATCH1, r11
+ mtspr SPRN_DAR, r10
+ mtspr SPRN_M_TW, r11
mfcr r11
/* If we are faulting a kernel address, we have to use the
@@ -408,10 +410,10 @@ DataStoreTLBMiss:
mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
/* Restore registers */
- mtspr SPRN_DAR, r11 /* Tag DAR */
-0: mfspr r10, SPRN_SPRG_SCRATCH0
- mfspr r11, SPRN_SPRG_SCRATCH1
+0: mfspr r10, SPRN_DAR
+ mtspr SPRN_DAR, r11 /* Tag DAR */
+ mfspr r11, SPRN_M_TW
rfi
patch_site 0b, patch__dtlbmiss_exit_1
@@ -427,10 +429,10 @@ DTLBMissIMMR:
mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
li r11, RPN_PATTERN
- mtspr SPRN_DAR, r11 /* Tag DAR */
-0: mfspr r10, SPRN_SPRG_SCRATCH0
- mfspr r11, SPRN_SPRG_SCRATCH1
+0: mfspr r10, SPRN_DAR
+ mtspr SPRN_DAR, r11 /* Tag DAR */
+ mfspr r11, SPRN_M_TW
rfi
patch_site 0b, patch__dtlbmiss_exit_2
@@ -464,10 +466,10 @@ DTLBMissLinear:
mtspr SPRN_MD_RPN, r10 /* Update TLB entry */
li r11, RPN_PATTERN
- mtspr SPRN_DAR, r11 /* Tag DAR */
-0: mfspr r10, SPRN_SPRG_SCRATCH0
- mfspr r11, SPRN_SPRG_SCRATCH1
+0: mfspr r10, SPRN_DAR
+ mtspr SPRN_DAR, r11 /* Tag DAR */
+ mfspr r11, SPRN_M_TW
rfi
patch_site 0b, patch__dtlbmiss_exit_3
diff --git a/arch/powerpc/perf/8xx-pmu.c b/arch/powerpc/perf/8xx-pmu.c
index 19124b0b171a..1ad03c55c88c 100644
--- a/arch/powerpc/perf/8xx-pmu.c
+++ b/arch/powerpc/perf/8xx-pmu.c
@@ -157,10 +157,6 @@ static void mpc8xx_pmu_read(struct perf_event *event)
static void mpc8xx_pmu_del(struct perf_event *event, int flags)
{
- /* mfspr r10, SPRN_SPRG_SCRATCH0 */
- unsigned int insn = PPC_INST_MFSPR | __PPC_RS(R10) |
- __PPC_SPR(SPRN_SPRG_SCRATCH0);
-
mpc8xx_pmu_read(event);
/* If it was the last user, stop counting to avoid useles overhead */
@@ -173,6 +169,10 @@ static void mpc8xx_pmu_del(struct perf_event *event, int flags)
break;
case PERF_8xx_ID_ITLB_LOAD_MISS:
if (atomic_dec_return(&itlb_miss_ref) == 0) {
+ /* mfspr r10, SPRN_SPRG_SCRATCH0 */
+ unsigned int insn = PPC_INST_MFSPR | __PPC_RS(R10) |
+ __PPC_SPR(SPRN_SPRG_SCRATCH0);
+
patch_instruction_site(&patch__itlbmiss_exit_1, insn);
#ifndef CONFIG_PIN_TLB_TEXT
patch_instruction_site(&patch__itlbmiss_exit_2, insn);
@@ -181,6 +181,10 @@ static void mpc8xx_pmu_del(struct perf_event *event, int flags)
break;
case PERF_8xx_ID_DTLB_LOAD_MISS:
if (atomic_dec_return(&dtlb_miss_ref) == 0) {
+ /* mfspr r10, SPRN_DAR */
+ unsigned int insn = PPC_INST_MFSPR | __PPC_RS(R10) |
+ __PPC_SPR(SPRN_DAR);
+
patch_instruction_site(&patch__dtlbmiss_exit_1, insn);
patch_instruction_site(&patch__dtlbmiss_exit_2, insn);
patch_instruction_site(&patch__dtlbmiss_exit_3, insn);
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 05/10] powerpc/8xx: drop exception entries for non-existing exceptions
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (3 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 04/10] powerpc/8xx: Use alternative scratch registers in DTLB miss handler Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 06/10] powerpc/8xx: move DataStoreTLBMiss perf handler Christophe Leroy
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
head_8xx.S has entries for all exceptions from 0x100 to 0x1f00.
Several of them do not exist and are never generated by the 8xx
in accordance with the documentation.
Remove those entry points to make some room for future growing
exception code.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/head_8xx.S | 29 -----------------------------
1 file changed, 29 deletions(-)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index b9e520e52498..4a3459c7d708 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -136,18 +136,6 @@ MachineCheck:
addi r3,r1,STACK_FRAME_OVERHEAD
EXC_XFER_STD(0x200, machine_check_exception)
-/* Data access exception.
- * This is "never generated" by the MPC8xx.
- */
- . = 0x300
-DataAccess:
-
-/* Instruction access exception.
- * This is "never generated" by the MPC8xx.
- */
- . = 0x400
-InstructionAccess:
-
/* External interrupt */
EXCEPTION(0x500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)
@@ -167,16 +155,9 @@ Alignment:
/* Program check exception */
EXCEPTION(0x700, ProgramCheck, program_check_exception, EXC_XFER_STD)
-/* No FPU on MPC8xx. This exception is not supposed to happen.
-*/
- EXCEPTION(0x800, FPUnavailable, unknown_exception, EXC_XFER_STD)
-
/* Decrementer */
EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
- EXCEPTION(0xa00, Trap_0a, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0xb00, Trap_0b, unknown_exception, EXC_XFER_STD)
-
/* System call */
. = 0xc00
SystemCall:
@@ -184,8 +165,6 @@ SystemCall:
/* Single step - not used on 601 */
EXCEPTION(0xd00, SingleStep, single_step_exception, EXC_XFER_STD)
- EXCEPTION(0xe00, Trap_0e, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0xf00, Trap_0f, unknown_exception, EXC_XFER_STD)
/* On the MPC8xx, this is a software emulation interrupt. It occurs
* for all unimplemented and illegal instructions.
@@ -514,14 +493,6 @@ DARFixed:/* Return from dcbx instruction bug workaround */
/* 0x300 is DataAccess exception, needed by bad_page_fault() */
EXC_XFER_LITE(0x300, handle_page_fault)
- EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1700, Trap_17, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1a00, Trap_1a, unknown_exception, EXC_XFER_STD)
- EXCEPTION(0x1b00, Trap_1b, unknown_exception, EXC_XFER_STD)
-
/* On the MPC8xx, these next four traps are used for development
* support of breakpoints and such. Someday I will get around to
* using them.
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 06/10] powerpc/8xx: move DataStoreTLBMiss perf handler
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (4 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 05/10] powerpc/8xx: drop exception entries for non-existing exceptions Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 07/10] powerpc/8xx: split breakpoint exception Christophe Leroy
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
Move DataStoreTLBMiss perf handler in order to cope
with future growing exception prolog.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/head_8xx.S | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 4a3459c7d708..d194cff6528b 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -171,18 +171,6 @@ SystemCall:
*/
EXCEPTION(0x1000, SoftEmu, program_check_exception, EXC_XFER_STD)
-/* Called from DataStoreTLBMiss when perf TLB misses events are activated */
-#ifdef CONFIG_PERF_EVENTS
- patch_site 0f, patch__dtlbmiss_perf
-0: lwz r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
- addi r10, r10, 1
- stw r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
- mfspr r10, SPRN_DAR
- mtspr SPRN_DAR, r11 /* Tag DAR */
- mfspr r11, SPRN_M_TW
- rfi
-#endif
-
. = 0x1100
/*
@@ -493,6 +481,18 @@ DARFixed:/* Return from dcbx instruction bug workaround */
/* 0x300 is DataAccess exception, needed by bad_page_fault() */
EXC_XFER_LITE(0x300, handle_page_fault)
+/* Called from DataStoreTLBMiss when perf TLB misses events are activated */
+#ifdef CONFIG_PERF_EVENTS
+ patch_site 0f, patch__dtlbmiss_perf
+0: lwz r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
+ addi r10, r10, 1
+ stw r10, (dtlb_miss_counter - PAGE_OFFSET)@l(0)
+ mfspr r10, SPRN_DAR
+ mtspr SPRN_DAR, r11 /* Tag DAR */
+ mfspr r11, SPRN_M_TW
+ rfi
+#endif
+
/* On the MPC8xx, these next four traps are used for development
* support of breakpoints and such. Someday I will get around to
* using them.
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 07/10] powerpc/8xx: split breakpoint exception
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (5 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 06/10] powerpc/8xx: move DataStoreTLBMiss perf handler Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 08/10] powerpc/8xx: Enable CONFIG_VMAP_STACK Christophe Leroy
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
Breakpoint exception is big.
Split it to support future growth on exception prolog.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/head_8xx.S | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index d194cff6528b..2fa02ae7a88c 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -497,14 +497,7 @@ DARFixed:/* Return from dcbx instruction bug workaround */
* support of breakpoints and such. Someday I will get around to
* using them.
*/
- . = 0x1c00
-DataBreakpoint:
- EXCEPTION_PROLOG_0
- mfspr r11, SPRN_SRR0
- cmplwi cr0, r11, (.Ldtlbie - PAGE_OFFSET)@l
- cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l
- beq- cr0, 11f
- beq- cr7, 11f
+do_databreakpoint:
EXCEPTION_PROLOG_1
EXCEPTION_PROLOG_2
addi r3,r1,STACK_FRAME_OVERHEAD
@@ -512,7 +505,15 @@ DataBreakpoint:
stw r4,_DAR(r11)
mfspr r5,SPRN_DSISR
EXC_XFER_STD(0x1c00, do_break)
-11:
+
+ . = 0x1c00
+DataBreakpoint:
+ EXCEPTION_PROLOG_0
+ mfspr r11, SPRN_SRR0
+ cmplwi cr0, r11, (.Ldtlbie - PAGE_OFFSET)@l
+ cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l
+ cror 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
+ bne do_databreakpoint
mtcr r10
mfspr r10, SPRN_SPRG_SCRATCH0
mfspr r11, SPRN_SPRG_SCRATCH1
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 08/10] powerpc/8xx: Enable CONFIG_VMAP_STACK
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (6 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 07/10] powerpc/8xx: split breakpoint exception Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 09/10] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 10/10] powerpc/32: Add stack overflow detection with VMAP stack Christophe Leroy
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
This patch enables CONFIG_VMAP_STACK. For that, a few changes are
done in head_8xx.S.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/head_8xx.S | 47 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 6137f5e3bb2d..ddbec19c3c22 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -178,6 +178,7 @@ config PPC
select HAVE_ARCH_NVRAM_OPS
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK
+ select HAVE_ARCH_VMAP_STACK if PPC_8xx
select HAVE_C_RECORDMCOUNT
select HAVE_CBPF_JIT if !PPC64
select HAVE_STACKPROTECTOR if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 2fa02ae7a88c..dfd68b72688e 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -127,8 +127,12 @@ instruction_counter:
. = 0x200
MachineCheck:
EXCEPTION_PROLOG
+#ifdef CONFIG_VMAP_STACK
+ lwz r4, _DAR(r11)
+#else
mfspr r4,SPRN_DAR
stw r4,_DAR(r11)
+#endif
li r5,RPN_PATTERN
mtspr SPRN_DAR,r5 /* Tag DAR, to be used in DTLB Error */
mfspr r5,SPRN_DSISR
@@ -143,8 +147,12 @@ MachineCheck:
. = 0x600
Alignment:
EXCEPTION_PROLOG
+#ifdef CONFIG_VMAP_STACK
+ lwz r4, _DAR(r11)
+#else
mfspr r4,SPRN_DAR
stw r4,_DAR(r11)
+#endif
li r5,RPN_PATTERN
mtspr SPRN_DAR,r5 /* Tag DAR, to be used in DTLB Error */
mfspr r5,SPRN_DSISR
@@ -467,17 +475,28 @@ DataTLBError:
cmpwi cr0, r11, RPN_PATTERN
beq- FixupDAR /* must be a buggy dcbX, icbi insn. */
DARFixed:/* Return from dcbx instruction bug workaround */
+#ifdef CONFIG_VMAP_STACK
+ li r11, RPN_PATTERN
+ mtspr SPRN_DAR, r11 /* Tag DAR, to be used in DTLB Error */
+ mfspr r11, SPRN_SRR1
+#endif
EXCEPTION_PROLOG_1
EXCEPTION_PROLOG_2
mfspr r5,SPRN_DSISR
stw r5,_DSISR(r11)
+#ifdef CONFIG_VMAP_STACK
+ lwz r4, _DAR(r11)
+#else
mfspr r4,SPRN_DAR
+#endif
andis. r10,r5,DSISR_NOHPTE@h
beq+ .Ldtlbie
tlbie r4
.Ldtlbie:
+#ifndef CONFIG_VMAP_STACK
li r10,RPN_PATTERN
mtspr SPRN_DAR,r10 /* Tag DAR, to be used in DTLB Error */
+#endif
/* 0x300 is DataAccess exception, needed by bad_page_fault() */
EXC_XFER_LITE(0x300, handle_page_fault)
@@ -498,6 +517,9 @@ DARFixed:/* Return from dcbx instruction bug workaround */
* using them.
*/
do_databreakpoint:
+#ifdef CONFIG_VMAP_STACK
+ mfspr r11, SPRN_SRR1
+#endif
EXCEPTION_PROLOG_1
EXCEPTION_PROLOG_2
addi r3,r1,STACK_FRAME_OVERHEAD
@@ -508,8 +530,21 @@ do_databreakpoint:
. = 0x1c00
DataBreakpoint:
- EXCEPTION_PROLOG_0
+ mtspr SPRN_SPRG_SCRATCH0, r10
+ mtspr SPRN_SPRG_SCRATCH1, r11
+#ifdef CONFIG_VMAP_STACK
+ mfspr r10, SPRN_SPRG_THREAD
+ mfspr r11, SPRN_DAR
+ stw r11, DAR(r10)
+ mfspr r11, SPRN_SRR1
+ stw r11, SRR1(r10)
+#endif
mfspr r11, SPRN_SRR0
+#ifdef CONFIG_VMAP_STACK
+ stw r11, SRR0(r10)
+#endif
+ mfcr r10
+
cmplwi cr0, r11, (.Ldtlbie - PAGE_OFFSET)@l
cmplwi cr7, r11, (.Litlbie - PAGE_OFFSET)@l
cror 4*cr0+eq, 4*cr0+eq, 4*cr7+eq
@@ -625,7 +660,12 @@ modified_instr:
.space 4 /* this is where the add instr. is stored */
bne+ 143f
subf r10,r0,r10 /* r10=r10-r0, only if reg RA is r0 */
+#ifdef CONFIG_VMAP_STACK
+143: mfspr r11, SPRN_SPRG_THREAD
+ stw r10, DAR(r11)
+#else
143: mtdar r10 /* store faulting EA in DAR */
+#endif
mfspr r10,SPRN_M_TW
b DARFixed /* Go back to normal TLB handling */
#else
@@ -679,7 +719,12 @@ modified_instr:
152:
mfdar r11
mtctr r11 /* restore ctr reg from DAR */
+#ifdef CONFIG_VMAP_STACK
+ mfspr r11, SPRN_SPRG_THREAD
+ stw r10, DAR(r11)
+#else
mtdar r10 /* save fault EA to DAR */
+#endif
mfspr r10,SPRN_M_TW
b DARFixed /* Go back to normal TLB handling */
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 09/10] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (7 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 08/10] powerpc/8xx: Enable CONFIG_VMAP_STACK Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 10/10] powerpc/32: Add stack overflow detection with VMAP stack Christophe Leroy
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
In order to ease stack overflow detection, align
stack to 2 * THREAD_SIZE when using VMAP_STACK.
This allow overflow detection using a single bit check.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/include/asm/thread_info.h | 13 +++++++++++++
arch/powerpc/kernel/setup_32.c | 2 +-
arch/powerpc/kernel/setup_64.c | 2 +-
arch/powerpc/kernel/vmlinux.lds.S | 2 +-
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 488d5c4670ff..a2270749b282 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -22,6 +22,19 @@
#define THREAD_SIZE (1 << THREAD_SHIFT)
+/*
+ * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
+ * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
+ * assembly.
+ */
+#ifdef CONFIG_VMAP_STACK
+#define THREAD_ALIGN_SHIFT (THREAD_SHIFT + 1)
+#else
+#define THREAD_ALIGN_SHIFT THREAD_SHIFT
+#endif
+
+#define THREAD_ALIGN (1 << THREAD_ALIGN_SHIFT)
+
#ifndef __ASSEMBLY__
#include <linux/cache.h>
#include <asm/processor.h>
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 94517e4a2723..ab0a9d6e3745 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -137,7 +137,7 @@ arch_initcall(ppc_init);
static void *__init alloc_stack(void)
{
- void *ptr = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
+ void *ptr = memblock_alloc(THREAD_SIZE, THREAD_ALIGN);
if (!ptr)
panic("cannot allocate %d bytes for stack at %pS\n",
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 44b4c432a273..f630fe4d36a8 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -644,7 +644,7 @@ static void *__init alloc_stack(unsigned long limit, int cpu)
BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16);
- ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE,
+ ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_ALIGN,
MEMBLOCK_LOW_LIMIT, limit,
early_cpu_to_node(cpu));
if (!ptr)
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 060a1acd7c6d..d38335129c06 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -346,7 +346,7 @@ SECTIONS
#endif
/* The initial task and kernel stack */
- INIT_TASK_DATA_SECTION(THREAD_SIZE)
+ INIT_TASK_DATA_SECTION(THREAD_ALIGN)
.data..page_aligned : AT(ADDR(.data..page_aligned) - LOAD_OFFSET) {
PAGE_ALIGNED_DATA(PAGE_SIZE)
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [RFC PATCH v2 10/10] powerpc/32: Add stack overflow detection with VMAP stack.
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
` (8 preceding siblings ...)
2019-08-31 10:18 ` [RFC PATCH v2 09/10] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK Christophe Leroy
@ 2019-08-31 10:18 ` Christophe Leroy
9 siblings, 0 replies; 11+ messages in thread
From: Christophe Leroy @ 2019-08-31 10:18 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman, npiggin, dja
Cc: linuxppc-dev, linux-kernel
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
arch/powerpc/kernel/entry_32.S | 12 ++++++++++++
arch/powerpc/kernel/head_32.h | 5 ++++-
arch/powerpc/kernel/head_8xx.S | 3 +++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index ef296572a513..68e03feb4bd1 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -184,9 +184,11 @@ transfer_to_handler:
*/
kuap_save_and_lock r11, r12, r9, r2, r0
addi r2, r12, -THREAD
+#ifndef CONFIG_VMAP_STACK
lwz r9,KSP_LIMIT(r12)
cmplw r1,r9 /* if r1 <= ksp_limit */
ble- stack_ovf /* then the kernel stack overflowed */
+#endif
5:
#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
lwz r12,TI_LOCAL_FLAGS(r2)
@@ -298,6 +300,15 @@ reenable_mmu:
* On kernel stack overflow, load up an initial stack pointer
* and call StackOverflow(regs), which should not return.
*/
+#ifdef CONFIG_VMAP_STACK
+_GLOBAL(stack_ovf)
+ lis r11, init_thread_union + THREAD_SIZE - INT_FRAME_SIZE@ha
+ addi r11, r11, init_thread_union + THREAD_SIZE - INT_FRAME_SIZE@l
+ EXCEPTION_PROLOG_2
+ SAVE_NVGPRS(r11)
+ addi r3, r1, STACK_FRAME_OVERHEAD
+ EXC_XFER_STD(0, StackOverflow)
+#else
stack_ovf:
/* sometimes we use a statically-allocated stack, which is OK. */
lis r12,_end@h
@@ -319,6 +330,7 @@ stack_ovf:
mtspr SPRN_SRR1,r10
SYNC
RFI
+#endif
#ifdef CONFIG_TRACE_IRQFLAGS
trace_syscall_entry_irq_off:
diff --git a/arch/powerpc/kernel/head_32.h b/arch/powerpc/kernel/head_32.h
index 4980babde59e..d442625d9649 100644
--- a/arch/powerpc/kernel/head_32.h
+++ b/arch/powerpc/kernel/head_32.h
@@ -51,7 +51,10 @@
#endif
lwz r11,TASK_STACK-THREAD(r11)
addi r11, r11, THREAD_SIZE - INT_FRAME_SIZE
-#ifndef CONFIG_VMAP_STACK
+#ifdef CONFIG_VMAP_STACK
+ mtcrf 0xfe, r11
+ bt 32 - THREAD_ALIGN_SHIFT, stack_ovf_trampoline
+#else
tophys(r11,r11)
#endif
1:
diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index dfd68b72688e..b9c9cfd72b19 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -572,6 +572,9 @@ InstructionBreakpoint:
EXCEPTION(0x1e00, Trap_1e, unknown_exception, EXC_XFER_STD)
EXCEPTION(0x1f00, Trap_1f, unknown_exception, EXC_XFER_STD)
+stack_ovf_trampoline:
+ b stack_ovf
+
. = 0x2000
/* This is the procedure to calculate the data EA for buggy dcbx,dcbi instructions
--
2.13.3
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2019-08-31 10:41 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-31 10:18 [RFC PATCH v2 00/10] Enable CONFIG_VMAP_STACK on PPC32 Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 01/10] powerpc/32: replace MTMSRD() by mtmsr Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 02/10] powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 03/10] powerpc/32: prepare for CONFIG_VMAP_STACK Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 04/10] powerpc/8xx: Use alternative scratch registers in DTLB miss handler Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 05/10] powerpc/8xx: drop exception entries for non-existing exceptions Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 06/10] powerpc/8xx: move DataStoreTLBMiss perf handler Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 07/10] powerpc/8xx: split breakpoint exception Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 08/10] powerpc/8xx: Enable CONFIG_VMAP_STACK Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 09/10] powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK Christophe Leroy
2019-08-31 10:18 ` [RFC PATCH v2 10/10] powerpc/32: Add stack overflow detection with VMAP stack Christophe Leroy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).