1. 15 9月, 2022 1 次提交
  2. 04 8月, 2022 1 次提交
  3. 08 7月, 2022 4 次提交
    • S
      KVM: x86: Fix implicit enum conversion goof in scattered reverse CPUID code · 90772c12
      Sean Christopherson 提交于
      mainline inclusion
      from mainline-5.13
      commit 462f8dde
      category: feature
      bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5EZEK
      CVE: NA
      
      Intel-SIG: commit 462f8dde KVM: x86: Fix implicit enum conversion
      goof in scattered reverse CPUID code.
      Backport for SGX virtualization support
      
      --------------------------------
      
      Take "enum kvm_only_cpuid_leafs" in scattered specific CPUID helpers
      (which is obvious in hindsight), and use "unsigned int" for leafs that
      can be the kernel's standard "enum cpuid_leaf" or the aforementioned
      KVM-only variant.  Loss of the enum params is a bit disapponting, but
      gcc obviously isn't providing any extra sanity checks, and the various
      BUILD_BUG_ON() assertions ensure the input is in range.
      
      This fixes implicit enum conversions that are detected by clang-11:
      
      arch/x86/kvm/cpuid.c:499:29: warning: implicit conversion from enumeration type 'enum kvm_only_cpuid_leafs' to different enumeration type 'enum cpuid_leafs' [-Wenum-conversion]
              kvm_cpu_cap_init_scattered(CPUID_12_EAX,
              ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~
      arch/x86/kvm/cpuid.c:837:31: warning: implicit conversion from enumeration type 'enum kvm_only_cpuid_leafs' to different enumeration type 'enum cpuid_leafs' [-Wenum-conversion]
                      cpuid_entry_override(entry, CPUID_12_EAX);
                      ~~~~~~~~~~~~~~~~~~~~        ^~~~~~~~~~~~
      2 warnings generated.
      
      Fixes: 4e66c0cb ("KVM: x86: Add support for reverse CPUID lookup of scattered features")
      Cc: Kai Huang <kai.huang@intel.com>
      Signed-off-by: NSean Christopherson <seanjc@google.com>
      Message-Id: <20210421010850.3009718-1-seanjc@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NZhiquan Li <zhiquan1.li@intel.com>
      90772c12
    • S
      KVM: x86: Add capability to grant VM access to privileged SGX attribute · 2c1e5e2f
      Sean Christopherson 提交于
      mainline inclusion
      from mainline-5.13
      commit fe7e9488
      category: feature
      bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5EZEK
      CVE: NA
      
      Intel-SIG: commit fe7e9488 KVM: x86: Add capability to grant VM
      access to privileged SGX attribute.
      Backport for SGX virtualization support
      
      --------------------------------
      
      Add a capability, KVM_CAP_SGX_ATTRIBUTE, that can be used by userspace
      to grant a VM access to a priveleged attribute, with args[0] holding a
      file handle to a valid SGX attribute file.
      
      The SGX subsystem restricts access to a subset of enclave attributes to
      provide additional security for an uncompromised kernel, e.g. to prevent
      malware from using the PROVISIONKEY to ensure its nodes are running
      inside a geniune SGX enclave and/or to obtain a stable fingerprint.
      
      To prevent userspace from circumventing such restrictions by running an
      enclave in a VM, KVM restricts guest access to privileged attributes by
      default.
      
      Cc: Andy Lutomirski <luto@amacapital.net>
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NKai Huang <kai.huang@intel.com>
      Message-Id: <0b099d65e933e068e3ea934b0523bab070cb8cea.1618196135.git.kai.huang@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NFan Du <fan.du@intel.com>
      Signed-off-by: NZhiquan Li <zhiquan1.li@intel.com>
      2c1e5e2f
    • S
      KVM: VMX: Enable SGX virtualization for SGX1, SGX2 and LC · 5698b7e8
      Sean Christopherson 提交于
      mainline inclusion
      from mainline-5.13
      commit 72add915
      category: feature
      bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5EZEK
      CVE: NA
      
      Intel-SIG: commit 72add915 KVM: VMX: Enable SGX virtualization for
      SGX1, SGX2 and LC.
      Backport for SGX virtualization support
      
      --------------------------------
      
      Enable SGX virtualization now that KVM has the VM-Exit handlers needed
      to trap-and-execute ENCLS to ensure correctness and/or enforce the CPU
      model exposed to the guest.  Add a KVM module param, "sgx", to allow an
      admin to disable SGX virtualization independent of the kernel.
      
      When supported in hardware and the kernel, advertise SGX1, SGX2 and SGX
      LC to userspace via CPUID and wire up the ENCLS_EXITING bitmap based on
      the guest's SGX capabilities, i.e. to allow ENCLS to be executed in an
      SGX-enabled guest.  With the exception of the provision key, all SGX
      attribute bits may be exposed to the guest.  Guest access to the
      provision key, which is controlled via securityfs, will be added in a
      future patch.
      
      Note, KVM does not yet support exposing ENCLS_C leafs or ENCLV leafs.
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NKai Huang <kai.huang@intel.com>
      Message-Id: <a99e9c23310c79f2f4175c1af4c4cbcef913c3e5.1618196135.git.kai.huang@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NFan Du <fan.du@intel.com>
      Signed-off-by: NZhiquan Li <zhiquan1.li@intel.com>
      5698b7e8
    • S
      KVM: x86: Add support for reverse CPUID lookup of scattered features · 09afd8d6
      Sean Christopherson 提交于
      mainline inclusion
      from mainline-5.13
      commit 4e66c0cb
      category: feature
      bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I5EZEK
      CVE: NA
      
      Intel-SIG: commit 4e66c0cb KVM: x86: Add support for reverse CPUID
      lookup of scattered features.
      Backport for SGX virtualization support
      
      --------------------------------
      
      Introduce a scheme that allows KVM's CPUID magic to support features
      that are scattered in the kernel's feature words.  To advertise and/or
      query guest support for CPUID-based features, KVM requires the bit
      number of an X86_FEATURE_* to match the bit number in its associated
      CPUID entry.  For scattered features, this does not hold true.
      
      Add a framework to allow defining KVM-only words, stored in
      kvm_cpu_caps after the shared kernel caps, that can be used to gather
      the scattered feature bits by translating X86_FEATURE_* flags into their
      KVM-defined feature.
      
      Note, because reverse_cpuid_check() effectively forces kvm_cpu_caps
      lookups to be resolved at compile time, there is no runtime cost for
      translating from kernel-defined to kvm-defined features.
      
      More details here:  https://lkml.kernel.org/r/X/jxCOLG+HUO4QlZ@google.comSigned-off-by: NSean Christopherson <seanjc@google.com>
      Signed-off-by: NKai Huang <kai.huang@intel.com>
      Message-Id: <16cad8d00475f67867fb36701fc7fb7c1ec86ce1.1618196135.git.kai.huang@intel.com>
      Signed-off-by: NFan Du <fan.du@intel.com>
      Signed-off-by: NZhiquan Li <zhiquan1.li@intel.com>
      09afd8d6
  4. 15 10月, 2021 2 次提交
  5. 03 6月, 2021 1 次提交
  6. 09 3月, 2021 1 次提交
  7. 13 11月, 2020 1 次提交
    • B
      KVM: x86: Introduce cr3_lm_rsvd_bits in kvm_vcpu_arch · 0107973a
      Babu Moger 提交于
      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: NBabu Moger <babu.moger@amd.com>
      Message-Id: <160521947657.32054.3264016688005356563.stgit@bmoger-ubuntu>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      0107973a
  8. 10 11月, 2020 1 次提交
  9. 08 11月, 2020 1 次提交
  10. 22 10月, 2020 5 次提交
    • S
      KVM: x86: Move call to update_exception_bitmap() into VMX code · a6337a35
      Sean Christopherson 提交于
      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: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200930041659.28181-4-sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a6337a35
    • S
      KVM: x86: Invoke vendor's vcpu_after_set_cpuid() after all common updates · c44d9b34
      Sean Christopherson 提交于
      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: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200930041659.28181-3-sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      c44d9b34
    • V
      KVM: x86: allocate vcpu->arch.cpuid_entries dynamically · 255cbecf
      Vitaly Kuznetsov 提交于
      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: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20201001130541.1398392-3-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NMaxim Levitsky <mlevitsk@redhat.com>
      255cbecf
    • V
      KVM: x86: disconnect kvm_check_cpuid() from vcpu->arch.cpuid_entries · f69858fc
      Vitaly Kuznetsov 提交于
      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: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20201001130541.1398392-2-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f69858fc
    • O
      kvm: x86: only provide PV features if enabled in guest's CPUID · 66570e96
      Oliver Upton 提交于
      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: NJim Mattson <jmattson@google.com>
      Reviewed-by: NPeter Shier <pshier@google.com>
      Signed-off-by: NOliver Upton <oupton@google.com>
      Change-Id: I202a0926f65035b872bfe8ad15307c026de59a98
      Message-Id: <20200818152429.1923996-4-oupton@google.com>
      Reviewed-by: NWanpeng Li <wanpengli@tencent.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      66570e96
  11. 28 9月, 2020 1 次提交
  12. 31 8月, 2020 1 次提交
  13. 10 8月, 2020 1 次提交
    • P
      x86: Expose SERIALIZE for supported cpuid · 43bd9ef4
      Paolo Bonzini 提交于
      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: NCathy Zhang <cathy.zhang@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      43bd9ef4
  14. 31 7月, 2020 1 次提交
  15. 11 7月, 2020 1 次提交
  16. 09 7月, 2020 10 次提交
  17. 05 6月, 2020 3 次提交
  18. 01 6月, 2020 2 次提交
    • L
      KVM: x86/pmu: Support full width counting · 27461da3
      Like Xu 提交于
      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: NLike Xu <like.xu@linux.intel.com>
      Message-Id: <20200529074347.124619-3-like.xu@linux.intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      27461da3
    • V
      KVM: x86: announce KVM_FEATURE_ASYNC_PF_INT · 72de5fa4
      Vitaly Kuznetsov 提交于
      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: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20200525144125.143875-8-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      72de5fa4
  19. 16 5月, 2020 1 次提交
  20. 14 5月, 2020 1 次提交