From: David Woodhouse <[email protected]>

I rebased Jörg's KVM Planes + SEV-SNP series¹ to 7.4-rc2² and used it
to add VSM support³. Here's a batch of fixes.

Thirteen of the sixteen apply in order, without conflicts, to the
kvm-planes-v7.1 branch. The other three need what has landed upstream
since v7.1: patch 1 fixes the s390 arm64 KVM module, which only
arrived in 7.4; patch 12 touches the PID-table clearing in
vmx_vcpu_free() from b41f2ca6c060; and patch 16 extends the VMSA
invalidation from d1a3c2162334.

The ones that matter:

 - 01 s390: arm64: Pass plane_level to the kvm_set_routing_entry() stub
   The arm64 KVM module on s390 kept the old prototype; the kernel
   test robot caught it on the rebased tree.

 - 05 Initialise Hyper-V state on every plane vCPU
   kvm_set_cpuid() passed the plane 0 vCPU to kvm_hv_vcpu_init() for
   every plane, and a twin created late got vp_index -1.

 - 08 Publish a new plane only once KVM_CREATE_PLANE cannot fail
   A failed create left a freed plane in kvm->planes[], where the SNP
   VMPL switch could still find it, and VM teardown freed it again.

 - 10 Keep current_vcpu in sync in vcpu_load()
   A reschedule inside an ioctl on a plane fd put and loaded the wrong
   twin, and a failed twin create left current_vcpu dangling.

 - 11 Load each plane twin while updating it after KVM_SET_CPUID
   On VMX the vendor callback wrote the twins' controls into the
   caller's VMCS.

 - 12 Leave the IPIv PID-table entry to the plane 0 vCPU
   A twin has the same vCPU ID as plane 0, so creating or freeing one
   repointed or cleared plane 0's entry. Latent for now, since planes
   inhibit APICv.

 - 13 Leave TSC matching to the plane 0 vCPUs
   Each twin counted as another vCPU with a matching TSC, so the master
   clock could never come back on.

 - 14 Derive runtime CPUID bits from the executing plane
   OSXSAVE, OSPKE, APIC, MWAIT and the XSAVE sizes follow per-plane
   registers, but the table they live in is shared.

Three things I've noticed and *not* fixed here:

 - The AVIC physical ID table is indexed by vCPU ID too, so it has the
   same collision as the IPIv PID table in patch 12. It's masked while
   APICv is inhibited for planes, as it is today.

 - A host-side TSC write on plane 0 (or KVM_SET_TSC_KHZ) after the
   twins exist doesn't reach them. Fixing that means loading each twin,
   and I'd rather agree how before doing it.

 - For Jörg and Tom: the SNP VMPL switch stops the current plane with
   kvm_vcpu_set_plane_stopped() and no latch, so KVM_GET_PLANE_RUN_STATE
   reports it as STOPPED, and a VMM that saves and restores that value
   turns it into a userspace stop. Does VMPL want a notion of
   KVM-initiated suspension of its own, or is that the intended
   contract?

¹ https://lore.kernel.org/all/[email protected]/
² 
https://git.infradead.org/?p=users/dwmw2/linux.git;a=shortlog;h=refs/heads/vsm2/planes-fixes
³ https://lore.kernel.org/kvm/[email protected]/

David Woodhouse (14):
  KVM: s390: arm64: Pass plane_level to the kvm_set_routing_entry() stub
  KVM: SVM: Derive the plane limit from the immutable VM type
  KVM: planes: Report KVM_MAX_PLANES from the system fd
  KVM: Guard the per-plane KVM_SIGNAL_MSI cases with __KVM_HAVE_MSI
  KVM: x86: Initialise Hyper-V state on every plane vCPU
  KVM: x86: Widen the plane vCPU fd ioctl allowlist
  KVM: x86/mmu: Free obsolete roots of all planes
  KVM: planes: Publish a new plane only once KVM_CREATE_PLANE cannot
    fail
  KVM: planes: Kick the running twin's pCPU, not the request target's
  KVM: planes: Keep current_vcpu in sync in vcpu_load()
  KVM: x86: Load each plane twin while updating it after KVM_SET_CPUID
  KVM: VMX: Leave the IPIv PID-table entry to the plane 0 vCPU
  KVM: planes: Annotate the lockless twin-publication protocol
  KVM: SVM: Make KVM_REQ_VMSA_PAGE_RELOAD per plane

Mushahid Hussain (2):
  KVM: x86: Leave TSC matching to the plane 0 vCPUs
  KVM: x86: Derive runtime CPUID bits from the executing plane

 Documentation/virt/kvm/api.rst  |  21 ++++--
 arch/s390/kvm/arm64/arm.c       |   3 +-
 arch/x86/include/asm/kvm_host.h |   3 +-
 arch/x86/kvm/cpuid.c            | 128 +++++++++++++++++++++++---------
 arch/x86/kvm/cpuid.h            |   6 +-
 arch/x86/kvm/hyperv.c           |   7 +-
 arch/x86/kvm/irq.c              |   5 +-
 arch/x86/kvm/mmu/mmu.c          |  16 +++-
 arch/x86/kvm/svm/sev.c          |  29 ++++++--
 arch/x86/kvm/svm/svm.c          |  10 ++-
 arch/x86/kvm/svm/svm.h          |   2 -
 arch/x86/kvm/vmx/vmx.c          |  10 ++-
 arch/x86/kvm/x86.c              |  87 ++++++++++++++++++++--
 include/linux/kvm_host.h        |   7 +-
 virt/kvm/kvm_main.c             | 115 +++++++++++++++++++++++-----
 15 files changed, 365 insertions(+), 84 deletions(-)

-- 
2.50.1


Reply via email to