[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • Date: Tue, 23 Aug 2022 08:59:17 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V9PhqpGn/KsmYU3j1aKqBBHT7BohlM4/U9f4V+NLOig=; b=R9Bx941TCiSCVZyEHM6LJUxNC41gVGH+hmaNYnISK0GW44CJ9vZZOnHl0mwqbc8QALQEynDz5eA1Y7gHc4N/uK5Mom/zL5qmC8KMnfgrrXAwfNTeVfKYPY25CLp87Mc3nUovfO7iax0YA59CmwV4fRkjLzTPSNUxaXI7xTWDk+ijBOxZO37FxpJuK69YtIcn+M3UDbh+0EDl6EhzmthaGmI9t4BsT08GJPeRFNwvfQR3UYT+fPCU+Tv0Wyvk/gP6yc0g3e2ZRuLvJQo4ZxWvuVmJT4iBDu9UW7aUHfzYq66vWNtYltHKKOClL/EKNjv128BjW7KkeM0UN94y3WpUlQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ccicQT5b6CGUYwphaAB+QfbwOvk1LqxfgcdLiS7njWMW3H8jvxUagoSpeK51NhxDek+QuX2c5UIdpR8tBLM76ah2C5MTEhd8832LON1oi7j8fOuRteSz5CHcRfOrUf0sHfW+/tmtAYDjp39I0jMbeWTR2FJaYEAt8r1GaE/dWZv7VBFMMuu7QeNRgkZ+RqtVmLn9zRX3GMXqkaVyEZ/ykwQahQeBNVOhSXuRmmf2A3RCc8H7xRMjIo6GAe6/Wd3s6I11MiItxo/RV7aQ3vA+k7BUMTpo6zEKQkSGeboSicxYBHB/nDnXGtXtygzu1Tonbcn163rlTg/WWS+DyjFgcA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>
  • Delivery-date: Tue, 23 Aug 2022 08:59:37 +0000
  • Ironport-data: A9a23:NU15lql0ozCWPwkzFVe7Dofo5mJPLRO08EFM2KgSY1vmP7IAGkQgjxdl23q3D9WdSWsbjYSa9Cl2TjqnBWN9arJuhPrzQlrcmafNfOKvFfQ/tuOhZJ+yecuwBSOG/nIFU+v9sTUN9U9gG+QbkrmlMFdhwNkk+ZPQdHNzqhxQOHcSKmGKKXGldnKPrsaiqcojRp6wNaxORNB066sGLrj2rJILAZ2SZ0ST8myStwg1H93e6B//fplV5GRHJEcfC4tzOwErl76EhCfnclADUquPRVtg50MQtkk1FSVX6TEwmc0kujQ9C6ik9eRSOvk9CzJqB7jjaFxwcPzpkU2cCX60lnp8cc6mBDtGuYsSSSYNWuXkv4j4v2OCq3vCPbX5WCfDO2GQEjw/Lep7yowV0refCHQBPM2tJhKrHMwvas1EZ/VsM2AAn18t861BeQz2FzxfAyJ49IVE0LZfeXMXyHuTl+BLntUjDgL6QMD6ocHVnsm92nLl1R6MuJ6oRI6vTwKW2yjQ3RHRJJSDTvZtHCB71Ph0qT45ZEaIHPFBXK936hE+mg3PkZv9DYWKH4Odl3yC4JmgRrC9Ch5dQ+YhNyimom2Se3pQg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OuGIcsFfYkFtGKCymYfLevYVFIjLh3rC8Qc5I82G7KmX/8VioKWM0apzxs/oEddCdndsuuvhMAtlQ3g+QL1aBslwwA8ve2Xdr4rgjWyd/Wo4TxgSd9DajyM65UsoKhVm0xPWllJkSjf8QTGvy2Ke6IBTtnQedtJghPg+3V2/w8pNH4hZduxx9PAPIkdvH/DfIq+cMM1O7yUWMQgvajknSYRirqP51164aCa5ifhdXbpIZLKhOoBsY9F11g3dcfi0ZTNkOmbwc7GsnNTkyIwk++Qwd5+lxqv4y947KcqJG90JDx6NsN+Jow3znjFeB4bVRPuSyD6fHeOz8LPWaNkZGUPiTmsLSbxljqhQDK282gOsCHWXlZ5ShRJSPwWeDkz1d58RWy4WlMJjT7Q7OHR/bEfx2H6iVtbhyObUhu1eFWNp7rMaV6cskarDULlPV5iwL/DfpdmRYi6wFjCI6a8lkUhpNJ3z5F9S7aAvmwCAf8sNeijuB9tdC2sbsonRF5Ef5vLJyRAQPwZO4JMDZV9IQrISHGr4ppskBjWZmtnaHKp12W8aO/ZL+9g+cFVqpIMQ2VbVGoG613jwUL2BE85N67dfkaIyt5U9yYuesYCbayWaMKEWrwG8nQZsk+ND1aqe52GIWbi6CmY9CNS4FxWi+UgrsBFdyXkATRfWncTqZxEbqW87pxQ8NzIlGSL3miN2+DE9rKIHw0KXGhKlKln0HKp9BA/sIbnzjwxkhuYWeo5gcKCJWAWiEecpzIyNG4jjDkAK+EPhJqji3S+EpNkwCbabFIxvrmMbOyxBNEDxFLDViqaAty8r9j7Qh5FqzOM0Znu3S6NE2qvqHLwueRV2/4zRGGM3DIFhe2b/eihgMeNd9pQMp9zuhEfkCFf9ulXBH11k7B+//i3wwPHEpnewuSBe5Wf6Lp10=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYtrt8/1v0WOY/4kiCtfQ8qrAcS628L8cA
  • Thread-topic: [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1

On 23/08/2022 07:42, Jan Beulich wrote:
> While the SDM isn't very clear about this, our present behavior make
> Linux 5.19 unhappy. As of commit 8ad7e8f69695 ("x86/fpu/xsave: Support
> XSAVEC in the kernel") they're using this CPUID output also to size
> the compacted area used by XSAVEC. Getting back zero there isn't really
> liked, yet fpr PV that's the default on capable hardware: XSAVES isn't

for.

> exposed to PV domains.
>
> Considering that the size reported is that of the compacted save area,
> I view Linux'es assumption as appropriate (short of the SDM properly
> considering the case). Therefore we need to populate the field also when
> only XSAVEC is supported for a guest.

This is a mess.  The SDM is fairly clear (but only in Vol1) that this
leaf is specific to XSAVES.  The APM has only an equation, which shows
it as the compacted size without reference to instructions.

Ideally I'd like the opinion from some architects and a clarification to
the SDM...

> Fixes: 460b9a4b3630 ("x86/xsaves: enable xsaves/xrstors for hvm guest")
> Fixes: 8d050ed1097c ("x86: don't expose XSAVES capability to PV guests")
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

CC Marek.  Looks like Jan has found the issue you reported on IRC.

Jan: Be aware that I submitted
https://lore.kernel.org/lkml/20220810221909.12768-1-andrew.cooper3@xxxxxxxxxx/
to Linux to correct some of the diagnostics.

> ---
> I actually wonder why we surface the XSAVES feature bit to HVM domains,
> when we don't support any of the features.

Because that's what was originally accepted into Xen, and I couldn't
retract it when fixing CPUID handling at first because it would regress
across migrate to a newer Xen.  With CPUID data now in the migration
stream, we could in principle fix it, but at this point it's definitely
not worth the complexity or risk to adjust.

>  It's solely because of this
> that by default only PV domains are affected by the issue (HVM would be
> affected only when XSAVES was hidden via guest config settings).
> Wouldn't we better mask the bit (e.g. in recalculate_xstate()) when we
> find that no features requiring XSAVES are visible to the domain? That
> would likely come closer to real hardware, which pretty certainly won't
> offer XSAVES without also offering at least one dependent feature.
>
> --- a/xen/arch/x86/cpuid.c
> +++ b/xen/arch/x86/cpuid.c
> @@ -1142,7 +1142,7 @@ void guest_cpuid(const struct vcpu *v, u
>          switch ( subleaf )
>          {
>          case 1:
> -            if ( p->xstate.xsaves )
> +            if ( p->xstate.xsavec || p->xstate.xsaves )

If we're doing this, then it wants to be xsavec only, with the comment
being extended to explain why.

But this is going to further complicate my several-year-old series
trying to get Xen's XSTATE handling into a position where we can start
to offer supervisor states.

>              {
>                  /*
>                   * TODO: Figure out what to do for XSS state.  VT-x manages


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.