From patchwork Wed Jan 4 12:39:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9496651 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 10BB8606B5 for ; Wed, 4 Jan 2017 12:47:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 023D827BE5 for ; Wed, 4 Jan 2017 12:47:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB25227F88; Wed, 4 Jan 2017 12:47:54 +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 6D60D27BE5 for ; Wed, 4 Jan 2017 12:47:54 +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 1cOkxd-0005jy-FR; Wed, 04 Jan 2017 12:46:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOkxc-0005ff-1m for xen-devel@lists.xen.org; Wed, 04 Jan 2017 12:46:32 +0000 Received: from [85.158.139.211] by server-6.bemta-5.messagelabs.com id 3F/07-15802-7AEEC685; Wed, 04 Jan 2017 12:46:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphkeJIrShJLcpLzFFi42JxWrrBXnfZu5w IgzdvNS2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oz5j7ewF9w1qGjv/snYwLhfrYuRk0NCwF9i yputrCA2m4C+xO4Xn5hAbBEBdYnTHReB4hwczAJ+Eoce+IKEhQWSJc7v+wZWwiKgIrH28BxmE JtXwFPi4oXH7BAj5STOH/8JFucEij/buI4RxBYS8JCYcnEZO4StJnGt/xI7RK+gxMmZT1hAbG YBCYmDL14wT2DknYUkNQtJagEj0ypGjeLUorLUIl0jM72kosz0jJLcxMwcXUMDU73c1OLixPT UnMSkYr3k/NxNjMDQqWdgYNzBeHuy3yFGSQ4mJVHevvacCCG+pPyUyozE4oz4otKc1OJDjDIc HEoSvDPeAuUEi1LTUyvSMnOAQQyTluDgURLhTQdJ8xYXJOYWZ6ZDpE4xKkqJ8y4BSQiAJDJK8 +DaYJFziVFWSpiXkYGBQYinILUoN7MEVf4VozgHo5IwbxXIFJ7MvBK46a+AFjMBLd4ekA2yuC QRISXVwNh2VYJdeZbNrVMt0r9q9u/5ata7bK7khusXJnDevsx38PHEKbZWUk6771XNe9F7pqm mymlirUej6lueuYxM5/kqUpRrlBYVx2xxf6S1/pHYgTNdgjuv1oaUaay/NStY8mTz6o7NsXPv XeTivicStvHZ1NpHInGCLdzh+nfXtx3YWud35eLUJUlKLMUZiYZazEXFiQBYSdnHlwIAAA== X-Env-Sender: prvs=1701003ad=Andrew.Cooper3@citrix.com X-Msg-Ref: server-10.tower-206.messagelabs.com!1483533988!61174735!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20839 invoked from network); 4 Jan 2017 12:46:30 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-10.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 4 Jan 2017 12:46:30 -0000 X-IronPort-AV: E=Sophos;i="5.33,459,1477958400"; d="scan'208";a="406724763" From: Andrew Cooper To: Xen-devel Date: Wed, 4 Jan 2017 12:39:37 +0000 Message-ID: <1483533584-8015-21-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483533584-8015-1-git-send-email-andrew.cooper3@citrix.com> References: <1483533584-8015-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 20/27] x86/cpuid: Drop the temporary linear feature bitmap from struct cpuid_policy 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 With most uses of the *_featureset API removed, the remaining uses are only during XEN_SYSCTL_get_cpu_featureset, init_guest_cpuid(), and recalculate_cpuid_policy(), none of which are hot paths. Drop the temporary infrastructure, and have the current users recreate the linear bitmap using cpuid_policy_to_featureset(). This avoids storing duplicated information in struct cpuid_policy. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich --- xen/arch/x86/cpuid.c | 19 ++++++++++--------- xen/arch/x86/sysctl.c | 21 ++++++++++++--------- xen/include/asm-x86/cpuid.h | 9 --------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 86f598f..a261843 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -126,24 +126,23 @@ static void __init calculate_raw_policy(void) for ( i = 1; i < min(ARRAY_SIZE(p->extd.raw), p->extd.max_leaf + 1 - 0x80000000ul); ++i ) cpuid_leaf(0x80000000 + i, &p->extd.raw[i]); - - cpuid_policy_to_featureset(p, p->fs); } static void __init calculate_host_policy(void) { struct cpuid_policy *p = &host_policy; - memcpy(p->fs, boot_cpu_data.x86_capability, sizeof(p->fs)); - - cpuid_featureset_to_policy(host_featureset, p); + 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]; unsigned int i; + cpuid_policy_to_featureset(&host_policy, host_featureset); + for ( i = 0; i < FSCAPINTS; ++i ) pv_featureset[i] = host_featureset[i] & pv_featuremask[i]; @@ -165,12 +164,15 @@ 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]; unsigned int i; const uint32_t *hvm_featuremask; if ( !hvm_enabled ) return; + cpuid_policy_to_featureset(&host_policy, host_featureset); + hvm_featuremask = hvm_funcs.hap_supported ? hvm_hap_featuremask : hvm_shadow_featuremask; @@ -199,8 +201,7 @@ static void __init calculate_hvm_max_policy(void) * long mode (and init_amd() has cleared it out of host capabilities), but * HVM guests are able if running in protected mode. */ - if ( (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && - test_bit(X86_FEATURE_SEP, raw_featureset) ) + if ( (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && raw_policy.basic.sep ) __set_bit(X86_FEATURE_SEP, hvm_featureset); /* @@ -267,7 +268,7 @@ void recalculate_cpuid_policy(struct domain *d) unsigned int i; cpuid_policy_to_featureset(p, fs); - memcpy(max_fs, max->fs, sizeof(max_fs)); + cpuid_policy_to_featureset(max, max_fs); /* Allow a toolstack to possibly select ITSC... */ if ( cpu_has_itsc ) @@ -295,7 +296,7 @@ void recalculate_cpuid_policy(struct domain *d) /* Fold host's FDP_EXCP_ONLY and NO_FPU_SEL into guest's view. */ fs[FEATURESET_7b0] &= ~special_features[FEATURESET_7b0]; - fs[FEATURESET_7b0] |= (host_featureset[FEATURESET_7b0] & + fs[FEATURESET_7b0] |= (host_policy.feat._7b0 & special_features[FEATURESET_7b0]); sanitise_featureset(fs); diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c index 14e7dc7..87da541 100644 --- a/xen/arch/x86/sysctl.c +++ b/xen/arch/x86/sysctl.c @@ -199,13 +199,14 @@ long arch_do_sysctl( case XEN_SYSCTL_get_cpu_featureset: { - static const uint32_t *const featureset_table[] = { - [XEN_SYSCTL_cpu_featureset_raw] = raw_featureset, - [XEN_SYSCTL_cpu_featureset_host] = host_featureset, - [XEN_SYSCTL_cpu_featureset_pv] = pv_featureset, - [XEN_SYSCTL_cpu_featureset_hvm] = hvm_featureset, + static const struct cpuid_policy *const policy_table[] = { + [XEN_SYSCTL_cpu_featureset_raw] = &raw_policy, + [XEN_SYSCTL_cpu_featureset_host] = &host_policy, + [XEN_SYSCTL_cpu_featureset_pv] = &pv_max_policy, + [XEN_SYSCTL_cpu_featureset_hvm] = &hvm_max_policy, }; - const uint32_t *featureset = NULL; + const struct cpuid_policy *p = NULL; + uint32_t featureset[FSCAPINTS]; unsigned int nr; /* Request for maximum number of features? */ @@ -223,13 +224,15 @@ long arch_do_sysctl( FSCAPINTS); /* Look up requested featureset. */ - if ( sysctl->u.cpu_featureset.index < ARRAY_SIZE(featureset_table) ) - featureset = featureset_table[sysctl->u.cpu_featureset.index]; + if ( sysctl->u.cpu_featureset.index < ARRAY_SIZE(policy_table) ) + p = policy_table[sysctl->u.cpu_featureset.index]; /* Bad featureset index? */ - if ( !featureset ) + if ( !p ) ret = -EINVAL; + cpuid_policy_to_featureset(p, featureset); + /* Copy the requested featureset into place. */ if ( !ret && copy_to_guest(sysctl->u.cpu_featureset.features, featureset, nr) ) diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h index 0371e6e..9788cac 100644 --- a/xen/include/asm-x86/cpuid.h +++ b/xen/include/asm-x86/cpuid.h @@ -253,9 +253,6 @@ struct cpuid_policy }; }; } extd; - - /* Temporary featureset bitmap. */ - uint32_t fs[FSCAPINTS]; }; /* Fill in a featureset bitmap from a CPUID policy. */ @@ -293,12 +290,6 @@ static inline void cpuid_featureset_to_policy( extern struct cpuid_policy raw_policy, host_policy, pv_max_policy, hvm_max_policy; -/* Temporary compatibility defines. */ -#define raw_featureset raw_policy.fs -#define host_featureset host_policy.fs -#define pv_featureset pv_max_policy.fs -#define hvm_featureset hvm_max_policy.fs - /* Allocate and initialise a CPUID policy suitable for the domain. */ int init_domain_cpuid_policy(struct domain *d);