All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <Andrew.Cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Wei Liu" <wl@xen.org>, "Roger Pau Monne" <roger.pau@citrix.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1
Date: Tue, 23 Aug 2022 08:59:17 +0000	[thread overview]
Message-ID: <27f97ef0-148d-a0c3-ae13-0ed4d640a10c@citrix.com> (raw)
In-Reply-To: <a4ec41e6-16cd-4452-19c1-5d6d9e3bddf8@suse.com>

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@suse.com>

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@citrix.com/
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


  reply	other threads:[~2022-08-23  8:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-23  6:42 [PATCH] x86/CPUID: surface suitable value in EBX of XSTATE subleaf 1 Jan Beulich
2022-08-23  8:59 ` Andrew Cooper [this message]
2022-08-23  9:27   ` Jan Beulich
2022-08-23 10:48     ` Andrew Cooper
2022-08-23 12:01       ` Jan Beulich
2022-08-24 12:02         ` Andrew Cooper
2022-08-24 12:11         ` Andrew Cooper
2022-08-24  6:00       ` Jan Beulich
2022-08-24 12:19         ` Andrew Cooper
2022-08-24 12:36           ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27f97ef0-148d-a0c3-ae13-0ed4d640a10c@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=roger.pau@citrix.com \
    --cc=tglx@linutronix.de \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.