Enable CONFIG_VMAP_STACK on PPC32
v2 cover Enable CONFIG_VMAP_STACK on PPC32
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(-)
Signature · 1 line
2.13.3
RFC PATCH v2 1/10 powerpc/32: replace MTMSRD() by mtmsr
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.
--- arch/powerpc/kernel/entry_32.S | 18 +++++++++--------- arch/powerpc/kernel/head_32.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)
arch/powerpc/kernel/entry_32.S +9 -9
@@ -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)
arch/powerpc/kernel/head_32.h +2 -2
@@ -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)
Signature · 1 line
2.13.3
RFC PATCH v2 2/10 powerpc/32: Add EXCEPTION_PROLOG_0 in head_32.h
In reply to Christophe LeroyThis patch creates a macro for the very first part of exception prolog, this will help when implementing CONFIG_VMAP_STACK
--- 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(-)
arch/powerpc/kernel/head_32.S +1 -3
@@ -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)
arch/powerpc/kernel/head_32.h +6 -3
@@ -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_0mtspr SPRN_SPRG_SCRATCH0 ,r10 mtspr SPRN_SPRG_SCRATCH1,r11 mfcr r10 - EXCEPTION_PROLOG_1 - EXCEPTION_PROLOG_2 .endm .macro EXCEPTION_PROLOG_1
arch/powerpc/kernel/head_8xx.S +2 -7
@@ -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
Signature · 1 line
2.13.3
RFC PATCH v2 3/10 powerpc/32: prepare for CONFIG_VMAP_STACK
In reply to Christophe LeroyTo 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.
--- 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(-)
arch/powerpc/include/asm/processor.h +5 -0
@@ -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;
arch/powerpc/include/asm/thread_info.h +5 -0
@@ -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)
arch/powerpc/kernel/asm-offsets.c +5 -0
@@ -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);
arch/powerpc/kernel/entry_32.S +7 -0
@@ -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)
arch/powerpc/kernel/head_32.h +79 -3
146 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH v2 4/10 powerpc/8xx: Use alternative scratch registers in DTLB miss handler
In reply to Christophe LeroyIn 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.
--- arch/powerpc/kernel/head_8xx.S | 28 +++++++++++++++------------- arch/powerpc/perf/8xx-pmu.c | 12 ++++++++---- 2 files changed, 23 insertions(+), 17 deletions(-)
arch/powerpc/kernel/head_8xx.S +15 -13
@@ -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
arch/powerpc/perf/8xx-pmu.c +8 -4
@@ -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);
Signature · 1 line
2.13.3
RFC PATCH v2 5/10 powerpc/8xx: drop exception entries for non-existing exceptions
In reply to Christophe Leroyhead_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.
--- arch/powerpc/kernel/head_8xx.S | 29 ----------------------------- 1 file changed, 29 deletions(-)
arch/powerpc/kernel/head_8xx.S +0 -29
@@ -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.
Signature · 1 line
2.13.3
RFC PATCH v2 6/10 powerpc/8xx: move DataStoreTLBMiss perf handler
In reply to Christophe LeroyMove DataStoreTLBMiss perf handler in order to cope with future growing exception prolog.
--- arch/powerpc/kernel/head_8xx.S | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
arch/powerpc/kernel/head_8xx.S +12 -12
@@ -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.
Signature · 1 line
2.13.3
RFC PATCH v2 7/10 powerpc/8xx: split breakpoint exception
In reply to Christophe LeroyBreakpoint exception is big.
Split it to support future growth on exception prolog.
--- arch/powerpc/kernel/head_8xx.S | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
arch/powerpc/kernel/head_8xx.S +10 -9
@@ -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
Signature · 1 line
2.13.3
RFC PATCH v2 8/10 powerpc/8xx: Enable CONFIG_VMAP_STACK
In reply to Christophe LeroyThis patch enables CONFIG_VMAP_STACK. For that, a few changes are done in head_8xx.S.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/kernel/head_8xx.S | 47 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-)
arch/powerpc/Kconfig +1 -0
@@ -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)
arch/powerpc/kernel/head_8xx.S +46 -1
107 lines not on this page · raw message
Signature · 1 line
2.13.3
RFC PATCH v2 9/10 powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK
In reply to Christophe LeroyIn 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.
--- 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(-)
arch/powerpc/include/asm/thread_info.h +13 -0
@@ -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>
arch/powerpc/kernel/setup_32.c +1 -1
@@ -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",
arch/powerpc/kernel/setup_64.c +1 -1
@@ -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)
arch/powerpc/kernel/vmlinux.lds.S +1 -1
@@ -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)
Signature · 1 line
2.13.3
RFC PATCH v2 10/10 powerpc/32: Add stack overflow detection with VMAP stack.
In reply to Christophe LeroyTo 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.
--- 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(-)
arch/powerpc/kernel/entry_32.S +12 -0
@@ -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:
arch/powerpc/kernel/head_32.h +4 -1
@@ -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 +#elsetophys (r11 ,r11 ) #endif 1:
arch/powerpc/kernel/head_8xx.S +3 -0
@@ -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
Signature · 1 line
2.13.3