1. 19 May, 2021 1 commit
  2. 28 Jan, 2021 1 commit
    • Michael Roth's avatar
      KVM: x86: fix CPUID entries returned by KVM_GET_CPUID2 ioctl · 181f4948
      Michael Roth authored
      Recent commit 255cbecf modified struct kvm_vcpu_arch to make
      'cpuid_entries' a pointer to an array of kvm_cpuid_entry2 entries
      rather than embedding the array in the struct. KVM_SET_CPUID and
      KVM_SET_CPUID2 were updated accordingly, but KVM_GET_CPUID2 was missed.
      
      As a result, KVM_GET_CPUID2 currently returns random fields from struct
      kvm_vcpu_arch to userspace rather than the expected CPUID values. Fix
      this by treating 'cpuid_entries' as a pointer when copying its
      contents to userspace buffer.
      
      Fixes: 255cbecf
      
       ("KVM: x86: allocate vcpu->arch.cpuid_entries dynamically")
      Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: default avatarMichael Roth <michael.roth@amd.com.com>
      Message-Id: <20210128024451.1816770-1-michael.roth@amd.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      181f4948
  3. 12 Dec, 2020 1 commit
  4. 15 Nov, 2020 1 commit
    • Jim Mattson's avatar
      kvm: x86: Sink cpuid update into vendor-specific set_cr4 functions · 2259c17f
      Jim Mattson authored
      On emulated VM-entry and VM-exit, update the CPUID bits that reflect
      CR4.OSXSAVE and CR4.PKE.
      
      This fixes a bug where the CPUID bits could continue to reflect L2 CR4
      values after emulated VM-exit to L1. It also fixes a related bug where
      the CPUID bits could continue to reflect L1 CR4 values after emulated
      VM-entry to L2. The latter bug is mainly relevant to SVM, wherein
      CPUID is not a required intercept. However, it could also be relevant
      to VMX, because the code to conditionally update these CPUID bits
      assumes that the guest CPUID and the guest CR4 are always in sync.
      
      Fixes: 8eb3f87d ("KVM: nVMX: fix guest CR4 loading when emulating L2 to L1 exit")
      Fixes: 2acf923e ("KVM: VMX: Enable XSAVE/XRSTOR for guest")
      Fixes: b9baba86
      
       ("KVM, pkeys: expose CPUID/CR4 to guest")
      Reported-by: default avatarAbhiroop Dabral <adabral@paloaltonetworks.com>
      Signed-off-by: default avatarJim Mattson <jmattson@google.com>
      Reviewed-by: default avatarRicardo Koller <ricarkol@google.com>
      Reviewed-by: default avatarPeter Shier <pshier@google.com>
      Cc: Haozhong Zhang <haozhong.zhang@intel.com>
      Cc: Dexuan Cui <dexuan.cui@intel.com>
      Cc: Huaitong Han <huaitong.han@intel.com>
      Message-Id: <20201029170648.483210-1-jmattson@google.com>
      2259c17f
  5. 13 Nov, 2020 1 commit
    • Babu Moger's avatar
      KVM: x86: Introduce cr3_lm_rsvd_bits in kvm_vcpu_arch · 0107973a
      Babu Moger authored
      SEV guests fail to boot on a system that supports the PCID feature.
      
      While emulating the RSM instruction, KVM reads the guest CR3
      and calls kvm_set_cr3(). If the vCPU is in the long mode,
      kvm_set_cr3() does a sanity check for the CR3 value. In this case,
      it validates whether the value has any reserved bits set. The
      reserved bit range is 63:cpuid_maxphysaddr(). When AMD memory
      encryption is enabled, the memory encryption bit is set in the CR3
      value. The memory encryption bit may fall within the KVM reserved
      bit range, causing the KVM emulation failure.
      
      Introduce a new field cr3_lm_rsvd_bits in kvm_vcpu_arch which will
      cache the reserved bits in the CR3 value. This will be initialized
      to rsvd_bits(cpuid_maxphyaddr(vcpu), 63).
      
      If the architecture has any special bits(like AMD SEV encryption bit)
      that needs to be masked from the reserved bits, should be cleared
      in vendor specific kvm_x86_ops.vcpu_after_set_cpuid handler.
      
      Fixes: a780a3ea
      
       ("KVM: X86: Fix reserved bits check for MOV to CR3")
      Signed-off-by: default avatarBabu Moger <babu.moger@amd.com>
      Message-Id: <160521947657.32054.3264016688005356563.stgit@bmoger-ubuntu>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      0107973a
  6. 09 Nov, 2020 1 commit
  7. 08 Nov, 2020 1 commit
  8. 21 Oct, 2020 5 commits
    • Sean Christopherson's avatar
      KVM: x86: Move call to update_exception_bitmap() into VMX code · a6337a35
      Sean Christopherson authored
      
      Now that vcpu_after_set_cpuid() and update_exception_bitmap() are called
      back-to-back, subsume the exception bitmap update into the common CPUID
      update.  Drop the SVM invocation entirely as SVM's exception bitmap
      doesn't vary with respect to guest CPUID.
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200930041659.28181-4-sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      a6337a35
    • Sean Christopherson's avatar
      KVM: x86: Invoke vendor's vcpu_after_set_cpuid() after all common updates · c44d9b34
      Sean Christopherson authored
      Move the call to kvm_x86_ops.vcpu_after_set_cpuid() to the very end of
      kvm_vcpu_after_set_cpuid() to allow the vendor implementation to react
      to changes made by the common code.  In the near future, this will be
      used by VMX to update its CR4 guest/host masks to account for reserved
      bits.  In the long term, SGX support will update the allowed XCR0 mask
      for enclaves based on the vCPU's allowed XCR0.
      
      vcpu_after_set_cpuid() (nee kvm_update_cpuid()) was originally added by
      commit 2acf923e
      
       ("KVM: VMX: Enable XSAVE/XRSTOR for guest"), and was
      called separately after kvm_x86_ops.vcpu_after_set_cpuid() (nee
      kvm_x86_ops->cpuid_update()).  There is no indication that the placement
      of the common code updates after the vendor updates was anything more
      than a "new function at the end" decision.
      
      Inspection of the current code reveals no dependency on kvm_x86_ops'
      vcpu_after_set_cpuid() in kvm_vcpu_after_set_cpuid() or any of its
      helpers.  The bulk of the common code depends only on the guest's CPUID
      configuration, kvm_mmu_reset_context() does not consume dynamic vendor
      state, and there are no collisions between kvm_pmu_refresh() and VMX's
      update of PT state.
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200930041659.28181-3-sean.j.christopherson@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      c44d9b34
    • Vitaly Kuznetsov's avatar
      KVM: x86: allocate vcpu->arch.cpuid_entries dynamically · 255cbecf
      Vitaly Kuznetsov authored
      
      The current limit for guest CPUID leaves (KVM_MAX_CPUID_ENTRIES, 80)
      is reported to be insufficient but before we bump it let's switch to
      allocating vcpu->arch.cpuid_entries[] array dynamically. Currently,
      'struct kvm_cpuid_entry2' is 40 bytes so vcpu->arch.cpuid_entries is
      3200 bytes which accounts for 1/4 of the whole 'struct kvm_vcpu_arch'
      but having it pre-allocated (for all vCPUs which we also pre-allocate)
      gives us no real benefits.
      
      Another plus of the dynamic allocation is that we now do kvm_check_cpuid()
      check before we assign anything to vcpu->arch.cpuid_nent/cpuid_entries so
      no changes are made in case the check fails.
      
      Opportunistically remove unneeded 'out' labels from
      kvm_vcpu_ioctl_set_cpuid()/kvm_vcpu_ioctl_set_cpuid2() and return
      directly whenever possible.
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20201001130541.1398392-3-vkuznets@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      255cbecf
    • Vitaly Kuznetsov's avatar
      KVM: x86: disconnect kvm_check_cpuid() from vcpu->arch.cpuid_entries · f69858fc
      Vitaly Kuznetsov authored
      
      As a preparatory step to allocating vcpu->arch.cpuid_entries dynamically
      make kvm_check_cpuid() check work with an arbitrary 'struct kvm_cpuid_entry2'
      array.
      
      Currently, when kvm_check_cpuid() fails we reset vcpu->arch.cpuid_nent to
      0 and this is kind of weird, i.e. one would expect CPUIDs to remain
      unchanged when KVM_SET_CPUID[2] call fails.
      
      No functional change intended. It would've been possible to move the updated
      kvm_check_cpuid() in kvm_vcpu_ioctl_set_cpuid2() and check the supplied
      input before we start updating vcpu->arch.cpuid_entries/nent but we
      can't do the same in kvm_vcpu_ioctl_set_cpuid() as we'll have to copy
      'struct kvm_cpuid_entry' entries first. The change will be made when
      vcpu->arch.cpuid_entries[] array becomes allocated dynamically.
      Suggested-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20201001130541.1398392-2-vkuznets@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f69858fc
    • Oliver Upton's avatar
      kvm: x86: only provide PV features if enabled in guest's CPUID · 66570e96
      Oliver Upton authored
      
      KVM unconditionally provides PV features to the guest, regardless of the
      configured CPUID. An unwitting guest that doesn't check
      KVM_CPUID_FEATURES before use could access paravirt features that
      userspace did not intend to provide. Fix this by checking the guest's
      CPUID before performing any paravirtual operations.
      
      Introduce a capability, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, to gate the
      aforementioned enforcement. Migrating a VM from a host w/o this patch to
      a host with this patch could silently change the ABI exposed to the
      guest, warranting that we default to the old behavior and opt-in for
      the new one.
      Reviewed-by: default avatarJim Mattson <jmattson@google.com>
      Reviewed-by: default avatarPeter Shier <pshier@google.com>
      Signed-off-by: default avatarOliver Upton <oupton@google.com>
      Change-Id: I202a0926f65035b872bfe8ad15307c026de59a98
      Message-Id: <20200818152429.1923996-4-oupton@google.com>
      Reviewed-by: default avatarWanpeng Li <wanpengli@tencent.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      66570e96
  9. 28 Sep, 2020 1 commit
  10. 30 Aug, 2020 1 commit
  11. 09 Aug, 2020 1 commit
    • Paolo Bonzini's avatar
      x86: Expose SERIALIZE for supported cpuid · 43bd9ef4
      Paolo Bonzini authored
      
      The SERIALIZE instruction is supported by Tntel processors, like
      Sapphire Rapids.  SERIALIZE is a faster serializing instruction which
      does not modify registers, arithmetic flags or memory, will not cause VM
      exit. It's availability is indicated by CPUID.(EAX=7,ECX=0):ECX[bit 14].
      
      Expose it in KVM supported CPUID.  This way, KVM could pass this
      information to guests and they can make use of these features accordingly.
      Signed-off-by: default avatarCathy Zhang <cathy.zhang@intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      43bd9ef4
  12. 30 Jul, 2020 1 commit
  13. 10 Jul, 2020 1 commit
  14. 09 Jul, 2020 6 commits
  15. 08 Jul, 2020 4 commits
  16. 04 Jun, 2020 3 commits
  17. 01 Jun, 2020 2 commits
    • Like Xu's avatar
      KVM: x86/pmu: Support full width counting · 27461da3
      Like Xu authored
      
      Intel CPUs have a new alternative MSR range (starting from MSR_IA32_PMC0)
      for GP counters that allows writing the full counter width. Enable this
      range from a new capability bit (IA32_PERF_CAPABILITIES.FW_WRITE[bit 13]).
      
      The guest would query CPUID to get the counter width, and sign extends
      the counter values as needed. The traditional MSRs always limit to 32bit,
      even though the counter internally is larger (48 or 57 bits).
      
      When the new capability is set, use the alternative range which do not
      have these restrictions. This lowers the overhead of perf stat slightly
      because it has to do less interrupts to accumulate the counter value.
      Signed-off-by: default avatarLike Xu <like.xu@linux.intel.com>
      Message-Id: <20200529074347.124619-3-like.xu@linux.intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      27461da3
    • Vitaly Kuznetsov's avatar
      KVM: x86: announce KVM_FEATURE_ASYNC_PF_INT · 72de5fa4
      Vitaly Kuznetsov authored
      
      Introduce new capability to indicate that KVM supports interrupt based
      delivery of 'page ready' APF events. This includes support for both
      MSR_KVM_ASYNC_PF_INT and MSR_KVM_ASYNC_PF_ACK.
      Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20200525144125.143875-8-vkuznets@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      72de5fa4
  18. 15 May, 2020 1 commit
  19. 13 May, 2020 1 commit
  20. 15 Apr, 2020 1 commit
  21. 31 Mar, 2020 2 commits
  22. 23 Mar, 2020 1 commit
  23. 18 Mar, 2020 2 commits