x86/xstate: Fixes to size calculations
v4 cover x86/xstate: Fixes to size calculations
Only minor changes in v4 vs v3. See patches for details.
The end result has been tested across the entire XenServer hardware lab. This found several false assupmtion about how the dynamic sizes behave.
Patches 1 and 6 the main bugfixes from this series. There's still lots more work to do in order to get AMX and/or CET working, but this is at least a 4-yo series finally off my plate.
Andrew Cooper (7):
x86/xstate: Fix initialisation of XSS cache
x86/xstate: Cross-check dynamic XSTATE sizes at boot x86/boot: Collect the Raw CPU Policy earlier on boot x86/xstate: Rework xstate_ctxt_size() as xstate_uncompressed_size() x86/cpu-policy: Simplify recalculate_xstate()
x86/cpuid: Fix handling of XSAVE dynamic leaves x86/defns: Clean up X86_{XCR0,XSS}_* constants
xen/arch/x86/cpu-policy.c | 56 ++-- xen/arch/x86/cpuid.c | 24 +- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/i387.c | 2 +- xen/arch/x86/include/asm/x86-defns.h | 55 ++-- xen/arch/x86/include/asm/xstate.h | 8 +- xen/arch/x86/setup.c | 4 +- xen/arch/x86/xstate.c | 294 +++++++++++++++++--- xen/include/public/arch-x86/cpufeatureset.h | 3 + xen/include/xen/lib/x86/cpu-policy.h | 2 +- 11 files changed, 330 insertions(+), 122 deletions(-)
Signature · 1 line
2.39.2
PATCH v4 1/7 x86/xstate: Fix initialisation of XSS cache
The clobbering of this_cpu(xcr0) and this_cpu(xss) to architecturally invalid values is to force the subsequent set_xcr0() and set_msr_xss() to reload the hardware register.
While XCR0 is reloaded in xstate_init(), MSR_XSS isn't. This causes get_msr_xss() to return the invalid value, and logic of the form:
old = get_msr_xss();
set_msr_xss(new);
...
set_msr_xss(old);to try and restore said invalid value.
The architecturally invalid value must be purged from the cache, meaning the hardware register must be written at least once. This in turn highlights that the invalid value must only be used in the case that the hardware register is available.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v3:
* Split out of later patch
--- xen/arch/x86/xstate.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
xen/arch/x86/xstate.c +11 -7
@@ -641,13 +641,6 @@ void xstate_init(struct cpuinfo_x86 *c)return ; } -/* -* Zap the cached values to make set_xcr0() and set_msr_xss() really -* write it. -*/ -this_cpu (xcr0) =0 ; -this_cpu (xss) = ~0 ; -cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); feature_mask = (((u64 )edx <<32 ) | eax) &XCNTXT_MASK ;BUG_ON (!valid_xcr0 (feature_mask));
@@ -657,8 +650,19 @@ void xstate_init(struct cpuinfo_x86 *c)* Set CR4_OSXSAVE and run "cpuid" to get xsave_cntxt_size. */ set_in_cr4 (X86_CR4_OSXSAVE ); + +/* +* Zap the cached values to make set_xcr0() and set_msr_xss() really write +* the hardware register. +*/ +this_cpu (xcr0) =0 ;if ( !set_xcr0 (feature_mask) )BUG (); +if ( cpu_has_xsaves ) + { +this_cpu (xss) = ~0 ; +set_msr_xss (0 ); + }if ( bsp ) {
Signature · 1 line
2.39.2
PATCH v4 2/7 x86/xstate: Cross-check dynamic XSTATE sizes at boot
In reply to Andrew CooperRight now, xstate_ctxt_size() performs a cross-check of size with CPUID in for every call. This is expensive, being used for domain create/migrate, as well as to service certain guest CPUID instructions.
Instead, arrange to check the sizes once at boot. See the code comments for details. Right now, it just checks hardware against the algorithm expectations. Later patches will add further cross-checking.
Introduce more X86_XCR0_* and X86_XSS_* constants CPUID bits. This is to maximise coverage in the sanity check, even if we don't expect to use/virtualise some of these features any time soon. Leave HDC and HWP alone for now; we don't have CPUID bits from them stored nicely.
Only perform the cross-checks when SELF_TESTS are active. It's only developers or new hardware liable to trip these checks, and Xen at least tracks "maximum value ever seen in xcr0" for the lifetime of the VM, which we don't want to be tickling in the general case.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v3:
* New
v4:
* Rebase over CONFIG_SELF_TESTS
* Swap one BUG_ON() for a WARN()
On Sapphire Rapids with the whole series inc diagnostics, we get this pattern:
(XEN) *** check_new_xstate(, 0x00000003)
(XEN) *** check_new_xstate(, 0x00000004)
(XEN) *** check_new_xstate(, 0x000000e0)
(XEN) *** check_new_xstate(, 0x00000200)
(XEN) *** check_new_xstate(, 0x00060000)
(XEN) *** check_new_xstate(, 0x00000100)
(XEN) *** check_new_xstate(, 0x00000400)
(XEN) *** check_new_xstate(, 0x00000800)
(XEN) *** check_new_xstate(, 0x00001000)
(XEN) *** check_new_xstate(, 0x00004000)
(XEN) *** check_new_xstate(, 0x00008000)
and on Genoa, this pattern:
(XEN) *** check_new_xstate(, 0x00000003)
(XEN) *** check_new_xstate(, 0x00000004)
(XEN) *** check_new_xstate(, 0x000000e0)
(XEN) *** check_new_xstate(, 0x00000200)
(XEN) *** check_new_xstate(, 0x00000800)
(XEN) *** check_new_xstate(, 0x00001000)
--- xen/arch/x86/include/asm/x86-defns.h | 25 +++- xen/arch/x86/xstate.c | 158 ++++++++++++++++++++ xen/include/public/arch-x86/cpufeatureset.h | 3 + 3 files changed, 185 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/x86-defns.h +24 -1
@@ -77,7 +77,7 @@#define X86_CR4_PKS 0x01000000/* Protection Key Supervisor */ /* -* XSTATE component flags in XCR0 +* XSTATE component flags in XCR0 | MSR_XSS */ #define X86_XCR0_FP_POS 0#define X86_XCR0_FP (1ULL << X86_XCR0_FP_POS)
@@ -95,11 +95,34 @@#define X86_XCR0_ZMM (1ULL << X86_XCR0_ZMM_POS)#define X86_XCR0_HI_ZMM_POS 7#define X86_XCR0_HI_ZMM (1ULL << X86_XCR0_HI_ZMM_POS) +#define X86_XSS_PROC_TRACE (_AC(1, ULL) << 8)#define X86_XCR0_PKRU_POS 9#define X86_XCR0_PKRU (1ULL << X86_XCR0_PKRU_POS) +#define X86_XSS_PASID (_AC(1, ULL) << 10) +#define X86_XSS_CET_U (_AC(1, ULL) << 11) +#define X86_XSS_CET_S (_AC(1, ULL) << 12) +#define X86_XSS_HDC (_AC(1, ULL) << 13) +#define X86_XSS_UINTR (_AC(1, ULL) << 14) +#define X86_XSS_LBR (_AC(1, ULL) << 15) +#define X86_XSS_HWP (_AC(1, ULL) << 16) +#define X86_XCR0_TILE_CFG (_AC(1, ULL) << 17) +#define X86_XCR0_TILE_DATA (_AC(1, ULL) << 18)#define X86_XCR0_LWP_POS 62#define X86_XCR0_LWP (1ULL << X86_XCR0_LWP_POS) +#define X86_XCR0_STATES \ + (X86_XCR0_FP | X86_XCR0_SSE | X86_XCR0_YMM | X86_XCR0_BNDREGS | \ + X86_XCR0_BNDCSR | X86_XCR0_OPMASK | X86_XCR0_ZMM | \ + X86_XCR0_HI_ZMM | X86_XCR0_PKRU | X86_XCR0_TILE_CFG | \ + X86_XCR0_TILE_DATA | \ + X86_XCR0_LWP) + +#define X86_XSS_STATES \ + (X86_XSS_PROC_TRACE | X86_XSS_PASID | X86_XSS_CET_U | \ + X86_XSS_CET_S | X86_XSS_HDC | X86_XSS_UINTR | X86_XSS_LBR | \ + X86_XSS_HWP | \ + 0) +/* * Debug status flags in DR6. *
xen/arch/x86/xstate.c +158 -0
173 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -266,6 +266,7 @@ XEN_CPUFEATURE(IBPB_RET, 8*32+30) /*A IBPB clears RSB/RAS too. */ XEN_CPUFEATURE(AVX512_4VNNIW, 9*32+ 2) /*A AVX512 Neural Network Instructions */ XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A AVX512 Multiply Accumulation Single Precision */ XEN_CPUFEATURE(FSRM, 9*32+ 4) /*A Fast Short REP MOVS */ +XEN_CPUFEATURE(UINTR, 9*32+ 5) /* User-mode Interrupts */ XEN_CPUFEATURE(AVX512_VP2INTERSECT, 9*32+8) /*a VP2INTERSECT{D,Q} insns */ XEN_CPUFEATURE(SRBDS_CTRL, 9*32+ 9) /* MSR_MCU_OPT_CTRL and RNGDS_MITG_DIS. */XEN_CPUFEATURE (MD_CLEAR ,9 *32 +10 )/*!A| VERW clears microarchitectural buffers */
@@ -274,8 +275,10 @@ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */ XEN_CPUFEATURE(SERIALIZE, 9*32+14) /*A SERIALIZE insn */ XEN_CPUFEATURE(HYBRID, 9*32+15) /* Heterogeneous platform */ XEN_CPUFEATURE(TSXLDTRK, 9*32+16) /*a TSX load tracking suspend/resume insns */ +XEN_CPUFEATURE(ARCH_LBR, 9*32+19) /* Architectural Last Branch Record */ XEN_CPUFEATURE(CET_IBT, 9*32+20) /* CET - Indirect Branch Tracking */ XEN_CPUFEATURE(AVX512_FP16, 9*32+23) /*A AVX512 FP16 instructions */ +XEN_CPUFEATURE(AMX_TILE, 9*32+24) /* AMX Tile architecture */ 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. */
Signature · 1 line
2.39.2
Re: [PATCH v4 2/7] x86/xstate: Cross-check dynamic XSTATE sizes at boot
Quoted 13 lines · Andrew Cooper
Right now,
xstate_ctxt_size()performs a cross-check of size with CPUID in for every call. This is expensive, being used for domain create/migrate, as well as to service certain guest CPUID instructions.Instead, arrange to check the sizes once at boot. See the code comments for details. Right now, it just checks hardware against the algorithm expectations. Later patches will add further cross-checking.
Introduce more X86_XCR0_* and X86_XSS_* constants CPUID bits. This is to maximise coverage in the sanity check, even if we don't expect to use/virtualise some of these features any time soon. Leave HDC and HWP alone for now; we don't have CPUID bits from them stored nicely.
Quoted 6 lines
Only perform the cross-checks when
SELF_TESTSare active. It's only developers or new hardware liable to trip these checks, and Xen at least tracks "maximum value ever seen in xcr0" for the lifetime of the VM, which we don't want to be tickling in the general case.Signed-off-by Andrew Cooper <[email protected]>
I may certainly give R-b on the patch as it is, but I have a few questions first:
Quoted 36 lines
xen/arch/x86/xstate.c +27
-0@@ -604,9 +604,164 @@ static bool valid_xcr0(uint64_t xcr0)if ( !(xcr0 &X86_XCR0_BNDREGS ) != !(xcr0 &X86_XCR0_BNDCSR ) )return false; +/* TILECFG and TILEDATA must be the same. */ +if ( !(xcr0 &X86_XCR0_TILE_CFG ) != !(xcr0 &X86_XCR0_TILE_DATA ) ) +return false; +return true; } +struct xcheck_state { +uint64_t states; +uint32_t uncomp_size; +uint32_t comp_size; +}; + +static void __init check_new_xstate (struct xcheck_state *s,uint64_t new) +{ +uint32_t hw_size; + +BUILD_BUG_ON (X86_XCR0_STATES &X86_XSS_STATES ); + +BUG_ON (s->states & new);/* States only increase. */ +BUG_ON (!valid_xcr0 (s->states | new));/* Xen thinks it's a good value. */ +BUG_ON (new & ~(X86_XCR0_STATES |X86_XSS_STATES ));/* Known state. */ +BUG_ON ((new &X86_XCR0_STATES ) && + (new &X86_XSS_STATES ));/* User or supervisor, not both. */ + + s->states |= new; +if ( new &X86_XCR0_STATES ) + { +if ( !set_xcr0 (s->states &X86_XCR0_STATES ) ) +BUG ();
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 646
Quoted 10 lines
xen/arch/x86/xstate.c +10
-0+ } +else +set_msr_xss (s->states &X86_XSS_STATES ); + +/* +* Check the uncompressed size. Some XSTATEs are out-of-order and fill in +* prior holes in the state area, so we check that the size doesn't +* decrease. +*/ + hw_size =cpuid_count_ebx (0xd ,0 );
Going forward, do we mean to get rid of XSTATE_CPUID? Else imo it should be used here (and again below).
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 652
Quoted 5 lines
xen/arch/x86/xstate.c +5
-0+if ( hw_size < s->uncomp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, uncompressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->uncomp_size); + + s->uncomp_size = hw_size;
Since XSS state doesn't affect uncompressed layout, this looks like largely dead code for that case. Did you consider moving this into the if() above? Alternatively, should the comparison use == when dealing with XSS bits?
Quoted 4 lines
xen/arch/x86/xstate.c +4
-0+/* +* Check the compressed size, if available. All components strictly +* appear in index order. In principle there are no holes, but some +* components have their base address 64-byte aligned for efficiency
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 667
Quoted 10 lines
xen/arch/x86/xstate.c +10
-0+* reasons (e.g. AMX-TILE) and there are other components small enough to +* fit in the gap (e.g. PKRU) without increasing the overall length. +*/ + hw_size =cpuid_count_ebx (0xd ,1 ); + +if ( cpu_has_xsavec ) + { +if ( hw_size < s->comp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, compressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->comp_size);
Unlike for uncompressed size, can't it be <= here, for - as the comment says - it being strictly index order, and no component having zero size?
Quoted 78 lines
xen/arch/x86/xstate.c +78
-0+ s->comp_size = hw_size; + } +else if ( hw_size )/* Compressed size reported, but no XSAVEC ? */ + { +static bool once; + +if ( !once ) + { +WARN (); + once = true; + } + } +} + +/* +* The {un,}compressed XSTATE sizes are reported by dynamic CPUID value, based +* on the current %XCR0 and MSR_XSS values. The exact layout is also feature +* and vendor specific. Cross-check Xen's understanding against real hardware +* on boot. +* +* Testing every combination is prohibitive, so we use a partial approach. +* Starting with nothing active, we add new XSTATEs and check that the CPUID +* dynamic values never decreases. +*/ +static void __init noinline xstate_check_sizes(void) +{ +uint64_t old_xcr0 =get_xcr0 (); +uint64_t old_xss =get_msr_xss (); +struct xcheck_state s = {}; + +/* +* User XSTATEs, increasing by index. +* +* Chronologically, Intel and AMD had identical layouts for AVX (YMM). +* AMD introduced LWP in Fam15h, following immediately on from YMM. Intel +* left an LWP-shaped hole when adding MPX (BND{CSR,REGS}) in Skylake. +* AMD removed LWP in Fam17h, putting PKRU in the same space, breaking +* layout compatibility with Intel and having a knock-on effect on all +* subsequent states. +*/ +check_new_xstate (&s,X86_XCR0_SSE |X86_XCR0_FP ); + +if ( cpu_has_avx ) +check_new_xstate (&s,X86_XCR0_YMM ); + +if ( cpu_has_mpx ) +check_new_xstate (&s,X86_XCR0_BNDCSR |X86_XCR0_BNDREGS ); + +if ( cpu_has_avx512f ) +check_new_xstate (&s,X86_XCR0_HI_ZMM |X86_XCR0_ZMM |X86_XCR0_OPMASK ); + +if ( cpu_has_pku ) +check_new_xstate (&s,X86_XCR0_PKRU ); + +if (boot_cpu_has (X86_FEATURE_AMX_TILE ) ) +check_new_xstate (&s,X86_XCR0_TILE_DATA |X86_XCR0_TILE_CFG ); + +if (boot_cpu_has (X86_FEATURE_LWP ) ) +check_new_xstate (&s,X86_XCR0_LWP ); + +/* +* Supervisor XSTATEs, increasing by index. +* +* Intel Broadwell has Processor Trace but no XSAVES. There doesn't +* appear to have been a new enumeration when X86_XSS_PROC_TRACE was +* introduced in Skylake. +*/ +if ( cpu_has_xsaves ) + { +if ( cpu_has_proc_trace ) +check_new_xstate (&s,X86_XSS_PROC_TRACE ); + +if (boot_cpu_has (X86_FEATURE_ENQCMD ) ) +check_new_xstate (&s,X86_XSS_PASID ); + +if (boot_cpu_has (X86_FEATURE_CET_SS ) || +boot_cpu_has (X86_FEATURE_CET_IBT ) ) + {
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 756
Quoted 10 lines
xen/arch/x86/xstate.c +10
-0+check_new_xstate (&s,X86_XSS_CET_U ); +check_new_xstate (&s,X86_XSS_CET_S ); + } + +if (boot_cpu_has (X86_FEATURE_UINTR ) ) +check_new_xstate (&s,X86_XSS_UINTR ); + +if (boot_cpu_has (X86_FEATURE_ARCH_LBR ) ) +check_new_xstate (&s,X86_XSS_LBR ); + }
In principle compressed state checking could be extended to also verify the offsets are strictly increasing. That, however, would require to interleave XCR0 and XSS checks, strictly by index. Did you consider (and then discard) doing so?
Jan
Re: [PATCH v4 2/7] x86/xstate: Cross-check dynamic XSTATE sizes at boot
Quoted 63 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
Right now,
xstate_ctxt_size()performs a cross-check of size with CPUID in for every call. This is expensive, being used for domain create/migrate, as well as to service certain guest CPUID instructions.Instead, arrange to check the sizes once at boot. See the code comments for details. Right now, it just checks hardware against the algorithm expectations. Later patches will add further cross-checking.
Introduce more X86_XCR0_* and X86_XSS_* constants CPUID bits. This is to maximise coverage in the sanity check, even if we don't expect to use/virtualise some of these features any time soon. Leave HDC and HWP alone for now; we don't have CPUID bits from them stored nicely.
Quoted 6 lines
Only perform the cross-checks when
SELF_TESTSare active. It's only developers or new hardware liable to trip these checks, and Xen at least tracks "maximum value ever seen in xcr0" for the lifetime of the VM, which we don't want to be tickling in the general case.Signed-off-by Andrew Cooper <[email protected]>I may certainly give R-b on the patch as it is, but I have a few questions first:
Quoted 40 lines
xen/arch/x86/xstate.c +31
-0@@ -604,9 +604,164 @@ static bool valid_xcr0(uint64_t xcr0)if ( !(xcr0 &X86_XCR0_BNDREGS ) != !(xcr0 &X86_XCR0_BNDCSR ) )return false; +/* TILECFG and TILEDATA must be the same. */ +if ( !(xcr0 &X86_XCR0_TILE_CFG ) != !(xcr0 &X86_XCR0_TILE_DATA ) ) +return false; +return true; } +struct xcheck_state { +uint64_t states; +uint32_t uncomp_size; +uint32_t comp_size; +}; + +static void __init check_new_xstate (struct xcheck_state *s,uint64_t new) +{ +uint32_t hw_size; + +BUILD_BUG_ON (X86_XCR0_STATES &X86_XSS_STATES ); + +BUG_ON (s->states & new);/* States only increase. */ +BUG_ON (!valid_xcr0 (s->states | new));/* Xen thinks it's a good value. */ +BUG_ON (new & ~(X86_XCR0_STATES |X86_XSS_STATES ));/* Known state. */ +BUG_ON ((new &X86_XCR0_STATES ) && + (new &X86_XSS_STATES ));/* User or supervisor, not both. */ + + s->states |= new; +if ( new &X86_XCR0_STATES ) + { +if ( !set_xcr0 (s->states &X86_XCR0_STATES ) ) +BUG (); + } +else +set_msr_xss (s->states &X86_XSS_STATES ); +
Quoted 8 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 646
Quoted 6 lines
xen/arch/x86/xstate.c +6
-0+/* +* Check the uncompressed size. Some XSTATEs are out-of-order and fill in +* prior holes in the state area, so we check that the size doesn't +* decrease. +*/ + hw_size =cpuid_count_ebx (0xd ,0 );Going forward, do we mean to get rid of
XSTATE_CPUID? Else imo it should be used here (and again below).
All documentation about CPUID, from the vendors and from secondary sources, is written in terms of numerals, not names.
XSTATE_CPUID is less meaningful than 0xd, and I would prefer to phase it out.
Quoted 7 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 652
Quoted 5 lines
xen/arch/x86/xstate.c +5
-0+if ( hw_size < s->uncomp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, uncompressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->uncomp_size); + + s->uncomp_size = hw_size;Since XSS state doesn't affect uncompressed layout, this looks like largely dead code for that case. Did you consider moving this into the
if()above?
If that were a printk() rather than a panic(), then having the assignment in the if() would be wrong.
So while it doesn't really matter given the way the logic is currently written, it's more code, and interferes with manual debugging to move the check into the if().
Quoted 1 line
Alternatively, should the comparison use == when dealing with XSS bits?
Hmm. We probably can make this check work, given that we ascend through user states first, and the supervisor states second.
Although I'd need to rerun such a change through the entire hardware lab. There have been enough unexpected surprises with "obvious" changes already.
Quoted 14 lines
Quoted 4 lines
xen/arch/x86/xstate.c +4
-0+/* +* Check the compressed size, if available. All components strictly +* appear in index order. In principle there are no holes, but some +* components have their base address 64-byte aligned for efficiency xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 667
Quoted 10 lines
xen/arch/x86/xstate.c +10
-0+* reasons (e.g. AMX-TILE) and there are other components small enough to +* fit in the gap (e.g. PKRU) without increasing the overall length. +*/ + hw_size =cpuid_count_ebx (0xd ,1 ); + +if ( cpu_has_xsavec ) + { +if ( hw_size < s->comp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, compressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->comp_size);
Quoted 2 lines
Unlike for uncompressed size, can't it be <= here, for - as the comment says - it being strictly index order, and no component having zero size?
The first version of this patch did have <=, and it really failed on SPR.
When you activate AMX first, then PKRU next, PKRU really does fit in the alignment hole, and the overall compressed size is the same.
It's a consequence of doing all the user states first, then all the supervisor states second. I did have them strictly in index order to begin with, but then hit the enumeration issue on Broadwell and reworked xstate_check_sizes() to have a single common cpu_has_xsaves around all supervisor states.
I could potentially undo that, but the consequence is needing an cpu_has_xsaves in every call passing in X86_XSS_*.
Quoted 84 lines
Quoted 84 lines
xen/arch/x86/xstate.c +84
-0+ s->comp_size = hw_size; + } +else if ( hw_size )/* Compressed size reported, but no XSAVEC ? */ + { +static bool once; + +if ( !once ) + { +WARN (); + once = true; + } + } +} + +/* +* The {un,}compressed XSTATE sizes are reported by dynamic CPUID value, based +* on the current %XCR0 and MSR_XSS values. The exact layout is also feature +* and vendor specific. Cross-check Xen's understanding against real hardware +* on boot. +* +* Testing every combination is prohibitive, so we use a partial approach. +* Starting with nothing active, we add new XSTATEs and check that the CPUID +* dynamic values never decreases. +*/ +static void __init noinline xstate_check_sizes(void) +{ +uint64_t old_xcr0 =get_xcr0 (); +uint64_t old_xss =get_msr_xss (); +struct xcheck_state s = {}; + +/* +* User XSTATEs, increasing by index. +* +* Chronologically, Intel and AMD had identical layouts for AVX (YMM). +* AMD introduced LWP in Fam15h, following immediately on from YMM. Intel +* left an LWP-shaped hole when adding MPX (BND{CSR,REGS}) in Skylake. +* AMD removed LWP in Fam17h, putting PKRU in the same space, breaking +* layout compatibility with Intel and having a knock-on effect on all +* subsequent states. +*/ +check_new_xstate (&s,X86_XCR0_SSE |X86_XCR0_FP ); + +if ( cpu_has_avx ) +check_new_xstate (&s,X86_XCR0_YMM ); + +if ( cpu_has_mpx ) +check_new_xstate (&s,X86_XCR0_BNDCSR |X86_XCR0_BNDREGS ); + +if ( cpu_has_avx512f ) +check_new_xstate (&s,X86_XCR0_HI_ZMM |X86_XCR0_ZMM |X86_XCR0_OPMASK ); + +if ( cpu_has_pku ) +check_new_xstate (&s,X86_XCR0_PKRU ); + +if (boot_cpu_has (X86_FEATURE_AMX_TILE ) ) +check_new_xstate (&s,X86_XCR0_TILE_DATA |X86_XCR0_TILE_CFG ); + +if (boot_cpu_has (X86_FEATURE_LWP ) ) +check_new_xstate (&s,X86_XCR0_LWP ); + +/* +* Supervisor XSTATEs, increasing by index. +* +* Intel Broadwell has Processor Trace but no XSAVES. There doesn't +* appear to have been a new enumeration when X86_XSS_PROC_TRACE was +* introduced in Skylake. +*/ +if ( cpu_has_xsaves ) + { +if ( cpu_has_proc_trace ) +check_new_xstate (&s,X86_XSS_PROC_TRACE ); + +if (boot_cpu_has (X86_FEATURE_ENQCMD ) ) +check_new_xstate (&s,X86_XSS_PASID ); + +if (boot_cpu_has (X86_FEATURE_CET_SS ) || +boot_cpu_has (X86_FEATURE_CET_IBT ) ) + { +check_new_xstate (&s,X86_XSS_CET_U ); +check_new_xstate (&s,X86_XSS_CET_S ); + } + +if (boot_cpu_has (X86_FEATURE_UINTR ) ) +check_new_xstate (&s,X86_XSS_UINTR );
Quoted 8 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 756
Quoted 4 lines
xen/arch/x86/xstate.c +4
-0+ +if (boot_cpu_has (X86_FEATURE_ARCH_LBR ) ) +check_new_xstate (&s,X86_XSS_LBR ); + }In principle compressed state checking could be extended to also verify the offsets are strictly increasing. That, however, would require to interleave XCR0 and XSS checks, strictly by index. Did you consider (and then discard) doing so?
What offsets are you referring to?
Compressed images have no offset information. Every "row" which has ecx.xss set has ebx (offset) reported as 0. The offset information for the user rows are only applicable for uncompressed images.
The layout of a compressed image is a strict function of RFBM derived from component sizes alone.
~Andrew
Re: [PATCH v4 2/7] x86/xstate: Cross-check dynamic XSTATE sizes at boot
Quoted 51 lines · Andrew Cooper
Quoted 41 lines · Jan Beulich
Quoted 40 lines · Andrew Cooper
xen/arch/x86/xstate.c +31
-0@@ -604,9 +604,164 @@ static bool valid_xcr0(uint64_t xcr0)if ( !(xcr0 &X86_XCR0_BNDREGS ) != !(xcr0 &X86_XCR0_BNDCSR ) )return false; +/* TILECFG and TILEDATA must be the same. */ +if ( !(xcr0 &X86_XCR0_TILE_CFG ) != !(xcr0 &X86_XCR0_TILE_DATA ) ) +return false; +return true; } +struct xcheck_state { +uint64_t states; +uint32_t uncomp_size; +uint32_t comp_size; +}; + +static void __init check_new_xstate (struct xcheck_state *s,uint64_t new) +{ +uint32_t hw_size; + +BUILD_BUG_ON (X86_XCR0_STATES &X86_XSS_STATES ); + +BUG_ON (s->states & new);/* States only increase. */ +BUG_ON (!valid_xcr0 (s->states | new));/* Xen thinks it's a good value. */ +BUG_ON (new & ~(X86_XCR0_STATES |X86_XSS_STATES ));/* Known state. */ +BUG_ON ((new &X86_XCR0_STATES ) && + (new &X86_XSS_STATES ));/* User or supervisor, not both. */ + + s->states |= new; +if ( new &X86_XCR0_STATES ) + { +if ( !set_xcr0 (s->states &X86_XCR0_STATES ) ) +BUG (); + } +else +set_msr_xss (s->states &X86_XSS_STATES ); +Quoted 8 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 646
Quoted 6 lines
xen/arch/x86/xstate.c +6
-0+/* +* Check the uncompressed size. Some XSTATEs are out-of-order and fill in +* prior holes in the state area, so we check that the size doesn't +* decrease. +*/ + hw_size =cpuid_count_ebx (0xd ,0 );Going forward, do we mean to get rid of
XSTATE_CPUID? Else imo it should be used here (and again below).
Quoted 5 lines
All documentation about CPUID, from the vendors and from secondary sources, is written in terms of numerals, not names.
XSTATE_CPUIDis less meaningful than0xd, and I would prefer to phase it out.
Fair enough; hence why I was asking.
Quoted 10 lines
Quoted 7 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 652
Quoted 5 lines
xen/arch/x86/xstate.c +5
-0+if ( hw_size < s->uncomp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, uncompressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->uncomp_size); + + s->uncomp_size = hw_size;Since XSS state doesn't affect uncompressed layout, this looks like largely dead code for that case. Did you consider moving this into the
if()above?If that were a
printk()rather than apanic(), then having the assignment in theif()would be wrong.
Would it? For an XSS component the uncompressed size isn't supposed to change. (Or else doing an == check, as per below, wouldn't be an option.)
Quoted 4 lines
So while it doesn't really matter given the way the logic is currently written, it's more code, and interferes with manual debugging to move the check into the
if().
Quoted 8 lines
Quoted 1 line
Alternatively, should the comparison use == when dealing with XSS bits?
Hmm. We probably can make this check work, given that we ascend through user states first, and the supervisor states second.
Although I'd need to rerun such a change through the entire hardware lab. There have been enough unexpected surprises with "obvious" changes already.
Well, we can of course decide to go with what you have for now, and then see about tightening the check. I fear though that doing so may then be forgotten ...
Quoted 23 lines
Quoted 14 lines
Quoted 4 lines
xen/arch/x86/xstate.c +4
-0+/* +* Check the compressed size, if available. All components strictly +* appear in index order. In principle there are no holes, but some +* components have their base address 64-byte aligned for efficiency xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 667
Quoted 10 lines
xen/arch/x86/xstate.c +10
-0+* reasons (e.g. AMX-TILE) and there are other components small enough to +* fit in the gap (e.g. PKRU) without increasing the overall length. +*/ + hw_size =cpuid_count_ebx (0xd ,1 ); + +if ( cpu_has_xsavec ) + { +if ( hw_size < s->comp_size ) +panic ("XSTATE 0x%016" PRIx64", new bits {%63pbl}, compressed hw size %#x < prev size %#x\n" , + s->states, &new, hw_size, s->comp_size);Quoted 2 lines
Unlike for uncompressed size, can't it be <= here, for - as the comment says - it being strictly index order, and no component having zero size?
The first version of this patch did have <=, and it really failed on SPR.
When you activate AMX first, then PKRU next, PKRU really does fit in the alignment hole, and the overall compressed size is the same.
Quoted 8 lines
It's a consequence of doing all the user states first, then all the supervisor states second. I did have them strictly in index order to begin with, but then hit the enumeration issue on Broadwell and reworked
xstate_check_sizes()to have a single commoncpu_has_xsavesaround all supervisor states.I could potentially undo that, but the consequence is needing an
cpu_has_xsavesin every call passing in X86_XSS_*.
Just to say as much: To me, doing things strictly in order would feel more "natural" (even if, see below, the other reason that would have seemed desirable, really has vaporized). Other than the need for cpu_has_xsaves, is there a particular reason you split things as all XCR0 first, then all XSS? (I'm a little worried anyway that this code will need updating for each new component addition. Yet "automating" this won't work, because of the need for the cpu_has_* checks.)
Quoted 93 lines
Quoted 84 lines
Quoted 84 lines
xen/arch/x86/xstate.c +84
-0+ s->comp_size = hw_size; + } +else if ( hw_size )/* Compressed size reported, but no XSAVEC ? */ + { +static bool once; + +if ( !once ) + { +WARN (); + once = true; + } + } +} + +/* +* The {un,}compressed XSTATE sizes are reported by dynamic CPUID value, based +* on the current %XCR0 and MSR_XSS values. The exact layout is also feature +* and vendor specific. Cross-check Xen's understanding against real hardware +* on boot. +* +* Testing every combination is prohibitive, so we use a partial approach. +* Starting with nothing active, we add new XSTATEs and check that the CPUID +* dynamic values never decreases. +*/ +static void __init noinline xstate_check_sizes(void) +{ +uint64_t old_xcr0 =get_xcr0 (); +uint64_t old_xss =get_msr_xss (); +struct xcheck_state s = {}; + +/* +* User XSTATEs, increasing by index. +* +* Chronologically, Intel and AMD had identical layouts for AVX (YMM). +* AMD introduced LWP in Fam15h, following immediately on from YMM. Intel +* left an LWP-shaped hole when adding MPX (BND{CSR,REGS}) in Skylake. +* AMD removed LWP in Fam17h, putting PKRU in the same space, breaking +* layout compatibility with Intel and having a knock-on effect on all +* subsequent states. +*/ +check_new_xstate (&s,X86_XCR0_SSE |X86_XCR0_FP ); + +if ( cpu_has_avx ) +check_new_xstate (&s,X86_XCR0_YMM ); + +if ( cpu_has_mpx ) +check_new_xstate (&s,X86_XCR0_BNDCSR |X86_XCR0_BNDREGS ); + +if ( cpu_has_avx512f ) +check_new_xstate (&s,X86_XCR0_HI_ZMM |X86_XCR0_ZMM |X86_XCR0_OPMASK ); + +if ( cpu_has_pku ) +check_new_xstate (&s,X86_XCR0_PKRU ); + +if (boot_cpu_has (X86_FEATURE_AMX_TILE ) ) +check_new_xstate (&s,X86_XCR0_TILE_DATA |X86_XCR0_TILE_CFG ); + +if (boot_cpu_has (X86_FEATURE_LWP ) ) +check_new_xstate (&s,X86_XCR0_LWP ); + +/* +* Supervisor XSTATEs, increasing by index. +* +* Intel Broadwell has Processor Trace but no XSAVES. There doesn't +* appear to have been a new enumeration when X86_XSS_PROC_TRACE was +* introduced in Skylake. +*/ +if ( cpu_has_xsaves ) + { +if ( cpu_has_proc_trace ) +check_new_xstate (&s,X86_XSS_PROC_TRACE ); + +if (boot_cpu_has (X86_FEATURE_ENQCMD ) ) +check_new_xstate (&s,X86_XSS_PASID ); + +if (boot_cpu_has (X86_FEATURE_CET_SS ) || +boot_cpu_has (X86_FEATURE_CET_IBT ) ) + { +check_new_xstate (&s,X86_XSS_CET_U ); +check_new_xstate (&s,X86_XSS_CET_S ); + } + +if (boot_cpu_has (X86_FEATURE_UINTR ) ) +check_new_xstate (&s,X86_XSS_UINTR );Quoted 8 lines
xen/arch/x86/xstate.c static bool valid_xcr0(uint64_t xcr0) · line 756
Quoted 4 lines
xen/arch/x86/xstate.c +4
-0+ +if (boot_cpu_has (X86_FEATURE_ARCH_LBR ) ) +check_new_xstate (&s,X86_XSS_LBR ); + }In principle compressed state checking could be extended to also verify the offsets are strictly increasing. That, however, would require to interleave XCR0 and XSS checks, strictly by index. Did you consider (and then discard) doing so?
Quoted 5 lines
What offsets are you referring to?
Compressed images have no offset information. Every "row" which has ecx.xss set has ebx (offset) reported as 0. The offset information for the user rows are only applicable for uncompressed images.
Hmm, right, nothing to compare our calculations against. And for the compressed form the (calculated) offsets aren't any different from the previous component's accumulated size.
Jan
PATCH v4 2/7 x86/xstate: Cross-check dynamic XSTATE sizes at boot
In reply to Andrew CooperRight now, xstate_ctxt_size() performs a cross-check of size with CPUID in for every call. This is expensive, being used for domain create/migrate, as well as to service certain guest CPUID instructions.
Instead, arrange to check the sizes once at boot. See the code comments for details. Right now, it just checks hardware against the algorithm expectations. Later patches will cross-check Xen's XSTATE calculations too.
Introduce more X86_XCR0_* and X86_XSS_* constants CPUID bits. This is to maximise coverage in the sanity check, even if we don't expect to use/virtualise some of these features any time soon. Leave HDC and HWP alone for now; we don't have CPUID bits from them stored nicely.
Only perform the cross-checks when SELF_TESTS are active. It's only developers or new hardware liable to trip these checks, and Xen at least tracks "maximum value ever seen in xcr0" for the lifetime of the VM, which we don't want to be tickling in the general case.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v3:
* New
v4:
* Rebase over CONFIG_SELF_TESTS
* Swap one BUG_ON() for a WARN()
v4.5:
* Reorder xstate_check_sizes() to strictly increase by index. In turn this strengthens the compressed check to "size always increases".
* For new superivsor states, check that the uncomressed size doesn't change.
On Sapphire Rapids with the whole series inc diagnostics, we get this pattern:
(XEN) *** check_new_xstate(, 0x00000003)
(XEN) *** check_new_xstate(, 0x00000004)
(XEN) *** check_new_xstate(, 0x000000e0)
(XEN) *** check_new_xstate(, 0x00000100)
(XEN) *** check_new_xstate(, 0x00000200)
(XEN) *** check_new_xstate(, 0x00000400)
(XEN) *** check_new_xstate(, 0x00000800)
(XEN) *** check_new_xstate(, 0x00001000)
(XEN) *** check_new_xstate(, 0x00004000)
(XEN) *** check_new_xstate(, 0x00008000)
(XEN) *** check_new_xstate(, 0x00060000)
and on Genoa, this pattern:
(Xen) *** check_new_xstate(, 0x00000003)
(Xen) *** check_new_xstate(, 0x00000004)
(Xen) *** check_new_xstate(, 0x000000e0)
(Xen) *** check_new_xstate(, 0x00000200)
(Xen) *** check_new_xstate(, 0x00000800)
(Xen) *** check_new_xstate(, 0x00001000)
--- xen/arch/x86/include/asm/x86-defns.h | 25 ++- xen/arch/x86/xstate.c | 170 ++++++++++++++++++++ xen/include/public/arch-x86/cpufeatureset.h | 3 + 3 files changed, 197 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/x86-defns.h +24 -1
@@ -77,7 +77,7 @@#define X86_CR4_PKS 0x01000000/* Protection Key Supervisor */ /* -* XSTATE component flags in XCR0 +* XSTATE component flags in XCR0 | MSR_XSS */ #define X86_XCR0_FP_POS 0#define X86_XCR0_FP (1ULL << X86_XCR0_FP_POS)
@@ -95,11 +95,34 @@#define X86_XCR0_ZMM (1ULL << X86_XCR0_ZMM_POS)#define X86_XCR0_HI_ZMM_POS 7#define X86_XCR0_HI_ZMM (1ULL << X86_XCR0_HI_ZMM_POS) +#define X86_XSS_PROC_TRACE (_AC(1, ULL) << 8)#define X86_XCR0_PKRU_POS 9#define X86_XCR0_PKRU (1ULL << X86_XCR0_PKRU_POS) +#define X86_XSS_PASID (_AC(1, ULL) << 10) +#define X86_XSS_CET_U (_AC(1, ULL) << 11) +#define X86_XSS_CET_S (_AC(1, ULL) << 12) +#define X86_XSS_HDC (_AC(1, ULL) << 13) +#define X86_XSS_UINTR (_AC(1, ULL) << 14) +#define X86_XSS_LBR (_AC(1, ULL) << 15) +#define X86_XSS_HWP (_AC(1, ULL) << 16) +#define X86_XCR0_TILE_CFG (_AC(1, ULL) << 17) +#define X86_XCR0_TILE_DATA (_AC(1, ULL) << 18)#define X86_XCR0_LWP_POS 62#define X86_XCR0_LWP (1ULL << X86_XCR0_LWP_POS) +#define X86_XCR0_STATES \ + (X86_XCR0_FP | X86_XCR0_SSE | X86_XCR0_YMM | X86_XCR0_BNDREGS | \ + X86_XCR0_BNDCSR | X86_XCR0_OPMASK | X86_XCR0_ZMM | \ + X86_XCR0_HI_ZMM | X86_XCR0_PKRU | X86_XCR0_TILE_CFG | \ + X86_XCR0_TILE_DATA | \ + X86_XCR0_LWP) + +#define X86_XSS_STATES \ + (X86_XSS_PROC_TRACE | X86_XSS_PASID | X86_XSS_CET_U | \ + X86_XSS_CET_S | X86_XSS_HDC | X86_XSS_UINTR | X86_XSS_LBR | \ + X86_XSS_HWP | \ + 0) +/* * Debug status flags in DR6. *
xen/arch/x86/xstate.c +170 -0
185 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +3 -0
@@ -266,6 +266,7 @@ XEN_CPUFEATURE(IBPB_RET, 8*32+30) /*A IBPB clears RSB/RAS too. */ XEN_CPUFEATURE(AVX512_4VNNIW, 9*32+ 2) /*A AVX512 Neural Network Instructions */ XEN_CPUFEATURE(AVX512_4FMAPS, 9*32+ 3) /*A AVX512 Multiply Accumulation Single Precision */ XEN_CPUFEATURE(FSRM, 9*32+ 4) /*A Fast Short REP MOVS */ +XEN_CPUFEATURE(UINTR, 9*32+ 5) /* User-mode Interrupts */ XEN_CPUFEATURE(AVX512_VP2INTERSECT, 9*32+8) /*a VP2INTERSECT{D,Q} insns */ XEN_CPUFEATURE(SRBDS_CTRL, 9*32+ 9) /* MSR_MCU_OPT_CTRL and RNGDS_MITG_DIS. */XEN_CPUFEATURE (MD_CLEAR ,9 *32 +10 )/*!A| VERW clears microarchitectural buffers */
@@ -274,8 +275,10 @@ XEN_CPUFEATURE(TSX_FORCE_ABORT, 9*32+13) /* MSR_TSX_FORCE_ABORT.RTM_ABORT */ XEN_CPUFEATURE(SERIALIZE, 9*32+14) /*A SERIALIZE insn */ XEN_CPUFEATURE(HYBRID, 9*32+15) /* Heterogeneous platform */ XEN_CPUFEATURE(TSXLDTRK, 9*32+16) /*a TSX load tracking suspend/resume insns */ +XEN_CPUFEATURE(ARCH_LBR, 9*32+19) /* Architectural Last Branch Record */ XEN_CPUFEATURE(CET_IBT, 9*32+20) /* CET - Indirect Branch Tracking */ XEN_CPUFEATURE(AVX512_FP16, 9*32+23) /*A AVX512 FP16 instructions */ +XEN_CPUFEATURE(AMX_TILE, 9*32+24) /* AMX Tile architecture */ 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. */
Signature · 1 line
2.39.2
Re: [PATCH for-4.19 v4.5 2/7] x86/xstate: Cross-check dynamic XSTATE sizes at boot
Quoted 13 lines · Andrew Cooper
Right now,
xstate_ctxt_size()performs a cross-check of size with CPUID in for every call. This is expensive, being used for domain create/migrate, as well as to service certain guest CPUID instructions.Instead, arrange to check the sizes once at boot. See the code comments for details. Right now, it just checks hardware against the algorithm expectations. Later patches will cross-check Xen's XSTATE calculations too.
Introduce more X86_XCR0_* and X86_XSS_* constants CPUID bits. This is to maximise coverage in the sanity check, even if we don't expect to use/virtualise some of these features any time soon. Leave HDC and HWP alone for now; we don't have CPUID bits from them stored nicely.
Quoted 6 lines
Only perform the cross-checks when
SELF_TESTSare active. It's only developers or new hardware liable to trip these checks, and Xen at least tracks "maximum value ever seen in xcr0" for the lifetime of the VM, which we don't want to be tickling in the general case.Signed-off-by Andrew Cooper <[email protected]>
PATCH v4 3/7 x86/boot: Collect the Raw CPU Policy earlier on boot
In reply to Andrew CooperThis is a tangle, but it's a small step in the right direction.
In the following change, xstate_init() is going to start using the Raw policy.
calculate_raw_cpu_policy() is sufficiently separate from the other policies to safely move like this.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
This is necessary for the forthcoming xstate_{un,}compressed_size() to perform boot-time sanity checks on state components which aren't fully enabled yet. I decided that doing this was better than extending the xstate_{offsets,sizes}[] logic that we're intending to retire in due course.
v3:
* New.
v4:
* Adjust commit message a little.
--- xen/arch/x86/cpu-policy.c | 1 - xen/arch/x86/setup.c | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/cpu-policy.c +0 -1
@@ -845,7 +845,6 @@ static void __init calculate_hvm_def_policy(void)void __init init_guest_cpu_policies (void ) { -calculate_raw_cpu_policy ();calculate_host_policy ();if (IS_ENABLED (CONFIG_PV ) )
xen/arch/x86/setup.c +3 -1
@@ -1888,7 +1888,9 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */ -identify_cpu (&boot_cpu_data); +calculate_raw_cpu_policy ();/* Needs microcode. No other dependenices. */ + +identify_cpu (&boot_cpu_data);/* Needs microcode and raw policy. */ set_in_cr4 (X86_CR4_OSFXSR |X86_CR4_OSXMMEXCPT );
Signature · 1 line
2.39.2
Re: [PATCH v4 3/7] x86/boot: Collect the Raw CPU Policy earlier on boot
Quoted 10 lines · Andrew Cooper
This is a tangle, but it's a small step in the right direction.
In the following change,
xstate_init()is going to start using the Raw policy.
calculate_raw_cpu_policy()is sufficiently separate from the other policies to safely move like this.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH v4 4/7 x86/xstate: Rework xstate_ctxt_size() as xstate_uncompressed_size()
In reply to Andrew CooperWe're soon going to need a compressed helper of the same form.
The size of the uncompressed image depends on the single element with the largest offset + size. Sadly this isn't always the element with the largest index.
Name the per-xstate-component cpu_policy struture, for legibility of the logic in xstate_uncompressed_size(). Cross-check with hardware during boot, and remove hw_uncompressed_size().
This means that the migration paths don't need to mess with XCR0 just to sanity check the buffer size. It also means we can drop the "fastpath" check against xfeature_mask (there to skip some XCR0 writes); this path is going to be dead logic the moment Xen starts using supervisor states itself.
The users of hw_uncompressed_size() in xstate_init() can (and indeed need) to be replaced with CPUID instructions. They run with feature_mask in XCR0, and prior to setup_xstate_features() on the BSP.
No practical change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v2:
* Scan all features. LWP/APX_F are out-of-order.
v3:
* Rebase over boot time check.
* Use the raw CPU policy.
v4:
* Explain the ASSERT() checking X86_XCR0_STATES.
* Drop the xfeature_mask check.
* Drop the comment about 0, because we'll probably never be able to clean up the use from the CPUID path.
--- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/include/asm/xstate.h | 2 +- xen/arch/x86/xstate.c | 76 ++++++++++++++++------------ xen/include/xen/lib/x86/cpu-policy.h | 2 +- 5 files changed, 49 insertions(+), 35 deletions(-)
xen/arch/x86/domctl.c +1 -1
@@ -833,7 +833,7 @@ long arch_do_domctl(uint32_t offset =0 ;#define PV_XSAVE_HDR_SIZE (2 * sizeof(uint64_t)) -#define PV_XSAVE_SIZE (xcr0) (PV_XSAVE_HDR_SIZE + xstate_ctxt_size(xcr0)) +#define PV_XSAVE_SIZE (xcr0) (PV_XSAVE_HDR_SIZE + xstate_uncompressed_size(xcr0)) ret = -ESRCH ; if ( (evc->vcpu >= d->max_vcpus) ||
xen/arch/x86/hvm/hvm.c +1 -1
@@ -1206,7 +1206,7 @@ HVM_REGISTER_SAVE_RESTORE(CPU, hvm_save_cpu_ctxt, NULL, hvm_load_cpu_ctxt, 1,#define HVM_CPU_XSAVE_SIZE (xcr0) (offsetof(struct hvm_hw_cpu_xsave, \ save_area) + \ - xstate_ctxt_size(xcr0)) + xstate_uncompressed_size(xcr0)) static int cf_check hvm_save_cpu_xsave_states(struct vcpu *v,hvm_domain_context_t *h)
xen/arch/x86/include/asm/xstate.h +1 -1
@@ -107,7 +107,7 @@ void compress_xsave_states(struct vcpu *v, const void *src, unsigned int size);void xstate_free_save_area (struct vcpu *v);int xstate_alloc_save_area (struct vcpu *v);void xstate_init (struct cpuinfo_x86 *c); -unsigned int xstate_ctxt_size (u64 xcr0); +unsigned int xstate_uncompressed_size (uint64_t xcr0);static inline uint64_t xgetbv (unsigned int index) {
xen/arch/x86/xstate.c +45 -31
130 lines not on this page · raw message
xen/include/xen/lib/x86/cpu-policy.h +1 -1
@@ -248,7 +248,7 @@ struct cpu_policy };/* Per-component common state. Valid for i >= 2. */ -struct { +struct xstate_component {uint32_t size, offset;bool xss:1 , align:1 ;uint32_t _res_d;
Signature · 1 line
2.39.2
Re: [PATCH v4 4/7] x86/xstate: Rework xstate_ctxt_size() as xstate_uncompressed_size()
Quoted 15 lines · Andrew Cooper
We're soon going to need a compressed helper of the same form.
The size of the uncompressed image depends on the single element with the largest offset + size. Sadly this isn't always the element with the largest index.
Name the per-xstate-component
cpu_policystruture, for legibility of the logic inxstate_uncompressed_size(). Cross-check with hardware during boot, and removehw_uncompressed_size().This means that the migration paths don't need to mess with XCR0 just to sanity check the buffer size. It also means we can drop the "fastpath" check against
xfeature_mask(there to skip some XCR0 writes); this path is going to be dead logic the moment Xen starts using supervisor states itself.
Quoted 7 lines
The users of
hw_uncompressed_size()inxstate_init()can (and indeed need) to be replaced with CPUID instructions. They run withfeature_maskin XCR0, and prior tosetup_xstate_features()on the BSP.No practical change.
Signed-off-by Andrew Cooper <[email protected]>
Albeit possibly also subject to use of XSTATE_CPUID, as per the question on the earlier patch.
Jan
PATCH v4 5/7 x86/cpu-policy: Simplify recalculate_xstate()
In reply to Andrew CooperMake use of xstate_uncompressed_size() helper rather than maintaining the running calculation while accumulating feature components.
The rest of the CPUID data can come direct from the raw cpu policy. All per-component data form an ABI through the behaviour of the X{SAVE,RSTOR}* instructions.
Use for_each_set_bit() rather than opencoding a slightly awkward version of it. Mask the attributes in ecx down based on the visible features. This isn't actually necessary for any components or attributes defined at the time of writing (up to AMX), but is added out of an abundance of caution.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v2:
* Tie ALIGN64 to xsavec rather than xsaves.
v3:
* Tweak commit message.
--- xen/arch/x86/cpu-policy.c | 55 +++++++++++-------------------- xen/arch/x86/include/asm/xstate.h | 1 + 2 files changed, 21 insertions(+), 35 deletions(-)
xen/arch/x86/cpu-policy.c +20 -35
@@ -193,8 +193,7 @@ static void sanitise_featureset(uint32_t *fs)static void recalculate_xstate (struct cpu_policy *p) {uint64_t xstates =XSTATE_FP_SSE ; -uint32_t xstate_size =XSTATE_AREA_MIN_SIZE ; -unsigned int i, Da1 = p->xstate.Da1; +unsigned int i, ecx_mask =0 , Da1 = p->xstate.Da1;/* * The Da1 leaf is the only piece of information preserved in the common
@@ -206,61 +205,47 @@ static void recalculate_xstate(struct cpu_policy *p)return ;if ( p->basic.avx ) - { xstates |=X86_XCR0_YMM ; - xstate_size =max (xstate_size, - xstate_offsets[X86_XCR0_YMM_POS ] + - xstate_sizes[X86_XCR0_YMM_POS ]); - }if ( p->feat.mpx ) - { xstates |=X86_XCR0_BNDREGS |X86_XCR0_BNDCSR ; - xstate_size =max (xstate_size, - xstate_offsets[X86_XCR0_BNDCSR_POS ] + - xstate_sizes[X86_XCR0_BNDCSR_POS ]); - }if ( p->feat.avx512f ) - { xstates |=X86_XCR0_OPMASK |X86_XCR0_ZMM |X86_XCR0_HI_ZMM ; - xstate_size =max (xstate_size, - xstate_offsets[X86_XCR0_HI_ZMM_POS ] + - xstate_sizes[X86_XCR0_HI_ZMM_POS ]); - }if ( p->feat.pku ) - { xstates |=X86_XCR0_PKRU ; - xstate_size =max (xstate_size, - xstate_offsets[X86_XCR0_PKRU_POS ] + - xstate_sizes[X86_XCR0_PKRU_POS ]); - } - p->xstate.max_size = xstate_size; +/* Subleaf 0 */ + p->xstate.max_size = +xstate_uncompressed_size (xstates & ~XSTATE_XSAVES_ONLY ); p->xstate.xcr0_low = xstates & ~XSTATE_XSAVES_ONLY ; p->xstate.xcr0_high = (xstates & ~XSTATE_XSAVES_ONLY ) >>32 ; +/* Subleaf 1 */ p->xstate.Da1 = Da1; +if ( p->xstate.xsavec ) + ecx_mask |=XSTATE_ALIGN64 ; +if ( p->xstate.xsaves ) { + ecx_mask |=XSTATE_XSS ; p->xstate.xss_low = xstates &XSTATE_XSAVES_ONLY ; p->xstate.xss_high = (xstates &XSTATE_XSAVES_ONLY ) >>32 ; } -else - xstates &= ~XSTATE_XSAVES_ONLY ; -for ( i =2 ; i <min (63UL ,ARRAY_SIZE (p->xstate.comp)); ++i ) +/* Subleafs 2+ */ + xstates &= ~XSTATE_FP_SSE ; +BUILD_BUG_ON (ARRAY_SIZE (p->xstate.comp) <63 ); + for_each_set_bit ( i, &xstates, 63 ) { -uint64_t curr_xstate =1UL << i; - -if ( !(xstates & curr_xstate) ) -continue ; - - p->xstate.comp[i].size = xstate_sizes[i]; - p->xstate.comp[i].offset = xstate_offsets[i]; - p->xstate.comp[i].xss = curr_xstate &XSTATE_XSAVES_ONLY ; - p->xstate.comp[i].align = curr_xstate & xstate_align; +/* +* Pass through size (eax) and offset (ebx) directly. Visbility of +* attributes in ecx limited by visible features in Da1. +*/ + p->xstate.raw[i].a = raw_cpu_policy.xstate.raw[i].a; + p->xstate.raw[i].b = raw_cpu_policy.xstate.raw[i].b; + p->xstate.raw[i].c = raw_cpu_policy.xstate.raw[i].c & ecx_mask; } }
xen/arch/x86/include/asm/xstate.h +1 -0
@@ -40,6 +40,7 @@ extern uint32_t mxcsr_mask;#define XSTATE_XSAVES_ONLY 0#define XSTATE_COMPACTION_ENABLED (1ULL << 63) +#define XSTATE_XSS (1U << 0)#define XSTATE_ALIGN64 (1U << 1)extern u64 xfeature_mask;
Signature · 1 line
2.39.2
PATCH v4 6/7 x86/cpuid: Fix handling of XSAVE dynamic leaves
In reply to Andrew CooperFirst, if XSAVE is available in hardware but not visible to the guest, the dynamic leaves shouldn't be filled in.
Second, the comment concerning XSS state is wrong. VT-x doesn't manage host/guest state automatically, but there is provision for "host only" bits to be set, so the implications are still accurate.
Introduce xstate_compressed_size() to mirror the uncompressed one. Cross check it at boot.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v3:
* Adjust commit message about !XSAVE guests
* Rebase over boot time cross check
* Use raw policy
v4:
* Drop the TODO comment. The CPUID path is always liable to pass 0 here.
* ASSERT() a nonzero c->size like we do in the uncompressed helper.
--- xen/arch/x86/cpuid.c | 24 +++++++-------------- xen/arch/x86/include/asm/xstate.h | 1 + xen/arch/x86/xstate.c | 36 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 16 deletions(-)
xen/arch/x86/cpuid.c +8 -16
@@ -330,23 +330,15 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,case XSTATE_CPUID :switch ( subleaf ) { -case 1 : -if ( !p->xstate.xsavec && !p->xstate.xsaves ) -break ; - -/* -* TODO: Figure out what to do for XSS state. VT-x manages host -* vs guest MSR_XSS automatically, so as soon as we start -* supporting any XSS states, the wrong XSS will be in context. -*/ -BUILD_BUG_ON (XSTATE_XSAVES_ONLY !=0 ); - fallthrough;case 0 : -/* -* Read CPUID[0xD,0/1].EBX from hardware. They vary with enabled -* XSTATE, and appropriate XCR0|XSS are in context. -*/ - res->b =cpuid_count_ebx (leaf, subleaf); +if ( p->basic.xsave ) + res->b =xstate_uncompressed_size (v->arch.xcr0); +break ; + +case 1 : +if ( p->xstate.xsavec ) + res->b =xstate_compressed_size (v->arch.xcr0 | + v->arch.msrs->xss.raw);break ; }break ;
xen/arch/x86/include/asm/xstate.h +1 -0
@@ -109,6 +109,7 @@ void xstate_free_save_area(struct vcpu *v);int xstate_alloc_save_area (struct vcpu *v);void xstate_init (struct cpuinfo_x86 *c);unsigned int xstate_uncompressed_size (uint64_t xcr0); +unsigned int xstate_compressed_size (uint64_t xstates);static inline uint64_t xgetbv (unsigned int index) {
xen/arch/x86/xstate.c +36 -0
@@ -619,6 +619,36 @@ unsigned int xstate_uncompressed_size(uint64_t xcr0)return size; } +unsigned int xstate_compressed_size (uint64_t xstates) +{ +unsigned int i, size =XSTATE_AREA_MIN_SIZE ; + +if ( xstates ==0 ) +return 0 ; + +if ( xstates <= (X86_XCR0_SSE |X86_XCR0_FP ) ) +return size; + +/* +* For the compressed size, every non-legacy component matters. Some +* componenets require aligning to 64 first. +*/ + xstates &= ~(X86_XCR0_SSE |X86_XCR0_FP ); + for_each_set_bit ( i, &xstates, 63 ) + { +const struct xstate_component *c = &raw_cpu_policy.xstate.comp[i]; + +ASSERT (c->size); + +if ( c->align ) + size =ROUNDUP (size,64 ); + + size += c->size; + } + +return size; +} +struct xcheck_state {uint64_t states;uint32_t uncomp_size;
@@ -681,6 +711,12 @@ static void __init check_new_xstate(struct xcheck_state *s, uint64_t new) s->states, &new, hw_size, s->comp_size); s->comp_size = hw_size; + + xen_size =xstate_compressed_size (s->states); + +if ( xen_size != hw_size ) +panic ("XSTATE 0x%016" PRIx64", compressed hw size %#x != xen size %#x\n" , + s->states, hw_size, xen_size); }else if ( hw_size )/* Compressed size reported, but no XSAVEC ? */ {
Signature · 1 line
2.39.2
PATCH v4 7/7 x86/defns: Clean up X86_{XCR0,XSS}_* constants
In reply to Andrew CooperWith the exception of one case in read_bndcfgu() which can use ilog2(), the *_POS defines are unused. Drop them.
X86_XCR0_X87 is the name used by both the SDM and APM, rather than X86_XCR0_FP.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Oleksii Kurochko <[email protected]>
v3:
* New
--- xen/arch/x86/i387.c | 2 +- xen/arch/x86/include/asm/x86-defns.h | 32 ++++++++++------------------ xen/arch/x86/include/asm/xstate.h | 4 ++-- xen/arch/x86/xstate.c | 18 ++++++++-------- 4 files changed, 23 insertions(+), 33 deletions(-)
xen/arch/x86/i387.c +1 -1
@@ -369,7 +369,7 @@ void vcpu_setup_fpu(struct vcpu *v, struct xsave_struct *xsave_area, { v->arch.xsave_area->xsave_hdr.xstate_bv &= ~XSTATE_FP_SSE ;if ( fcw_default !=FCW_DEFAULT ) - v->arch.xsave_area->xsave_hdr.xstate_bv |=X86_XCR0_FP ; + v->arch.xsave_area->xsave_hdr.xstate_bv |=X86_XCR0_X87 ; } }
xen/arch/x86/include/asm/x86-defns.h +11 -21
@@ -79,25 +79,16 @@/* * XSTATE component flags in XCR0 | MSR_XSS */ -#define X86_XCR0_FP_POS 0 -#define X86_XCR0_FP (1ULL << X86_XCR0_FP_POS) -#define X86_XCR0_SSE_POS 1 -#define X86_XCR0_SSE (1ULL << X86_XCR0_SSE_POS) -#define X86_XCR0_YMM_POS 2 -#define X86_XCR0_YMM (1ULL << X86_XCR0_YMM_POS) -#define X86_XCR0_BNDREGS_POS 3 -#define X86_XCR0_BNDREGS (1ULL << X86_XCR0_BNDREGS_POS) -#define X86_XCR0_BNDCSR_POS 4 -#define X86_XCR0_BNDCSR (1ULL << X86_XCR0_BNDCSR_POS) -#define X86_XCR0_OPMASK_POS 5 -#define X86_XCR0_OPMASK (1ULL << X86_XCR0_OPMASK_POS) -#define X86_XCR0_ZMM_POS 6 -#define X86_XCR0_ZMM (1ULL << X86_XCR0_ZMM_POS) -#define X86_XCR0_HI_ZMM_POS 7 -#define X86_XCR0_HI_ZMM (1ULL << X86_XCR0_HI_ZMM_POS) +#define X86_XCR0_X87 (_AC(1, ULL) << 0) +#define X86_XCR0_SSE (_AC(1, ULL) << 1) +#define X86_XCR0_YMM (_AC(1, ULL) << 2) +#define X86_XCR0_BNDREGS (_AC(1, ULL) << 3) +#define X86_XCR0_BNDCSR (_AC(1, ULL) << 4) +#define X86_XCR0_OPMASK (_AC(1, ULL) << 5) +#define X86_XCR0_ZMM (_AC(1, ULL) << 6) +#define X86_XCR0_HI_ZMM (_AC(1, ULL) << 7)#define X86_XSS_PROC_TRACE (_AC(1, ULL) << 8) -#define X86_XCR0_PKRU_POS 9 -#define X86_XCR0_PKRU (1ULL << X86_XCR0_PKRU_POS) +#define X86_XCR0_PKRU (_AC(1, ULL) << 9)#define X86_XSS_PASID (_AC(1, ULL) << 10)#define X86_XSS_CET_U (_AC(1, ULL) << 11)#define X86_XSS_CET_S (_AC(1, ULL) << 12)
@@ -107,11 +98,10 @@#define X86_XSS_HWP (_AC(1, ULL) << 16)#define X86_XCR0_TILE_CFG (_AC(1, ULL) << 17)#define X86_XCR0_TILE_DATA (_AC(1, ULL) << 18) -#define X86_XCR0_LWP_POS 62 -#define X86_XCR0_LWP (1ULL << X86_XCR0_LWP_POS) +#define X86_XCR0_LWP (_AC(1, ULL) << 62)#define X86_XCR0_STATES \ - (X86_XCR0_FP | X86_XCR0_SSE | X86_XCR0_YMM | X86_XCR0_BNDREGS | \ + (X86_XCR0_X87 | X86_XCR0_SSE | X86_XCR0_YMM | X86_XCR0_BNDREGS | \ X86_XCR0_BNDCSR | X86_XCR0_OPMASK | X86_XCR0_ZMM | \ X86_XCR0_HI_ZMM | X86_XCR0_PKRU | X86_XCR0_TILE_CFG | \ X86_XCR0_TILE_DATA | \
xen/arch/x86/include/asm/xstate.h +2 -2
@@ -29,8 +29,8 @@ extern uint32_t mxcsr_mask;#define XSAVE_HDR_OFFSET FXSAVE_SIZE#define XSTATE_AREA_MIN_SIZE (FXSAVE_SIZE + XSAVE_HDR_SIZE) -#define XSTATE_FP_SSE (X86_XCR0_FP | X86_XCR0_SSE) -#define XCNTXT_MASK (X86_XCR0_FP | X86_XCR0_SSE | X86_XCR0_YMM | \ +#define XSTATE_FP_SSE (X86_XCR0_X87 | X86_XCR0_SSE) +#define XCNTXT_MASK (X86_XCR0_X87 | X86_XCR0_SSE | X86_XCR0_YMM | \ X86_XCR0_OPMASK | X86_XCR0_ZMM | X86_XCR0_HI_ZMM | \ XSTATE_NONLAZY)
xen/arch/x86/xstate.c +9 -9
@@ -313,7 +313,7 @@ void xsave(struct vcpu *v, uint64_t mask) "=m" (*ptr), \ "a" (lmask), "d" (hmask), "D" (ptr)) -if ( fip_width ==8 || !(mask &X86_XCR0_FP ) ) +if ( fip_width ==8 || !(mask &X86_XCR0_X87 ) ) {XSAVE ("0x48," ); }
@@ -366,7 +366,7 @@ void xsave(struct vcpu *v, uint64_t mask) fip_width =8 ; }#undef XSAVE -if ( mask &X86_XCR0_FP ) +if ( mask &X86_XCR0_X87 ) ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET ] = fip_width; }
@@ -558,7 +558,7 @@ void xstate_free_save_area(struct vcpu *v)static bool valid_xcr0 (uint64_t xcr0) {/* FP must be unconditionally set. */ -if ( !(xcr0 &X86_XCR0_FP ) ) +if ( !(xcr0 &X86_XCR0_X87 ) )return false;/* YMM depends on SSE. */
@@ -597,7 +597,7 @@ unsigned int xstate_uncompressed_size(uint64_t xcr0)if ( xcr0 ==0 )return 0 ; -if ( xcr0 <= (X86_XCR0_SSE |X86_XCR0_FP ) ) +if ( xcr0 <= (X86_XCR0_SSE |X86_XCR0_X87 ) )return size;/*
@@ -605,7 +605,7 @@ unsigned int xstate_uncompressed_size(uint64_t xcr0)* maximum offset+size. Some states (e.g. LWP, APX_F) are out-of-order * with respect their index. */ - xcr0 &= ~(X86_XCR0_SSE |X86_XCR0_FP ); + xcr0 &= ~(X86_XCR0_SSE |X86_XCR0_X87 ); for_each_set_bit ( i, &xcr0, 63 ) {const struct xstate_component *c = &raw_cpu_policy.xstate.comp[i];
@@ -626,14 +626,14 @@ unsigned int xstate_compressed_size(uint64_t xstates)if ( xstates ==0 )return 0 ; -if ( xstates <= (X86_XCR0_SSE |X86_XCR0_FP ) ) +if ( xstates <= (X86_XCR0_SSE |X86_XCR0_X87 ) )return size;/* * For the compressed size, every non-legacy component matters. Some * componenets require aligning to 64 first. */ - xstates &= ~(X86_XCR0_SSE |X86_XCR0_FP ); + xstates &= ~(X86_XCR0_SSE |X86_XCR0_X87 ); for_each_set_bit ( i, &xstates, 63 ) {const struct xstate_component *c = &raw_cpu_policy.xstate.comp[i];
@@ -756,7 +756,7 @@ static void __init noinline xstate_check_sizes(void)* layout compatibility with Intel and having a knock-on effect on all * subsequent states. */ -check_new_xstate (&s,X86_XCR0_SSE |X86_XCR0_FP ); +check_new_xstate (&s,X86_XCR0_SSE |X86_XCR0_X87 );if ( cpu_has_avx )check_new_xstate (&s,X86_XCR0_YMM );
@@ -1008,7 +1008,7 @@ uint64_t read_bndcfgu(void) : "=m" (*xstate) : "a" (X86_XCR0_BNDCSR), "d" (0), "D" (xstate) ); - bndcsr = (void *)xstate + xstate_offsets[X86_XCR0_BNDCSR_POS ]; + bndcsr = (void *)xstate + xstate_offsets[ilog2 (X86_XCR0_BNDCSR )]; }if ( cr0 &X86_CR0_TS )
Signature · 1 line
2.39.2
Quoted 5 lines · Andrew Cooper
Only minor changes in v4 vs v3. See patches for details.
The end result has been tested across the entire XenServer hardware lab. This
found several false assupmtion about how the dynamic sizes behave.
~ Oleksii
Quoted 30 lines
Patches 1 and 6 the main bugfixes from this series. There's still lots more
work to do in order to get AMX and/or CET working, but this is at least a 4-yo
series finally off my plate.Andrew Cooper (7):
x86/xstate: Fix initialisation of XSS cache
x86/xstate: Cross-check dynamic XSTATE sizes at boot x86/boot: Collect the Raw CPU Policy earlier on boot x86/xstate: Reworkxstate_ctxt_size()asxstate_uncompressed_size()x86/cpu-policy: Simplifyrecalculate_xstate()
x86/cpuid: Fix handling of XSAVE dynamic leaves x86/defns: Clean up X86_{XCR0,XSS}_* constantsxen/arch/x86/cpu-policy.c | 56 ++-- xen/arch/x86/cpuid.c | 24 +- xen/arch/x86/domctl.c | 2 +- xen/arch/x86/hvm/hvm.c | 2 +- xen/arch/x86/i387.c | 2 +- xen/arch/x86/include/asm/x86-defns.h | 55 ++-- xen/arch/x86/include/asm/xstate.h | 8 +- xen/arch/x86/setup.c | 4 +- xen/arch/x86/xstate.c | 294 +++++++++++++++++- --
xen/include/public/arch-x86/cpufeatureset.h | 3 + xen/include/xen/lib/x86/cpu-policy.h | 2 +-11 files changed, 330 insertions(+), 122 deletions(-)