[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v2 4/4] x86/cpuid: Fix handling of xsave dynamic leaves
On 29.04.2024 20:28, Andrew Cooper wrote: > If max leaf is greater than 0xd but xsave not available to the guest, then the > current XSAVE size should not be filled in. This is a latent bug for now as > the guest max leaf is 0xd, but will become problematic in the future. Why would this not be an issue when .max_leaf == 0xd, but .xsave == 0? Without my "x86/CPUID: shrink max_{,sub}leaf fields according to actual leaf contents" I don't think we shrink max_leaf to below 0xd when there's no xsave for the guest? > 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,hw}_compressed_size() helpers to mirror the uncompressed > ones. > > This in turn higlights a bug in xstate_init(). Defaulting this_cpu(xss) to ~0 > requires a forced write to clear it back out. This in turn highlights that > it's only a safe default on systems with XSAVES. Well, yes, such an explicit write was expected to appear when some xsaves- based component would actually be enabled. Much like the set_xcr0() there. > Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> > --- > CC: Jan Beulich <JBeulich@xxxxxxxx> > CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> > > The more I think about it, the more I think that cross-checking with hardware > is a bad move. It's horribly expensive, and for supervisor states in > particular, liable to interfere with functionality. I agree, but I'd also like to see the cross checking not dropped entirely. Can't we arrange for such to happen during boot, before we enable any such functionality? After all even in debug builds it's not overly useful to do the same cross-checking (i.e. for identical inputs) over and over again. Of course doing in an exhaustive manner may be okay for the uncompressed values, but might be a little too much for all possible combinations in order to check compressed values, too. > --- a/xen/arch/x86/xstate.c > +++ b/xen/arch/x86/xstate.c > @@ -614,6 +614,65 @@ unsigned int xstate_uncompressed_size(uint64_t xcr0) > return size; > } > > +static unsigned int hw_compressed_size(uint64_t xstates) > +{ > + uint64_t curr_xcr0 = get_xcr0(), curr_xss = get_msr_xss(); > + unsigned int size; > + bool ok; > + > + ok = set_xcr0(xstates & ~XSTATE_XSAVES_ONLY); > + ASSERT(ok); > + set_msr_xss(xstates & XSTATE_XSAVES_ONLY); > + > + size = cpuid_count_ebx(XSTATE_CPUID, 1); > + > + ok = set_xcr0(curr_xcr0); > + ASSERT(ok); > + set_msr_xss(curr_xss); > + > + return size; > +} > + > +unsigned int xstate_compressed_size(uint64_t xstates) > +{ > + unsigned int i, size = XSTATE_AREA_MIN_SIZE; > + > + if ( xstates == 0 ) /* TODO: clean up paths passing 0 in here. */ > + return 0; > + > + if ( xstates <= (X86_XCR0_SSE | X86_XCR0_FP) ) Same comment as on the earlier change regarding the (lack of) use of .... > + return size; > + > + /* > + * For the compressed size, every component matters. Some are > + * automatically rounded up to 64 first. > + */ > + xstates &= ~XSTATE_FP_SSE; ... this constant up there. > + for_each_set_bit ( i, &xstates, 63 ) > + { > + if ( test_bit(i, &xstate_align) ) > + size = ROUNDUP(size, 64); > + > + size += xstate_sizes[i]; > + } The comment is a little misleading: As you have it in code, it is not the component's size that is rounded up, but its position. Maybe "Some have their start automatically rounded up to 64 first"? Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |