Skip to content

Commit cf13435

Browse files
mikeympe
authored andcommitted
powerpc/tm: Fix userspace r13 corruption
When we treclaim we store the userspace checkpointed r13 to a scratch SPR and then later save the scratch SPR to the user thread struct. Unfortunately, this doesn't work as accessing the user thread struct can take an SLB fault and the SLB fault handler will write the same scratch SPRG that now contains the userspace r13. To fix this, we store r13 to the kernel stack (which can't fault) before we access the user thread struct. Found by running P8 guest + powervm + disable_1tb_segments + TM. Seen as a random userspace segfault with r13 looking like a kernel address. Signed-off-by: Michael Neuling <mikey@neuling.org> Reviewed-by: Breno Leitao <leitao@debian.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 8604895 commit cf13435

File tree

1 file changed

+9
-2
lines changed
  • arch/powerpc/kernel

1 file changed

+9
-2
lines changed

arch/powerpc/kernel/tm.S

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,20 @@ _GLOBAL(tm_reclaim)
176176
std r1, PACATMSCRATCH(r13)
177177
ld r1, PACAR1(r13)
178178

179-
/* Store the PPR in r11 and reset to decent value */
180179
std r11, GPR11(r1) /* Temporary stash */
181180

181+
/*
182+
* Store r13 away so we can free up the scratch SPR for the SLB fault
183+
* handler (needed once we start accessing the thread_struct).
184+
*/
185+
GET_SCRATCH0(r11)
186+
std r11, GPR13(r1)
187+
182188
/* Reset MSR RI so we can take SLB faults again */
183189
li r11, MSR_RI
184190
mtmsrd r11, 1
185191

192+
/* Store the PPR in r11 and reset to decent value */
186193
mfspr r11, SPRN_PPR
187194
HMT_MEDIUM
188195

@@ -211,7 +218,7 @@ _GLOBAL(tm_reclaim)
211218
ld r4, GPR7(r1) /* user r7 */
212219
ld r5, GPR11(r1) /* user r11 */
213220
ld r6, GPR12(r1) /* user r12 */
214-
GET_SCRATCH0(8) /* user r13 */
221+
ld r8, GPR13(r1) /* user r13 */
215222
std r3, GPR1(r7)
216223
std r4, GPR7(r7)
217224
std r5, GPR11(r7)

0 commit comments

Comments
 (0)