x86/hvm: Dispatch cpuid_viridian_leaves() from guest_cpuid()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 Jan 2017 11:59:02 +0000 (11:59 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 Jan 2017 11:59:02 +0000 (11:59 +0000)
... rather than from the legacy path.  Update the API to match guest_cpuid(),
and remove its dependence on current.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpuid.c
xen/arch/x86/hvm/hvm.c
xen/arch/x86/hvm/viridian.c
xen/include/asm-x86/hvm/viridian.h

index fc3c90eba457b15dba8e7ec8e9938f840d9852f8..45522b452d87ddaf9bbbe094432e563904b1f3e2 100644 (file)
@@ -337,6 +337,18 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
 
     *res = EMPTY_LEAF;
 
+    /*
+     * First pass:
+     * - Dispatch the virtualised leaves to their respective handlers.
+     */
+    switch ( leaf )
+    {
+    case 0x40000000 ... 0x400000ff:
+        if ( is_viridian_domain(d) )
+            return cpuid_viridian_leaves(v, leaf, subleaf, res);
+        break;
+    }
+
     /* {hvm,pv}_cpuid() have this expectation. */
     ASSERT(v == current);
 
index 9f74334f55cdde04f3c2ea51a84a6bb5df802505..2230db9a5dadc9f734ba4dd27021bd13f823d524 100644 (file)
@@ -3353,9 +3353,6 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
     if ( !edx )
         edx = &dummy;
 
-    if ( cpuid_viridian_leaves(input, eax, ebx, ecx, edx) )
-        return;
-
     if ( cpuid_hypervisor_leaves(input, count, eax, ebx, ecx, edx) )
         return;
 
index f6abdd28073cd751e2d35306ba4c47900288394b..37c8f68d9508125f0f19871c9081cafe5e0eb3f2 100644 (file)
 #define CPUID6A_MSR_BITMAPS     (1 << 1)
 #define CPUID6A_NESTED_PAGING   (1 << 3)
 
-int cpuid_viridian_leaves(unsigned int leaf, unsigned int *eax,
-                          unsigned int *ebx, unsigned int *ecx,
-                          unsigned int *edx)
+void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
+                           uint32_t subleaf, struct cpuid_leaf *res)
 {
-    struct domain *d = current->domain;
+    const struct domain *d = v->domain;
 
-    if ( !is_viridian_domain(d) )
-        return 0;
+    ASSERT(is_viridian_domain(d));
+    ASSERT(leaf >= 0x40000000 && leaf < 0x40000100);
 
     leaf -= 0x40000000;
-    if ( leaf > 6 )
-        return 0;
 
-    *eax = *ebx = *ecx = *edx = 0;
     switch ( leaf )
     {
     case 0:
-        *eax = 0x40000006; /* Maximum leaf */
-        *ebx = 0x7263694d; /* Magic numbers  */
-        *ecx = 0x666F736F;
-        *edx = 0x76482074;
+        res->a = 0x40000006; /* Maximum leaf */
+        res->b = 0x7263694d; /* Magic numbers  */
+        res->c = 0x666F736F;
+        res->d = 0x76482074;
         break;
+
     case 1:
-        *eax = 0x31237648; /* Version number */
+        res->a = 0x31237648; /* Version number */
         break;
+
     case 2:
         /* Hypervisor information, but only if the guest has set its
            own version number. */
         if ( d->arch.hvm_domain.viridian.guest_os_id.raw == 0 )
             break;
-        *eax = 1; /* Build number */
-        *ebx = (xen_major_version() << 16) | xen_minor_version();
-        *ecx = 0; /* SP */
-        *edx = 0; /* Service branch and number */
+        res->a = 1; /* Build number */
+        res->b = (xen_major_version() << 16) | xen_minor_version();
+        res->c = 0; /* SP */
+        res->d = 0; /* Service branch and number */
         break;
+
     case 3:
         /* Which hypervisor MSRs are available to the guest */
-        *eax = (CPUID3A_MSR_APIC_ACCESS |
-                CPUID3A_MSR_HYPERCALL   |
-                CPUID3A_MSR_VP_INDEX);
+        res->a = (CPUID3A_MSR_APIC_ACCESS |
+                  CPUID3A_MSR_HYPERCALL   |
+                  CPUID3A_MSR_VP_INDEX);
         if ( !(viridian_feature_mask(d) & HVMPV_no_freq) )
-            *eax |= CPUID3A_MSR_FREQ;
+            res->a |= CPUID3A_MSR_FREQ;
         if ( viridian_feature_mask(d) & HVMPV_time_ref_count )
-            *eax |= CPUID3A_MSR_TIME_REF_COUNT;
+            res->a |= CPUID3A_MSR_TIME_REF_COUNT;
         if ( viridian_feature_mask(d) & HVMPV_reference_tsc )
-            *eax |= CPUID3A_MSR_REFERENCE_TSC;
+            res->a |= CPUID3A_MSR_REFERENCE_TSC;
         break;
+
     case 4:
         /* Recommended hypercall usage. */
         if ( (d->arch.hvm_domain.viridian.guest_os_id.raw == 0) ||
              (d->arch.hvm_domain.viridian.guest_os_id.fields.os < 4) )
             break;
-        *eax = CPUID4A_RELAX_TIMER_INT;
+        res->a = CPUID4A_RELAX_TIMER_INT;
         if ( viridian_feature_mask(d) & HVMPV_hcall_remote_tlb_flush )
-            *eax |= CPUID4A_HCALL_REMOTE_TLB_FLUSH;
+            res->a |= CPUID4A_HCALL_REMOTE_TLB_FLUSH;
         if ( !cpu_has_vmx_apic_reg_virt )
-            *eax |= CPUID4A_MSR_BASED_APIC;
-        *ebx = 2047; /* long spin count */
+            res->a |= CPUID4A_MSR_BASED_APIC;
+        res->b = 2047; /* long spin count */
         break;
+
     case 6:
         /* Detected and in use hardware features. */
         if ( cpu_has_vmx_virtualize_apic_accesses )
-            *eax |= CPUID6A_APIC_OVERLAY;
+            res->a |= CPUID6A_APIC_OVERLAY;
         if ( cpu_has_vmx_msr_bitmap || (read_efer() & EFER_SVME) )
-            *eax |= CPUID6A_MSR_BITMAPS;
+            res->a |= CPUID6A_MSR_BITMAPS;
         if ( hap_enabled(d) )
-            *eax |= CPUID6A_NESTED_PAGING;
+            res->a |= CPUID6A_NESTED_PAGING;
         break;
     }
-
-    return 1;
 }
 
 static void dump_guest_os_id(const struct domain *d)
index bdbccd5376bebd08d7f9c6a133255fa1dac2f683..8c45d0f8eeed41af82406dfd6e505c539e72479c 100644 (file)
@@ -97,13 +97,8 @@ struct viridian_domain
     union viridian_reference_tsc reference_tsc;
 };
 
-int
-cpuid_viridian_leaves(
-    unsigned int leaf,
-    unsigned int *eax,
-    unsigned int *ebx,
-    unsigned int *ecx,
-    unsigned int *edx);
+void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
+                           uint32_t subleaf, struct cpuid_leaf *res);
 
 int
 wrmsr_viridian_regs(