From: Mingwei Zhang <mizhang@google.com>
To: "Chang S. Bae" <chang.seok.bae@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Jim Mattson <jmattson@google.com>,
Venkatesh Srinivas <venkateshs@google.com>,
Aaron Lewis <aaronlewis@google.com>,
Chao Gao <chao.gao@intel.com>
Subject: Re: [PATCH v3 01/13] x86/fpu/xstate: Avoid getting xstate address of init_fpstate if fpstate contains the component
Date: Sat, 25 Feb 2023 01:09:24 +0000 [thread overview]
Message-ID: <Y/lfxHXVdqeFadGD@google.com> (raw)
In-Reply-To: <691106c3-b339-578b-6e43-77f737f127f9@intel.com>
On Fri, Feb 24, 2023, Chang S. Bae wrote:
> On 2/24/2023 3:56 PM, Mingwei Zhang wrote:
> > On Wed, Feb 22, 2023, Chang S. Bae wrote:
> > >
> > > /*
> > > - * The ptrace buffer is in non-compacted XSAVE format. In
> > > - * non-compacted format disabled features still occupy state space,
> > > - * but there is no state to copy from in the compacted
> > > - * init_fpstate. The gap tracking will zero these states.
> > > + * Indicate which states to copy from fpstate. When not present in
> > > + * fpstate, those extended states are either initialized or
> > > + * disabled. They are also known to have an all zeros init state.
> > > + * Thus, remove them from 'mask' to zero those features in the user
> > > + * buffer instead of retrieving them from init_fpstate.
> > > */
> > > - mask = fpstate->user_xfeatures;
> >
> > Do we need to change this line and the comments? I don't see any of
> > these was relevant to this issue. The original code semantic is to
> > traverse all user_xfeatures, if it is available in fpstate, copy it from
> > there; otherwise, copy it from init_fpstate. We do not assume the
> > component in init_fpstate (but not in fpstate) are all zeros, do we? If
> > it is safe to assume that, then it might be ok. But at least in this
> > patch, I want to keep the original semantics as is without the
> > assumption.
>
> Here it has [1]:
>
> *
> * XSAVE could be used, but that would require to reshuffle the
> * data when XSAVEC/S is available because XSAVEC/S uses xstate
> * compaction. But doing so is a pointless exercise because most
> * components have an all zeros init state except for the legacy
> * ones (FP and SSE). Those can be saved with FXSAVE into the
> * legacy area. Adding new features requires to ensure that init
> * state is all zeroes or if not to add the necessary handling
> * here.
> */
> fxsave(&init_fpstate.regs.fxsave);
ah, I see.
>
> Thus, init_fpstate has zeros for those extended states. Then, copying from
> init_fpstate is the same as membuf_zero() by the gap tracking. But, we have
> two ways to do the same thing here.
>
> So I think it works that simply copying the state from fpstate only for
> those present there, then letting the gap tracking zero out for the rest of
> the userspace buffer for features that are either disabled or initialized.
>
> Then, we can remove accessing init_fpstate in the copy loop and which is the
> source of the problem. So I think this line change is relevant and also
> makes the code simple.
>
> I guess I'm fine if you don't want to do this. Then, let me follow up with
> something like this at first. Something like yours could be a fallback
> option for other good reasons, otherwise.
hmm. I see. But this is still because of the software implementation.
What if there is a new hardware component that requires a non-zero init
state.
For instance, in the past, we had PKRU component, whose init value is
0x555...54. Of course, that is a bad example because now we kick it out
of the XSAVE/XRSTOR and special handling that, but there is no guarantee
that in the future we will never need a non-zero init state.
So, I will send out my fix and let you, Thomas and potentially other
folks to decide what is the best option. Overall, I get your point.
Thanks
-Mingwei
>
> Thanks,
> Chang
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/fpu/xstate.c#n386
>
>
next prev parent reply other threads:[~2023-02-25 1:09 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-21 16:36 [PATCH v3 00/13] Overhauling amx_test Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 01/13] x86/fpu/xstate: Avoid getting xstate address of init_fpstate if fpstate contains the component Mingwei Zhang
2023-02-21 20:54 ` Thomas Gleixner
2023-02-22 3:05 ` Chang S. Bae
2023-02-22 8:38 ` Thomas Gleixner
2023-02-22 18:40 ` Mingwei Zhang
2023-02-22 22:13 ` Chang S. Bae
2023-02-24 23:56 ` Mingwei Zhang
2023-02-25 0:47 ` Chang S. Bae
2023-02-25 1:09 ` Mingwei Zhang [this message]
2023-02-25 1:39 ` Chang S. Bae
2023-02-21 16:36 ` [PATCH v3 02/13] KVM: selftests: x86: Add a working xstate data structure Mingwei Zhang
2023-03-24 20:36 ` Sean Christopherson
2023-02-21 16:36 ` [PATCH v3 03/13] KVM: selftests: x86: Fix an error in comment of amx_test Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 04/13] KVM: selftests: x86: Enable checking on xcomp_bv in amx_test Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 05/13] KVM: selftests: x86: Add check of CR0.TS in the #NM handler " Mingwei Zhang
2023-03-24 20:38 ` Sean Christopherson
2023-02-21 16:36 ` [PATCH v3 06/13] KVM: selftests: x86: Add the XFD check to IA32_XFD in #NM handler Mingwei Zhang
2023-03-24 20:39 ` Sean Christopherson
2023-02-21 16:36 ` [PATCH v3 07/13] KVM: selftests: x86: Fix the checks to XFD_ERR using and operation Mingwei Zhang
2023-03-24 20:41 ` Sean Christopherson
2023-02-21 16:36 ` [PATCH v3 08/13] KVM: selftests: x86: Repeat the checking of xheader when IA32_XFD[XTILEDATA] is set in amx_test Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 09/13] KVM: selftests: x86: Assert that XTILE is XSAVE-enabled Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 10/13] KVM: selftests: x86: Assert that both XTILE{CFG,DATA} are XSAVE-enabled Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 11/13] KVM: selftests: x86: Remove redundant check that XSAVE is supported Mingwei Zhang
2023-03-24 20:43 ` Sean Christopherson
2023-02-21 16:36 ` [PATCH v3 12/13] KVM: selftests: x86: Check that the palette table exists before using it Mingwei Zhang
2023-02-21 16:36 ` [PATCH v3 13/13] KVM: selftests: x86: Check that XTILEDATA supports XFD Mingwei Zhang
2023-03-24 20:58 ` [PATCH v3 00/13] Overhauling amx_test Sean Christopherson
2023-03-24 21:01 ` Sean Christopherson
2023-03-24 21:30 ` Sean Christopherson
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=Y/lfxHXVdqeFadGD@google.com \
--to=mizhang@google.com \
--cc=aaronlewis@google.com \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=venkateshs@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).