From: Sean Christopherson <seanjc@google.com>
To: "Chang S. Bae" <chang.seok.bae@intel.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
hpa@zytor.com, avagin@gmail.com, kvm@vger.kernel.org
Subject: Re: [PATCH 3/4] x86/fpu: Clarify the XSTATE clearing only for extended components
Date: Sat, 17 Sep 2022 00:25:25 +0000 [thread overview]
Message-ID: <YyUT9VlEuXWMfsrP@google.com> (raw)
In-Reply-To: <20220916201158.8072-4-chang.seok.bae@intel.com>
On Fri, Sep 16, 2022, Chang S. Bae wrote:
> Commit 087df48c298c ("x86/fpu: Replace KVMs xstate component clearing")
> refactored the MPX state clearing code.
>
> But, legacy states are not warranted in this routine.
Why not? I could probably figure it out eventually, but that info should be
provided in the changelog.
> Rename the function to clarify that only extended components are acceptable.
The function rename isn't the interesting part of the patch, explicitly disallowing
"legacy" states is what's interesting. The shortlog+changelog should reflect that.
> Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
> Cc: x86@kernel.org
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> arch/x86/include/asm/fpu/api.h | 2 +-
> arch/x86/kernel/fpu/xstate.c | 7 +++++--
> arch/x86/kvm/x86.c | 4 ++--
> 3 files changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
> index 503a577814b2..c9d5dc85ca06 100644
> --- a/arch/x86/include/asm/fpu/api.h
> +++ b/arch/x86/include/asm/fpu/api.h
> @@ -130,7 +130,7 @@ static inline void fpstate_free(struct fpu *fpu) { }
> #endif
>
> /* fpstate-related functions which are exported to KVM */
> -extern void fpstate_clear_xstate_component(struct fpstate *fps, unsigned int xfeature);
> +extern void fpstate_clear_extended_xstate(struct fpstate *fps, unsigned int xfeature);
>
> extern u64 xstate_get_guest_group_perm(void);
>
> diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
> index d7676cfc32eb..a35f91360e3f 100644
> --- a/arch/x86/kernel/fpu/xstate.c
> +++ b/arch/x86/kernel/fpu/xstate.c
> @@ -1371,14 +1371,17 @@ void xrstors(struct xregs_state *xstate, u64 mask)
> }
>
> #if IS_ENABLED(CONFIG_KVM)
> -void fpstate_clear_xstate_component(struct fpstate *fps, unsigned int xfeature)
> +void fpstate_clear_extended_xstate(struct fpstate *fps, unsigned int xfeature)
> {
> void *addr = get_xsave_addr(&fps->regs.xsave, xfeature);
>
> + if (xfeature <= XFEATURE_SSE)
This should WARN_ON_ONCE(), silently doing nothing in the presence of buggy code
isn't much better than clobbering state.
> + return;
> +
> if (addr)
> memset(addr, 0, xstate_sizes[xfeature]);
> }
> -EXPORT_SYMBOL_GPL(fpstate_clear_xstate_component);
> +EXPORT_SYMBOL_GPL(fpstate_clear_extended_xstate);
> #endif
>
> #ifdef CONFIG_X86_64
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 43a6a7efc6ec..82ab270ea734 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11760,8 +11760,8 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> if (init_event)
> kvm_put_guest_fpu(vcpu);
>
> - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDREGS);
> - fpstate_clear_xstate_component(fpstate, XFEATURE_BNDCSR);
> + fpstate_clear_extended_xstate(fpstate, XFEATURE_BNDREGS);
> + fpstate_clear_extended_xstate(fpstate, XFEATURE_BNDCSR);
From a KVM perspective, I strongly prefer the existing name. The "component"
part makes it very clear that the helper clears a single component, whereas it's
not obvious at first glances that the version without "component" only affects
the specified feature.
The obvious alternative is something like fpstate_clear_extended_xstate_component(),
but I don't really see the point. "xstate" is "extended state" after all, which
is partly why I find fpstate_clear_extended_xstate() confusing; it makes me think
the helper is for some fancy "extended extended state".
next prev parent reply other threads:[~2022-09-17 0:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 20:11 [PATCH 0/4] x86/fpu: Fix MXCSR handling and SSE component definition Chang S. Bae
2022-09-16 20:11 ` [PATCH 1/4] x86/fpu: Fix the MXCSR state reshuffling between userspace and kernel buffers Chang S. Bae
2022-09-16 20:11 ` [PATCH 2/4] selftests/x86/mxcsr: Test the MXCSR state write via ptrace Chang S. Bae
2022-09-16 20:11 ` [PATCH 3/4] x86/fpu: Clarify the XSTATE clearing only for extended components Chang S. Bae
2022-09-17 0:25 ` Sean Christopherson [this message]
2022-09-16 20:11 ` [PATCH 4/4] x86/fpu: Correct the legacy state offset and size information 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=YyUT9VlEuXWMfsrP@google.com \
--to=seanjc@google.com \
--cc=avagin@gmail.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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.