Skip to content

Commit d825a04

Browse files
committed
KVM: PPC: Book3S: PR: Don't clobber our exit handler id
We call a C helper to save all svcpu fields into our vcpu. The C ABI states that r12 is considered volatile. However, we keep our exit handler id in r12 currently. So we need to save it away into a non-volatile register instead that definitely does get preserved across the C call. This bug usually didn't hit anyone yet since gcc is smart enough to generate code that doesn't even need r12 which means it stayed identical throughout the call by sheer luck. But we can't rely on that. Signed-off-by: Alexander Graf <[email protected]>
1 parent 91648ec commit d825a04

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arch/powerpc/kvm/book3s_interrupts.S

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,17 @@ kvm_start_lightweight:
132132
*
133133
*/
134134

135+
PPC_LL r3, GPR4(r1) /* vcpu pointer */
136+
137+
/*
138+
* kvmppc_copy_from_svcpu can clobber volatile registers, save
139+
* the exit handler id to the vcpu and restore it from there later.
140+
*/
141+
stw r12, VCPU_TRAP(r3)
142+
135143
/* Transfer reg values from shadow vcpu back to vcpu struct */
136144
/* On 64-bit, interrupts are still off at this point */
137-
PPC_LL r3, GPR4(r1) /* vcpu pointer */
145+
138146
GET_SHADOW_VCPU(r4)
139147
bl FUNC(kvmppc_copy_from_svcpu)
140148
nop
@@ -151,7 +159,6 @@ kvm_start_lightweight:
151159
*/
152160
ld r3, PACA_SPRG3(r13)
153161
mtspr SPRN_SPRG3, r3
154-
155162
#endif /* CONFIG_PPC_BOOK3S_64 */
156163

157164
/* R7 = vcpu */
@@ -177,7 +184,7 @@ kvm_start_lightweight:
177184
PPC_STL r31, VCPU_GPR(R31)(r7)
178185

179186
/* Pass the exit number as 3rd argument to kvmppc_handle_exit */
180-
mr r5, r12
187+
lwz r5, VCPU_TRAP(r7)
181188

182189
/* Restore r3 (kvm_run) and r4 (vcpu) */
183190
REST_2GPRS(3, r1)

0 commit comments

Comments
 (0)