Skip to contentSkip to conversation

powerpc/tm: do not use r13 for tabort_syscall

PATCH In review Nicholas Piggin 2 participants 3 messages Jul 22, 2016 – Aug 22, 2016 PowerPC

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

PATCH 1/1 powerpc/tm: do not use r13 for tabort_syscall

tabort_syscall runs with RI=1, so a nested recoverable machine check will load the paca into r13 and overwrite what we loaded it with, because exceptions returning to privileged mode do not restore r13.

This has survived testing with sc instruction inside transaction (bare sc, not glibc syscall because glibc can tabort before sc). Verified the transaction is failing failing with with TM_CAUSE_SYSCALL.

Cc Michael Neuling <[email protected]>
Cc Sam Bobroff <[email protected]>
Cc Michael Ellerman <[email protected]>

---

 arch/powerpc/kernel/entry_64.S | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
arch/powerpc/kernel/entry_64.S +10 -10
index 73e461a..387dee3 100644
@@ -368,13 +368,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 tabort_syscall:
 	/* Firstly we need to enable TM in the kernel */
 	mfmsr	r10
-	li	r13, 1
-	rldimi	r10, r13, MSR_TM_LG, 63-MSR_TM_LG
-	mtmsrd	r10, 0
+	li	r9,1
+	rldimi	r10,r9,MSR_TM_LG,63-MSR_TM_LG
+	mtmsrd	r10,0
 
 	/* tabort, this dooms the transaction, nothing else */
-	li	r13, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
-	TABORT(R13)
+	li	r9,(TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
+	TABORT(R9)
 
 	/*
 	 * Return directly to userspace. We have corrupted user register state,
@@ -382,11 +382,11 @@ tabort_syscall:
 	 * resume after the tbegin of the aborted transaction with the
 	 * checkpointed register state.
 	 */
-	li	r13, MSR_RI
-	andc	r10, r10, r13
-	mtmsrd	r10, 1
-	mtspr	SPRN_SRR0, r11
-	mtspr	SPRN_SRR1, r12
+	li	r9,MSR_RI
+	andc	r10,r10,r9
+	mtmsrd	r10,1
+	mtspr	SPRN_SRR0,r11
+	mtspr	SPRN_SRR1,r12
 
 	rfid
 	b	.	/* prevent speculative execution */
Signature · 1 line
2.8.1
#1 lore raw
Quoted 11 lines · Nicholas Piggin

tabort_syscall runs with RI=3D1, so a nested recoverable machine check will load the paca into r13 and overwrite what we loaded it with, because exceptions returning to privileged mode do not restore r13.
=20
This has survived testing with sc instruction inside transaction (bare sc, not glibc syscall because glibc can tabort before sc). Verified the transaction is failing failing with with TM_CAUSE_SYSCALL.
=20

Thanks.

This looks good, but should probably be cc: stable from when the syscall tm abort went in.

There are some random whitespace changes in here too, which if we avoid will make the patch smaller (and easier to read).

Mikey

Quoted 30 lines

Cc: Michael Neuling <[email protected]>
Cc: Sam Bobroff <[email protected]>
Cc: Michael Ellerman <[email protected]>
=20
---
=20
=C2=A0arch/powerpc/kernel/entry_64.S | 20 ++++++++++---------- =C2=A01 file changed, 10 insertions(+), 10 deletions(-) =20

arch/powerpc/kernel/entry_64.S +0 -0
index 73e461a..387dee3 100644
@@ -368,13 +368,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)

=C2=A0tabort_syscall:
=C2=A0 /* Firstly we need to enable TM in the kernel */
=C2=A0 mfmsr r10

arch/powerpc/kernel/entry_64.S +3 -3
-	li	r13, 1
-	rldimi	r10, r13, MSR_TM_LG, 63-MSR_TM_LG
-	mtmsrd	r10, 0
+	li	r9,1
+	rldimi	r10,r9,MSR_TM_LG,63-MSR_TM_LG
+	mtmsrd	r10,0

=C2=A0
=C2=A0 /* tabort, this dooms the transaction, nothing else */

arch/powerpc/kernel/entry_64.S +2 -2
-	li	r13, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
-	TABORT(R13)
+	li	r9,(TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
+	TABORT(R9)
Quoted 3 lines

=C2=A0
=C2=A0 /*
=C2=A0 =C2=A0* Return directly to userspace. We have corrupted user regis=

ter

Quoted 3 lines

state,

arch/powerpc/kernel/entry_64.S +0 -0
@@ -382,11 +382,11 @@ tabort_syscall:

=C2=A0 =C2=A0* resume after the tbegin of the aborted transaction with th=

e

Quoted 15 lines

=C2=A0 =C2=A0* checkpointed register state.
=C2=A0 =C2=A0*/

arch/powerpc/kernel/entry_64.S +5 -5
-	li	r13, MSR_RI
-	andc	r10, r10, r13
-	mtmsrd	r10, 1
-	mtspr	SPRN_SRR0, r11
-	mtspr	SPRN_SRR1, r12
+	li	r9,MSR_RI
+	andc	r10,r10,r9
+	mtmsrd	r10,1
+	mtspr	SPRN_SRR0,r11
+	mtspr	SPRN_SRR1,r12

=C2=A0
=C2=A0 rfid
=C2=A0 b . /* prevent speculative execution */

Acked-by on v1 1/1
#2 lore raw
In reply to Nicholas Piggin
Quoted 10 lines · Nicholas Piggin

tabort_syscall runs with RI=3D1, so a nested recoverable machine check will load the paca into r13 and overwrite what we loaded it with, because exceptions returning to privileged mode do not restore r13.
=20
This has survived testing with sc instruction inside transaction (bare sc, not glibc syscall because glibc can tabort before sc). Verified the transaction is failing failing with with TM_CAUSE_SYSCALL.
=20

Quoted 2 lines
Cc Michael Neuling <[email protected]>

FWIW

Quoted 29 lines

Cc: Sam Bobroff <[email protected]>
Cc: Michael Ellerman <[email protected]>
=20
---
=20
=C2=A0arch/powerpc/kernel/entry_64.S | 20 ++++++++++---------- =C2=A01 file changed, 10 insertions(+), 10 deletions(-) =20

arch/powerpc/kernel/entry_64.S +0 -0
index 73e461a..387dee3 100644
@@ -368,13 +368,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)

=C2=A0tabort_syscall:
=C2=A0 /* Firstly we need to enable TM in the kernel */
=C2=A0 mfmsr r10

arch/powerpc/kernel/entry_64.S +3 -3
-	li	r13, 1
-	rldimi	r10, r13, MSR_TM_LG, 63-MSR_TM_LG
-	mtmsrd	r10, 0
+	li	r9,1
+	rldimi	r10,r9,MSR_TM_LG,63-MSR_TM_LG
+	mtmsrd	r10,0

=C2=A0
=C2=A0 /* tabort, this dooms the transaction, nothing else */

arch/powerpc/kernel/entry_64.S +2 -2
-	li	r13, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
-	TABORT(R13)
+	li	r9,(TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
+	TABORT(R9)
Quoted 3 lines

=C2=A0
=C2=A0 /*
=C2=A0 =C2=A0* Return directly to userspace. We have corrupted user regis=

ter

Quoted 3 lines

state,

arch/powerpc/kernel/entry_64.S +0 -0
@@ -382,11 +382,11 @@ tabort_syscall:

=C2=A0 =C2=A0* resume after the tbegin of the aborted transaction with th=

e

Quoted 15 lines

=C2=A0 =C2=A0* checkpointed register state.
=C2=A0 =C2=A0*/

arch/powerpc/kernel/entry_64.S +5 -5
-	li	r13, MSR_RI
-	andc	r10, r10, r13
-	mtmsrd	r10, 1
-	mtspr	SPRN_SRR0, r11
-	mtspr	SPRN_SRR1, r12
+	li	r9,MSR_RI
+	andc	r10,r10,r9
+	mtmsrd	r10,1
+	mtspr	SPRN_SRR0,r11
+	mtspr	SPRN_SRR1,r12

=C2=A0
=C2=A0 rfid
=C2=A0 b . /* prevent speculative execution */