[PATCH 3/3] KVM: PPC: Book3S PR: Implement ARCH_COMPAT register

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This provides basic support for the KVM_REG_PPC_ARCH_COMPAT register
in PR KVM.  At present the value is sanity-checked when set, but
doesn't actually affect anything yet.

Implementing this makes it possible to use a qemu command-line
argument such as "-cpu host,compat=power7" on a POWER8 machine,
just as we would with HV KVM.  In turn this means that we can use the
same libvirt XML for nested virtualization with PR KVM as we do with
HV KVM.

Signed-off-by: Paul Mackerras <paulus@xxxxxxxxx>
---
 arch/powerpc/include/asm/kvm_host.h |  2 ++
 arch/powerpc/kvm/book3s_pr.c        | 39 +++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
index 3502649..f435a889 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -515,6 +515,8 @@ struct kvm_vcpu_arch {
 	u32 ivor[64];
 	ulong ivpr;
 	u32 pvr;
+	u32 pvr_arch;
+	u32 compat_arch;
 
 	u32 shadow_pid;
 	u32 shadow_pid1;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index faffb27..7183bdc 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -398,6 +398,28 @@ static void kvmppc_set_msr_pr(struct kvm_vcpu *vcpu, u64 msr)
 		kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP);
 }
 
+/*
+ * Evaluate the architecture level of a PVR value.
+ * The result is in terms of PVR_ARCH_* values.
+ */
+static u32 pvr_to_arch(u32 pvr)
+{
+	switch (PVR_VER(pvr)) {
+	case PVR_POWER5p:
+		return PVR_ARCH_204;
+	case PVR_POWER6:
+		return PVR_ARCH_205;
+	case PVR_POWER7:
+	case PVR_POWER7p:
+		return PVR_ARCH_206;
+	case PVR_POWER8:
+	case PVR_POWER8E:
+		return PVR_ARCH_207;
+	default:
+		return 0;
+	}
+}
+
 void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr)
 {
 	u32 host_pvr;
@@ -473,6 +495,18 @@ void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr)
 		/* Enable HID2.PSE - in case we need it later */
 		mtspr(SPRN_HID2_GEKKO, mfspr(SPRN_HID2_GEKKO) | (1 << 29));
 	}
+
+	vcpu->arch.pvr_arch = pvr_to_arch(pvr);
+	if (vcpu->arch.pvr_arch < vcpu->arch.compat_arch)
+		vcpu->arch.compat_arch = 0;
+}
+
+static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 compat_arch)
+{
+	if (compat_arch > vcpu->arch.pvr_arch)
+		return -EINVAL;
+	vcpu->arch.compat_arch = vcpu->arch.pvr_arch;
+	return 0;
 }
 
 /* Book3s_32 CPUs always have 32 bytes cache line size, which Linux assumes. To
@@ -1332,6 +1366,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
 		else
 			*val = get_reg_val(id, 0);
 		break;
+	case KVM_REG_PPC_ARCH_COMPAT:
+		*val = get_reg_val(id, vcpu->arch.compat_arch);
+		break;
 	default:
 		r = -EINVAL;
 		break;
@@ -1361,6 +1398,8 @@ static int kvmppc_set_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
 	case KVM_REG_PPC_LPCR:
 	case KVM_REG_PPC_LPCR_64:
 		kvmppc_set_lpcr_pr(vcpu, set_reg_val(id, *val));
+	case KVM_REG_PPC_ARCH_COMPAT:
+		r = kvmppc_set_arch_compat(vcpu, set_reg_val(id, *val));
 		break;
 	default:
 		r = -EINVAL;
-- 
2.1.0.rc1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux