diff mbox

[v2,11/11] KVM: PPC: Book3S HV: Update kvmppc_set_arch_compat() for ISA v3.00

Message ID 1479861125-21394-12-git-send-email-paulus@ozlabs.org (mailing list archive)
State New, archived
Headers show

Commit Message

Paul Mackerras Nov. 23, 2016, 12:32 a.m. UTC
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>

The function kvmppc_set_arch_compat() is used to determine the value of the
processor compatibility register (PCR) for a guest running in a given
compatibility mode. There is currently no support for v3.00 of the ISA.

Add support for v3.00 of the ISA which adds an ISA v2.07 compatilibity mode
to the PCR.

We also add a check to ensure the processor we are running on is capable of
emulating the chosen processor (for example a POWER7 cannot emulate a
POWER8, similarly with a POWER8 and a POWER9).

Based on work by: Paul Mackerras <paulus@ozlabs.org>

[paulus@ozlabs.org - moved dummy PCR_ARCH_300 definition here; set
 guest_pcr_bit when arch_compat == 0, added comment.]

Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
---
 arch/powerpc/kvm/book3s_hv.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

Comments

kernel test robot Nov. 23, 2016, 6:26 a.m. UTC | #1
Hi Suraj,

[auto build test WARNING on next-20161122]
[cannot apply to kvm-ppc/kvm-ppc-next powerpc/next kvm/linux-next v4.9-rc6 v4.9-rc5 v4.9-rc4 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Paul-Mackerras/KVM-PPC-Book3S-HV-Support-KVM-guests-on-POWER9/20161123-124441
config: powerpc-allmodconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=powerpc 

All warnings (new ones prefixed by >>):

   arch/powerpc/kvm/book3s_hv.c: In function 'kvmppc_set_arch_compat':
   arch/powerpc/kvm/book3s_hv.c:320:23: error: 'PCR_ARCH_207' undeclared (first use in this function)
    #define PCR_ARCH_300 (PCR_ARCH_207 << 1)
                          ^
>> arch/powerpc/kvm/book3s_hv.c:329:18: note: in expansion of macro 'PCR_ARCH_300'
      host_pcr_bit = PCR_ARCH_300;
                     ^~~~~~~~~~~~
   arch/powerpc/kvm/book3s_hv.c:320:23: note: each undeclared identifier is reported only once for each function it appears in
    #define PCR_ARCH_300 (PCR_ARCH_207 << 1)
                          ^
>> arch/powerpc/kvm/book3s_hv.c:329:18: note: in expansion of macro 'PCR_ARCH_300'
      host_pcr_bit = PCR_ARCH_300;
                     ^~~~~~~~~~~~
   arch/powerpc/kvm/book3s_hv.c:351:8: error: 'PVR_ARCH_300' undeclared (first use in this function)
      case PVR_ARCH_300:
           ^~~~~~~~~~~~
   arch/powerpc/kvm/book3s_hv.c: In function 'kvmppc_set_one_reg_hv':
   arch/powerpc/kvm/book3s_hv.c:1474:46: error: 'PSSCR_GUEST_VIS' undeclared (first use in this function)
      vcpu->arch.psscr = set_reg_val(id, *val) & PSSCR_GUEST_VIS;
                                                 ^~~~~~~~~~~~~~~
   arch/powerpc/kvm/book3s_hv.c: In function 'kvmppc_setup_partition_table':
   arch/powerpc/kvm/book3s_hv.c:3113:2: error: implicit declaration of function 'mmu_partition_table_set_entry' [-Werror=implicit-function-declaration]
     mmu_partition_table_set_entry(kvm->arch.lpid, dw0, dw1);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/PCR_ARCH_300 +329 arch/powerpc/kvm/book3s_hv.c

   314	static void kvmppc_set_pvr_hv(struct kvm_vcpu *vcpu, u32 pvr)
   315	{
   316		vcpu->arch.pvr = pvr;
   317	}
   318	
   319	/* Dummy value used in computing PCR value below */
 > 320	#define PCR_ARCH_300	(PCR_ARCH_207 << 1)
   321	
   322	static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
   323	{
   324		unsigned long host_pcr_bit = 0, guest_pcr_bit = 0;
   325		struct kvmppc_vcore *vc = vcpu->arch.vcore;
   326	
   327		/* We can (emulate) our own architecture version and anything older */
   328		if (cpu_has_feature(CPU_FTR_ARCH_300))
 > 329			host_pcr_bit = PCR_ARCH_300;
   330		else if (cpu_has_feature(CPU_FTR_ARCH_207S))
   331			host_pcr_bit = PCR_ARCH_207;
   332		else if (cpu_has_feature(CPU_FTR_ARCH_206))

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 94294c3..7ee77fe 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -316,41 +316,54 @@  static void kvmppc_set_pvr_hv(struct kvm_vcpu *vcpu, u32 pvr)
 	vcpu->arch.pvr = pvr;
 }
 
+/* Dummy value used in computing PCR value below */
+#define PCR_ARCH_300	(PCR_ARCH_207 << 1)
+
 static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
 {
-	unsigned long pcr = 0;
+	unsigned long host_pcr_bit = 0, guest_pcr_bit = 0;
 	struct kvmppc_vcore *vc = vcpu->arch.vcore;
 
+	/* We can (emulate) our own architecture version and anything older */
+	if (cpu_has_feature(CPU_FTR_ARCH_300))
+		host_pcr_bit = PCR_ARCH_300;
+	else if (cpu_has_feature(CPU_FTR_ARCH_207S))
+		host_pcr_bit = PCR_ARCH_207;
+	else if (cpu_has_feature(CPU_FTR_ARCH_206))
+		host_pcr_bit = PCR_ARCH_206;
+	else
+		host_pcr_bit = PCR_ARCH_205;
+
+	/* Determine lowest PCR bit needed to run guest in given PVR level */
+	guest_pcr_bit = host_pcr_bit;
 	if (arch_compat) {
 		switch (arch_compat) {
 		case PVR_ARCH_205:
-			/*
-			 * If an arch bit is set in PCR, all the defined
-			 * higher-order arch bits also have to be set.
-			 */
-			pcr = PCR_ARCH_206 | PCR_ARCH_205;
+			guest_pcr_bit = PCR_ARCH_205;
 			break;
 		case PVR_ARCH_206:
 		case PVR_ARCH_206p:
-			pcr = PCR_ARCH_206;
+			guest_pcr_bit = PCR_ARCH_206;
 			break;
 		case PVR_ARCH_207:
+			guest_pcr_bit = PCR_ARCH_207;
+			break;
+		case PVR_ARCH_300:
+			guest_pcr_bit = PCR_ARCH_300;
 			break;
 		default:
 			return -EINVAL;
 		}
-
-		if (!cpu_has_feature(CPU_FTR_ARCH_207S)) {
-			/* POWER7 can't emulate POWER8 */
-			if (!(pcr & PCR_ARCH_206))
-				return -EINVAL;
-			pcr &= ~PCR_ARCH_206;
-		}
 	}
 
+	/* Check requested PCR bits don't exceed our capabilities */
+	if (guest_pcr_bit > host_pcr_bit)
+		return -EINVAL;
+
 	spin_lock(&vc->lock);
 	vc->arch_compat = arch_compat;
-	vc->pcr = pcr;
+	/* Set all PCR bits for which guest_pcr_bit <= bit < host_pcr_bit */
+	vc->pcr = host_pcr_bit - guest_pcr_bit;
 	spin_unlock(&vc->lock);
 
 	return 0;