From: Andrew Cooper Date: Wed, 11 Jan 2017 11:59:02 +0000 (+0000) Subject: x86/cpuid: Calculate appropriate max_leaf values for the global policies X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~3005 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9e9e2101cfea47b0392e2034038cbd2284528ab4;p=xen.git 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 Reviewed-by: Jan Beulich --- diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index fec00f9d65..c238776c63 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -136,19 +136,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); @@ -168,20 +179,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 fa711f0a0a..0f12c0c058 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: