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

[Xen-changelog] [xen master] x86/cpuid: Store the toolstacks choice of hypervisor max leaf



commit 9db5d75c91dba258a6e834b730d6e13263dcc271
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Jan 4 12:20:51 2017 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Jan 13 13:16:57 2017 +0000

    x86/cpuid: Store the toolstacks choice of hypervisor max leaf
    
    This removes all dependencies on the legacy cpuids[] array from
    cpuid_hypervisor_leaves().  Swap a BUG() to an ASSERT_UNREACHABLE(), because
    in the unlikely case that we hit it, returning all zeros to the guest is 
fine.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/domctl.c       |  8 ++++++++
 xen/arch/x86/traps.c        | 19 +++++--------------
 xen/include/asm-x86/cpuid.h |  3 +++
 3 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c
index a5a56ee..038521a 100644
--- a/xen/arch/x86/domctl.c
+++ b/xen/arch/x86/domctl.c
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;
+
     case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1:
         p->extd.raw[ctl->input[0] - 0x80000000] = leaf;
         break;
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index 7bb42ac..4f29c3a 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -906,26 +906,17 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, 
uint32_t leaf,
                              uint32_t subleaf, struct cpuid_leaf *res)
 {
     const struct domain *d = v->domain;
+    const struct cpuid_policy *p = d->arch.cpuid;
     uint32_t base = is_viridian_domain(d) ? 0x40000100 : 0x40000000;
     uint32_t idx  = leaf - base;
-    uint32_t limit, dummy;
+    unsigned int limit = is_viridian_domain(d) ? p->hv2_limit : p->hv_limit;
 
-    if ( idx > XEN_CPUID_MAX_NUM_LEAVES )
-        return; /* Avoid unnecessary pass through domain_cpuid() */
-
-    domain_cpuid(d, base, 0, &limit, &dummy, &dummy, &dummy);
     if ( limit == 0 )
         /* Default number of leaves */
         limit = XEN_CPUID_MAX_NUM_LEAVES;
     else
-    {
-        /* User-specified number of leaves */
-        limit &= 0xff;
-        if ( limit < 2 )
-            limit = 2;
-        else if ( limit > XEN_CPUID_MAX_NUM_LEAVES )
-            limit = XEN_CPUID_MAX_NUM_LEAVES;
-    }
+        /* Clamp toolstack value between 2 and MAX_NUM_LEAVES. */
+        limit = min(max(limit, 2u), XEN_CPUID_MAX_NUM_LEAVES + 0u);
 
     if ( idx > limit )
         return;
@@ -1015,7 +1006,7 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, 
uint32_t leaf,
         break;
 
     default:
-        BUG();
+        ASSERT_UNREACHABLE();
     }
 }
 
diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h
index 5b1448a..38e3975 100644
--- a/xen/include/asm-x86/cpuid.h
+++ b/xen/include/asm-x86/cpuid.h
@@ -200,6 +200,9 @@ struct cpuid_policy
 #undef __DECL_BITFIELD
 #undef _DECL_BITFIELD
 #undef DECL_BITFIELD
+
+    /* Toolstack selected Hypervisor max_leaf (if non-zero). */
+    uint8_t hv_limit, hv2_limit;
 };
 
 /* Fill in a featureset bitmap from a CPUID policy. */
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.