From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 6/6] x86/cpuid: Only recalculate the shared feature bits once
Date: Wed, 18 Jan 2017 19:40:58 +0000 [thread overview]
Message-ID: <1484768458-13117-7-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1484768458-13117-1-git-send-email-andrew.cooper3@citrix.com>
With accurate vendor information available, the shared bits can be sorted out
during recalculation, rather than at query time in the legacy cpuid path.
This means that:
* Duplication can be dropped from the automatically generated cpuid data.
* The toolstack need not worry about setting them appropriately.
* They can be dropped from the system maximum featuresets.
While editing gen-cpuid.py, reflow some comments which exceeded the expected
line length.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
---
tools/libxc/xc_cpuid_x86.c | 19 -------------------
xen/arch/x86/cpuid.c | 25 +++++--------------------
xen/tools/gen-cpuid.py | 29 ++++++++++-------------------
3 files changed, 15 insertions(+), 58 deletions(-)
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index 96d6025..918590f 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -41,7 +41,6 @@ enum {
#define DEF_MAX_BASE 0x0000000du
#define DEF_MAX_INTELEXT 0x80000008u
#define DEF_MAX_AMDEXT 0x8000001cu
-#define COMMON_1D CPUID_COMMON_1D_FEATURES
int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps)
{
@@ -712,24 +711,6 @@ static void sanitise_featureset(struct cpuid_domain_info *info)
disabled_features[i] &= ~dfs[i];
}
}
-
- switch ( info->vendor )
- {
- case VENDOR_INTEL:
- /* Intel clears the common bits in e1d. */
- info->featureset[featureword_of(X86_FEATURE_SYSCALL)] &= ~COMMON_1D;
- break;
-
- case VENDOR_AMD:
- /* AMD duplicates the common bits between 1d and e1d. */
- info->featureset[featureword_of(X86_FEATURE_SYSCALL)] =
- ((info->featureset[featureword_of(X86_FEATURE_FPU)] & COMMON_1D) |
- (info->featureset[featureword_of(X86_FEATURE_SYSCALL)] & ~COMMON_1D));
- break;
-
- default:
- break;
- }
}
int xc_cpuid_apply_policy(xc_interface *xch, domid_t domid,
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 7926d0b..a27a8d6 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -67,18 +67,6 @@ static void sanitise_featureset(uint32_t *fs)
disabled_features[j] &= ~dfs[j];
}
}
-
- /*
- * Sort out shared bits. We are constructing a featureset which needs to
- * be applicable to a cross-vendor case. Intel strictly clears the common
- * bits in e1d, while AMD strictly duplicates them.
- *
- * We duplicate them here to be compatible with AMD while on Intel, and
- * rely on logic closer to the guest to make the featureset stricter if
- * emulating Intel.
- */
- fs[FEATURESET_e1d] = ((fs[FEATURESET_1d] & CPUID_COMMON_1D_FEATURES) |
- (fs[FEATURESET_e1d] & ~CPUID_COMMON_1D_FEATURES));
}
static void recalculate_xstate(struct cpuid_policy *p)
@@ -165,6 +153,8 @@ static void recalculate_xstate(struct cpuid_policy *p)
static void recalculate_common(struct cpuid_policy *p)
{
+ p->extd.e1d &= ~CPUID_COMMON_1D_FEATURES;
+
switch ( p->x86_vendor )
{
case X86_VENDOR_INTEL:
@@ -177,6 +167,8 @@ static void recalculate_common(struct cpuid_policy *p)
p->extd.vendor_ebx = p->basic.vendor_ebx;
p->extd.vendor_ecx = p->basic.vendor_ecx;
p->extd.vendor_edx = p->basic.vendor_edx;
+
+ p->extd.e1d |= p->basic._1d & CPUID_COMMON_1D_FEATURES;
break;
}
}
@@ -665,10 +657,6 @@ static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
res->c = p->extd.e1c;
res->d = p->extd.e1d;
- /* If not emulating AMD, clear the duplicated features in e1d. */
- if ( p->x86_vendor != X86_VENDOR_AMD )
- res->d &= ~CPUID_COMMON_1D_FEATURES;
-
/*
* MTRR used to unconditionally leak into PV guests. They cannot MTRR
* infrastructure at all, and shouldn't be able to see the feature.
@@ -790,11 +778,8 @@ static void hvm_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
res->c = p->extd.e1c;
res->d = p->extd.e1d;
- /* If not emulating AMD, clear the duplicated features in e1d. */
- if ( p->x86_vendor != X86_VENDOR_AMD )
- res->d &= ~CPUID_COMMON_1D_FEATURES;
/* fast-forward MSR_APIC_BASE.EN if it hasn't already been clobbered. */
- else if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
+ if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
res->d &= ~cpufeat_bit(X86_FEATURE_APIC);
/*
diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py
index 6212e4f..5cab6db 100755
--- a/xen/tools/gen-cpuid.py
+++ b/xen/tools/gen-cpuid.py
@@ -129,16 +129,7 @@ def crunch_numbers(state):
common_1d = (FPU, VME, DE, PSE, TSC, MSR, PAE, MCE, CX8, APIC,
MTRR, PGE, MCA, CMOV, PAT, PSE36, MMX, FXSR)
- # All known features. Duplicate the common features in e1d
- e1d_base = SYSCALL & ~31
- state.known = featureset_to_uint32s(
- state.names.keys() + [ e1d_base + (x % 32) for x in common_1d ],
- nr_entries)
-
- # Fold common back into names
- for f in common_1d:
- state.names[e1d_base + (f % 32)] = "E1D_" + state.names[f]
-
+ state.known = featureset_to_uint32s(state.names.keys(), nr_entries)
state.common_1d = featureset_to_uint32s(common_1d, 1)[0]
state.special = featureset_to_uint32s(state.raw_special, nr_entries)
state.pv = featureset_to_uint32s(state.raw_pv, nr_entries)
@@ -248,13 +239,14 @@ def crunch_numbers(state):
# standard 3DNow in the earlier K6 processors.
_3DNOW: [_3DNOWEXT],
- # This is just the dependency between AVX512 and AVX2 of XSTATE feature flags.
- # If want to use AVX512, AVX2 must be supported and enabled.
+ # This is just the dependency between AVX512 and AVX2 of XSTATE
+ # feature flags. If want to use AVX512, AVX2 must be supported and
+ # enabled.
AVX2: [AVX512F],
- # AVX512F is taken to mean hardware support for EVEX encoded instructions,
- # 512bit registers, and the instructions themselves. All further AVX512 features
- # are built on top of AVX512F
+ # AVX512F is taken to mean hardware support for EVEX encoded
+ # instructions, 512bit registers, and the instructions themselves. All
+ # further AVX512 features are built on top of AVX512F
AVX512F: [AVX512DQ, AVX512IFMA, AVX512PF, AVX512ER, AVX512CD,
AVX512BW, AVX512VL, AVX512VBMI, AVX512_4VNNIW,
AVX512_4FMAPS, AVX512_VPOPCNTDQ],
@@ -305,10 +297,9 @@ def crunch_numbers(state):
if name and name[0] in "0123456789":
name = "_" + name
- # Don't generate names for the duplicate features, or ones
- # fast-forwarded from other state
- if (name.startswith("E1D_") or
- name in ("APIC", "OSXSAVE", "OSPKE")):
+ # Don't generate names for features fast-forwarded from other
+ # state
+ if name in ("APIC", "OSXSAVE", "OSPKE"):
name = ""
names.append(name.lower())
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-01-18 19:40 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-18 19:40 [PATCH 0/6] x86/cpuid: Handling of simple leaves in guest_cpuid() Andrew Cooper
2017-01-18 19:40 ` [PATCH 1/6] x86/cpuid: Hide VT-x/SVM from HVM-based control domains Andrew Cooper
2017-01-19 3:56 ` Doug Goldstein
2017-01-19 14:13 ` Andrew Cooper
2017-01-20 15:44 ` Jan Beulich
2017-01-24 14:38 ` Roger Pau Monné
2017-01-24 15:10 ` Jan Beulich
2017-01-24 15:41 ` Roger Pau Monné
2017-01-24 16:17 ` Andrew Cooper
2017-01-18 19:40 ` [PATCH 2/6] x86/cpuid: Remove BUG_ON() condition from guest_cpuid() Andrew Cooper
2017-01-19 3:57 ` Doug Goldstein
2017-01-20 15:45 ` Jan Beulich
2017-01-18 19:40 ` [PATCH 3/6] x86/cpuid: Handle leaf 0 in guest_cpuid() Andrew Cooper
2017-01-19 4:02 ` Doug Goldstein
2017-01-20 15:48 ` Jan Beulich
2017-01-18 19:40 ` [PATCH 4/6] x86/cpuid: Handle leaf 0x80000000 " Andrew Cooper
2017-01-19 4:03 ` Doug Goldstein
2017-01-20 15:58 ` Jan Beulich
2017-01-20 16:02 ` Andrew Cooper
2017-01-18 19:40 ` [PATCH 5/6] x86/cpuid: Handle the long vendor string " Andrew Cooper
2017-01-19 4:03 ` Doug Goldstein
2017-01-20 16:00 ` Jan Beulich
2017-01-20 16:03 ` Andrew Cooper
2017-01-18 19:40 ` Andrew Cooper [this message]
2017-01-19 4:03 ` [PATCH 6/6] x86/cpuid: Only recalculate the shared feature bits once Doug Goldstein
2017-01-19 11:01 ` Wei Liu
2017-01-20 16:06 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1484768458-13117-7-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).