Skip to contentSkip to conversation

KVM: PPC: booke: use shadow_msr

PATCH In review Scott Wood 2 participants 4 messages May 17, 2011 – Jun 2, 2011

Subsystems (2)
lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 3/13 KVM: PPC: booke: use shadow_msr

BKeep the guest MSR and the guest-mode true MSR separate, rather than modifying the guest MSR on each guest entry to produce a true MSR.

Any bits which should be modified based on guest MSR must be explicitly propagated from vcpu->arch.shared->msr to vcpu->arch.shadow_msr in kvmppc_set_msr().

While we're modifying the guest entry code, reorder a few instructions to bury some load latencies.

---
This is a resending of http://www.spinics.net/lists/kvm-ppc/msg02681.html

 arch/powerpc/include/asm/kvm_host.h |    2 +-
 arch/powerpc/kernel/asm-offsets.c   |    2 +-
 arch/powerpc/kvm/booke.c            |    2 ++
 arch/powerpc/kvm/booke_interrupts.S |   17 ++++++-----------
 4 files changed, 10 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -1
index 186f150..12cb180 100644
@@ -219,12 +219,12 @@ struct kvm_vcpu_arch {
 #endif
 
 #ifdef CONFIG_PPC_BOOK3S
-	ulong shadow_msr;
 	ulong hflags;
 	ulong guest_owned_ext;
 #endif
 	u32 vrsave; /* also USPRG0 */
 	u32 mmucr;
+	ulong shadow_msr;
 	ulong sprg4;
 	ulong sprg5;
 	ulong sprg6;
arch/powerpc/kernel/asm-offsets.c +1 -1
index cf0d822..431406c 100644
@@ -403,12 +403,12 @@ int main(void)
 	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
 	DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));
 	DEFINE(VCPU_SHARED_MSR, offsetof(struct kvm_vcpu_arch_shared, msr));
+	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
 
 	/* book3s */
 #ifdef CONFIG_PPC_BOOK3S
 	DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
 	DEFINE(VCPU_HOST_MSR, offsetof(struct kvm_vcpu, arch.host_msr));
-	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
 	DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, arch.trampoline_lowmem));
 	DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter));
 	DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler));
arch/powerpc/kvm/booke.c +2 -0
index 8462b3a..9810010 100644
@@ -514,6 +514,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	vcpu->arch.pc = 0;
 	vcpu->arch.shared->msr = 0;
+	vcpu->arch.shadow_msr = MSR_CE | MSR_EE | MSR_PR | MSR_DE |
+				MSR_ME | MSR_IS | MSR_DS;
 	kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */
 
 	vcpu->arch.shadow_pid = 1;
arch/powerpc/kvm/booke_interrupts.S +6 -11
index b58ccae..55410cc 100644
@@ -24,8 +24,6 @@
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
 
-#define KVMPPC_MSR_MASK (MSR_CE|MSR_EE|MSR_PR|MSR_DE|MSR_ME|MSR_IS|MSR_DS)
-
 #define VCPU_GPR(n)     (VCPU_GPRS + (n * 4))
 
 /* The host stack layout: */
@@ -405,20 +403,17 @@ lightweight_exit:
 
 	/* Finish loading guest volatiles and jump to guest. */
 	lwz	r3, VCPU_CTR(r4)
+	lwz	r5, VCPU_CR(r4)
+	lwz	r6, VCPU_PC(r4)
+	lwz	r7, VCPU_SHADOW_MSR(r4)
 	mtctr	r3
-	lwz	r3, VCPU_CR(r4)
-	mtcr	r3
+	mtcr	r5
+	mtsrr0	r6
+	mtsrr1	r7
 	lwz	r5, VCPU_GPR(r5)(r4)
 	lwz	r6, VCPU_GPR(r6)(r4)
 	lwz	r7, VCPU_GPR(r7)(r4)
 	lwz	r8, VCPU_GPR(r8)(r4)
-	lwz	r3, VCPU_PC(r4)
-	mtsrr0	r3
-	lwz	r3, VCPU_SHARED(r4)
-	lwz	r3, (VCPU_SHARED_MSR + 4)(r3)
-	oris	r3, r3, KVMPPC_MSR_MASK@h
-	ori	r3, r3, KVMPPC_MSR_MASK@l
-	mtsrr1	r3
 
 	/* Clear any debug events which occurred since we disabled MSR[DE].
 	 * XXX This gives us a 3-instruction window in which a breakpoint
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 1 line · Scott Wood

BKeep the guest MSR and the guest-mode true MSR separate, rather than

Bkeep?

Quoted 60 lines

modifying the guest MSR on each guest entry to produce a true MSR.

Any bits which should be modified based on guest MSR must be explicitly propagated from vcpu->arch.shared->msr to vcpu->arch.shadow_msr in kvmppc_set_msr().

While we're modifying the guest entry code, reorder a few instructions to bury some load latencies.

---
This is a resending of http://www.spinics.net/lists/kvm-ppc/msg02681.html

  arch/powerpc/include/asm/kvm_host.h |    2 +-
  arch/powerpc/kernel/asm-offsets.c   |    2 +-
  arch/powerpc/kvm/booke.c            |    2 ++
  arch/powerpc/kvm/booke_interrupts.S |   17 ++++++-----------
  4 files changed, 10 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -1
index 186f150..12cb180 100644
@@ -219,12 +219,12 @@ struct kvm_vcpu_arch {
  #endif
 
  #ifdef CONFIG_PPC_BOOK3S
-	ulong shadow_msr;
  	ulong hflags;
  	ulong guest_owned_ext;
  #endif
  	u32 vrsave; /* also USPRG0 */
  	u32 mmucr;
+	ulong shadow_msr;
  	ulong sprg4;
  	ulong sprg5;
  	ulong sprg6;
arch/powerpc/kernel/asm-offsets.c +1 -1
index cf0d822..431406c 100644
@@ -403,12 +403,12 @@ int main(void)
  	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
  	DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));
  	DEFINE(VCPU_SHARED_MSR, offsetof(struct kvm_vcpu_arch_shared, msr));
+	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
 
  	/* book3s */
  #ifdef CONFIG_PPC_BOOK3S
  	DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
  	DEFINE(VCPU_HOST_MSR, offsetof(struct kvm_vcpu, arch.host_msr));
-	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
  	DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, arch.trampoline_lowmem));
  	DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter));
  	DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler));
arch/powerpc/kvm/booke.c +0 -0
index 8462b3a..9810010 100644

arch/powerpc/kvm/booke.c int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) · line 518

Quoted 5 lines
arch/powerpc/kvm/booke.c +2 -0
@@ -514,6 +514,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
  	vcpu->arch.pc = 0;
  	vcpu->arch.shared->msr = 0;
+	vcpu->arch.shadow_msr = MSR_CE | MSR_EE | MSR_PR | MSR_DE |
+				MSR_ME | MSR_IS | MSR_DS;

Is there no define for this? Book3S has MSR_USER for it.

Alex

author
#2 lore raw
In reply to Scott Wood
Quoted 4 lines · On Thu, 19 May 2011 12:05:57 +0200 Alexander Graf <[email protected]> wrote:
Quoted 1 line · Scott Wood

BKeep the guest MSR and the guest-mode true MSR separate, rather than

Bkeep?

Doh.

Quoted 6 lines
Quoted 6 lines
arch/powerpc/kvm/booke.c +0 -0
index 8462b3a..9810010 100644
@@ -514,6 +514,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
Quoted 6 lines

arch/powerpc/kvm/booke.c int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) · line 518

Quoted 4 lines
arch/powerpc/kvm/booke.c +2 -0
  	vcpu->arch.pc = 0;
  	vcpu->arch.shared->msr = 0;
+	vcpu->arch.shadow_msr = MSR_CE | MSR_EE | MSR_PR | MSR_DE |
+				MSR_ME | MSR_IS | MSR_DS;

Is there no define for this? Book3S has MSR_USER for it.

I suppose we could do MSR_USER | MSR_IS | MSR_DS. It obfuscates a bit what is being set in a KVM guest, though OTOH I left out MSR_RI. :-P

-Scott

author
#3 lore raw

PATCH 3/13 KVM: PPC: booke: use shadow_msr

In reply to Scott Wood

Keep the guest MSR and the guest-mode true MSR separate, rather than modifying the guest MSR on each guest entry to produce a true MSR.

Any bits which should be modified based on guest MSR must be explicitly propagated from vcpu->arch.shared->msr to vcpu->arch.shadow_msr in kvmppc_set_msr().

While we're modifying the guest entry code, reorder a few instructions to bury some load latencies.

---
 arch/powerpc/include/asm/kvm_host.h |    2 +-
 arch/powerpc/kernel/asm-offsets.c   |    2 +-
 arch/powerpc/kvm/booke.c            |    1 +
 arch/powerpc/kvm/booke_interrupts.S |   17 ++++++-----------
 4 files changed, 9 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -1
index 186f150..12cb180 100644
@@ -219,12 +219,12 @@ struct kvm_vcpu_arch {
 #endif
 
 #ifdef CONFIG_PPC_BOOK3S
-	ulong shadow_msr;
 	ulong hflags;
 	ulong guest_owned_ext;
 #endif
 	u32 vrsave; /* also USPRG0 */
 	u32 mmucr;
+	ulong shadow_msr;
 	ulong sprg4;
 	ulong sprg5;
 	ulong sprg6;
arch/powerpc/kernel/asm-offsets.c +1 -1
index 36e1c8a..25de8e4 100644
@@ -404,12 +404,12 @@ int main(void)
 	DEFINE(VCPU_SHADOW_PID, offsetof(struct kvm_vcpu, arch.shadow_pid));
 	DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));
 	DEFINE(VCPU_SHARED_MSR, offsetof(struct kvm_vcpu_arch_shared, msr));
+	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
 
 	/* book3s */
 #ifdef CONFIG_PPC_BOOK3S
 	DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
 	DEFINE(VCPU_HOST_MSR, offsetof(struct kvm_vcpu, arch.host_msr));
-	DEFINE(VCPU_SHADOW_MSR, offsetof(struct kvm_vcpu, arch.shadow_msr));
 	DEFINE(VCPU_TRAMPOLINE_LOWMEM, offsetof(struct kvm_vcpu, arch.trampoline_lowmem));
 	DEFINE(VCPU_TRAMPOLINE_ENTER, offsetof(struct kvm_vcpu, arch.trampoline_enter));
 	DEFINE(VCPU_HIGHMEM_HANDLER, offsetof(struct kvm_vcpu, arch.highmem_handler));
arch/powerpc/kvm/booke.c +1 -0
index 8462b3a..05cedb5 100644
@@ -514,6 +514,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	vcpu->arch.pc = 0;
 	vcpu->arch.shared->msr = 0;
+	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
 	kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */
 
 	vcpu->arch.shadow_pid = 1;
arch/powerpc/kvm/booke_interrupts.S +6 -11
index b58ccae..55410cc 100644
@@ -24,8 +24,6 @@
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
 
-#define KVMPPC_MSR_MASK (MSR_CE|MSR_EE|MSR_PR|MSR_DE|MSR_ME|MSR_IS|MSR_DS)
-
 #define VCPU_GPR(n)     (VCPU_GPRS + (n * 4))
 
 /* The host stack layout: */
@@ -405,20 +403,17 @@ lightweight_exit:
 
 	/* Finish loading guest volatiles and jump to guest. */
 	lwz	r3, VCPU_CTR(r4)
+	lwz	r5, VCPU_CR(r4)
+	lwz	r6, VCPU_PC(r4)
+	lwz	r7, VCPU_SHADOW_MSR(r4)
 	mtctr	r3
-	lwz	r3, VCPU_CR(r4)
-	mtcr	r3
+	mtcr	r5
+	mtsrr0	r6
+	mtsrr1	r7
 	lwz	r5, VCPU_GPR(r5)(r4)
 	lwz	r6, VCPU_GPR(r6)(r4)
 	lwz	r7, VCPU_GPR(r7)(r4)
 	lwz	r8, VCPU_GPR(r8)(r4)
-	lwz	r3, VCPU_PC(r4)
-	mtsrr0	r3
-	lwz	r3, VCPU_SHARED(r4)
-	lwz	r3, (VCPU_SHARED_MSR + 4)(r3)
-	oris	r3, r3, KVMPPC_MSR_MASK@h
-	ori	r3, r3, KVMPPC_MSR_MASK@l
-	mtsrr1	r3
 
 	/* Clear any debug events which occurred since we disabled MSR[DE].
 	 * XXX This gives us a 3-instruction window in which a breakpoint
Signature · 1 line
1.7.4.1