Skip to content

Commit cd08f10

Browse files
chleroympe
authored andcommitted
powerpc/32s: Enable CONFIG_VMAP_STACK
A few changes to retrieve DAR and DSISR from struct regs instead of retrieving them directly, as they may have changed due to a TLB miss. Also modifies hash_page() and friends to work with virtual data addresses instead of physical ones. Same on load_up_fpu() and load_up_altivec(). Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> [mpe: Fix tovirt_vmstack call in head_32.S to fix CHRP build] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/2e2509a242fd5f3e23df4a06530c18060c4d321e.1576916812.git.christophe.leroy@c-s.fr
1 parent 94dd54c commit cd08f10

8 files changed

Lines changed: 61 additions & 24 deletions

File tree

‎arch/powerpc/kernel/entry_32.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ _GLOBAL(enter_rtas)
13391339
lis r6,1f@ha /* physical return address for rtas */
13401340
addi r6,r6,1f@l
13411341
tophys(r6,r6)
1342-
tophys(r7,r1)
1342+
tophys_novmstack r7, r1
13431343
lwz r8,RTASENTRY(r4)
13441344
lwz r4,RTASBASE(r4)
13451345
mfmsr r9

‎arch/powerpc/kernel/fpu.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX)
9494
/* enable use of FP after return */
9595
#ifdef CONFIG_PPC32
9696
mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
97+
#ifdef CONFIG_VMAP_STACK
98+
tovirt(r5, r5)
99+
#endif
97100
lwz r4,THREAD_FPEXC_MODE(r5)
98101
ori r9,r9,MSR_FP /* enable FP for current */
99102
or r9,r9,r4

‎arch/powerpc/kernel/head_32.S‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,21 @@ __secondary_hold_acknowledge:
272272
*/
273273
. = 0x200
274274
DO_KVM 0x200
275+
MachineCheck:
275276
EXCEPTION_PROLOG_0
277+
#ifdef CONFIG_VMAP_STACK
278+
li r11, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */
279+
mtmsr r11
280+
isync
281+
#endif
276282
#ifdef CONFIG_PPC_CHRP
277283
mfspr r11, SPRN_SPRG_THREAD
284+
tovirt_vmstack r11, r11
278285
lwz r11, RTAS_SP(r11)
279286
cmpwi cr1, r11, 0
280287
bne cr1, 7f
281288
#endif /* CONFIG_PPC_CHRP */
282-
EXCEPTION_PROLOG_1
289+
EXCEPTION_PROLOG_1 for_rtas=1
283290
7: EXCEPTION_PROLOG_2
284291
addi r3,r1,STACK_FRAME_OVERHEAD
285292
#ifdef CONFIG_PPC_CHRP
@@ -294,7 +301,7 @@ __secondary_hold_acknowledge:
294301
. = 0x300
295302
DO_KVM 0x300
296303
DataAccess:
297-
EXCEPTION_PROLOG
304+
EXCEPTION_PROLOG handle_dar_dsisr=1
298305
get_and_save_dar_dsisr_on_stack r4, r5, r11
299306
BEGIN_MMU_FTR_SECTION
300307
#ifdef CONFIG_PPC_KUAP
@@ -334,7 +341,7 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_HPTE_TABLE)
334341
. = 0x600
335342
DO_KVM 0x600
336343
Alignment:
337-
EXCEPTION_PROLOG
344+
EXCEPTION_PROLOG handle_dar_dsisr=1
338345
save_dar_dsisr_on_stack r4, r5, r11
339346
addi r3,r1,STACK_FRAME_OVERHEAD
340347
EXC_XFER_STD(0x600, alignment_exception)
@@ -645,6 +652,9 @@ handle_page_fault_tramp_1:
645652
handle_page_fault_tramp_2:
646653
EXC_XFER_LITE(0x300, handle_page_fault)
647654

655+
stack_overflow:
656+
vmap_stack_overflow_exception
657+
648658
AltiVecUnavailable:
649659
EXCEPTION_PROLOG
650660
#ifdef CONFIG_ALTIVEC

‎arch/powerpc/kernel/head_32.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
andi. r11, r11, MSR_PR
3939
.endm
4040

41-
.macro EXCEPTION_PROLOG_1
41+
.macro EXCEPTION_PROLOG_1 for_rtas=0
4242
#ifdef CONFIG_VMAP_STACK
43+
.ifeq \for_rtas
4344
li r11, MSR_KERNEL & ~(MSR_IR | MSR_RI) /* can take DTLB miss */
4445
mtmsr r11
4546
isync
47+
.endif
4648
subi r11, r1, INT_FRAME_SIZE /* use r1 if kernel */
4749
#else
4850
tophys(r11,r1) /* use tophys(r1) if kernel */

‎arch/powerpc/kernel/vector.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ _GLOBAL(load_up_altivec)
6767
#ifdef CONFIG_PPC32
6868
mfspr r5,SPRN_SPRG_THREAD /* current task's THREAD (phys) */
6969
oris r9,r9,MSR_VEC@h
70+
#ifdef CONFIG_VMAP_STACK
71+
tovirt(r5, r5)
72+
#endif
7073
#else
7174
ld r4,PACACURRENT(r13)
7275
addi r5,r4,THREAD /* Get THREAD */

‎arch/powerpc/mm/book3s32/hash_low.S‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#include <asm/feature-fixups.h>
2626
#include <asm/code-patching-asm.h>
2727

28+
#ifdef CONFIG_VMAP_STACK
29+
#define ADDR_OFFSET 0
30+
#else
31+
#define ADDR_OFFSET PAGE_OFFSET
32+
#endif
33+
2834
#ifdef CONFIG_SMP
2935
.section .bss
3036
.align 2
@@ -47,8 +53,8 @@ mmu_hash_lock:
4753
.text
4854
_GLOBAL(hash_page)
4955
#ifdef CONFIG_SMP
50-
lis r8, (mmu_hash_lock - PAGE_OFFSET)@h
51-
ori r8, r8, (mmu_hash_lock - PAGE_OFFSET)@l
56+
lis r8, (mmu_hash_lock - ADDR_OFFSET)@h
57+
ori r8, r8, (mmu_hash_lock - ADDR_OFFSET)@l
5258
lis r0,0x0fff
5359
b 10f
5460
11: lwz r6,0(r8)
@@ -66,9 +72,12 @@ _GLOBAL(hash_page)
6672
cmplw 0,r4,r0
6773
ori r3,r3,_PAGE_USER|_PAGE_PRESENT /* test low addresses as user */
6874
mfspr r5, SPRN_SPRG_PGDIR /* phys page-table root */
75+
#ifdef CONFIG_VMAP_STACK
76+
tovirt(r5, r5)
77+
#endif
6978
blt+ 112f /* assume user more likely */
70-
lis r5, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */
71-
addi r5 ,r5 ,(swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */
79+
lis r5, (swapper_pg_dir - ADDR_OFFSET)@ha /* if kernel address, use */
80+
addi r5 ,r5 ,(swapper_pg_dir - ADDR_OFFSET)@l /* kernel page table */
7281
rlwimi r3,r9,32-12,29,29 /* MSR_PR -> _PAGE_USER */
7382
112:
7483
#ifndef CONFIG_PTE_64BIT
@@ -80,6 +89,9 @@ _GLOBAL(hash_page)
8089
lwzx r8,r8,r5 /* Get L1 entry */
8190
rlwinm. r8,r8,0,0,20 /* extract pt base address */
8291
#endif
92+
#ifdef CONFIG_VMAP_STACK
93+
tovirt(r8, r8)
94+
#endif
8395
#ifdef CONFIG_SMP
8496
beq- hash_page_out /* return if no mapping */
8597
#else
@@ -137,9 +149,9 @@ retry:
137149

138150
#ifdef CONFIG_SMP
139151
eieio
140-
lis r8, (mmu_hash_lock - PAGE_OFFSET)@ha
152+
lis r8, (mmu_hash_lock - ADDR_OFFSET)@ha
141153
li r0,0
142-
stw r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
154+
stw r0, (mmu_hash_lock - ADDR_OFFSET)@l(r8)
143155
#endif
144156

145157
/* Return from the exception */
@@ -152,9 +164,9 @@ retry:
152164
#ifdef CONFIG_SMP
153165
hash_page_out:
154166
eieio
155-
lis r8, (mmu_hash_lock - PAGE_OFFSET)@ha
167+
lis r8, (mmu_hash_lock - ADDR_OFFSET)@ha
156168
li r0,0
157-
stw r0, (mmu_hash_lock - PAGE_OFFSET)@l(r8)
169+
stw r0, (mmu_hash_lock - ADDR_OFFSET)@l(r8)
158170
blr
159171
#endif /* CONFIG_SMP */
160172

@@ -329,7 +341,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
329341
patch_site 1f, patch__hash_page_A1
330342
patch_site 2f, patch__hash_page_A2
331343
/* Get the address of the primary PTE group in the hash table (r3) */
332-
0: lis r0, (Hash_base - PAGE_OFFSET)@h /* base address of hash table */
344+
0: lis r0, (Hash_base - ADDR_OFFSET)@h /* base address of hash table */
333345
1: rlwimi r0,r3,LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* VSID -> hash */
334346
2: rlwinm r3,r4,20+LG_PTEG_SIZE,HASH_LEFT,HASH_RIGHT /* PI -> hash */
335347
xor r3,r3,r0 /* make primary hash */
@@ -343,10 +355,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
343355
beq+ 10f /* no PTE: go look for an empty slot */
344356
tlbie r4
345357

346-
lis r4, (htab_hash_searches - PAGE_OFFSET)@ha
347-
lwz r6, (htab_hash_searches - PAGE_OFFSET)@l(r4)
358+
lis r4, (htab_hash_searches - ADDR_OFFSET)@ha
359+
lwz r6, (htab_hash_searches - ADDR_OFFSET)@l(r4)
348360
addi r6,r6,1 /* count how many searches we do */
349-
stw r6, (htab_hash_searches - PAGE_OFFSET)@l(r4)
361+
stw r6, (htab_hash_searches - ADDR_OFFSET)@l(r4)
350362

351363
/* Search the primary PTEG for a PTE whose 1st (d)word matches r5 */
352364
mtctr r0
@@ -378,10 +390,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
378390
beq+ found_empty
379391

380392
/* update counter of times that the primary PTEG is full */
381-
lis r4, (primary_pteg_full - PAGE_OFFSET)@ha
382-
lwz r6, (primary_pteg_full - PAGE_OFFSET)@l(r4)
393+
lis r4, (primary_pteg_full - ADDR_OFFSET)@ha
394+
lwz r6, (primary_pteg_full - ADDR_OFFSET)@l(r4)
383395
addi r6,r6,1
384-
stw r6, (primary_pteg_full - PAGE_OFFSET)@l(r4)
396+
stw r6, (primary_pteg_full - ADDR_OFFSET)@l(r4)
385397

386398
patch_site 0f, patch__hash_page_C
387399
/* Search the secondary PTEG for an empty slot */
@@ -415,8 +427,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_NEED_COHERENT)
415427
* lockup here but that shouldn't happen
416428
*/
417429

418-
1: lis r4, (next_slot - PAGE_OFFSET)@ha /* get next evict slot */
419-
lwz r6, (next_slot - PAGE_OFFSET)@l(r4)
430+
1: lis r4, (next_slot - ADDR_OFFSET)@ha /* get next evict slot */
431+
lwz r6, (next_slot - ADDR_OFFSET)@l(r4)
420432
addi r6,r6,HPTE_SIZE /* search for candidate */
421433
andi. r6,r6,7*HPTE_SIZE
422434
stw r6,next_slot@l(r4)

‎arch/powerpc/mm/book3s32/mmu.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ void __init MMU_init_hw(void)
413413
void __init MMU_init_hw_patch(void)
414414
{
415415
unsigned int hmask = Hash_mask >> (16 - LG_HPTEG_SIZE);
416+
unsigned int hash;
416417

417418
if (ppc_md.progress)
418419
ppc_md.progress("hash:patch", 0x345);
@@ -424,8 +425,12 @@ void __init MMU_init_hw_patch(void)
424425
/*
425426
* Patch up the instructions in hashtable.S:create_hpte
426427
*/
427-
modify_instruction_site(&patch__hash_page_A0, 0xffff,
428-
((unsigned int)Hash - PAGE_OFFSET) >> 16);
428+
if (IS_ENABLED(CONFIG_VMAP_STACK))
429+
hash = (unsigned int)Hash;
430+
else
431+
hash = (unsigned int)Hash - PAGE_OFFSET;
432+
433+
modify_instruction_site(&patch__hash_page_A0, 0xffff, hash >> 16);
429434
modify_instruction_site(&patch__hash_page_A1, 0x7c0, hash_mb << 6);
430435
modify_instruction_site(&patch__hash_page_A2, 0x7c0, hash_mb2 << 6);
431436
modify_instruction_site(&patch__hash_page_B, 0xffff, hmask);

‎arch/powerpc/platforms/Kconfig.cputype‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ config PPC_BOOK3S_6xx
3131
select PPC_HAVE_PMU_SUPPORT
3232
select PPC_HAVE_KUEP
3333
select PPC_HAVE_KUAP
34+
select HAVE_ARCH_VMAP_STACK
3435

3536
config PPC_BOOK3S_601
3637
bool "PowerPC 601"
3738
select PPC_BOOK3S_32
3839
select PPC_FPU
3940
select PPC_HAVE_KUAP
41+
select HAVE_ARCH_VMAP_STACK
4042

4143
config PPC_85xx
4244
bool "Freescale 85xx"

0 commit comments

Comments
 (0)