x86: Introduce MSR_ARCH_CAPS into featuresets
v2 cover x86: Introduce MSR_ARCH_CAPS into featuresets
Also combined with "x86: Feature check cleanup" for simplicity.
See individual patches for v2 deltas.
Andrew Cooper (10):
x86/boot: Rework dom0 feature configuration x86/boot: Adjust MSR_ARCH_CAPS handling for the Host policy x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS x86/cpu-policy: MSR_ARCH_CAPS feature names x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy x86/boot: Expose MSR_ARCH_CAPS data in guest max policies x86/cpufeature: Rework {boot_,}cpu_has()
x86/vtx: Remove opencoded MSR_ARCH_CAPS check x86/tsx: Remove opencoded MSR_ARCH_CAPS check x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
tools/misc/xen-cpuid.c | 57 +++++++++----- tools/tests/cpu-policy/test-cpu-policy.c | 5 -- xen/arch/x86/cpu-policy.c | 83 ++++++++++----------- xen/arch/x86/cpu/common.c | 5 ++ xen/arch/x86/hvm/vmx/vmx.c | 8 +- xen/arch/x86/include/asm/cpufeature.h | 23 +++++- xen/arch/x86/include/asm/processor.h | 2 +- xen/arch/x86/spec_ctrl.c | 56 +++++++------- xen/arch/x86/tsx.c | 13 ++-- xen/include/public/arch-x86/cpufeatureset.h | 29 ++++++- xen/include/xen/lib/x86/cpu-policy.h | 50 ++++++------- xen/lib/x86/cpuid.c | 11 ++- xen/tools/gen-cpuid.py | 3 + 13 files changed, 208 insertions(+), 137 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/10 x86/boot: Rework dom0 feature configuration
Right now, dom0's feature configuration is split between between the common path and a dom0-specific one. This mostly is by accident, and causes some very subtle bugs.
First, start by clearly defining init_dom0_cpuid_policy() to be the domain that Xen builds automatically. The late hwdom case is still constructed in a mostly normal way, with the control domain having full discretion over the CPU policy.
Identifying this highlights a latent bug - the two halves of the MSR_ARCH_CAPS bodge are asymmetric with respect to the hardware domain. This means that shim, or a control-only dom0 sees the MSR_ARCH_CAPS CPUID bit but none of the MSR content. This in turn declares the hardware to be retpoline-safe by failing to advertise the {R,}RSBA bits appropriately. Restrict this logic to the hardware domain, although the special case will cease to exist shortly.
For the CPUID Faulting adjustment, the comment in ctxt_switch_levelling() isn't actually relevant. Provide a better explanation.
Move the recalculate_cpuid_policy() call outside of the dom0-cpuid= case. This is no change for now, but will become necessary shortly.
Finally, place the second half of the MSR_ARCH_CAPS bodge after the recalculate_cpuid_policy() call. This is necessary to avoid transiently breaking the hardware domain's view while the handling is cleaned up. This special case will cease to exist shortly.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/cpu-policy.c | 57 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-)
xen/arch/x86/cpu-policy.c +31 -26
@@ -687,29 +687,6 @@ int init_domain_cpu_policy(struct domain *d)if ( !p )return -ENOMEM ; -/* See comment in ctxt_switch_levelling() */ -if ( !opt_dom0_cpuid_faulting &&is_control_domain (d) &&is_pv_domain (d) ) - p->platform_info.cpuid_faulting = false; - -/* -* Expose the "hardware speculation behaviour" bits of ARCH_CAPS to dom0, -* so dom0 can turn off workarounds as appropriate. Temporary, until the -* domain policy logic gains a better understanding of MSRs. -*/ -if (is_hardware_domain (d) && cpu_has_arch_caps ) - { -uint64_t val; - -rdmsrl (MSR_ARCH_CAPABILITIES , val); - - p->arch_caps.raw = val & - (ARCH_CAPS_RDCL_NO |ARCH_CAPS_IBRS_ALL |ARCH_CAPS_RSBA | -ARCH_CAPS_SSB_NO |ARCH_CAPS_MDS_NO |ARCH_CAPS_IF_PSCHANGE_MC_NO | -ARCH_CAPS_TAA_NO |ARCH_CAPS_SBDR_SSDP_NO |ARCH_CAPS_FBSDP_NO | -ARCH_CAPS_PSDP_NO |ARCH_CAPS_FB_CLEAR |ARCH_CAPS_RRSBA | -ARCH_CAPS_BHI_NO |ARCH_CAPS_PBRSB_NO ); - } - d->arch.cpu_policy = p;recalculate_cpuid_policy (d);
@@ -845,11 +822,15 @@ void recalculate_cpuid_policy(struct domain *d) p->extd.raw[0x19 ] =EMPTY_LEAF ; } +/* +* Adjust the CPU policy for dom0. Really, this is "the domain Xen builds +* automatically on boot", and might not have the domid 0 (e.g. pvshim). +*/ void __init init_dom0_cpuid_policy (struct domain *d) {struct cpu_policy *p = d->arch.cpuid; -/* dom0 can't migrate. Give it ITSC if available. */ +/* Dom0 doesn't migrate relative to Xen. Give it ITSC if available. */ if ( cpu_has_itsc ) p->extd.itsc = true;
@@ -858,7 +839,7 @@ void __init init_dom0_cpuid_policy(struct domain *d)* so dom0 can turn off workarounds as appropriate. Temporary, until the * domain policy logic gains a better understanding of MSRs. */ -if ( cpu_has_arch_caps ) +if (is_hardware_domain (d) && cpu_has_arch_caps ) p->feat.arch_caps = true;/* Apply dom0-cpuid= command line settings, if provided. */
@@ -876,8 +857,32 @@ void __init init_dom0_cpuid_policy(struct domain *d) }x86_cpu_featureset_to_policy (fs, p); + } + +/* +* PV Control domains used to require unfiltered CPUID. This was fixed in +* Xen 4.13, but there is an cmdline knob to restore the prior behaviour. +* +* If the domain is getting unfiltered CPUID, don't let the guest kernel +* play with CPUID faulting either, as Xen's CPUID path won't cope. +*/ +if ( !opt_dom0_cpuid_faulting &&is_control_domain (d) &&is_pv_domain (d) ) + p->platform_info.cpuid_faulting = false; -recalculate_cpuid_policy (d); +recalculate_cpuid_policy (d); + +if (is_hardware_domain (d) && cpu_has_arch_caps ) + { +uint64_t val; + +rdmsrl (MSR_ARCH_CAPABILITIES , val); + + p->arch_caps.raw = val & + (ARCH_CAPS_RDCL_NO |ARCH_CAPS_IBRS_ALL |ARCH_CAPS_RSBA | +ARCH_CAPS_SSB_NO |ARCH_CAPS_MDS_NO |ARCH_CAPS_IF_PSCHANGE_MC_NO | +ARCH_CAPS_TAA_NO |ARCH_CAPS_SBDR_SSDP_NO |ARCH_CAPS_FBSDP_NO | +ARCH_CAPS_PSDP_NO |ARCH_CAPS_FB_CLEAR |ARCH_CAPS_RRSBA | +ARCH_CAPS_BHI_NO |ARCH_CAPS_PBRSB_NO ); } }
Signature · 1 line
2.30.2
PATCH v2 2/10 x86/boot: Adjust MSR_ARCH_CAPS handling for the Host policy
In reply to Andrew CooperWe are about to move MSR_ARCH_CAPS into featureset, but the order of operations (copy raw policy, then copy x86_capabilitiles[] in) will end up clobbering the ARCH_CAPS value.
Some toolstacks use this information to handle TSX compatibility across the CPUs and microcode versions where support was removed.
To avoid this transient breakage, read from raw_cpu_policy rather than modifying it in place. This logic will be removed entirely in due course.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/cpu-policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/cpu-policy.c +1 -1
@@ -411,7 +411,7 @@ static void __init calculate_host_policy(void) p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;/* Temporary, until we have known_features[] for feature bits in MSRs. */ - p->arch_caps.raw &= + p->arch_caps.raw = raw_cpu_policy.arch_caps.raw & (ARCH_CAPS_RDCL_NO | ARCH_CAPS_IBRS_ALL | ARCH_CAPS_RSBA | ARCH_CAPS_SKIP_L1DFL | ARCH_CAPS_SSB_NO | ARCH_CAPS_MDS_NO | ARCH_CAPS_IF_PSCHANGE_MC_NO | ARCH_CAPS_TSX_CTRL | ARCH_CAPS_TAA_NO |
Signature · 1 line
2.30.2
PATCH v2 3/10 x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS
In reply to Andrew CooperBits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.
As both halves are present now, the arch_caps field is full width. Adjust the unit test, which notices.
The bool bitfield names in the arch_caps union are unused, and somewhat out of date. They'll shortly be automatically generated.
Add CPUID and MSR prefixes to the ./xen-cpuid verbose output, now that there are a mix of the two.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v2:
* Adjust the unit test.
* Use an m prefix on the short name.
* Add CPUID/MSR to the verbose name.
--- tools/misc/xen-cpuid.c | 44 +++++++++++------- tools/tests/cpu-policy/test-cpu-policy.c | 5 --- xen/include/public/arch-x86/cpufeatureset.h | 4 ++ xen/include/xen/lib/x86/cpu-policy.h | 50 ++++++++++----------- xen/lib/x86/cpuid.c | 4 ++ 5 files changed, 59 insertions(+), 48 deletions(-)
tools/misc/xen-cpuid.c +27 -17
@@ -226,31 +226,41 @@ static const char *const str_7d2[32] = [ 4] = "bhi-ctrl", [ 5] = "mcdt-no", }; +static const char *const str_10Al[32 ] = +{ +}; + +static const char *const str_10Ah[32 ] = +{ +}; +static const struct {const char *name;const char *abbr;const char *const *strs; } decodes[] = { - {"0x00000001.edx" ,"1d" , str_1d }, - {"0x00000001.ecx" ,"1c" , str_1c }, - {"0x80000001.edx" ,"e1d" , str_e1d }, - {"0x80000001.ecx" ,"e1c" , str_e1c }, - {"0x0000000d:1.eax" ,"Da1" , str_Da1 }, - {"0x00000007:0.ebx" ,"7b0" , str_7b0 }, - {"0x00000007:0.ecx" ,"7c0" , str_7c0 }, - {"0x80000007.edx" ,"e7d" , str_e7d }, - {"0x80000008.ebx" ,"e8b" , str_e8b }, - {"0x00000007:0.edx" ,"7d0" , str_7d0 }, - {"0x00000007:1.eax" ,"7a1" , str_7a1 }, - {"0x80000021.eax" ,"e21a" , str_e21a }, - {"0x00000007:1.ebx" ,"7b1" , str_7b1 }, - {"0x00000007:2.edx" ,"7d2" , str_7d2 }, - {"0x00000007:1.ecx" ,"7c1" , str_7c1 }, - {"0x00000007:1.edx" ,"7d1" , str_7d1 }, + {"CPUID 0x00000001.edx" ,"1d" , str_1d }, + {"CPUID 0x00000001.ecx" ,"1c" , str_1c }, + {"CPUID 0x80000001.edx" ,"e1d" , str_e1d }, + {"CPUID 0x80000001.ecx" ,"e1c" , str_e1c }, + {"CPUID 0x0000000d:1.eax" ,"Da1" , str_Da1 }, + {"CPUID 0x00000007:0.ebx" ,"7b0" , str_7b0 }, + {"CPUID 0x00000007:0.ecx" ,"7c0" , str_7c0 }, + {"CPUID 0x80000007.edx" ,"e7d" , str_e7d }, + {"CPUID 0x80000008.ebx" ,"e8b" , str_e8b }, + {"CPUID 0x00000007:0.edx" ,"7d0" , str_7d0 }, + {"CPUID 0x00000007:1.eax" ,"7a1" , str_7a1 }, + {"CPUID 0x80000021.eax" ,"e21a" , str_e21a }, + {"CPUID 0x00000007:1.ebx" ,"7b1" , str_7b1 }, + {"CPUID 0x00000007:2.edx" ,"7d2" , str_7d2 }, + {"CPUID 0x00000007:1.ecx" ,"7c1" , str_7c1 }, + {"CPUID 0x00000007:1.edx" ,"7d1" , str_7d1 }, + {"MSR 0x0000010a.lo" ,"m10Al" , str_10Al }, + {"MSR 0x0000010a.hi" ,"m10Ah" , str_10Ah }, }; -#define COL_ALIGN "18" +#define COL_ALIGN "24"static const char *const fs_names[] = { [XEN_SYSCTL_cpu_featureset_raw] ="Raw" ,
tools/tests/cpu-policy/test-cpu-policy.c +0 -5
@@ -391,11 +391,6 @@ static void test_msr_deserialise_failure(void) .msr = { .idx = 0xce, .val = ~0ull }, .rc = -EOVERFLOW, }, - { - .name = "truncated val", - .msr = { .idx = 0x10a, .val = ~0ull }, - .rc = -EOVERFLOW, - }, };printf ("Testing MSR deserialise failure:\n" );
xen/include/public/arch-x86/cpufeatureset.h +4 -0
@@ -307,6 +307,10 @@ XEN_CPUFEATURE(AVX_VNNI_INT8, 15*32+ 4) /*A AVX-VNNI-INT8 Instructions */ XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */XEN_CPUFEATURE (CET_SSS ,15 *32 +18 )/* CET Supervisor Shadow Stacks safe to use */ +/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */ + +/* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */ +#endif /* XEN_CPUFEATURE */ /* Clean up from a default include. Close the enum (for C). */
xen/include/xen/lib/x86/cpu-policy.h +24 -26
63 lines not on this page · raw message
xen/lib/x86/cpuid.c +4 -0
@@ -79,6 +79,8 @@ void x86_cpu_policy_to_featureset( fs[FEATURESET_7d2] = p->feat._7d2; fs[FEATURESET_7c1] = p->feat._7c1; fs[FEATURESET_7d1] = p->feat._7d1; + fs[FEATURESET_m10Al] = p->arch_caps.lo; + fs[FEATURESET_m10Ah] = p->arch_caps.hi; } void x86_cpu_featureset_to_policy(
@@ -100,6 +102,8 @@ void x86_cpu_featureset_to_policy( p->feat._7d2 = fs[FEATURESET_7d2]; p->feat._7c1 = fs[FEATURESET_7c1]; p->feat._7d1 = fs[FEATURESET_7d1]; + p->arch_caps.lo = fs[FEATURESET_m10Al]; + p->arch_caps.hi = fs[FEATURESET_m10Ah]; }void x86_cpu_policy_recalc_synth (struct cpu_policy *p)
Signature · 1 line
2.30.2
Re: [PATCH v2 03/10] x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS
Quoted 6 lines · Andrew Cooper
Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.
As both halves are present now, the
arch_capsfield is full width. Adjust the unit test, which notices.
Quoted 7 lines
The bool bitfield names in the
arch_capsunion are unused, and somewhat out of date. They'll shortly be automatically generated.Add CPUID and MSR prefixes to the ./xen-cpuid verbose output, now that there are a mix of the two.
Signed-off-by Andrew Cooper <[email protected]>
albeit ...
Quoted 42 lines
tools/misc/xen-cpuid.c +14
-16@@ -226,31 +226,41 @@ static const char *const str_7d2[32] = [ 4] = "bhi-ctrl", [ 5] = "mcdt-no", }; +static const char *const str_10Al[32 ] = +{ +}; + +static const char *const str_10Ah[32 ] = +{ +}; +static const struct {const char *name;const char *abbr;const char *const *strs; } decodes[] = { - {"0x00000001.edx" ,"1d" , str_1d }, - {"0x00000001.ecx" ,"1c" , str_1c }, - {"0x80000001.edx" ,"e1d" , str_e1d }, - {"0x80000001.ecx" ,"e1c" , str_e1c }, - {"0x0000000d:1.eax" ,"Da1" , str_Da1 }, - {"0x00000007:0.ebx" ,"7b0" , str_7b0 }, - {"0x00000007:0.ecx" ,"7c0" , str_7c0 }, - {"0x80000007.edx" ,"e7d" , str_e7d }, - {"0x80000008.ebx" ,"e8b" , str_e8b }, - {"0x00000007:0.edx" ,"7d0" , str_7d0 }, - {"0x00000007:1.eax" ,"7a1" , str_7a1 }, - {"0x80000021.eax" ,"e21a" , str_e21a }, - {"0x00000007:1.ebx" ,"7b1" , str_7b1 }, - {"0x00000007:2.edx" ,"7d2" , str_7d2 }, - {"0x00000007:1.ecx" ,"7c1" , str_7c1 }, - {"0x00000007:1.edx" ,"7d1" , str_7d1 }, + {"CPUID 0x00000001.edx" ,"1d" , str_1d }, + {"CPUID 0x00000001.ecx" ,"1c" , str_1c }, + {"CPUID 0x80000001.edx" ,"e1d" , str_e1d }, + {"CPUID 0x80000001.ecx" ,"e1c" , str_e1c }, + {"CPUID 0x0000000d:1.eax" ,"Da1" , str_Da1 }, + {"CPUID 0x00000007:0.ebx" ,"7b0" , str_7b0 },
tools/misc/xen-cpuid.c static const char *const str_7d2[32] = · line 258
Quoted 10 lines
tools/misc/xen-cpuid.c +10
-0+ { "CPUID 0x00000007:0.ecx", "7c0", str_7c0 }, + { "CPUID 0x80000007.edx", "e7d", str_e7d }, + { "CPUID 0x80000008.ebx", "e8b", str_e8b }, + { "CPUID 0x00000007:0.edx", "7d0", str_7d0 }, + { "CPUID 0x00000007:1.eax", "7a1", str_7a1 }, + { "CPUID 0x80000021.eax", "e21a", str_e21a }, + { "CPUID 0x00000007:1.ebx", "7b1", str_7b1 }, + { "CPUID 0x00000007:2.edx", "7d2", str_7d2 }, + { "CPUID 0x00000007:1.ecx", "7c1", str_7c1 }, + { "CPUID 0x00000007:1.edx", "7d1", str_7d1 },
... I'm not really happy about this added verbosity. In a tool of this name, I think it's pretty clear that unadorned names are CPUID stuff.
tools/misc/xen-cpuid.c static const char *const str_7d2[32] = · line 260
Quoted 2 lines
tools/misc/xen-cpuid.c +2
-0+ { "MSR 0x0000010a.lo", "m10Al", str_10Al }, + { "MSR 0x0000010a.hi", "m10Ah", str_10Ah },
Once we gain a few more MSRs, I'm afraid the raw numbers aren't going to be very useful. As vaguely suggested before, how about
{ "MSR_ARCH_CAPS.lo", "m10Al", str_10Al },
{ "MSR_ARCH_CAPS.hi", "m10Ah", str_10Ah },?
Jan
Re: [PATCH v2 03/10] x86/cpu-policy: Infrastructure for MSR_ARCH_CAPS
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Bits through 24 are already defined, meaning that we're not far off needing the second word. Put both in right away.
As both halves are present now, the
arch_capsfield is full width. Adjust the unit test, which notices.
Quoted 8 lines
Quoted 7 lines
The bool bitfield names in the
arch_capsunion are unused, and somewhat out of date. They'll shortly be automatically generated.Add CPUID and MSR prefixes to the ./xen-cpuid verbose output, now that there are a mix of the two.
Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks,
Quoted 48 lines
albeit ...
Quoted 46 lines
tools/misc/xen-cpuid.c +18
-16@@ -226,31 +226,41 @@ static const char *const str_7d2[32] = [ 4] = "bhi-ctrl", [ 5] = "mcdt-no", }; +static const char *const str_10Al[32 ] = +{ +}; + +static const char *const str_10Ah[32 ] = +{ +}; +static const struct {const char *name;const char *abbr;const char *const *strs; } decodes[] = { - {"0x00000001.edx" ,"1d" , str_1d }, - {"0x00000001.ecx" ,"1c" , str_1c }, - {"0x80000001.edx" ,"e1d" , str_e1d }, - {"0x80000001.ecx" ,"e1c" , str_e1c }, - {"0x0000000d:1.eax" ,"Da1" , str_Da1 }, - {"0x00000007:0.ebx" ,"7b0" , str_7b0 }, - {"0x00000007:0.ecx" ,"7c0" , str_7c0 }, - {"0x80000007.edx" ,"e7d" , str_e7d }, - {"0x80000008.ebx" ,"e8b" , str_e8b }, - {"0x00000007:0.edx" ,"7d0" , str_7d0 }, - {"0x00000007:1.eax" ,"7a1" , str_7a1 }, - {"0x80000021.eax" ,"e21a" , str_e21a }, - {"0x00000007:1.ebx" ,"7b1" , str_7b1 }, - {"0x00000007:2.edx" ,"7d2" , str_7d2 }, - {"0x00000007:1.ecx" ,"7c1" , str_7c1 }, - {"0x00000007:1.edx" ,"7d1" , str_7d1 }, + {"CPUID 0x00000001.edx" ,"1d" , str_1d }, + {"CPUID 0x00000001.ecx" ,"1c" , str_1c }, + {"CPUID 0x80000001.edx" ,"e1d" , str_e1d }, + {"CPUID 0x80000001.ecx" ,"e1c" , str_e1c }, + {"CPUID 0x0000000d:1.eax" ,"Da1" , str_Da1 }, + {"CPUID 0x00000007:0.ebx" ,"7b0" , str_7b0 }, + {"CPUID 0x00000007:0.ecx" ,"7c0" , str_7c0 }, + {"CPUID 0x80000007.edx" ,"e7d" , str_e7d }, + {"CPUID 0x80000008.ebx" ,"e8b" , str_e8b }, + {"CPUID 0x00000007:0.edx" ,"7d0" , str_7d0 },
Quoted 8 lines
tools/misc/xen-cpuid.c static const char *const str_7d2[32] = · line 258
Quoted 6 lines
tools/misc/xen-cpuid.c +6
-0+ { "CPUID 0x00000007:1.eax", "7a1", str_7a1 }, + { "CPUID 0x80000021.eax", "e21a", str_e21a }, + { "CPUID 0x00000007:1.ebx", "7b1", str_7b1 }, + { "CPUID 0x00000007:2.edx", "7d2", str_7d2 }, + { "CPUID 0x00000007:1.ecx", "7c1", str_7c1 }, + { "CPUID 0x00000007:1.edx", "7d1", str_7d1 },... I'm not really happy about this added verbosity. In a tool of this name, I think it's pretty clear that unadorned names are CPUID stuff.
You might make the connection, but it's unreasonable to expect the same of everyone else. This is used by end users.
If nothing else, the name of the binary is made stale by this change.
Quoted 9 lines
tools/misc/xen-cpuid.c static const char *const str_7d2[32] = · line 260
Quoted 2 lines
tools/misc/xen-cpuid.c +2
-0+ { "MSR 0x0000010a.lo", "m10Al", str_10Al }, + { "MSR 0x0000010a.hi", "m10Ah", str_10Ah },Once we gain a few more MSRs, I'm afraid the raw numbers aren't going to be very useful. As vaguely suggested before, how about
{ "MSR_ARCH_CAPS.lo", "m10Al", str_10Al }, { "MSR_ARCH_CAPS.hi", "m10Ah", str_10Ah },?
I've done this. I remain to be convinced, but it probably is nicer for people who don't know the MSR indices like I do.
~Andrew
PATCH v2 4/10 x86/cpu-policy: MSR_ARCH_CAPS feature names
In reply to Andrew CooperSeed the default visibility from the dom0 special case, which for the most part just exposes the *_NO bits. EIBRS is the one non-*_NO bit, which is "just" a status bit to the guest indicating a change in implemention of IBRS which is already fully supported.
Insert a block dependency from the ARCH_CAPS CPUID bit to the entire content of the MSR. This is because MSRs have no structure information similar to CPUID, and used by x86_cpu_policy_clear_out_of_range_leaves(), in order to bulk-clear inaccessable words.
The overall CPUID bit is still max-only, so all of MSR_ARCH_CAPS is hidden in the default policies.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
There is no libxl logic because libxl still uses the older xend format which is specific to CPUID data. That is going to need untangling at some other point.
v2:
* Don't expose SKIP_L1DFL to guests (it's only applicable for nested virt)
* Fix SBDR_SSDP_NO and FBSDP_NO names.
* Extend the commit message.
--- tools/misc/xen-cpuid.c | 13 ++++++++++++ xen/include/public/arch-x86/cpufeatureset.h | 23 +++++++++++++++++++++ xen/tools/gen-cpuid.py | 3 +++ 3 files changed, 39 insertions(+)
tools/misc/xen-cpuid.c +13 -0
@@ -228,6 +228,19 @@ static const char *const str_7d2[32] =static const char *const str_10Al[32 ] = { + [0 ] ="rdcl-no" , [1 ] ="eibrs" , + [2 ] ="rsba" , [3 ] ="skip-l1dfl" , + [4 ] ="intel-ssb-no" , [5 ] ="mds-no" , + [6 ] ="if-pschange-mc-no" , [7 ] ="tsx-ctrl" , + [8 ] ="taa-no" , [9 ] ="mcu-ctrl" , + [10 ] ="misc-pkg-ctrl" , [11 ] ="energy-ctrl" , + [12 ] ="doitm" , [13 ] ="sbdr-ssdp-no" , + [14 ] ="fbsdp-no" , [15 ] ="psdp-no" , +/* 16 */ [17 ] ="fb-clear" , + [18 ] ="fb-clear-ctrl" , [19 ] ="rrsba" , + [20 ] ="bhi-no" , [21 ] ="xapic-status" , +/* 22 */ [23 ] ="ovrclk-status" , + [24 ] ="pbrsb-no" , }; static const char *const str_10Ah[32] =
xen/include/public/arch-x86/cpufeatureset.h +23 -0
@@ -308,6 +308,29 @@ XEN_CPUFEATURE(AVX_NE_CONVERT, 15*32+ 5) /*A AVX-NE-CONVERT Instructions */XEN_CPUFEATURE (CET_SSS ,15 *32 +18 )/* CET Supervisor Shadow Stacks safe to use */ /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.eax, word 16 */ +XEN_CPUFEATURE(RDCL_NO, 16*32+ 0) /*A No Rogue Data Cache Load (Meltdown) */ +XEN_CPUFEATURE(EIBRS, 16*32+ 1) /*A Enhanced IBRS */ +XEN_CPUFEATURE(RSBA, 16*32+ 2) /*!A RSB Alternative (Retpoline not safe) */ +XEN_CPUFEATURE(SKIP_L1DFL, 16*32+ 3) /* Don't need to flush L1D on VMEntry */ +XEN_CPUFEATURE(INTEL_SSB_NO, 16*32+ 4) /*A No Speculative Store Bypass */ +XEN_CPUFEATURE(MDS_NO, 16*32+ 5) /*A No Microarchitectural Data Sampling */ +XEN_CPUFEATURE(IF_PSCHANGE_MC_NO, 16*32+ 6) /*A No Instruction fetch #MC */ +XEN_CPUFEATURE(TSX_CTRL, 16*32+ 7) /* MSR_TSX_CTRL */ +XEN_CPUFEATURE(TAA_NO, 16*32+ 8) /*A No TSX Async Abort */ +XEN_CPUFEATURE(MCU_CTRL, 16*32+ 9) /* MSR_MCU_CTRL */ +XEN_CPUFEATURE(MISC_PKG_CTRL, 16*32+10) /* MSR_MISC_PKG_CTRL */ +XEN_CPUFEATURE(ENERGY_FILTERING, 16*32+11) /* MSR_MISC_PKG_CTRL.ENERGY_FILTERING */ +XEN_CPUFEATURE(DOITM, 16*32+12) /* Data Operand Invariant Timing Mode */ +XEN_CPUFEATURE(SBDR_SSDP_NO, 16*32+13) /*A No Shared Buffer Data Read or Sideband Stale Data Propagation */ +XEN_CPUFEATURE(FBSDP_NO, 16*32+14) /*A No Fill Buffer Stale Data Propagation */ +XEN_CPUFEATURE(PSDP_NO, 16*32+15) /*A No Primary Stale Data Propagation */ +XEN_CPUFEATURE(FB_CLEAR, 16*32+17) /*A Fill Buffers cleared by VERW */ +XEN_CPUFEATURE(FB_CLEAR_CTRL, 16*32+18) /* MSR_OPT_CPU_CTRL.FB_CLEAR_DIS */ +XEN_CPUFEATURE(RRSBA, 16*32+19) /*!A Restricted RSB Alternative */ +XEN_CPUFEATURE(BHI_NO, 16*32+20) /*A No Branch History Injection */ +XEN_CPUFEATURE(XAPIC_STATUS, 16*32+21) /* MSR_XAPIC_DISABLE_STATUS */ +XEN_CPUFEATURE(OVRCLK_STATUS, 16*32+23) /* MSR_OVERCLOCKING_STATUS */ +XEN_CPUFEATURE (PBRSB_NO ,16 *32 +24 )/*A No Post-Barrier RSB predictions */ /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 */
xen/tools/gen-cpuid.py +3 -0
@@ -325,6 +325,9 @@ def crunch_numbers(state): # In principle the TSXLDTRK insns could also be considered independent. RTM: [TSXLDTRK], + + # The ARCH_CAPS CPUID bit enumerates the availability of the whole register. + ARCH_CAPS: list(range(RDCL_NO, RDCL_NO + 64)), } deep_features = tuple(sorted(deps.keys()))
Signature · 1 line
2.30.2
Re: [PATCH v2 04/10] x86/cpu-policy: MSR_ARCH_CAPS feature names
Quoted 10 lines · Andrew Cooper
Seed the default visibility from the dom0 special case, which for the most part just exposes the
*_NObits. EIBRS is the one non-*_NO bit, which is "just" a status bit to the guest indicating a change in implemention of IBRS which is already fully supported.Insert a block dependency from the
ARCH_CAPSCPUID bit to the entire content of the MSR. This is because MSRs have no structure information similar to CPUID, and used byx86_cpu_policy_clear_out_of_range_leaves(), in order to bulk-clear inaccessable words.
Quoted 4 lines
The overall CPUID bit is still max-only, so all of
MSR_ARCH_CAPSis hidden in the default policies.Signed-off-by Andrew Cooper <[email protected]>
PATCH v2 5/10 x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy
In reply to Andrew CooperExtend x86_cpu_policy_fill_native() with a read of ARCH_CAPS based on the CPUID information just read, removing the specially handling in calculate_raw_cpu_policy().
Right now, the only use of x86_cpu_policy_fill_native() outside of Xen is the unit tests. Getting MSR data in this context is left to whomever first encounters a genuine need to have it.
Extend generic_identify() to read ARCH_CAPS into x86_capability[], which is fed into the Host Policy. This in turn means there's no need to special case arch_caps in calculate_host_policy().
No practical change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v2:
* Extend commit message to discuss the absence of MSRs outside of __XEN__
--- xen/arch/x86/cpu-policy.c | 12 ------------ xen/arch/x86/cpu/common.c | 5 +++++ xen/lib/x86/cpuid.c | 7 ++++++- 3 files changed, 11 insertions(+), 13 deletions(-)
xen/arch/x86/cpu-policy.c +0 -12
@@ -354,9 +354,6 @@ void calculate_raw_cpu_policy(void)/* 0x000000ce MSR_INTEL_PLATFORM_INFO */ /* Was already added by probe_cpuid_faulting() */ - -if ( cpu_has_arch_caps ) -rdmsrl (MSR_ARCH_CAPABILITIES , p->arch_caps.raw); }static void __init calculate_host_policy (void )
@@ -409,15 +406,6 @@ static void __init calculate_host_policy(void)/* 0x000000ce MSR_INTEL_PLATFORM_INFO */ /* probe_cpuid_faulting() sanity checks presence of MISC_FEATURES_ENABLES */ p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting; - -/* Temporary, until we have known_features[] for feature bits in MSRs. */ - p->arch_caps.raw = raw_cpu_policy.arch_caps.raw & - (ARCH_CAPS_RDCL_NO |ARCH_CAPS_IBRS_ALL |ARCH_CAPS_RSBA | -ARCH_CAPS_SKIP_L1DFL |ARCH_CAPS_SSB_NO |ARCH_CAPS_MDS_NO | -ARCH_CAPS_IF_PSCHANGE_MC_NO |ARCH_CAPS_TSX_CTRL |ARCH_CAPS_TAA_NO | -ARCH_CAPS_SBDR_SSDP_NO |ARCH_CAPS_FBSDP_NO |ARCH_CAPS_PSDP_NO | -ARCH_CAPS_FB_CLEAR |ARCH_CAPS_RRSBA |ARCH_CAPS_BHI_NO | -ARCH_CAPS_PBRSB_NO ); }static void __init guest_common_default_feature_adjustments (uint32_t *fs)
xen/arch/x86/cpu/common.c +5 -0
@@ -477,6 +477,11 @@ static void generic_identify(struct cpuinfo_x86 *c)cpuid_count (0xd ,1 , &c->x86_capability[FEATURESET_Da1], &tmp, &tmp, &tmp); + +if (test_bit (X86_FEATURE_ARCH_CAPS , c->x86_capability)) +rdmsr (MSR_ARCH_CAPABILITIES , + c->x86_capability[FEATURESET_10Al], + c->x86_capability[FEATURESET_10Ah]); }/*
xen/lib/x86/cpuid.c +6 -1
@@ -226,7 +226,12 @@ void x86_cpu_policy_fill_native(struct cpu_policy *p) p->hv_limit =0 ; p->hv2_limit =0 ; -/* TODO MSRs */ +#ifdef __XEN__ +/* TODO MSR_PLATFORM_INFO */ + +if ( p->feat.arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , p->arch_caps.raw); +#endif x86_cpu_policy_recalc_synth (p); }
Signature · 1 line
2.30.2
Re: [PATCH v2 05/10] x86/boot: Record MSR_ARCH_CAPS for the Raw and Host CPU policy
xen/arch/x86/cpu/common.c static void generic_identify(struct cpuinfo_x86 *c) · line 484
Quoted 13 lines · Andrew Cooper
xen/arch/x86/cpu/common.c +5
-0@@ -477,6 +477,11 @@ static void generic_identify(struct cpuinfo_x86 *c)cpuid_count (0xd ,1 , &c->x86_capability[FEATURESET_Da1], &tmp, &tmp, &tmp); + +if (test_bit (X86_FEATURE_ARCH_CAPS , c->x86_capability)) +rdmsr (MSR_ARCH_CAPABILITIES , + c->x86_capability[FEATURESET_10Al], + c->x86_capability[FEATURESET_10Ah]);
I managed to send out a stale version. I've corrected this and the other instances locally.
~Andrew
PATCH v2 6/10 x86/boot: Expose MSR_ARCH_CAPS data in guest max policies
In reply to Andrew CooperWe already have common and default feature adjustment helpers. Introduce one for max featuresets too.
Offer MSR_ARCH_CAPS unconditionally in the max policy, and stop clobbering the data inherited from the Host policy. This will be necessary to level a VM safely for migration. Annotate the ARCH_CAPS CPUID bit as special. Note:ARCH_CAPS is still max-only for now, so will not be inhereted by the default policies.
With this done, the special case for dom0 can be shrunk to just resampling the Host policy (as ARCH_CAPS isn't visible by default yet).
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v2:
* Annotate ARCH_CAPS as special.
--- xen/arch/x86/cpu-policy.c | 42 ++++++++++++--------- xen/include/public/arch-x86/cpufeatureset.h | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-)
xen/arch/x86/cpu-policy.c +24 -18
@@ -408,6 +408,25 @@ static void __init calculate_host_policy(void) p->platform_info.cpuid_faulting = cpu_has_cpuid_faulting; } +static void __init guest_common_max_feature_adjustments (uint32_t *fs) +{ +if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) + { +/* +* MSR_ARCH_CAPS is just feature data, and we can offer it to guests +* unconditionally, although limit it to Intel systems as it is highly +* uarch-specific. +* +* In particular, the RSBA and RRSBA bits mean "you might migrate to a +* system where RSB underflow uses alternative predictors (a.k.a +* Retpoline not safe)", so these need to be visible to a guest in all +* cases, even when it's only some other server in the pool which +* suffers the identified behaviour. +*/ +__set_bit (X86_FEATURE_ARCH_CAPS , fs); + } +} +static void __init guest_common_default_feature_adjustments (uint32_t *fs) {/*
@@ -483,6 +502,7 @@ static void __init calculate_pv_max_policy(void)__clear_bit (X86_FEATURE_IBRS , fs); } +guest_common_max_feature_adjustments (fs);guest_common_feature_adjustments (fs);sanitise_featureset (fs);
@@ -490,8 +510,6 @@ static void __init calculate_pv_max_policy(void)recalculate_xstate (p); p->extd.raw[0xa ] =EMPTY_LEAF ;/* No SVM for PV guests. */ - - p->arch_caps.raw =0 ;/* Not supported yet. */ }static void __init calculate_pv_def_policy (void )
@@ -598,6 +616,7 @@ static void __init calculate_hvm_max_policy(void)if ( !cpu_has_vmx )__clear_bit (X86_FEATURE_PKS , fs); +guest_common_max_feature_adjustments (fs);guest_common_feature_adjustments (fs);sanitise_featureset (fs);
@@ -606,8 +625,6 @@ static void __init calculate_hvm_max_policy(void)/* It's always possible to emulate CPUID faulting for HVM guests */ p->platform_info.cpuid_faulting = true; - - p->arch_caps.raw =0 ;/* Not supported yet. */ }static void __init calculate_hvm_def_policy (void )
@@ -828,7 +845,10 @@ void __init init_dom0_cpuid_policy(struct domain *d)* domain policy logic gains a better understanding of MSRs. */ if (is_hardware_domain (d) && cpu_has_arch_caps ) + { p->feat.arch_caps = true; + p->arch_caps.raw = host_cpu_policy.arch_caps.raw; + }/* Apply dom0-cpuid= command line settings, if provided. */ if ( dom0_cpuid_cmdline )
@@ -858,20 +878,6 @@ void __init init_dom0_cpuid_policy(struct domain *d) p->platform_info.cpuid_faulting = false;recalculate_cpuid_policy (d); - -if (is_hardware_domain (d) && cpu_has_arch_caps ) - { -uint64_t val; - -rdmsrl (MSR_ARCH_CAPABILITIES , val); - - p->arch_caps.raw = val & - (ARCH_CAPS_RDCL_NO |ARCH_CAPS_IBRS_ALL |ARCH_CAPS_RSBA | -ARCH_CAPS_SSB_NO |ARCH_CAPS_MDS_NO |ARCH_CAPS_IF_PSCHANGE_MC_NO | -ARCH_CAPS_TAA_NO |ARCH_CAPS_SBDR_SSDP_NO |ARCH_CAPS_FBSDP_NO | -ARCH_CAPS_PSDP_NO |ARCH_CAPS_FB_CLEAR |ARCH_CAPS_RRSBA | -ARCH_CAPS_BHI_NO |ARCH_CAPS_PBRSB_NO ); - } }static void __init __maybe_unused build_assertions (void )
xen/include/public/arch-x86/cpufeatureset.h +1 -1
@@ -271,7 +271,7 @@ XEN_CPUFEATURE(AVX512_FP16, 9*32+23) /* AVX512 FP16 instructions */ XEN_CPUFEATURE(IBRSB, 9*32+26) /*A IBRS and IBPB support (used by Intel) */ XEN_CPUFEATURE(STIBP, 9*32+27) /*A STIBP */ XEN_CPUFEATURE(L1D_FLUSH, 9*32+28) /*S MSR_FLUSH_CMD and L1D flush. */ -XEN_CPUFEATURE(ARCH_CAPS, 9*32+29) /*a IA32_ARCH_CAPABILITIES MSR */ +XEN_CPUFEATURE(ARCH_CAPS, 9*32+29) /*!a IA32_ARCH_CAPABILITIES MSR */ XEN_CPUFEATURE(CORE_CAPS, 9*32+30) /* IA32_CORE_CAPABILITIES MSR */XEN_CPUFEATURE (SSBD ,9 *32 +31 )/*A MSR_SPEC_CTRL.SSBD available */
Signature · 1 line
2.30.2
Re: [PATCH v2 06/10] x86/boot: Expose MSR_ARCH_CAPS data in guest max policies
Quoted 9 lines · Andrew Cooper
We already have common and default feature adjustment helpers. Introduce one for max featuresets too.
Offer
MSR_ARCH_CAPSunconditionally in the max policy, and stop clobbering the data inherited from the Host policy. This will be necessary to level a VM safely for migration. Annotate theARCH_CAPSCPUID bit as special. Note:ARCH_CAPSis still max-only for now, so will not be inhereted by the default policies.
Quoted 4 lines
With this done, the special case for dom0 can be shrunk to just resampling the Host policy (as
ARCH_CAPSisn't visible by default yet).Signed-off-by Andrew Cooper <[email protected]>
PATCH v2 7/10 x86/cpufeature: Rework {boot_,}cpu_has()
In reply to Andrew CooperOne area where Xen deviates from Linux is that test_bit() forces a volatile read. This leads to poor code generation, because the optimiser cannot merge bit operations on the same word.
Drop the use of test_bit(), and write the expressions in regular C. This removes the include of bitops.h (which is a frequent source of header tangles), and it offers the optimiser far more flexibility.
Bloat-o-meter reports a net change of:
add/remove: 0/0 grow/shrink: 21/87 up/down: 641/-2751 (-2110)
with half of that in x86_emulate() alone. vmx_ctxt_switch_to() seems to be the fastpath with the greatest delta at -24, where the optimiser has successfully removed the branch hidden in cpu_has_msr_tsc_aux.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
v2:
* Drop stdbool. It is already covered by other includes.
--- xen/arch/x86/include/asm/cpufeature.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +9 -3
@@ -17,7 +17,6 @@#define X86_FEATURE_ALWAYS X86_FEATURE_LM #ifndef __ASSEMBLY__ -#include <xen/bitops.h> struct cpuinfo_x86 { unsigned char x86; /* CPU family */
@@ -43,8 +42,15 @@ struct cpuinfo_x86 {extern struct cpuinfo_x86 boot_cpu_data; -#define cpu_has (c, bit) test_bit(bit, (c)->x86_capability) -#define boot_cpu_has (bit) test_bit(bit, boot_cpu_data.x86_capability) +static inline bool cpu_has (const struct cpuinfo_x86 *info,unsigned int feat) +{ +return info->x86_capability[cpufeat_word (feat)] &cpufeat_mask (feat); +} + +static inline bool boot_cpu_has (unsigned int feat) +{ +return cpu_has (&boot_cpu_data, feat); +}#define CPUID_PM_LEAF 6#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1
Signature · 1 line
2.30.2
PATCH v2 8/10 x86/vtx: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperMSR_ARCH_CAPS data is now included in featureset information.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 8 ++------ xen/arch/x86/include/asm/cpufeature.h | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +2 -6
@@ -2849,8 +2849,6 @@ static void __init ler_to_fixup_check(void);*/ static bool __init has_if_pschange_mc (void ) { -uint64_t caps =0 ; -/* * If we are virtualised, there is nothing we can do. Our EPT tables are * shadowed by our hypervisor, and not walked by hardware.
@@ -2858,10 +2856,8 @@ static bool __init has_if_pschange_mc(void)if ( cpu_has_hypervisor )return false; -if ( cpu_has_arch_caps ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps); - -if ( caps &ARCH_CAPS_IF_PSCHANGE_MC_NO ) +/* Hardware reports itself as fixed. */ +if ( cpu_has_if_pschange_mc_no )return false;/*
xen/arch/x86/include/asm/cpufeature.h +3 -0
@@ -182,6 +182,9 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_vnni_int8 boot_cpu_has(X86_FEATURE_AVX_VNNI_INT8)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT) +/* MSR_ARCH_CAPS */ +#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO) +/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
Signature · 1 line
2.30.2
PATCH v2 9/10 x86/tsx: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperThe current cpu_has_tsx_ctrl tristate is serving double pupose; to signal the first pass through tsx_init(), and the availability of MSR_TSX_CTRL.
Drop the variable, replacing it with a once boolean, and altering cpu_has_tsx_ctrl to come out of the feature information.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/processor.h | 2 +- xen/arch/x86/tsx.c | 13 ++++++++----- 3 files changed, 10 insertions(+), 6 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -184,6 +184,7 @@ static inline bool boot_cpu_has(unsigned int feat)/* MSR_ARCH_CAPS */ #define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO) +#define cpu_has_tsx_ctrl boot_cpu_has(X86_FEATURE_TSX_CTRL)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/arch/x86/include/asm/processor.h +1 -1
@@ -535,7 +535,7 @@ static inline uint8_t get_cpu_family(uint32_t raw, uint8_t *model,return fam; } -extern int8_t opt_tsx, cpu_has_tsx_ctrl; +extern int8_t opt_tsx;extern bool rtm_disabled;void tsx_init (void );
xen/arch/x86/tsx.c +8 -5
@@ -19,7 +19,6 @@* controlling TSX behaviour, and where TSX isn't force-disabled by firmware. */ int8_t __read_mostly opt_tsx =-1 ; -int8_t __read_mostly cpu_has_tsx_ctrl =-1 ;bool __read_mostly rtm_disabled; static int __init cf_check parse_tsx(const char *s)
@@ -37,24 +36,28 @@ custom_param("tsx", parse_tsx);void tsx_init (void ) { +static bool __read_mostly once; +/* * This function is first called between microcode being loaded, and CPUID * being scanned generally. Read into boot_cpu_data.x86_capability[] for * the cpu_has_* bits we care about using here. */ -if (unlikely (cpu_has_tsx_ctrl <0 ) ) +if (unlikely (!once) ) { -uint64_t caps =0 ;bool has_rtm_always_abort; + once = true; +if ( boot_cpu_data.cpuid_level >=7 ) boot_cpu_data.x86_capability[FEATURESET_7d0] =cpuid_count_edx (7 ,0 );if ( cpu_has_arch_caps ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps); +rdmsr (MSR_ARCH_CAPABILITIES , + boot_cpu_data.x86_capability[FEATURESET_10Al], + boot_cpu_data.x86_capability[FEATURESET_10Ah]); - cpu_has_tsx_ctrl = !!(caps &ARCH_CAPS_TSX_CTRL ); has_rtm_always_abort = cpu_has_rtm_always_abort;if ( cpu_has_tsx_ctrl && cpu_has_srbds_ctrl )
Signature · 1 line
2.30.2
PATCH v2 10/10 x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperMSR_ARCH_CAPS data is now included in featureset information. Replace opencoded checks with regular feature ones.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/cpufeature.h | 7 ++++ xen/arch/x86/spec_ctrl.c | 56 +++++++++++++-------------- 2 files changed, 33 insertions(+), 30 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +7 -0
@@ -183,8 +183,15 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT)/* MSR_ARCH_CAPS */ +#define cpu_has_rdcl_no boot_cpu_has(X86_FEATURE_RDCL_NO) +#define cpu_has_eibrs boot_cpu_has(X86_FEATURE_EIBRS) +#define cpu_has_rsba boot_cpu_has(X86_FEATURE_RSBA) +#define cpu_has_skip_l1dfl boot_cpu_has(X86_FEATURE_SKIP_L1DFL) +#define cpu_has_mds_no boot_cpu_has(X86_FEATURE_MDS_NO)#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO)#define cpu_has_tsx_ctrl boot_cpu_has(X86_FEATURE_TSX_CTRL) +#define cpu_has_taa_no boot_cpu_has(X86_FEATURE_TAA_NO) +#define cpu_has_fb_clear boot_cpu_has(X86_FEATURE_FB_CLEAR)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/arch/x86/spec_ctrl.c +26 -30
183 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH v2 10/10] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 6 lines · Andrew Cooper
MSR_ARCH_CAPSdata is now included in featureset information. Replace opencoded checks with regular feature ones.No functional change.
Signed-off-by Andrew Cooper <[email protected]>