From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: Dave Hansen <dave.hansen@intel.com>, <linux-kernel@vger.kernel.org>
Cc: <x86@kernel.org>, <tglx@linutronix.de>, <mingo@redhat.com>,
<bp@alien8.de>, <dave.hansen@linux.intel.com>, <hpa@zytor.com>,
<yuan.yao@intel.com>
Subject: Re: [PATCH 1/1] x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly
Date: Thu, 20 Oct 2022 11:52:26 -0700 [thread overview]
Message-ID: <8cc1bd3c-3b6e-6c3c-31e6-f39206013e67@intel.com> (raw)
In-Reply-To: <f086b776-75ad-47b1-e87a-7fb07c1cee3b@intel.com>
On 10/20/2022 9:57 AM, Dave Hansen wrote:
> On 10/18/22 15:13, Chang S. Bae wrote:
>> @@ -1141,10 +1141,14 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
>> */
>> pkru.pkru = pkru_val;
>> membuf_write(&to, &pkru, sizeof(pkru));
>> + } else if (!(header.xfeatures & BIT_ULL(i))) {
>> + /*
>> + * Every extended state component has an all zeros
>> + * init state.
>> + */
>> + membuf_zero(&to, xstate_sizes[i]);
>> } else {
>> - copy_feature(header.xfeatures & BIT_ULL(i), &to,
>> - __raw_xsave_addr(xsave, i),
>> - __raw_xsave_addr(xinit, i),
>> + membuf_write(&to, __raw_xsave_addr(xsave, i),
>> xstate_sizes[i]);
>> }
>
> Just to add a bit more context, this is inside this loop:
>
> mask = fpstate->user_xfeatures;
> for_each_extended_xfeature(i, mask) {
> if (zerofrom < xstate_offsets[i])
> membuf_zero(&to, xstate_offsets[i] - zerofrom);
> ...
> }
> if (to.left)
> membuf_zero(&to, to.left);
>
> In other words, the loop and the surrounding code already know how to
> membuf_zero() any gaps in the middle or the end of the user buffer.
> Would it be simpler to just adjust the 'mask' over which the loop iterates?
Yeah, right!
> I think that would end up being something like:
>
> mask = fpstate->user_xfeatures &
> (xsave->xfeatures | xinit->xfeatures);
>
> Logically, that makes sense too. We're copying out of either 'xsave' or
> 'xinit'. If a feature isn't in either one of those we can't do the
> copy_feature() on it.
Yes, it is. But, one tricky part here is xinit->xstate_bv is zero.
Instead, xinit->xcomp_bv appears to be relevant. Also, we want this for
dynamic features that rely on XSAVES. Then, the change can be something
like this:
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index e77cabfa802f..3f3286d7e1a8 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -1125,6 +1125,15 @@ void __copy_xstate_to_uabi_buf(struct membuf to,
struct fpstate *fpstate,
*/
mask = fpstate->user_xfeatures;
+ /*
+ * Dynamic features are not present in init_fpstate since they have
+ * an all zeros init state. When they are in init state, instead of
+ * retrieving them from init_fpstate, remove those from 'mask' to
+ * zero the user buffer.
+ */
+ if (fpu_state_size_dynamic())
+ mask &= (header.xfeatures | xinit->header.xcomp_bv);
Thanks,
Chang
next prev parent reply other threads:[~2022-10-20 18:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 19:12 [PATCH 0/3] x86/fpu: Improve the init_fpstate setup code Chang S. Bae
2022-08-24 19:12 ` [PATCH 1/3] x86/fpu: Configure init_fpstate attributes orderly Chang S. Bae
2022-10-03 21:18 ` Neel Natu
2022-10-17 13:47 ` [tip: x86/urgent] " tip-bot2 for Chang S. Bae
2022-08-24 19:12 ` [PATCH 2/3] x86/fpu: Fix the init_fpstate size check with the actual size Chang S. Bae
2022-10-17 13:47 ` [tip: x86/urgent] " tip-bot2 for Chang S. Bae
2022-08-24 19:12 ` [PATCH 3/3] x86/fpu: Exclude dynamic states from init_fpstate Chang S. Bae
2022-10-17 13:47 ` [tip: x86/urgent] " tip-bot2 for Chang S. Bae
2022-10-18 22:13 ` [PATCH 0/1] x86/fpu: Follow up on the init_fpstate fix Chang S. Bae
2022-10-18 22:13 ` [PATCH 1/1] x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly Chang S. Bae
2022-10-20 16:57 ` Dave Hansen
2022-10-20 18:52 ` Chang S. Bae [this message]
2022-10-21 18:58 ` [PATCH v2] " Chang S. Bae
2022-10-21 22:25 ` [tip: x86/urgent] " tip-bot2 for Chang S. Bae
2022-10-22 6:23 ` Ingo Molnar
2022-10-22 13:02 ` Chang S. Bae
2023-02-27 21:05 ` [PATCH 0/2] x86/fpu/xstate: Follow up on the init_fpstate fallout again Chang S. Bae
2023-02-27 21:05 ` [PATCH 1/2] x86/fpu/xstate: Prevent false-positive warning in __copy_xstate_uabi_buf() Chang S. Bae
2023-02-27 21:05 ` [PATCH 2/2] selftests/x86/amx: Add a ptrace test Chang S. Bae
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=8cc1bd3c-3b6e-6c3c-31e6-f39206013e67@intel.com \
--to=chang.seok.bae@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yuan.yao@intel.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
all inboxes | Powered by JetHome®