From patchwork Mon Jan 9 11:03:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9504355 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 049B560710 for ; Mon, 9 Jan 2017 11:18:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 132552848D for ; Mon, 9 Jan 2017 11:18:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 023D828493; Mon, 9 Jan 2017 11:18:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 337BC2848B for ; Mon, 9 Jan 2017 11:18:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQXwH-0003iQ-JT; Mon, 09 Jan 2017 11:16:33 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cQXwF-0003gj-Qx for xen-devel@lists.xen.org; Mon, 09 Jan 2017 11:16:31 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id A3/C9-14551-F0173785; Mon, 09 Jan 2017 11:16:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrohUpevsDj CYP4rbYslHxezODB6HN39mymAMYo1My8pvyKBNWPZyxa2gjVSFZenPGVsYJwk2sXIwSEh4C8x 565eFyMnB5uAvsTuF5+YQGwRAXWJ0x0XWUFKmAV0JVb91AAJCwskSdye9IsFxGYRUJF407KKF cTmFfCS2H78L1irhICcxPnjP5lBbE6g+LQ/JxhBbCEBT4mFD18wQ9hqEtf6L7FD9ApKnJz5BG wms4CExMEXL5gnMPLOQpKahSS1gJFpFaNGcWpRWWqRrpGBXlJRZnpGSW5iZo6uoYGxXm5qcXF iempOYlKxXnJ+7iZGYODUMzAw7mBsPuF3iFGSg0lJlNcxqiBCiC8pP6UyI7E4I76oNCe1+BCj DAeHkgTvq/ziCCHBotT01Iq0zBxgCMOkJTh4lER4Z4OkeYsLEnOLM9MhUqcYFaXEeW+AJARAE hmleXBtsLi5xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUUmYdxHIFJ7MvBK46a+AFjMBLY60A1 tckoiQkmpgnJ/GEPX1NIvAYluTqV0ndq97+/56V3FCNLepJWtjpdJs2VNRa8JzVdS36X9USFz Nfm7KORsRV71uDgulUpYvO1j6PuwJf6Yx188wdoXRk+gNC+TuLLv4ZVrCm5fbl+lOWnl57t/1 P9fP+J6ezpO6xd7pDsfsi7M1vrgc73+R/yaW5fO0P3VGXkosxRmJhlrMRcWJAG9mQOaWAgAA X-Env-Sender: prvs=175ce6123=Andrew.Cooper3@citrix.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1483960586!62824564!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59725 invoked from network); 9 Jan 2017 11:16:30 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 9 Jan 2017 11:16:30 -0000 X-IronPort-AV: E=Sophos;i="5.33,339,1477958400"; d="scan'208";a="398663318" From: Andrew Cooper To: Xen-devel Date: Mon, 9 Jan 2017 11:03:36 +0000 Message-ID: <1483959822-30484-20-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483959822-30484-1-git-send-email-andrew.cooper3@citrix.com> References: <1483959822-30484-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v2 19/25] x86/cpuid: Calculate appropriate max_leaf values for the global policies X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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: