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

[Xen-devel] [PATCH v2 19/25] x86/cpuid: Calculate appropriate max_leaf values for the global policies



Derive host_policy from raw_policy, and {pv,hvm}_max_policy from host_policy.
Clamp the raw values to the maximum we will offer to guests.

This simplifies the PV and HVM policy calculations, removing the need for an
intermediate linear host_featureset bitmap.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/cpuid.c        | 28 ++++++++++++++++++++--------
 xen/include/asm-x86/cpuid.h |  2 +-
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 677688d..c9f882b 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -135,19 +135,30 @@ static void __init calculate_host_policy(void)
 {
     struct cpuid_policy *p = &host_policy;
 
+    *p = raw_policy;
+
+    p->basic.max_leaf =
+        min_t(uint32_t, p->basic.max_leaf,   ARRAY_SIZE(p->basic.raw) - 1);
+    p->feat.max_subleaf =
+        min_t(uint32_t, p->feat.max_subleaf, ARRAY_SIZE(p->feat.raw) - 1);
+    p->extd.max_leaf =
+        min_t(uint32_t, p->extd.max_leaf,
+              0x80000000u + ARRAY_SIZE(p->extd.raw) - 1);
+
     cpuid_featureset_to_policy(boot_cpu_data.x86_capability, p);
 }
 
 static void __init calculate_pv_max_policy(void)
 {
     struct cpuid_policy *p = &pv_max_policy;
-    uint32_t pv_featureset[FSCAPINTS], host_featureset[FSCAPINTS];
+    uint32_t pv_featureset[FSCAPINTS];
     unsigned int i;
 
-    cpuid_policy_to_featureset(&host_policy, host_featureset);
+    *p = host_policy;
+    cpuid_policy_to_featureset(p, pv_featureset);
 
-    for ( i = 0; i < FSCAPINTS; ++i )
-        pv_featureset[i] = host_featureset[i] & pv_featuremask[i];
+    for ( i = 0; i < ARRAY_SIZE(pv_featureset); ++i )
+        pv_featureset[i] &= pv_featuremask[i];
 
     /* Unconditionally claim to be able to set the hypervisor bit. */
     __set_bit(X86_FEATURE_HYPERVISOR, pv_featureset);
@@ -167,20 +178,21 @@ static void __init calculate_pv_max_policy(void)
 static void __init calculate_hvm_max_policy(void)
 {
     struct cpuid_policy *p = &hvm_max_policy;
-    uint32_t hvm_featureset[FSCAPINTS], host_featureset[FSCAPINTS];
+    uint32_t hvm_featureset[FSCAPINTS];
     unsigned int i;
     const uint32_t *hvm_featuremask;
 
     if ( !hvm_enabled )
         return;
 
-    cpuid_policy_to_featureset(&host_policy, host_featureset);
+    *p = host_policy;
+    cpuid_policy_to_featureset(p, hvm_featureset);
 
     hvm_featuremask = hvm_funcs.hap_supported ?
         hvm_hap_featuremask : hvm_shadow_featuremask;
 
-    for ( i = 0; i < FSCAPINTS; ++i )
-        hvm_featureset[i] = host_featureset[i] & hvm_featuremask[i];
+    for ( i = 0; i < ARRAY_SIZE(hvm_featureset); ++i )
+        hvm_featureset[i] &= hvm_featuremask[i];
 
     /* Unconditionally claim to be able to set the hypervisor bit. */
     __set_bit(X86_FEATURE_HYPERVISOR, hvm_featureset);
diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h
index 4cb54f2..d7cf2e6 100644
--- a/xen/include/asm-x86/cpuid.h
+++ b/xen/include/asm-x86/cpuid.h
@@ -78,10 +78,10 @@ struct cpuid_policy
      * Global *_policy objects:
      *
      * - Host accurate:
-     *   - max_{,sub}leaf
      *   - {xcr0,xss}_{high,low}
      *
      * - Guest accurate:
+     *   - max_{,sub}leaf
      *   - All FEATURESET_* words
      *
      * Per-domain objects:
-- 
2.1.4


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

 


Rackspace

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