All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 0/6] x86/fpu: Preparatory changes for guest AMX support
@ 2021-12-14  2:50 Thomas Gleixner
  2021-12-14  2:50 ` [patch 1/6] x86/fpu: Extend fpu_xstate_prctl() with guest permissions Thomas Gleixner
                   ` (8 more replies)
  0 siblings, 9 replies; 47+ messages in thread
From: Thomas Gleixner @ 2021-12-14  2:50 UTC (permalink / raw)
  To: LKML
  Cc: Jing Liu, Yang Zhong, Paolo Bonzini, x86, kvm,
	Sean Christoperson, Jin Nakajima, Kevin Tian

Folks,

this is a follow up to the initial sketch of patches which got picked up by
Jing and have been posted in combination with the KVM parts:

   https://lore.kernel.org/r/20211208000359.2853257-1-yang.zhong@intel.com

This update is only touching the x86/fpu code and not changing anything on
the KVM side.

    BIG FAT WARNING: This is compile tested only!

In course of the dicsussion of the above patchset it turned out that there
are a few conceptual issues vs. hardware and software state and also
vs. guest restore.

This series addresses this with the following changes vs. the original
approach:

  1) fpstate reallocation is now independent of fpu_swap_kvm_fpstate()

     It is triggered directly via XSETBV and XFD MSR write emulation which
     are used both for runtime and restore purposes.

     For this it provides two wrappers around a common update function, one
     for XCR0 and one for XFD.

     Both check the validity of the arguments and the correct sizing of the
     guest FPU fpstate. If the size is not sufficient, fpstate is
     reallocated.

     The functions can fail.

  2) XFD synchronization

     KVM must neither touch the XFD MSR nor the fpstate->xfd software state
     in order to guarantee state consistency.

     In the MSR write emulation case the XFD specific update handler has to
     be invoked. See #1

     If MSR write emulation is disabled because the buffer size is
     sufficient for all use cases, i.e.:

     		guest_fpu::xfeatures == guest_fpu::perm

     then there is no guarantee that the XFD software state on VMEXIT is
     the same as the state on VMENTER.

     A separate synchronization function is provided which reads the XFD
     MSR and updates the relevant software state. This function has to be
     invoked after a VMEXIT before reenabling interrupts.

With that the KVM logic looks like this:

     xsetbv_emulate()
	ret = fpu_update_guest_xcr0(&vcpu->arch.guest_fpu, xcr0);
	if (ret)
		handle_fail()
	....


     kvm_emulate_wrmsr()
        ....
	case MSR_IA32_XFD:
	     ret = fpu_update_guest_xfd(&vcpu->arch.guest_fpu, vcpu->arch.xcr0, msrval);
	     if (ret)
		handle_fail()
	     ....

This covers both the case of a running vCPU and the case of restore.

The XFD synchronization mechanism is only relevant for a running vCPU after
VMEXIT when XFD MSR write emulation is disabled:

     vcpu_run()
	vcpu_enter_guest()
	  for (;;) {
	      ...
	      vmenter();
	      ...
	  };
	  ...

	  if (!xfd_write_emulated(vcpu))
		fpu_sync_guest_vmexit_xfd_state();

	  local_irq_enable();

It has no relevance for the guest restore case.

With that all XFD/fpstate related issues should be covered in a consistent
way.

CPUID validation can be done without exporting yet more FPU functions:

      if (requested_xfeatures & ~vcpu->arch.guest_fpu.perm)
      		return -ENOPONY;

That's the purpose of fpu_guest::perm from the beginning along with
fpu_guest::xfeatures for other validation purposes.

XFD_ERR MSR handling is completely separate and as discussed a KVM only
issue for now. KVM has to ensure that the MSR is 0 before interrupts are
enabled. So this is not touched here.

The only remaining issue is the KVM XSTATE save/restore size checking which
probably requires some FPU core assistance. But that requires some more
thoughts vs. the IOCTL interface extension and once that is settled it
needs to be solved in one go. But that's an orthogonal issue to the above.

The series is also available from git:

   git://git.kernel.org/pub/scm/linux/kernel/git/people/tglx/devel.git x86/fpu-kvm

Thanks,

	tglx
---
 include/asm/fpu/api.h    |   63 ++++++++++++++++++++++++
 include/asm/fpu/types.h  |   22 ++++++++
 include/uapi/asm/prctl.h |   26 +++++----
 kernel/fpu/core.c        |  123 ++++++++++++++++++++++++++++++++++++++++++++---
 kernel/fpu/xstate.c      |  118 +++++++++++++++++++++++++++------------------
 kernel/fpu/xstate.h      |   20 ++++++-
 kernel/process.c         |    2 
 7 files changed, 307 insertions(+), 67 deletions(-)

^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2021-12-17 15:34 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.