Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 1 May 2023 19:06:20 +0000 (12:06 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 1 May 2023 19:06:20 +0000 (12:06 -0700)
Pull kvm updates from Paolo Bonzini:
 "s390:

   - More phys_to_virt conversions

   - Improvement of AP management for VSIE (nested virtualization)

  ARM64:

   - Numerous fixes for the pathological lock inversion issue that
     plagued KVM/arm64 since... forever.

   - New framework allowing SMCCC-compliant hypercalls to be forwarded
     to userspace, hopefully paving the way for some more features being
     moved to VMMs rather than be implemented in the kernel.

   - Large rework of the timer code to allow a VM-wide offset to be
     applied to both virtual and physical counters as well as a
     per-timer, per-vcpu offset that complements the global one. This
     last part allows the NV timer code to be implemented on top.

   - A small set of fixes to make sure that we don't change anything
     affecting the EL1&0 translation regime just after having having
     taken an exception to EL2 until we have executed a DSB. This
     ensures that speculative walks started in EL1&0 have completed.

   - The usual selftest fixes and improvements.

  x86:

   - Optimize CR0.WP toggling by avoiding an MMU reload when TDP is
     enabled, and by giving the guest control of CR0.WP when EPT is
     enabled on VMX (VMX-only because SVM doesn't support per-bit
     controls)

   - Add CR0/CR4 helpers to query single bits, and clean up related code
     where KVM was interpreting kvm_read_cr4_bits()'s "unsigned long"
     return as a bool

   - Move AMD_PSFD to cpufeatures.h and purge KVM's definition

   - Avoid unnecessary writes+flushes when the guest is only adding new
     PTEs

   - Overhaul .sync_page() and .invlpg() to utilize .sync_page()'s
     optimizations when emulating invalidations

   - Clean up the range-based flushing APIs

   - Revamp the TDP MMU's reaping of Accessed/Dirty bits to clear a
     single A/D bit using a LOCK AND instead of XCHG, and skip all of
     the "handle changed SPTE" overhead associated with writing the
     entire entry

   - Track the number of "tail" entries in a pte_list_desc to avoid
     having to walk (potentially) all descriptors during insertion and
     deletion, which gets quite expensive if the guest is spamming
     fork()

   - Disallow virtualizing legacy LBRs if architectural LBRs are
     available, the two are mutually exclusive in hardware

   - Disallow writes to immutable feature MSRs (notably
     PERF_CAPABILITIES) after KVM_RUN, similar to CPUID features

   - Overhaul the vmx_pmu_caps selftest to better validate
     PERF_CAPABILITIES

   - Apply PMU filters to emulated events and add test coverage to the
     pmu_event_filter selftest

   - AMD SVM:
       - Add support for virtual NMIs
       - Fixes for edge cases related to virtual interrupts

   - Intel AMX:
       - Don't advertise XTILE_CFG in KVM_GET_SUPPORTED_CPUID if
         XTILE_DATA is not being reported due to userspace not opting in
         via prctl()
       - Fix a bug in emulation of ENCLS in compatibility mode
       - Allow emulation of NOP and PAUSE for L2
       - AMX selftests improvements
       - Misc cleanups

  MIPS:

   - Constify MIPS's internal callbacks (a leftover from the hardware
     enabling rework that landed in 6.3)

  Generic:

   - Drop unnecessary casts from "void *" throughout kvm_main.c

   - Tweak the layout of "struct kvm_mmu_memory_cache" to shrink the
     struct size by 8 bytes on 64-bit kernels by utilizing a padding
     hole

  Documentation:

   - Fix goof introduced by the conversion to rST"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (211 commits)
  KVM: s390: pci: fix virtual-physical confusion on module unload/load
  KVM: s390: vsie: clarifications on setting the APCB
  KVM: s390: interrupt: fix virtual-physical confusion for next alert GISA
  KVM: arm64: Have kvm_psci_vcpu_on() use WRITE_ONCE() to update mp_state
  KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init()
  KVM: selftests: Test the PMU event "Instructions retired"
  KVM: selftests: Copy full counter values from guest in PMU event filter test
  KVM: selftests: Use error codes to signal errors in PMU event filter test
  KVM: selftests: Print detailed info in PMU event filter asserts
  KVM: selftests: Add helpers for PMC asserts in PMU event filter test
  KVM: selftests: Add a common helper for the PMU event filter guest code
  KVM: selftests: Fix spelling mistake "perrmited" -> "permitted"
  KVM: arm64: vhe: Drop extra isb() on guest exit
  KVM: arm64: vhe: Synchronise with page table walker on MMU update
  KVM: arm64: pkvm: Document the side effects of kvm_flush_dcache_to_poc()
  KVM: arm64: nvhe: Synchronise with page table walker on TLBI
  KVM: arm64: Handle 32bit CNTPCTSS traps
  KVM: arm64: nvhe: Synchronise with page table walker on vcpu run
  KVM: arm64: vgic: Don't acquire its_lock before config_lock
  KVM: selftests: Add test to verify KVM's supported XCR0
  ...

23 files changed:
1  2 
Documentation/virt/kvm/api.rst
arch/arm64/include/asm/kvm_host.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kvm/arm.c
arch/arm64/kvm/hypercalls.c
arch/arm64/kvm/pmu-emul.c
arch/arm64/kvm/sys_regs.c
arch/arm64/tools/sysreg
arch/powerpc/include/asm/kvm_ppc.h
arch/powerpc/kvm/book3s_64_mmu_hv.c
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_pr.c
arch/powerpc/kvm/powerpc.c
arch/s390/kvm/kvm-s390.c
arch/x86/include/asm/cpufeatures.h
arch/x86/kvm/kvm_onhyperv.h
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm_onhyperv.h
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h
virt/kvm/kvm_main.c

Simple merge
Simple merge
Simple merge
@@@ -2228,8 -2217,23 +2228,19 @@@ static const struct arm64_cpu_capabilit
                .capability = ARM64_HAS_ECV,
                .type = ARM64_CPUCAP_SYSTEM_FEATURE,
                .matches = has_cpuid_feature,
 -              .sys_reg = SYS_ID_AA64MMFR0_EL1,
 -              .field_pos = ID_AA64MMFR0_EL1_ECV_SHIFT,
 -              .field_width = 4,
 -              .sign = FTR_UNSIGNED,
 -              .min_field_value = 1,
 +              ARM64_CPUID_FIELDS(ID_AA64MMFR0_EL1, ECV, IMP)
        },
+       {
+               .desc = "Enhanced Counter Virtualization (CNTPOFF)",
+               .capability = ARM64_HAS_ECV_CNTPOFF,
+               .type = ARM64_CPUCAP_SYSTEM_FEATURE,
+               .matches = has_cpuid_feature,
+               .sys_reg = SYS_ID_AA64MMFR0_EL1,
+               .field_pos = ID_AA64MMFR0_EL1_ECV_SHIFT,
+               .field_width = 4,
+               .sign = FTR_UNSIGNED,
+               .min_field_value = ID_AA64MMFR0_EL1_ECV_CNTPOFF,
+       },
  #ifdef CONFIG_ARM64_PAN
        {
                .desc = "Privileged Access Never",
@@@ -218,7 -234,7 +232,8 @@@ int kvm_vm_ioctl_check_extension(struc
        case KVM_CAP_VCPU_ATTRIBUTES:
        case KVM_CAP_PTP_KVM:
        case KVM_CAP_ARM_SYSTEM_SUSPEND:
 +      case KVM_CAP_IRQFD_RESAMPLE:
+       case KVM_CAP_COUNTER_OFFSET:
                r = 1;
                break;
        case KVM_CAP_SET_GUEST_DEBUG2:
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -7,16 -7,10 +7,15 @@@
  #define __ARCH_X86_KVM_KVM_ONHYPERV_H__
  
  #if IS_ENABLED(CONFIG_HYPERV)
- int hv_remote_flush_tlb_with_range(struct kvm *kvm,
-               struct kvm_tlb_range *range);
- int hv_remote_flush_tlb(struct kvm *kvm);
+ int hv_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, gfn_t nr_pages);
+ int hv_flush_remote_tlbs(struct kvm *kvm);
  void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp);
  #else /* !CONFIG_HYPERV */
- static inline int hv_remote_flush_tlb(struct kvm *kvm)
++static inline int hv_flush_remote_tlbs(struct kvm *kvm)
 +{
 +      return -EOPNOTSUPP;
 +}
 +
  static inline void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp)
  {
  }
@@@ -3757,37 -3819,6 +3823,37 @@@ static void svm_flush_tlb_asid(struct k
                svm->current_vmcb->asid_generation--;
  }
  
-        * flushes should be routed to hv_remote_flush_tlb() without requesting
 +static void svm_flush_tlb_current(struct kvm_vcpu *vcpu)
 +{
 +      hpa_t root_tdp = vcpu->arch.mmu->root.hpa;
 +
 +      /*
 +       * When running on Hyper-V with EnlightenedNptTlb enabled, explicitly
 +       * flush the NPT mappings via hypercall as flushing the ASID only
 +       * affects virtual to physical mappings, it does not invalidate guest
 +       * physical to host physical mappings.
 +       */
 +      if (svm_hv_is_enlightened_tlb_enabled(vcpu) && VALID_PAGE(root_tdp))
 +              hyperv_flush_guest_mapping(root_tdp);
 +
 +      svm_flush_tlb_asid(vcpu);
 +}
 +
 +static void svm_flush_tlb_all(struct kvm_vcpu *vcpu)
 +{
 +      /*
 +       * When running on Hyper-V with EnlightenedNptTlb enabled, remote TLB
-        * a KVM bug or a prior hv_remote_flush_tlb() call failed, both of
++       * flushes should be routed to hv_flush_remote_tlbs() without requesting
 +       * a "regular" remote flush.  Reaching this point means either there's
-               hv_remote_flush_tlb(vcpu->kvm);
++       * a KVM bug or a prior hv_flush_remote_tlbs() call failed, both of
 +       * which might be fatal to the guest.  Yell, but try to recover.
 +       */
 +      if (WARN_ON_ONCE(svm_hv_is_enlightened_tlb_enabled(vcpu)))
++              hv_flush_remote_tlbs(vcpu->kvm);
 +
 +      svm_flush_tlb_asid(vcpu);
 +}
 +
  static void svm_flush_tlb_gva(struct kvm_vcpu *vcpu, gva_t gva)
  {
        struct vcpu_svm *svm = to_svm(vcpu);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge