Skip to content

Commit 0df977e

Browse files
chleroympe
authored andcommitted
powerpc/6xx: Don't use SPRN_SPRG2 for storing stack pointer while in RTAS
When calling RTAS, the stack pointer is stored in SPRN_SPRG2 in order to be able to restore it in case of machine check in RTAS. As machine check is not a perfomance critical path, this patch frees SPRN_SPRG2 by using a field in thread struct instead. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 4005833 commit 0df977e

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

arch/powerpc/include/asm/processor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ struct thread_struct {
250250
#ifdef CONFIG_PPC32
251251
void *pgdir; /* root of page-table tree */
252252
unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */
253+
#ifdef CONFIG_PPC_RTAS
254+
unsigned long rtas_sp; /* stack pointer for when in RTAS */
255+
#endif
253256
#endif
254257
/* Debug Registers */
255258
struct debug_reg debug;

arch/powerpc/include/asm/reg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,6 @@
11671167
#ifdef CONFIG_PPC_BOOK3S_32
11681168
#define SPRN_SPRG_SCRATCH0 SPRN_SPRG0
11691169
#define SPRN_SPRG_SCRATCH1 SPRN_SPRG1
1170-
#define SPRN_SPRG_RTAS SPRN_SPRG2
11711170
#define SPRN_SPRG_603_LRU SPRN_SPRG4
11721171
#endif
11731172

arch/powerpc/kernel/asm-offsets.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ int main(void)
9393
OFFSET(THREAD_INFO, task_struct, stack);
9494
DEFINE(THREAD_INFO_GAP, _ALIGN_UP(sizeof(struct thread_info), 16));
9595
OFFSET(KSP_LIMIT, thread_struct, ksp_limit);
96+
#ifdef CONFIG_PPC_RTAS
97+
OFFSET(RTAS_SP, thread_struct, rtas_sp);
98+
#endif
9699
#endif /* CONFIG_PPC64 */
97100

98101
#ifdef CONFIG_LIVEPATCH

arch/powerpc/kernel/entry_32.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ _GLOBAL(enter_rtas)
13321332
MTMSRD(r0) /* don't get trashed */
13331333
li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
13341334
mtlr r6
1335-
mtspr SPRN_SPRG_RTAS,r7
1335+
stw r7, THREAD + RTAS_SP(r2)
13361336
mtspr SPRN_SRR0,r8
13371337
mtspr SPRN_SRR1,r9
13381338
RFI
@@ -1341,7 +1341,8 @@ _GLOBAL(enter_rtas)
13411341
lwz r9,8(r9) /* original msr value */
13421342
addi r1,r1,INT_FRAME_SIZE
13431343
li r0,0
1344-
mtspr SPRN_SPRG_RTAS,r0
1344+
tophys(r7, r2)
1345+
stw r0, THREAD + RTAS_SP(r7)
13451346
mtspr SPRN_SRR0,r8
13461347
mtspr SPRN_SRR1,r9
13471348
RFI /* return to caller */

arch/powerpc/kernel/head_32.S

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,8 @@ i##n: \
352352
* registers that might have bad values includes all the GPRs
353353
* and all the BATs. We indicate that we are in RTAS by putting
354354
* a non-zero value, the address of the exception frame to use,
355-
* in SPRG2. The machine check handler checks SPRG2 and uses its
356-
* value if it is non-zero. If we ever needed to free up SPRG2,
357-
* we could use a field in the thread_info or thread_struct instead.
355+
* in thread.rtas_sp. The machine check handler checks thread.rtas_sp
356+
* and uses its value if it is non-zero.
358357
* (Other exception handlers assume that r1 is a valid kernel stack
359358
* pointer when we take an exception from supervisor mode.)
360359
* -- paulus.
@@ -365,16 +364,15 @@ i##n: \
365364
mtspr SPRN_SPRG_SCRATCH1,r11
366365
mfcr r10
367366
#ifdef CONFIG_PPC_CHRP
368-
mfspr r11,SPRN_SPRG_RTAS
369-
cmpwi 0,r11,0
370-
bne 7f
367+
mfspr r11, SPRN_SPRG_THREAD
368+
lwz r11, RTAS_SP(r11)
369+
cmpwi cr1, r11, 0
370+
bne cr1, 7f
371371
#endif /* CONFIG_PPC_CHRP */
372372
EXCEPTION_PROLOG_1
373373
7: EXCEPTION_PROLOG_2
374374
addi r3,r1,STACK_FRAME_OVERHEAD
375375
#ifdef CONFIG_PPC_CHRP
376-
mfspr r4,SPRN_SPRG_RTAS
377-
cmpwi cr1,r4,0
378376
bne cr1,1f
379377
#endif
380378
EXC_XFER_STD(0x200, machine_check_exception)
@@ -865,8 +863,10 @@ __secondary_start:
865863
tophys(r4,r2)
866864
addi r4,r4,THREAD /* phys address of our thread_struct */
867865
mtspr SPRN_SPRG_THREAD,r4
866+
#ifdef CONFIG_PPC_RTAS
868867
li r3,0
869-
mtspr SPRN_SPRG_RTAS,r3 /* 0 => not in RTAS */
868+
stw r3, RTAS_SP(r4) /* 0 => not in RTAS */
869+
#endif
870870

871871
/* enable MMU and jump to start_secondary */
872872
li r4,MSR_KERNEL
@@ -950,8 +950,10 @@ start_here:
950950
tophys(r4,r2)
951951
addi r4,r4,THREAD /* init task's THREAD */
952952
mtspr SPRN_SPRG_THREAD,r4
953+
#ifdef CONFIG_PPC_RTAS
953954
li r3,0
954-
mtspr SPRN_SPRG_RTAS,r3 /* 0 => not in RTAS */
955+
stw r3, RTAS_SP(r4) /* 0 => not in RTAS */
956+
#endif
955957

956958
/* stack */
957959
lis r1,init_thread_union@ha

0 commit comments

Comments
 (0)