From: "Liu, Jing2" <jing2.liu@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>
Cc: Yang Zhong <yang.zhong@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
x86@kernel.org, kvm@vger.kernel.org,
Sean Christoperson <seanjc@google.com>,
Jin Nakajima <jun.nakajima@intel.com>,
Kevin Tian <kevin.tian@intel.com>
Subject: Re: [patch 6/6] x86/fpu: Provide kvm_sync_guest_vmexit_xfd_state()
Date: Wed, 15 Dec 2021 14:35:36 +0800 [thread overview]
Message-ID: <62cc7ba5-8a46-2396-e728-cf5902c22306@linux.intel.com> (raw)
In-Reply-To: <20211214024948.108057289@linutronix.de>
Hi Thomas,
On 12/14/2021 10:50 AM, Thomas Gleixner wrote:
> KVM can disable the write emulation for the XFD MSR when the vCPU's fpstate
> is already correctly sized to reduce the overhead.
>
> When write emulation is disabled the XFD MSR state after a VMEXIT is
> unknown and therefore not in sync with the software states in fpstate and
> the per CPU XFD cache.
>
> Provide kvm_sync_guest_vmexit_xfd_state() which has to be invoked after a
> VMEXIT before enabling interrupts when write emulation is disabled for the
> XFD MSR.
Thanks for this function.
s/kvm_sync_guest_vmexit_xfd_state/fpu_sync_guest_vmexit_xfd_state
in subject and changelog.
Thanks,
Jing
>
> It could be invoked unconditionally even when write emulation is enabled
> for the price of a pointless MSR read.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
> arch/x86/include/asm/fpu/api.h | 6 ++++++
> arch/x86/kernel/fpu/core.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> --- a/arch/x86/include/asm/fpu/api.h
> +++ b/arch/x86/include/asm/fpu/api.h
> @@ -194,6 +194,12 @@ static inline int fpu_update_guest_xfd(s
> return __fpu_update_guest_features(guest_fpu, xcr0, xfd);
> }
>
> +#ifdef CONFIG_X86_64
> +extern void fpu_sync_guest_vmexit_xfd_state(void);
> +#else
> +static inline void fpu_sync_guest_vmexit_xfd_state(void) { }
> +#endif
> +
> extern void fpu_copy_guest_fpstate_to_uabi(struct fpu_guest *gfpu, void *buf, unsigned int size, u32 pkru);
> extern int fpu_copy_uabi_to_guest_fpstate(struct fpu_guest *gfpu, const void *buf, u64 xcr0, u32 *vpkru);
>
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -318,6 +318,32 @@ int __fpu_update_guest_features(struct f
> }
> EXPORT_SYMBOL_GPL(__fpu_update_guest_features);
>
> +#ifdef CONFIG_X86_64
> +/**
> + * fpu_sync_guest_vmexit_xfd_state - Synchronize XFD MSR and software state
> + *
> + * Must be invoked from KVM after a VMEXIT before enabling interrupts when
> + * XFD write emulation is disabled. This is required because the guest can
> + * freely modify XFD and the state at VMEXIT is not guaranteed to be the
> + * same as the state on VMENTER. So software state has to be udpated before
> + * any operation which depends on it can take place.
> + *
> + * Note: It can be invoked unconditionally even when write emulation is
> + * enabled for the price of a then pointless MSR read.
> + */
> +void fpu_sync_guest_vmexit_xfd_state(void)
> +{
> + struct fpstate *fps = current->thread.fpu.fpstate;
> +
> + lockdep_assert_irqs_disabled();
> + if (fpu_state_size_dynamic()) {
> + rdmsrl(MSR_IA32_XFD, fps->xfd);
> + __this_cpu_write(xfd_state, fps->xfd);
> + }
> +}
> +EXPORT_SYMBOL_GPL(fpu_sync_guest_vmexit_xfd_state);
> +#endif /* CONFIG_X86_64 */
> +
> int fpu_swap_kvm_fpstate(struct fpu_guest *guest_fpu, bool enter_guest)
> {
> struct fpstate *guest_fps = guest_fpu->fpstate;
>
next prev parent reply other threads:[~2021-12-15 6:35 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 2:50 [patch 0/6] x86/fpu: Preparatory changes for guest AMX support Thomas Gleixner
2021-12-14 2:50 ` [patch 1/6] x86/fpu: Extend fpu_xstate_prctl() with guest permissions Thomas Gleixner
2021-12-14 5:13 ` Tian, Kevin
2021-12-14 10:37 ` Paolo Bonzini
2021-12-14 2:50 ` [patch 2/6] x86/fpu: Prepare guest FPU for dynamically enabled FPU features Thomas Gleixner
2021-12-14 2:50 ` [patch 3/6] x86/fpu: Make XFD initialization in __fpstate_reset() a function argument Thomas Gleixner
2021-12-14 2:50 ` [patch 4/6] x86/fpu: Add guest support to xfd_enable_feature() Thomas Gleixner
2021-12-14 6:05 ` Tian, Kevin
2021-12-14 10:21 ` Paolo Bonzini
2021-12-14 13:15 ` Thomas Gleixner
2021-12-15 5:46 ` Tian, Kevin
2021-12-15 9:53 ` Thomas Gleixner
2021-12-15 10:02 ` Tian, Kevin
2021-12-14 2:50 ` [patch 5/6] x86/fpu: Provide fpu_update_guest_xcr0/xfd() Thomas Gleixner
2021-12-14 6:25 ` Tian, Kevin
2021-12-14 15:09 ` Wang, Wei W
2021-12-14 15:40 ` Thomas Gleixner
2021-12-14 16:11 ` Wang, Wei W
2021-12-14 18:04 ` Thomas Gleixner
2021-12-14 19:07 ` Juan Quintela
2021-12-14 20:28 ` Thomas Gleixner
2021-12-14 21:35 ` Juan Quintela
2021-12-15 2:17 ` Wang, Wei W
2021-12-15 10:09 ` Thomas Gleixner
2021-12-15 10:27 ` Paolo Bonzini
2021-12-15 10:41 ` Paolo Bonzini
2021-12-16 1:00 ` Tian, Kevin
2021-12-16 5:36 ` Tian, Kevin
2021-12-16 21:07 ` Paolo Bonzini
2021-12-16 10:21 ` Tian, Kevin
2021-12-16 10:24 ` Paolo Bonzini
2021-12-16 10:26 ` Paolo Bonzini
2021-12-16 13:00 ` Tian, Kevin
2021-12-16 1:04 ` Tian, Kevin
2021-12-16 9:34 ` Thomas Gleixner
2021-12-16 9:59 ` Tian, Kevin
2021-12-16 14:12 ` Thomas Gleixner
2021-12-17 15:33 ` Tian, Kevin
2021-12-15 6:14 ` Tian, Kevin
2021-12-14 2:50 ` [patch 6/6] x86/fpu: Provide kvm_sync_guest_vmexit_xfd_state() Thomas Gleixner
2021-12-15 6:35 ` Liu, Jing2 [this message]
2021-12-15 9:49 ` Thomas Gleixner
2021-12-14 6:50 ` [patch 0/6] x86/fpu: Preparatory changes for guest AMX support Tian, Kevin
2021-12-14 6:52 ` Liu, Jing2
2021-12-14 7:54 ` Tian, Kevin
2021-12-14 10:42 ` Paolo Bonzini
2021-12-14 13:24 ` Thomas Gleixner
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=62cc7ba5-8a46-2396-e728-cf5902c22306@linux.intel.com \
--to=jing2.liu@linux.intel.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yang.zhong@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