diff options
author | ian <ian@FreeBSD.org> | 2014-03-09 03:49:06 +0000 |
---|---|---|
committer | ian <ian@FreeBSD.org> | 2014-03-09 03:49:06 +0000 |
commit | 4313fc83a057fb0f0a817e8544fa5a7bbae7d719 (patch) | |
tree | fe7a84fcde6a0592aad47cba8bb88b369159b200 | |
parent | fddbc87fe1aceed4f6e19423f2198de2555e3771 (diff) | |
download | FreeBSD-src-4313fc83a057fb0f0a817e8544fa5a7bbae7d719.zip FreeBSD-src-4313fc83a057fb0f0a817e8544fa5a7bbae7d719.tar.gz |
Remove all dregs of a per-thread undefined-exception-mode stack. This is
a leftover from the days when a low-level debugger had hooks in the
undefined exception vector and needed stack space to function. These days
it effectively isn't used because we switch immediately to the svc32 mode
stack on exception entry. For that, the single undef mode stack per core
that gets set up at init time works fine.
The stack wasn't necessary but it was harmful, because the space for it
was carved out of the normal per-thread svc32 stack, in effect cutting
that 8K stack in half. If svc32 mode used more than 4k of stack space it
wandered down into the undef mode stack, and then an undef exception would
overwrite a couple words on the stack while switching to svc32 mode,
corrupting the scv32 stack. Having another stack abut the bottom of the
svc32 stack also effectively mooted the guard page below the stack.
This work is based on analysis and patches submitted by Juergen Weiss.
-rw-r--r-- | sys/arm/arm/genassym.c | 1 | ||||
-rw-r--r-- | sys/arm/arm/machdep.c | 2 | ||||
-rw-r--r-- | sys/arm/arm/swtch.S | 26 | ||||
-rw-r--r-- | sys/arm/arm/vm_machdep.c | 2 | ||||
-rw-r--r-- | sys/arm/include/param.h | 6 | ||||
-rw-r--r-- | sys/arm/include/pcb.h | 1 |
6 files changed, 2 insertions, 36 deletions
diff --git a/sys/arm/arm/genassym.c b/sys/arm/arm/genassym.c index 6f94032..ab0be4c 100644 --- a/sys/arm/arm/genassym.c +++ b/sys/arm/arm/genassym.c @@ -60,7 +60,6 @@ ASSYM(PCB_NOALIGNFLT, PCB_NOALIGNFLT); ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault)); ASSYM(PCB_DACR, offsetof(struct pcb, pcb_dacr)); ASSYM(PCB_FLAGS, offsetof(struct pcb, pcb_flags)); -ASSYM(PCB_UND_SP, offsetof(struct pcb, un_32.pcb32_und_sp)); ASSYM(PCB_PAGEDIR, offsetof(struct pcb, pcb_pagedir)); ASSYM(PCB_L1VEC, offsetof(struct pcb, pcb_l1vec)); ASSYM(PCB_PL1VEC, offsetof(struct pcb, pcb_pl1vec)); diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c index 35f1432..289f253 100644 --- a/sys/arm/arm/machdep.c +++ b/sys/arm/arm/machdep.c @@ -379,8 +379,6 @@ cpu_startup(void *dummy) bufinit(); vm_pager_bufferinit(); - pcb->un_32.pcb32_und_sp = (u_int)thread0.td_kstack + - USPACE_UNDEF_STACK_TOP; pcb->un_32.pcb32_sp = (u_int)thread0.td_kstack + USPACE_SVC_STACK_TOP; vector_page_setprot(VM_PROT_READ); diff --git a/sys/arm/arm/swtch.S b/sys/arm/arm/swtch.S index 743d4c3..2703b03 100644 --- a/sys/arm/arm/swtch.S +++ b/sys/arm/arm/swtch.S @@ -303,17 +303,6 @@ ENTRY(cpu_switch) /* Get the user structure for the new process in r9 */ ldr r9, [r1, #(TD_PCB)] - mrs r3, cpsr - /* - * We can do that, since - * PSR_SVC32_MODE|PSR_UND32_MODE == MSR_UND32_MODE - */ - orr r8, r3, #(PSR_UND32_MODE) - msr cpsr_c, r8 - - str sp, [r2, #(PCB_UND_SP)] - - msr cpsr_c, r3 /* Restore the old mode */ /* rem: r2 = old PCB */ /* rem: r9 = new PCB */ /* rem: interrupts are enabled */ @@ -422,10 +411,6 @@ ENTRY(cpu_switch) movne r0, #0 /* We *know* vector_page's VA is 0x0 */ movne lr, pc ldrne pc, [r10, #CF_TLB_FLUSHID_SE] - /* - * We can do that, since - * PSR_SVC32_MODE|PSR_UND32_MODE == MSR_UND32_MODE - */ .Lcs_context_switched: @@ -444,17 +429,6 @@ ENTRY(cpu_switch) /* rem: r9 = new PCB */ - mrs r3, cpsr - /* - * We can do that, since - * PSR_SVC32_MODE|PSR_UND32_MODE == MSR_UND32_MODE - */ - orr r2, r3, #(PSR_UND32_MODE) - msr cpsr_c, r2 - - ldr sp, [r9, #(PCB_UND_SP)] - - msr cpsr_c, r3 /* Restore the old mode */ /* Restore all the save registers */ #ifndef _ARM_ARCH_5E add r7, r9, #PCB_R8 diff --git a/sys/arm/arm/vm_machdep.c b/sys/arm/arm/vm_machdep.c index c51ae56..8e17720 100644 --- a/sys/arm/arm/vm_machdep.c +++ b/sys/arm/arm/vm_machdep.c @@ -144,7 +144,6 @@ cpu_fork(register struct thread *td1, register struct proc *p2, bcopy(td1->td_pcb, pcb2, sizeof(*pcb2)); mdp2 = &p2->p_md; bcopy(&td1->td_proc->p_md, mdp2, sizeof(*mdp2)); - pcb2->un_32.pcb32_und_sp = td2->td_kstack + USPACE_UNDEF_STACK_TOP; pcb2->un_32.pcb32_sp = td2->td_kstack + USPACE_SVC_STACK_TOP - sizeof(*pcb2); pmap_activate(td2); @@ -366,7 +365,6 @@ cpu_set_upcall(struct thread *td, struct thread *td0) tf->tf_spsr &= ~PSR_C_bit; tf->tf_r0 = 0; td->td_pcb->un_32.pcb32_sp = (u_int)sf; - td->td_pcb->un_32.pcb32_und_sp = td->td_kstack + USPACE_UNDEF_STACK_TOP; KASSERT((td->td_pcb->un_32.pcb32_sp & 7) == 0, ("cpu_set_upcall: Incorrect stack alignment")); diff --git a/sys/arm/include/param.h b/sys/arm/include/param.h index 15fc279..5cd0b7b 100644 --- a/sys/arm/include/param.h +++ b/sys/arm/include/param.h @@ -125,10 +125,8 @@ #define KSTACK_GUARD_PAGES 1 #endif /* !KSTACK_GUARD_PAGES */ -#define USPACE_SVC_STACK_TOP KSTACK_PAGES * PAGE_SIZE -#define USPACE_SVC_STACK_BOTTOM (USPACE_SVC_STACK_TOP - 0x1000) -#define USPACE_UNDEF_STACK_TOP (USPACE_SVC_STACK_BOTTOM - 0x10) -#define USPACE_UNDEF_STACK_BOTTOM (FPCONTEXTSIZE + 10) +#define USPACE_SVC_STACK_TOP (KSTACK_PAGES * PAGE_SIZE) + /* * Mach derived conversion macros */ diff --git a/sys/arm/include/pcb.h b/sys/arm/include/pcb.h index 8d98f2e..252d94e 100644 --- a/sys/arm/include/pcb.h +++ b/sys/arm/include/pcb.h @@ -61,7 +61,6 @@ struct pcb_arm32 { u_int pcb32_sp; /* used */ u_int pcb32_lr; u_int pcb32_pc; - u_int pcb32_und_sp; }; #define pcb_pagedir un_32.pcb32_pagedir #define pcb_pl1vec un_32.pcb32_pl1vec |