Skip to contentSkip to conversation

KVM: PPC: booke: save/restore VRSAVE (a.k.a. USPRG0)

PATCH Superseded Scott Wood 2 participants 3 messages Apr 18, 2011 – Apr 19, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 1/2 KVM: PPC: booke: save/restore VRSAVE (a.k.a. USPRG0)

Linux doesn't use USPRG0 (now renamed VRSAVE in the architecture, even when Altivec isn't involved), but a guest might.

---
Sent to the right list this time... <sigh>

 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |    1 +
 arch/powerpc/kvm/booke_interrupts.S |    5 ++++-
 3 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
index bfb0e0f..34b8732 100644
@@ -228,6 +228,7 @@ struct kvm_vcpu_arch {
 	ulong hflags;
 	ulong guest_owned_ext;
 #endif
+	u32 vrsave; /* also USPRG0 */
 	u32 mmucr;
 	ulong shadow_msr;
 	ulong sprg4;
arch/powerpc/kernel/asm-offsets.c +1 -0
index 2b223de..7b9e35e 100644
@@ -395,6 +395,7 @@ int main(void)
 	DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
 	DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
 	DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
+	DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave));
 	DEFINE(VCPU_SPRG4, offsetof(struct kvm_vcpu, arch.sprg4));
 	DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
 	DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
arch/powerpc/kvm/booke_interrupts.S +4 -1
index 54c19d2..cde29c4 100644
@@ -184,6 +184,8 @@ _GLOBAL(kvmppc_resume_host)
 	stw	r3, VCPU_GPR(r4)(r4)
 	mfspr	r3, SPRN_SRR0
 	stw	r3, VCPU_PC(r4)
+	mfspr	r3, SPRN_VRSAVE
+	stw	r3, VCPU_VRSAVE(r4)
 
 	/* Restore host stack pointer and PID before IVPR, since the host
 	 * exception handlers use them. */
@@ -395,9 +397,10 @@ lightweight_exit:
 	 * because host interrupt handlers would get confused. */
 	lwz	r1, VCPU_GPR(r1)(r4)
 
-	/* XXX handle USPRG0 */
 	/* Host interrupt handlers may have clobbered these guest-readable
 	 * SPRGs, so we need to reload them here with the guest's values. */
+	lwz	r3, VCPU_VRSAVE(r4)
+	mtspr	SPRN_VRSAVE, r3
 	lwz	r3, VCPU_SPRG4(r4)
 	mtspr	SPRN_SPRG4W, r3
 	lwz	r3, VCPU_SPRG5(r4)
Signature · 1 line
1.7.1
#1 lore raw
Quoted 41 lines · Scott Wood

Linux doesn't use USPRG0 (now renamed VRSAVE in the architecture, even when Altivec isn't involved), but a guest might.

---
Sent to the right list this time... <sigh>

arch/powerpc/include/asm/kvm_host.h |    1 +
arch/powerpc/kernel/asm-offsets.c   |    1 +
arch/powerpc/kvm/booke_interrupts.S |    5 ++++-
3 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -0
index bfb0e0f..34b8732 100644
@@ -228,6 +228,7 @@ struct kvm_vcpu_arch {
 	ulong hflags;
 	ulong guest_owned_ext;
 #endif
+	u32 vrsave; /* also USPRG0 */
 	u32 mmucr;
 	ulong shadow_msr;
 	ulong sprg4;
arch/powerpc/kernel/asm-offsets.c +1 -0
index 2b223de..7b9e35e 100644
@@ -395,6 +395,7 @@ int main(void)
 	DEFINE(VCPU_HOST_STACK, offsetof(struct kvm_vcpu, arch.host_stack));
 	DEFINE(VCPU_HOST_PID, offsetof(struct kvm_vcpu, arch.host_pid));
 	DEFINE(VCPU_GPRS, offsetof(struct kvm_vcpu, arch.gpr));
+	DEFINE(VCPU_VRSAVE, offsetof(struct kvm_vcpu, arch.vrsave));
 	DEFINE(VCPU_SPRG4, offsetof(struct kvm_vcpu, arch.sprg4));
 	DEFINE(VCPU_SPRG5, offsetof(struct kvm_vcpu, arch.sprg5));
 	DEFINE(VCPU_SPRG6, offsetof(struct kvm_vcpu, arch.sprg6));
arch/powerpc/kvm/booke_interrupts.S +0 -0
index 54c19d2..cde29c4 100644

arch/powerpc/kvm/booke_interrupts.S _GLOBAL(kvmppc_resume_host) · line 188

Quoted 5 lines
arch/powerpc/kvm/booke_interrupts.S +2 -0
@@ -184,6 +184,8 @@ _GLOBAL(kvmppc_resume_host)
 	stw	r3, VCPU_GPR(r4)(r4)
 	mfspr	r3, SPRN_SRR0
 	stw	r3, VCPU_PC(r4)
+	mfspr	r3, SPRN_VRSAVE
+	stw	r3, VCPU_VRSAVE(r4)

Do we need to swap this on every exit or is vcpu_load/put enough?

Alex

author
#2 lore raw

Re: [PATCH 1/2] KVM: PPC: booke: save/restore VRSAVE (a.k.a.

In reply to Scott Wood
Quoted 14 lines · On Tue, 19 Apr 2011 00:43:51 +0200 Alexander Graf <[email protected]> wrote:

arch/powerpc/kvm/booke_interrupts.S _GLOBAL(kvmppc_resume_host) · line 188

Quoted 10 lines · Scott Wood
arch/powerpc/kvm/booke_interrupts.S +2 -0
index 54c19d2..cde29c4 100644
@@ -184,6 +184,8 @@ _GLOBAL(kvmppc_resume_host)
 	stw	r3, VCPU_GPR(r4)(r4)
 	mfspr	r3, SPRN_SRR0
 	stw	r3, VCPU_PC(r4)
+	mfspr	r3, SPRN_VRSAVE
+	stw	r3, VCPU_VRSAVE(r4)

Do we need to swap this on every exit or is vcpu_load/put enough?

vcpu_load/put is OK.

-Scott