Skip to content

Commit 4c2de74

Browse files
npigginmpe
authored andcommitted
powerpc/64: Interrupts save PPR on stack rather than thread_struct
PPR is the odd register out when it comes to interrupt handling, it is saved in current->thread.ppr while all others are saved on the stack. The difficulty with this is that accessing thread.ppr can cause a SLB fault, but the SLB fault handler implementation in C change had assumed the normal exception entry handlers would not cause an SLB fault. Fix this by allocating room in the interrupt stack to save PPR. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3eeacd9 commit 4c2de74

7 files changed

Lines changed: 19 additions & 23 deletions

File tree

‎arch/powerpc/include/asm/exception-64s.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,10 @@
236236
* PPR save/restore macros used in exceptions_64s.S
237237
* Used for P7 or later processors
238238
*/
239-
#define SAVE_PPR(area, ra, rb) \
239+
#define SAVE_PPR(area, ra) \
240240
BEGIN_FTR_SECTION_NESTED(940) \
241-
ld ra,PACACURRENT(r13); \
242-
ld rb,area+EX_PPR(r13); /* Read PPR from paca */ \
243-
std rb,TASKTHREADPPR(ra); \
241+
ld ra,area+EX_PPR(r13); /* Read PPR from paca */ \
242+
std ra,_PPR(r1); \
244243
END_FTR_SECTION_NESTED(CPU_FTR_HAS_PPR,CPU_FTR_HAS_PPR,940)
245244

246245
#define RESTORE_PPR_PACA(area, ra) \
@@ -508,7 +507,7 @@ END_FTR_SECTION_NESTED(ftr,ftr,943)
508507
3: EXCEPTION_PROLOG_COMMON_1(); \
509508
beq 4f; /* if from kernel mode */ \
510509
ACCOUNT_CPU_USER_ENTRY(r13, r9, r10); \
511-
SAVE_PPR(area, r9, r10); \
510+
SAVE_PPR(area, r9); \
512511
4: EXCEPTION_PROLOG_COMMON_2(area) \
513512
EXCEPTION_PROLOG_COMMON_3(n) \
514513
ACCOUNT_STOLEN_TIME

‎arch/powerpc/include/asm/processor.h‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
/* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
3333
#define PPR_PRIORITY 3
3434
#ifdef __ASSEMBLY__
35-
#define INIT_PPR (PPR_PRIORITY << 50)
35+
#define DEFAULT_PPR (PPR_PRIORITY << 50)
3636
#else
37-
#define INIT_PPR ((u64)PPR_PRIORITY << 50)
37+
#define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
3838
#endif /* __ASSEMBLY__ */
3939
#endif /* CONFIG_PPC64 */
4040

@@ -341,7 +341,6 @@ struct thread_struct {
341341
* onwards.
342342
*/
343343
int dscr_inherit;
344-
unsigned long ppr; /* used to save/restore SMT priority */
345344
unsigned long tidr;
346345
#endif
347346
#ifdef CONFIG_PPC_BOOK3S_64
@@ -389,7 +388,6 @@ struct thread_struct {
389388
.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
390389
.addr_limit = KERNEL_DS, \
391390
.fpexc_mode = 0, \
392-
.ppr = INIT_PPR, \
393391
.fscr = FSCR_TAR | FSCR_EBB \
394392
}
395393
#endif

‎arch/powerpc/include/asm/ptrace.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ struct pt_regs
5151
unsigned long result;
5252
};
5353
};
54+
55+
#ifdef CONFIG_PPC64
56+
unsigned long ppr;
57+
#endif
5458
};
5559
#endif
5660

‎arch/powerpc/kernel/asm-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ int main(void)
8989
#ifdef CONFIG_PPC64
9090
DEFINE(SIGSEGV, SIGSEGV);
9191
DEFINE(NMI_MASK, NMI_MASK);
92-
OFFSET(TASKTHREADPPR, task_struct, thread.ppr);
9392
#else
9493
OFFSET(THREAD_INFO, task_struct, stack);
9594
DEFINE(THREAD_INFO_GAP, _ALIGN_UP(sizeof(struct thread_info), 16));
@@ -323,6 +322,7 @@ int main(void)
323322
STACK_PT_REGS_OFFSET(_ESR, dsisr);
324323
#else /* CONFIG_PPC64 */
325324
STACK_PT_REGS_OFFSET(SOFTE, softe);
325+
STACK_PT_REGS_OFFSET(_PPR, ppr);
326326
#endif /* CONFIG_PPC64 */
327327

328328
#if defined(CONFIG_PPC32)

‎arch/powerpc/kernel/entry_64.S‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
386386

387387
4: /* Anything else left to do? */
388388
BEGIN_FTR_SECTION
389-
lis r3,INIT_PPR@highest /* Set thread.ppr = 3 */
390-
ld r10,PACACURRENT(r13)
389+
lis r3,DEFAULT_PPR@highest /* Set default PPR */
391390
sldi r3,r3,32 /* bits 11-13 are used for ppr */
392-
std r3,TASKTHREADPPR(r10)
391+
std r3,_PPR(r1)
393392
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
394393

395394
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
@@ -942,12 +941,6 @@ fast_exception_return:
942941
andi. r0,r3,MSR_RI
943942
beq- .Lunrecov_restore
944943

945-
/* Load PPR from thread struct before we clear MSR:RI */
946-
BEGIN_FTR_SECTION
947-
ld r2,PACACURRENT(r13)
948-
ld r2,TASKTHREADPPR(r2)
949-
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
950-
951944
/*
952945
* Clear RI before restoring r13. If we are returning to
953946
* userspace and we take an exception after restoring r13,
@@ -968,7 +961,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
968961
andi. r0,r3,MSR_PR
969962
beq 1f
970963
BEGIN_FTR_SECTION
971-
mtspr SPRN_PPR,r2 /* Restore PPR */
964+
/* Restore PPR */
965+
ld r2,_PPR(r1)
966+
mtspr SPRN_PPR,r2
972967
END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
973968
ACCOUNT_CPU_USER_EXIT(r13, r2, r4)
974969
REST_GPR(13, r1)

‎arch/powerpc/kernel/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
17101710
p->thread.dscr = mfspr(SPRN_DSCR);
17111711
}
17121712
if (cpu_has_feature(CPU_FTR_HAS_PPR))
1713-
p->thread.ppr = INIT_PPR;
1713+
childregs->ppr = DEFAULT_PPR;
17141714

17151715
p->thread.tidr = 0;
17161716
#endif

‎arch/powerpc/kernel/ptrace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ static int ppr_get(struct task_struct *target,
16091609
void *kbuf, void __user *ubuf)
16101610
{
16111611
return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
1612-
&target->thread.ppr, 0, sizeof(u64));
1612+
&target->thread.regs->ppr, 0, sizeof(u64));
16131613
}
16141614

16151615
static int ppr_set(struct task_struct *target,
@@ -1618,7 +1618,7 @@ static int ppr_set(struct task_struct *target,
16181618
const void *kbuf, const void __user *ubuf)
16191619
{
16201620
return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1621-
&target->thread.ppr, 0, sizeof(u64));
1621+
&target->thread.regs->ppr, 0, sizeof(u64));
16221622
}
16231623

16241624
static int dscr_get(struct task_struct *target,

0 commit comments

Comments
 (0)