x86: Changes for Intel Feb 2022 microcode
cover x86: Changes for Intel Feb 2022 microcode
Changes for two software visible changes in the Intel Feb 2022 microcode drop.
1) Deprecation of TSX on more client parts
2) Retrofitting of AMD's MSR_SPEC_CTRL.PSFD to various CPUs
These patches have been committed and backported to 4.14 and later.
Andrew Cooper (6):
x86/spec-ctrl: Clean up MSR_MCU_OPT_CTRL handling x86/tsx: Move has_rtm_always_abort to an outer scope x86/tsx: Cope with TSX deprecation on WHL-R/CFL-R tests/tsx: Extend test-tsx to check MSR_MCU_OPT_CTRL x86/cpuid: Infrastructure for cpuid word 7:2.edx x86/spec-ctrl: Support Intel PSFD for guests
docs/misc/xen-command-line.pandoc | 25 +++++-- tools/libs/light/libxl_cpuid.c | 2 + tools/misc/xen-cpuid.c | 6 ++ tools/tests/tsx/test-tsx.c | 9 ++- xen/arch/x86/acpi/power.c | 3 +- xen/arch/x86/cpu/common.c | 4 ++ xen/arch/x86/cpu/intel.c | 32 +++++++++ xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/msr-index.h | 2 + xen/arch/x86/include/asm/processor.h | 3 + xen/arch/x86/include/asm/spec_ctrl.h | 2 - xen/arch/x86/msr.c | 2 +- xen/arch/x86/platform_hypercall.c | 3 + xen/arch/x86/smpboot.c | 3 +- xen/arch/x86/spec_ctrl.c | 52 +++++++------- xen/arch/x86/tsx.c | 102 ++++++++++++++++++++++++---- xen/include/public/arch-x86/cpufeatureset.h | 3 + xen/include/xen/lib/x86/cpuid.h | 13 +++- xen/tools/gen-cpuid.py | 2 +- 19 files changed, 211 insertions(+), 58 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/6 x86/spec-ctrl: Clean up MSR_MCU_OPT_CTRL handling
Introduce cpu_has_srbds_ctrl as more users are going to appear shortly.
MSR_MCU_OPT_CTRL is gaining extra functionality, meaning that the current default_xen_mcu_opt_ctrl is no longer a good fit.
Introduce two new helpers, update_mcu_opt_ctrl() which does a full RMW cycle on the MSR, and set_in_mcu_opt_ctrl() which lets callers configure specific bits at a time without clobbering each others settings.
No functional change.
--- xen/arch/x86/acpi/power.c | 3 +-- xen/arch/x86/cpu/intel.c | 32 +++++++++++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/processor.h | 3 +++ xen/arch/x86/include/asm/spec_ctrl.h | 2 -- xen/arch/x86/smpboot.c | 3 +-- xen/arch/x86/spec_ctrl.c | 38 ++++++++++++----------------------- 7 files changed, 51 insertions(+), 31 deletions(-)
xen/arch/x86/acpi/power.c +1 -2
@@ -301,8 +301,7 @@ static int enter_state(u32 state) ci->last_spec_ctrl = default_xen_spec_ctrl; } -if (boot_cpu_has (X86_FEATURE_SRBDS_CTRL ) ) -wrmsrl (MSR_MCU_OPT_CTRL , default_xen_mcu_opt_ctrl); +update_mcu_opt_ctrl ();/* (re)initialise SYSCALL/SYSENTER state, amongst other things. */ percpu_traps_init ();
xen/arch/x86/cpu/intel.c +32 -0
@@ -15,6 +15,38 @@#include "cpu.h" /* +* MSR_MCU_OPT_CTRL is a collection of unrelated functionality, with separate +* enablement requirements, but which want to be consistent across the system. +*/ +static uint32_t __read_mostly mcu_opt_ctrl_mask; +static uint32_t __read_mostly mcu_opt_ctrl_val; + +void update_mcu_opt_ctrl (void ) +{ +uint32_t mask = mcu_opt_ctrl_mask, lo, hi; + +if ( !mask ) +return ; + +rdmsr (MSR_MCU_OPT_CTRL , lo, hi); + + lo &= ~mask; + lo |= mcu_opt_ctrl_val; + +wrmsr (MSR_MCU_OPT_CTRL , lo, hi); +} + +void __init set_in_mcu_opt_ctrl (uint32_t mask,uint32_t val) +{ + mcu_opt_ctrl_mask |= mask; + + mcu_opt_ctrl_val &= ~mask; + mcu_opt_ctrl_val |= (val & mask); + +update_mcu_opt_ctrl (); +} + +/* * Processors which have self-snooping capability can handle conflicting * memory type across CPUs by snooping its own cache. However, there exists * CPU models in which having conflicting memory types still leads to
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -134,6 +134,7 @@#define cpu_has_avx512_4vnniw boot_cpu_has(X86_FEATURE_AVX512_4VNNIW)#define cpu_has_avx512_4fmaps boot_cpu_has(X86_FEATURE_AVX512_4FMAPS)#define cpu_has_avx512_vp2intersect boot_cpu_has(X86_FEATURE_AVX512_VP2INTERSECT) +#define cpu_has_srbds_ctrl boot_cpu_has(X86_FEATURE_SRBDS_CTRL)#define cpu_has_rtm_always_abort boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)#define cpu_has_tsx_force_abort boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)#define cpu_has_serialize boot_cpu_has(X86_FEATURE_SERIALIZE)
xen/arch/x86/include/asm/processor.h +3 -0
@@ -626,6 +626,9 @@ extern int8_t opt_tsx, cpu_has_tsx_ctrl;extern bool rtm_disabled;void tsx_init (void ); +void update_mcu_opt_ctrl (void ); +void set_in_mcu_opt_ctrl (uint32_t mask,uint32_t val); +enum ap_boot_method {AP_BOOT_NORMAL ,AP_BOOT_SKINIT ,
xen/arch/x86/include/asm/spec_ctrl.h +0 -2
@@ -54,8 +54,6 @@ extern int8_t opt_pv_l1tf_hwdom, opt_pv_l1tf_domu;*/ extern paddr_t l1tf_addr_mask, l1tf_safe_maddr; -extern uint64_t default_xen_mcu_opt_ctrl; -static inline void init_shadow_spec_ctrl_state (void ) {struct cpu_info *info =get_cpu_info ();
xen/arch/x86/smpboot.c +1 -2
@@ -385,8 +385,7 @@ void start_secondary(void *unused)wrmsrl (MSR_SPEC_CTRL , default_xen_spec_ctrl); info->last_spec_ctrl = default_xen_spec_ctrl; } -if (boot_cpu_has (X86_FEATURE_SRBDS_CTRL ) ) -wrmsrl (MSR_MCU_OPT_CTRL , default_xen_mcu_opt_ctrl); +update_mcu_opt_ctrl ();tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */
xen/arch/x86/spec_ctrl.c +13 -25
@@ -67,7 +67,6 @@ static bool __initdata cpu_has_bug_msbds_only; /* => minimal HT impact. */static bool __initdata cpu_has_bug_mds;/* Any other M{LP,SB,FB}DS combination. */ static int8_t __initdata opt_srb_lock =-1 ; -uint64_t __read_mostly default_xen_mcu_opt_ctrl;static int __init parse_spec_ctrl (const char *s) {
@@ -376,7 +375,7 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) (default_xen_spec_ctrl &SPEC_CTRL_SSBD ) ?" SSBD+" :" SSBD-" , !(caps &ARCH_CAPS_TSX_CTRL ) ?"" : (opt_tsx &1 ) ?" TSX+" :" TSX-" , - !boot_cpu_has (X86_FEATURE_SRBDS_CTRL ) ?"" : + !cpu_has_srbds_ctrl ?"" : opt_srb_lock ?" SRB_LOCK+" :" SRB_LOCK-" , opt_ibpb ?" IBPB" :"" , opt_l1d_flush ? " L1D_FLUSH" : "",
@@ -1251,32 +1250,24 @@ void __init init_speculation_mitigations(void)tsx_init (); } -/* Calculate suitable defaults for MSR_MCU_OPT_CTRL */ -if (boot_cpu_has (X86_FEATURE_SRBDS_CTRL ) ) +/* +* On some SRBDS-affected hardware, it may be safe to relax srb-lock by +* default. +* +* On parts which enumerate MDS_NO and not TAA_NO, TSX is the only known +* way to access the Fill Buffer. If TSX isn't available (inc. SKU +* reasons on some models), or TSX is explicitly disabled, then there is +* no need for the extra overhead to protect RDRAND/RDSEED. +*/ +if ( cpu_has_srbds_ctrl ) { -uint64_t val; - -rdmsrl (MSR_MCU_OPT_CTRL , val); - -/* -* On some SRBDS-affected hardware, it may be safe to relax srb-lock -* by default. -* -* On parts which enumerate MDS_NO and not TAA_NO, TSX is the only way -* to access the Fill Buffer. If TSX isn't available (inc. SKU -* reasons on some models), or TSX is explicitly disabled, then there -* is no need for the extra overhead to protect RDRAND/RDSEED. -*/ if ( opt_srb_lock ==-1 && (caps & (ARCH_CAPS_MDS_NO |ARCH_CAPS_TAA_NO )) ==ARCH_CAPS_MDS_NO && (!cpu_has_hle || ((caps &ARCH_CAPS_TSX_CTRL ) && rtm_disabled)) ) opt_srb_lock =0 ; - val &= ~MCU_OPT_CTRL_RNGDS_MITG_DIS ; -if ( !opt_srb_lock ) - val |=MCU_OPT_CTRL_RNGDS_MITG_DIS ; - - default_xen_mcu_opt_ctrl = val; +set_in_mcu_opt_ctrl (MCU_OPT_CTRL_RNGDS_MITG_DIS , + opt_srb_lock ?0 :MCU_OPT_CTRL_RNGDS_MITG_DIS ); }print_details (thunk, caps);
@@ -1314,9 +1305,6 @@ void __init init_speculation_mitigations(void)wrmsrl (MSR_SPEC_CTRL , val); info->last_spec_ctrl = val; } - -if (boot_cpu_has (X86_FEATURE_SRBDS_CTRL ) ) -wrmsrl (MSR_MCU_OPT_CTRL , default_xen_mcu_opt_ctrl); }static void __init __maybe_unused build_assertions (void )
Signature · 1 line
2.11.0
PATCH 2/6 x86/tsx: Move has_rtm_always_abort to an outer scope
In reply to Andrew CooperWe are about to introduce a second path which needs to conditionally force the presence of RTM_ALWAYS_ABORT.
No functional change.
--- xen/arch/x86/tsx.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
xen/arch/x86/tsx.c +12 -14
@@ -42,6 +42,7 @@ void tsx_init(void)if (unlikely (cpu_has_tsx_ctrl <0 ) ) {uint64_t caps =0 ; +bool has_rtm_always_abort;if ( boot_cpu_data.cpuid_level >=7 ) boot_cpu_data.x86_capability[cpufeat_word (X86_FEATURE_ARCH_CAPS )]
@@ -51,6 +52,7 @@ void tsx_init(void)rdmsrl (MSR_ARCH_CAPABILITIES , caps); cpu_has_tsx_ctrl = !!(caps &ARCH_CAPS_TSX_CTRL ); + has_rtm_always_abort = cpu_has_rtm_always_abort;if ( cpu_has_tsx_force_abort ) {
@@ -67,11 +69,7 @@ void tsx_init(void)* RTM_ALWAYS_ABORT enumerates the new functionality, but is also * read as zero if TSX_FORCE_ABORT.ENABLE_RTM has been set before * we run. -* -* Undo this behaviour in Xen's view of the world. */ -bool has_rtm_always_abort = cpu_has_rtm_always_abort; -if ( !has_rtm_always_abort ) {uint64_t val;
@@ -83,15 +81,6 @@ void tsx_init(void) }/* -* Always force RTM_ALWAYS_ABORT, even if it currently visible. -* If the user explicitly opts to enable TSX, we'll set -* TSX_FORCE_ABORT.ENABLE_RTM and cause RTM_ALWAYS_ABORT to be -* hidden from the general CPUID scan later. -*/ -if ( has_rtm_always_abort ) -setup_force_cpu_cap (X86_FEATURE_RTM_ALWAYS_ABORT ); - -/* * If no explicit tsx= option is provided, pick a default. * * This deliberately overrides the implicit opt_tsx=-3 from
@@ -108,10 +97,19 @@ void tsx_init(void)* With RTM_ALWAYS_ABORT, disable TSX. */ if ( opt_tsx <0 ) - opt_tsx = !cpu_has_rtm_always_abort; + opt_tsx = !has_rtm_always_abort; }/* +* Always force RTM_ALWAYS_ABORT, even if it currently visible. If +* the user explicitly opts to enable TSX, we'll set the appropriate +* RTM_ENABLE bit and cause RTM_ALWAYS_ABORT to be hidden from the +* general CPUID scan later. +*/ +if ( has_rtm_always_abort ) +setup_force_cpu_cap (X86_FEATURE_RTM_ALWAYS_ABORT ); + +/* * The TSX features (HLE/RTM) are handled specially. They both * enumerate features but, on certain parts, have mechanisms to be * hidden without disrupting running software.
Signature · 1 line
2.11.0
PATCH 3/6 x86/tsx: Cope with TSX deprecation on WHL-R/CFL-R
In reply to Andrew CooperThe February 2022 microcode is formally de-featuring TSX on the TAA-impacted client CPUs. The backup TAA mitigation (VERW regaining its flushing side effect) is being dropped, meaning that smt=0 spec-ctrl=md-clear no longer protects against TAA on these parts.
The new functionality enumerates itself via the RTM_ALWAYS_ABORT CPUID bit (the same as June 2021), but has its control in MSR_MCU_OPT_CTRL as opposed to MSR_TSX_FORCE_ABORT.
TSX now defaults to being disabled on ucode load. Furthermore, if SGX is enabled in the BIOS, TSX is locked and cannot be re-enabled. In this case, override opt_tsx to 0, so the RTM/HLE CPUID bits get hidden by default.
While updating the command line documentation, take the opportunity to add a paragraph explaining what TSX being disabled actually means, and how migration compatibility works.
--- docs/misc/xen-command-line.pandoc | 25 +++++++++--- xen/arch/x86/include/asm/msr-index.h | 2 + xen/arch/x86/spec_ctrl.c | 7 +++- xen/arch/x86/tsx.c | 76 ++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 7 deletions(-)
docs/misc/xen-command-line.pandoc +20 -5
@@ -2387,7 +2387,9 @@ Several microcode updates are relevant: Introduced MSR_TSX_CTRL on all TSX-enabled MDS_NO parts to date, CLX/WHL-R/CFL-R, with the controls becoming architectural moving forward and formally retiring HLE from the architecture. The user can disable TSX - to mitigate TAA, and elect to hide the HLE/RTM CPUID bits. + to mitigate TAA, and elect to hide the HLE/RTM CPUID bits. Also causes + VERW to once-again flush the microarchiectural buffers in case a TAA + mitigation is wanted along with TSX being enabled. * June 2021, removing the workaround for March 2019 on client CPUs and formally de-featured TSX on SKL/KBL/WHL/CFL (Note: SKX still retains the
@@ -2395,19 +2397,32 @@ Several microcode updates are relevant: PCR3 works fine, and TSX is disabled by default, but the user can re-enable TSX at their own risk, accepting that the memory order erratum is unfixed. + * February 2022, removing the VERW flushing workaround from November 2019 on + client CPUs and formally de-featuring TSX on WHL-R/CFL-R (Note: CLX still + retains the VERW flushing workaround). TSX defaults to disabled, and is + locked off when SGX is enabled in the BIOS. When SGX is not enabled, TSX + can be re-enabled at the users own risk, as it reintroduces the TSX Async + Abort speculative vulnerability. + On systems with the ability to configure TSX, this boolean offers system wide control of whether TSX is enabled or disabled. +When TSX is disabled, transactions unconditionally abort. This is compatible +with the TSX spec, which requires software to have a non-transactional path as +a fallback. The RTM and HLE CPUID bits are hidden from VMs by default, but +can be re-enabled if required. This allows VMs which previously saw RTM/HLE +to be migrated in, although any TSX-enabled software will run with reduced +performance. + + * When TSX is locked off by firmware, `tsx=` is ignored and treated as + `false`. + * An explicit `tsx=` choice is honoured, even if it is `true` and would result in a vulnerable system. * When no explicit `tsx=` choice is given, parts vulnerable to TAA will be mitigated by disabling TSX, as this is the lowest overhead option. - If the use of TSX is important, the more expensive TAA mitigations can be - opted in to with `smt=0 spec-ctrl=md-clear`, at which point TSX will remain - active by default. - * When no explicit `tsx=` option is given, parts susceptible to the memory ordering errata default to `true` to enable working TSX. Alternatively, selecting `tsx=0` will disable TSX and restore PCR3 to a working state.
xen/arch/x86/include/asm/msr-index.h +2 -0
@@ -78,6 +78,8 @@#define MSR_MCU_OPT_CTRL 0x00000123#define MCU_OPT_CTRL_RNGDS_MITG_DIS (_AC(1, ULL) << 0) +#define MCU_OPT_CTRL_RTM_ALLOW (_AC(1, ULL) << 1) +#define MCU_OPT_CTRL_RTM_LOCKED (_AC(1, ULL) << 2)#define MSR_RTIT_OUTPUT_BASE 0x00000560#define MSR_RTIT_OUTPUT_MASK 0x00000561
xen/arch/x86/spec_ctrl.c +5 -2
@@ -1233,11 +1233,14 @@ void __init init_speculation_mitigations(void)* the MDS mitigation of disabling HT and using VERW flushing. * * On CPUs which advertise MDS_NO, VERW has no flushing side effect until -* the TSX_CTRL microcode is loaded, despite the MD_CLEAR CPUID bit being +* the TSX_CTRL microcode (Nov 2019), despite the MD_CLEAR CPUID bit being * advertised, and there isn't a MD_CLEAR_2 flag to use... * +* Furthermore, the VERW flushing side effect is removed again on client +* parts with the Feb 2022 microcode. +* * If we're on affected hardware, able to do something about it (which -* implies that VERW now works), no explicit TSX choice and traditional +* implies that VERW might work), no explicit TSX choice and traditional * MDS mitigations (no-SMT, VERW) not obviosuly in use (someone might * plausibly value TSX higher than Hyperthreading...), disable TSX to * mitigate TAA.
xen/arch/x86/tsx.c +76 -0
94 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH 4/6 tests/tsx: Extend test-tsx to check MSR_MCU_OPT_CTRL
In reply to Andrew CooperThis MSR needs to be identical across the system for TSX to have identical behaviour everywhere. Furthermore, its CPUID bit (SRBDS_CTRL) shouldn't be visible to guests.
--- tools/tests/tsx/test-tsx.c | 9 ++++++++- xen/arch/x86/platform_hypercall.c | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-)
tools/tests/tsx/test-tsx.c +8 -1
@@ -42,6 +42,7 @@ enum {#define ARCH_CAPS_TSX_CTRL (1 << 7)#define MSR_TSX_FORCE_ABORT 0x0000010f#define MSR_TSX_CTRL 0x00000122 +#define MSR_MCU_OPT_CTRL 0x00000123static unsigned int nr_failures;#define fail (fmt, ...) \
@@ -155,6 +156,10 @@ static void test_tsx_msrs(void)printf ("Testing MSR_TSX_CTRL consistency\n" );test_tsx_msr_consistency (MSR_TSX_CTRL , host.msr.arch_caps.tsx_ctrl); + +printf ("Testing MSR_MCU_OPT_CTRL consistency\n" ); +test_tsx_msr_consistency ( +MSR_MCU_OPT_CTRL , host.cpuid.feat.srbds_ctrl); }/*
@@ -313,7 +318,8 @@ static void test_guest_policies(const struct xc_cpu_policy *max,if ( ((cm->feat.raw[0 ].d | cd->feat.raw[0 ].d) & (bitmaskof (X86_FEATURE_TSX_FORCE_ABORT ) | -bitmaskof (X86_FEATURE_RTM_ALWAYS_ABORT ))) || +bitmaskof (X86_FEATURE_RTM_ALWAYS_ABORT ) | +bitmaskof (X86_FEATURE_SRBDS_CTRL ))) || ((mm->arch_caps.raw | md->arch_caps.raw) &ARCH_CAPS_TSX_CTRL ) )fail (" Xen-only TSX controls offered to guest\n" );
@@ -388,6 +394,7 @@ static void test_guest(struct xen_domctl_createdomain *c)if ( guest_policy.cpuid.feat.hle || guest_policy.cpuid.feat.tsx_force_abort || guest_policy.cpuid.feat.rtm_always_abort || + guest_policy.cpuid.feat.srbds_ctrl || guest_policy.msr.arch_caps.tsx_ctrl )fail (" Unexpected features advertised\n" );
xen/arch/x86/platform_hypercall.c +3 -0
@@ -80,6 +80,9 @@ static bool msr_read_allowed(unsigned int msr)case MSR_TSX_CTRL :return cpu_has_tsx_ctrl; + +case MSR_MCU_OPT_CTRL : +return cpu_has_srbds_ctrl; }if ( ppin_msr && msr == ppin_msr )
Signature · 1 line
2.11.0
PATCH 5/6 x86/cpuid: Infrastructure for cpuid word 7:2.edx
In reply to Andrew CooperWhile in principle it would be nice to keep leaf 7 in order, that would involve having an extra 5 words of zeros in a featureset.
--- tools/misc/xen-cpuid.c | 5 +++++ xen/arch/x86/cpu/common.c | 4 ++++ xen/include/public/arch-x86/cpufeatureset.h | 2 ++ xen/include/xen/lib/x86/cpuid.h | 13 ++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-)
tools/misc/xen-cpuid.c +5 -0
@@ -200,6 +200,10 @@ static const char *const str_7b1[32] = [ 0] = "ppin", }; +static const char *const str_7d2[32 ] = +{ +}; + static const struct { const char *name; const char *abbr;
@@ -219,6 +223,7 @@ static const struct { { "0x00000007:1.eax", "7a1", str_7a1 }, { "0x80000021.eax", "e21a", str_e21a }, { "0x00000007:1.ebx", "7b1", str_7b1 }, + { "0x00000007:2.edx", "7d2", str_7d2 }, };#define COL_ALIGN "18"
xen/arch/x86/cpu/common.c +4 -0
@@ -447,6 +447,10 @@ static void generic_identify(struct cpuinfo_x86 *c) &c->x86_capability[FEATURESET_7a1], &c->x86_capability[FEATURESET_7b1], &tmp, &tmp); +if (max_subleaf >=2 ) +cpuid_count (7 ,2 , + &tmp, &tmp, &tmp, + &c->x86_capability[FEATURESET_7d2]); }if (c->cpuid_level >=0xd )
xen/include/public/arch-x86/cpufeatureset.h +2 -0
@@ -302,6 +302,8 @@ XEN_CPUFEATURE(NSCB, 11*32+ 6) /*A Null Selector Clears Base (and/* Intel-defined CPU features, CPUID level 0x00000007:1.ebx, word 12 */ XEN_CPUFEATURE (INTEL_PPIN ,12 *32 +0 )/* Protected Processor Inventory Number */ +/* Intel-defined CPU features, CPUID level 0x00000007:2.edx, word 13 */ +#endif /* XEN_CPUFEATURE */ /* Clean up from a default include. Close the enum (for C). */
xen/include/xen/lib/x86/cpuid.h +12 -1
@@ -17,6 +17,7 @@#define FEATURESET_7a1 10/* 0x00000007:1.eax */ #define FEATURESET_e21a 11/* 0x80000021.eax */ #define FEATURESET_7b1 12/* 0x00000007:1.ebx */ +#define FEATURESET_7d2 13/* 0x80000007:2.edx */ struct cpuid_leaf {
@@ -82,7 +83,7 @@ const char *x86_cpuid_vendor_to_str(unsigned int vendor);#define CPUID_GUEST_NR_BASIC (0xdu + 1)#define CPUID_GUEST_NR_CACHE (5u + 1) -#define CPUID_GUEST_NR_FEAT (1u + 1) +#define CPUID_GUEST_NR_FEAT (2u + 1)#define CPUID_GUEST_NR_TOPO (1u + 1)#define CPUID_GUEST_NR_XSTATE (62u + 1)#define CPUID_GUEST_NR_EXTD_INTEL (0x8u + 1)
@@ -193,6 +194,14 @@ struct cpuid_policyuint32_t _7b1; struct { DECL_BITFIELD(7b1); }; }; + uint32_t /* c */:32, /* d */:32; + +/* Subleaf 2. */ + uint32_t /* a */:32, /* b */:32, /* c */:32; +union { +uint32_t _7d2; + struct { DECL_BITFIELD(7d2); }; + }; }; } feat;
@@ -333,6 +342,7 @@ static inline void cpuid_policy_to_featureset( fs[FEATURESET_7a1] = p->feat._7a1; fs[FEATURESET_e21a] = p->extd.e21a; fs[FEATURESET_7b1] = p->feat._7b1; + fs[FEATURESET_7d2] = p->feat._7d2; }/* Fill in a CPUID policy from a featureset bitmap. */
@@ -352,6 +362,7 @@ static inline void cpuid_featureset_to_policy( p->feat._7a1 = fs[FEATURESET_7a1]; p->extd.e21a = fs[FEATURESET_e21a]; p->feat._7b1 = fs[FEATURESET_7b1]; + p->feat._7d2 = fs[FEATURESET_7d2]; }static inline uint64_t cpuid_policy_xcr0_max (const struct cpuid_policy *p)
Signature · 1 line
2.11.0
PATCH 6/6 x86/spec-ctrl: Support Intel PSFD for guests
In reply to Andrew CooperThe Feb 2022 microcode from Intel retrofits AMD's MSR_SPEC_CTRL.PSFD interface to Sunny Cove (IceLake) and later cores.
Update the MSR_SPEC_CTRL emulation, and expose it to guests.
--- tools/libs/light/libxl_cpuid.c | 2 ++ tools/misc/xen-cpuid.c | 1 + xen/arch/x86/msr.c | 2 +- xen/arch/x86/spec_ctrl.c | 7 +++++-- xen/include/public/arch-x86/cpufeatureset.h | 1 + xen/tools/gen-cpuid.py | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-)
tools/libs/light/libxl_cpuid.c +2 -0
@@ -234,6 +234,8 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) {"fsrs", 0x00000007, 1, CPUID_REG_EAX, 11, 1}, {"fsrcs", 0x00000007, 1, CPUID_REG_EAX, 12, 1}, + {"intel-psfd", 0x00000007, 2, CPUID_REG_EDX, 0, 1}, + {"lahfsahf", 0x80000001, NA, CPUID_REG_ECX, 0, 1}, {"cmplegacy", 0x80000001, NA, CPUID_REG_ECX, 1, 1}, {"svm", 0x80000001, NA, CPUID_REG_ECX, 2, 1},
tools/misc/xen-cpuid.c +1 -0
@@ -202,6 +202,7 @@ static const char *const str_7b1[32] =static const char *const str_7d2[32 ] = { + [0 ] ="intel-psfd" , }; static const struct {
xen/arch/x86/msr.c +1 -1
@@ -443,7 +443,7 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)uint64_t msr_spec_ctrl_valid_bits (const struct cpuid_policy *cp) {bool ssbd = cp->feat.ssbd || cp->extd.amd_ssbd; -bool psfd = cp->extd.psfd; +bool psfd = cp->feat.intel_psfd || cp->extd.psfd;/* * Note: SPEC_CTRL_STIBP is specified as safe to use (i.e. ignored)
xen/arch/x86/spec_ctrl.c +5 -2
@@ -307,11 +307,13 @@ custom_param("pv-l1tf", parse_pv_l1tf);static void __init print_details (enum ind_thunk thunk,uint64_t caps) { -unsigned int _7d0 =0 , e8b =0 , tmp; +unsigned int _7d0 =0 , _7d2 =0 , e8b =0 , max =0 , tmp;/* Collect diagnostics about available mitigations. */ if ( boot_cpu_data.cpuid_level >=7 ) -cpuid_count (7 ,0 , &tmp, &tmp, &tmp, &_7d0); +cpuid_count (7 ,0 , &max, &tmp, &tmp, &_7d0); +if ( max >=2 ) +cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp);
@@ -345,6 +347,7 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) (_7d0 &cpufeat_mask (X86_FEATURE_STIBP )) ?" STIBP" :"" , (e8b &cpufeat_mask (X86_FEATURE_AMD_SSBD )) || (_7d0 &cpufeat_mask (X86_FEATURE_SSBD )) ?" SSBD" :"" , + (_7d2 &cpufeat_mask (X86_FEATURE_INTEL_PSFD )) || (e8b &cpufeat_mask (X86_FEATURE_PSFD )) ?" PSFD" :"" , (_7d0 &cpufeat_mask (X86_FEATURE_L1D_FLUSH )) ?" L1D_FLUSH" :"" , (_7d0 & cpufeat_mask(X86_FEATURE_MD_CLEAR)) ? " MD_CLEAR" : "",
xen/include/public/arch-x86/cpufeatureset.h +1 -0
@@ -303,6 +303,7 @@ XEN_CPUFEATURE(NSCB, 11*32+ 6) /*A Null Selector Clears Base (andXEN_CPUFEATURE (INTEL_PPIN ,12 *32 +0 )/* Protected Processor Inventory Number */ /* Intel-defined CPU features, CPUID level 0x00000007:2.edx, word 13 */ +XEN_CPUFEATURE(INTEL_PSFD, 13*32+ 0) /*A MSR_SPEC_CTRL.PSFD */#endif /* XEN_CPUFEATURE */
xen/tools/gen-cpuid.py +1 -1
@@ -287,7 +287,7 @@ def crunch_numbers(state): # IBRSB/IBRS, and we pass this MSR directly to guests. Treating them # as dependent features simplifies Xen's logic, and prevents the guest # from seeing implausible configurations. - IBRSB: [STIBP, SSBD], + IBRSB: [STIBP, SSBD, INTEL_PSFD], IBRS: [AMD_STIBP, AMD_SSBD, PSFD, IBRS_ALWAYS, IBRS_FAST, IBRS_SAME_MODE], AMD_STIBP: [STIBP_ALWAYS],
Signature · 1 line
2.11.0