Patchwork [10/12] KVM: PPC: bookehv: Add EPCR support in mtspr/mfspr emulation

login
register
mail settings
Submitter Mihai Caraman
Date Oct. 11, 2012, 4:13 p.m.
Message ID <1349972009-23027-11-git-send-email-mihai.caraman@freescale.com>
Download mbox | patch
Permalink /patch/190953/
State Not Applicable
Headers show

Comments

Mihai Caraman - Oct. 11, 2012, 4:13 p.m.
Add EPCR support in booke mtspr/mfspr emulation. EPCR register is defined only
for 64-bit and HV categories, we will expose it at this point only to 64-bit
virtual processors running on 64-bit HV hosts.
Define a reusable setter function for vcpu's EPCR.

Signed-off-by: Mihai Caraman <mihai.caraman@freescale.com>
---
v1: extended guard defines with CONFIG_KVM_BOOKE_HV required by arch's epcr and
shadow_epcr fields.

 arch/powerpc/kvm/booke.c         |   10 ++++++++++
 arch/powerpc/kvm/booke.h         |    1 +
 arch/powerpc/kvm/booke_emulate.c |   12 +++++++++++-
 3 files changed, 22 insertions(+), 1 deletions(-)
Alexander Graf - Dec. 1, 2012, 1:59 p.m.
On 11.10.2012, at 18:13, Mihai Caraman wrote:

> Add EPCR support in booke mtspr/mfspr emulation. EPCR register is defined only
> for 64-bit and HV categories, we will expose it at this point only to 64-bit
> virtual processors running on 64-bit HV hosts.
> Define a reusable setter function for vcpu's EPCR.
> 
> Signed-off-by: Mihai Caraman <mihai.caraman@freescale.com>
> ---
> v1: extended guard defines with CONFIG_KVM_BOOKE_HV required by arch's epcr and
> shadow_epcr fields.

I removed that constraint in another patch I just sent out and will remove the guards on HV while applying the patch.


Alex

Patch

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 86f0d0d..e6159f5 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1473,6 +1473,16 @@  void kvmppc_core_flush_memslot(struct kvm *kvm, struct kvm_memory_slot *memslot)
 {
 }
 
+void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr)
+{
+#if defined(CONFIG_64BIT) && defined(CONFIG_KVM_BOOKE_HV)
+	vcpu->arch.epcr = new_epcr;
+	vcpu->arch.shadow_epcr &= ~SPRN_EPCR_GICM;
+	if (vcpu->arch.epcr  & SPRN_EPCR_ICM)
+		vcpu->arch.shadow_epcr |= SPRN_EPCR_GICM;
+#endif
+}
+
 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr)
 {
 	vcpu->arch.tcr = new_tcr;
diff --git a/arch/powerpc/kvm/booke.h b/arch/powerpc/kvm/booke.h
index ba61974..e9b88e4 100644
--- a/arch/powerpc/kvm/booke.h
+++ b/arch/powerpc/kvm/booke.h
@@ -69,6 +69,7 @@  extern unsigned long kvmppc_booke_handlers;
 void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr);
 void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr);
 
+void kvmppc_set_epcr(struct kvm_vcpu *vcpu, u32 new_epcr);
 void kvmppc_set_tcr(struct kvm_vcpu *vcpu, u32 new_tcr);
 void kvmppc_set_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
 void kvmppc_clr_tsr_bits(struct kvm_vcpu *vcpu, u32 tsr_bits);
diff --git a/arch/powerpc/kvm/booke_emulate.c b/arch/powerpc/kvm/booke_emulate.c
index 514790f..8d9d8f9 100644
--- a/arch/powerpc/kvm/booke_emulate.c
+++ b/arch/powerpc/kvm/booke_emulate.c
@@ -240,7 +240,12 @@  int kvmppc_booke_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn, ulong spr_val)
 	case SPRN_MCSR:
 		vcpu->arch.mcsr &= ~spr_val;
 		break;
-
+#if defined(CONFIG_64BIT) && defined(CONFIG_KVM_BOOKE_HV)
+	case SPRN_EPCR:
+		kvmppc_set_epcr(vcpu, spr_val);
+		mtspr(SPRN_EPCR, vcpu->arch.shadow_epcr);
+		break;
+#endif
 	default:
 		emulated = EMULATE_FAIL;
 	}
@@ -335,6 +340,11 @@  int kvmppc_booke_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val)
 	case SPRN_MCSR:
 		*spr_val = vcpu->arch.mcsr;
 		break;
+#if defined(CONFIG_64BIT) && defined(CONFIG_KVM_BOOKE_HV)
+	case SPRN_EPCR:
+		*spr_val = vcpu->arch.epcr;
+		break;
+#endif
 
 	default:
 		emulated = EMULATE_FAIL;