From patchwork Wed Feb 26 20:22:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11407175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 813AC1395 for ; Wed, 26 Feb 2020 20:23:49 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D1A82072D for ; Wed, 26 Feb 2020 20:23:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="BkkWXvQ4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D1A82072D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j73Co-0003vO-Ah; Wed, 26 Feb 2020 20:22:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j73Cn-0003uh-0T for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 20:22:53 +0000 X-Inumbo-ID: b595a90b-58d5-11ea-94dc-12813bfff9fa Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b595a90b-58d5-11ea-94dc-12813bfff9fa; Wed, 26 Feb 2020 20:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1582748549; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R21aiCvpBVK8pX/VEYsT9FBNc3fKBXVbw2HxNXegm9s=; b=BkkWXvQ4lBYMX2LFu1t4yxtDBy16z9rtJOPU01plyDqcTkGV7Dnxf9dE 9tJzP8fURf7yqSAqwx2btg16GSgHOoUcqHPZ1C8WM3gzXBlUhLibEomTm SDuWYoIc6z5NUCZew5uczjvQGP6iw6NmL3oz55JeUcnaGRlp7+cvSseRW c=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: gpR4kjurA5/tCzcdJ25V1t4YJUtWNdApY3/+bNFx4N1VayTDkMm439E3667pVIj9L9eJiTj64o xuHahg3BA7lFa9s5c7+HQdUG09yOh6KX7XzO0DgqEErJ46eq6kDlk9Asas6QMtlQgiZ3HG6tog kF9lR5rWTWvkl74bGk3PpRFDINLvmxmup9Yi5/cYAKKElbwT/wjQb+MWr9P0avGVWDU3R/GEto MYmNjFp44hxMYYZ6YVyUvzm2y11F4lBuYMtVwKIMiCLe5ILxZXSXoLP5S3DjxiZqovJjrSHJyi zPo= X-SBRS: 2.7 X-MesageID: 13496576 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.70,489,1574139600"; d="scan'208";a="13496576" From: Andrew Cooper To: Xen-devel Date: Wed, 26 Feb 2020 20:22:19 +0000 Message-ID: <20200226202221.6555-9-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200226202221.6555-1-andrew.cooper3@citrix.com> References: <20200226202221.6555-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 08/10] x86/cpuid: Introduce and use default CPUID policies X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" For now, the default and max policies remain identical, but this will change in the future. Write calculate_{pv,hvm}_def_policy() in a way which will cope with simple feature differences for now. Update XEN_SYSCTL_get_cpu_policy and init_domain_cpuid_policy() to use the default policies. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/cpuid.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- xen/arch/x86/sysctl.c | 4 ++-- xen/include/asm-x86/cpuid.h | 3 ++- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index cd9a02143c..6e01394fd2 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -18,6 +18,9 @@ const uint32_t special_features[] = INIT_SPECIAL_FEATURES; static const uint32_t pv_max_featuremask[] = INIT_PV_MAX_FEATURES; static const uint32_t hvm_shadow_max_featuremask[] = INIT_HVM_SHADOW_MAX_FEATURES; static const uint32_t hvm_hap_max_featuremask[] = INIT_HVM_HAP_MAX_FEATURES; +static const uint32_t pv_def_featuremask[] = INIT_PV_DEF_FEATURES; +static const uint32_t hvm_shadow_def_featuremask[] = INIT_HVM_SHADOW_DEF_FEATURES; +static const uint32_t hvm_hap_def_featuremask[] = INIT_HVM_HAP_DEF_FEATURES; static const uint32_t deep_features[] = INIT_DEEP_FEATURES; static int __init parse_xen_cpuid(const char *s) @@ -99,9 +102,11 @@ struct cpuid_policy __read_mostly raw_cpuid_policy, __read_mostly host_cpuid_policy; #ifdef CONFIG_PV struct cpuid_policy __read_mostly pv_max_cpuid_policy; +struct cpuid_policy __read_mostly pv_def_cpuid_policy; #endif #ifdef CONFIG_HVM struct cpuid_policy __read_mostly hvm_max_cpuid_policy; +struct cpuid_policy __read_mostly hvm_def_cpuid_policy; #endif static void sanitise_featureset(uint32_t *fs) @@ -381,6 +386,23 @@ static void __init calculate_pv_max_policy(void) p->extd.raw[0xa] = EMPTY_LEAF; /* No SVM for PV guests. */ } +static void __init calculate_pv_def_policy(void) +{ + struct cpuid_policy *p = &pv_def_cpuid_policy; + uint32_t pv_featureset[FSCAPINTS]; + unsigned int i; + + *p = pv_max_cpuid_policy; + cpuid_policy_to_featureset(p, pv_featureset); + + for ( i = 0; i < ARRAY_SIZE(pv_featureset); ++i ) + pv_featureset[i] &= pv_def_featuremask[i]; + + sanitise_featureset(pv_featureset); + cpuid_featureset_to_policy(pv_featureset, p); + recalculate_xstate(p); +} + static void __init calculate_hvm_max_policy(void) { struct cpuid_policy *p = &hvm_max_cpuid_policy; @@ -440,16 +462,45 @@ static void __init calculate_hvm_max_policy(void) recalculate_xstate(p); } +static void __init calculate_hvm_def_policy(void) +{ + struct cpuid_policy *p = &hvm_def_cpuid_policy; + uint32_t hvm_featureset[FSCAPINTS]; + unsigned int i; + const uint32_t *hvm_featuremask; + + *p = hvm_max_cpuid_policy; + cpuid_policy_to_featureset(p, hvm_featureset); + + hvm_featuremask = hvm_hap_supported() ? + hvm_hap_def_featuremask : hvm_shadow_def_featuremask; + + for ( i = 0; i < ARRAY_SIZE(hvm_featureset); ++i ) + hvm_featureset[i] &= hvm_featuremask[i]; + + guest_common_feature_adjustments(hvm_featureset); + + sanitise_featureset(hvm_featureset); + cpuid_featureset_to_policy(hvm_featureset, p); + recalculate_xstate(p); +} + void __init init_guest_cpuid(void) { calculate_raw_policy(); calculate_host_policy(); if ( IS_ENABLED(CONFIG_PV) ) + { calculate_pv_max_policy(); + calculate_pv_def_policy(); + } if ( hvm_enabled ) + { calculate_hvm_max_policy(); + calculate_hvm_def_policy(); + } } bool recheck_cpu_features(unsigned int cpu) @@ -625,8 +676,8 @@ void recalculate_cpuid_policy(struct domain *d) int init_domain_cpuid_policy(struct domain *d) { struct cpuid_policy *p = is_pv_domain(d) - ? (IS_ENABLED(CONFIG_PV) ? &pv_max_cpuid_policy : NULL) - : (IS_ENABLED(CONFIG_HVM) ? &hvm_max_cpuid_policy : NULL); + ? (IS_ENABLED(CONFIG_PV) ? &pv_def_cpuid_policy : NULL) + : (IS_ENABLED(CONFIG_HVM) ? &hvm_def_cpuid_policy : NULL); if ( !p ) { diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index cad7534373..b7948f2663 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -48,7 +48,7 @@ const struct cpu_policy system_policies[6] = { &pv_max_msr_policy, }, [ XEN_SYSCTL_cpu_policy_pv_default ] = { - &pv_max_cpuid_policy, + &pv_def_cpuid_policy, &pv_def_msr_policy, }, #endif @@ -58,7 +58,7 @@ const struct cpu_policy system_policies[6] = { &hvm_max_msr_policy, }, [ XEN_SYSCTL_cpu_policy_hvm_default ] = { - &hvm_max_cpuid_policy, + &hvm_def_cpuid_policy, &hvm_def_msr_policy, }, #endif diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h index 1b00e832d6..7baf6c9628 100644 --- a/xen/include/asm-x86/cpuid.h +++ b/xen/include/asm-x86/cpuid.h @@ -49,7 +49,8 @@ DECLARE_PER_CPU(struct cpuidmasks, cpuidmasks); extern struct cpuidmasks cpuidmask_defaults; extern struct cpuid_policy raw_cpuid_policy, host_cpuid_policy, - pv_max_cpuid_policy, hvm_max_cpuid_policy; + pv_max_cpuid_policy, pv_def_cpuid_policy, + hvm_max_cpuid_policy, hvm_def_cpuid_policy; extern const struct cpu_policy system_policies[];