]> xenbits.xensource.com Git - xen.git/commitdiff
x86/vpmu: disable VPMU if guest's CPUID indicates no PMU support
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 1 Mar 2017 16:51:16 +0000 (17:51 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 1 Mar 2017 16:51:16 +0000 (17:51 +0100)
When toolstack overrides Intel CPUID leaf 0xa's PMU version with an
invalid value VPMU should not be available to the guest.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/cpu/vpmu_intel.c
xen/arch/x86/domctl.c
xen/include/asm-x86/cpuid.h

index 0ce68f1b70ba7a130d2220f96cf68d9aec25d1e5..626bed561a65b2eabc016328a50d80c44e247dc7 100644 (file)
@@ -883,6 +883,10 @@ int vmx_vpmu_initialise(struct vcpu *v)
     if ( vpmu_mode == XENPMU_MODE_OFF )
         return 0;
 
+    if ( v->domain->arch.cpuid->basic.pmu_version <= 1 ||
+         v->domain->arch.cpuid->basic.pmu_version >= 5 )
+        return -EINVAL;
+
     if ( (arch_pmc_cnt + fixed_pmc_cnt) == 0 )
         return -EINVAL;
 
index d5f8d2fd21b1f0f7eed94ebae56d8ded9523ace3..02b48e85c1ef47db3d6843c56fe6408b436bfd96 100644 (file)
@@ -252,6 +252,20 @@ static int update_domain_cpuid_info(struct domain *d,
         }
         break;
 
+    case 0xa:
+        if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL )
+            break;
+
+        /* If PMU version is zero then the guest doesn't have VPMU */
+        if ( p->basic.pmu_version == 0 )
+        {
+            struct vcpu *v;
+
+            for_each_vcpu ( d, v )
+                vpmu_destroy(v);
+        }
+        break;
+
     case 0xd:
         if ( ctl->input[1] != 1 )
             break;
index 6d1990bfe2bf2b63dce3584f71fd869d71396e24..aa482b719fa1b2be27aa78ae8346b1cab95c7575 100644 (file)
@@ -122,6 +122,18 @@ struct cpuid_policy
 
             /* Leaf 0x2 - TLB/Cache/Prefetch. */
             uint8_t l2_nr_queries; /* Documented as fixed to 1. */
+            uint8_t l2_desc[15];
+
+            uint64_t :64, :64; /* Leaf 0x3 - PSN. */
+            uint64_t :64, :64; /* Leaf 0x4 - Structured Cache. */
+            uint64_t :64, :64; /* Leaf 0x5 - MONITOR. */
+            uint64_t :64, :64; /* Leaf 0x6 - Therm/Perf. */
+            uint64_t :64, :64; /* Leaf 0x7 - Structured Features. */
+            uint64_t :64, :64; /* Leaf 0x8 - rsvd */
+            uint64_t :64, :64; /* Leaf 0x9 - DCA */
+
+            /* Leaf 0xa - Intel PMU. */
+            uint8_t pmu_version;
         };
     } basic;