1. 15 11月, 2019 10 次提交
  2. 22 10月, 2019 17 次提交
  3. 03 10月, 2019 1 次提交
  4. 01 10月, 2019 1 次提交
    • J
      kvm: vmx: Limit guest PMCs to those supported on the host · e1fba49c
      Jim Mattson 提交于
      KVM can only virtualize as many PMCs as the host supports.
      
      Limit the number of generic counters and fixed counters to the number
      of corresponding counters supported on the host, rather than to
      INTEL_PMC_MAX_GENERIC and INTEL_PMC_MAX_FIXED, respectively.
      
      Note that INTEL_PMC_MAX_GENERIC is currently 32, which exceeds the 18
      contiguous MSR indices reserved by Intel for event selectors. Since
      the existing code relies on a contiguous range of MSR indices for
      event selectors, it can't possibly work for more than 18 general
      purpose counters.
      
      Fixes: f5132b01 ("KVM: Expose a version 2 architectural PMU to a guests")
      Signed-off-by: NJim Mattson <jmattson@google.com>
      Reviewed-by: NMarc Orr <marcorr@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e1fba49c
  5. 28 9月, 2019 1 次提交
    • W
      KVM: VMX: Set VMENTER_L1D_FLUSH_NOT_REQUIRED if !X86_BUG_L1TF · 19a36d32
      Waiman Long 提交于
      The l1tf_vmx_mitigation is only set to VMENTER_L1D_FLUSH_NOT_REQUIRED
      when the ARCH_CAPABILITIES MSR indicates that L1D flush is not required.
      However, if the CPU is not affected by L1TF, l1tf_vmx_mitigation will
      still be set to VMENTER_L1D_FLUSH_AUTO. This is certainly not the best
      option for a !X86_BUG_L1TF CPU.
      
      So force l1tf_vmx_mitigation to VMENTER_L1D_FLUSH_NOT_REQUIRED to make it
      more explicit in case users are checking the vmentry_l1d_flush parameter.
      Signed-off-by: NWaiman Long <longman@redhat.com>
      [Patch rewritten accoring to Borislav Petkov's suggestion. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      19a36d32
  6. 26 9月, 2019 1 次提交
  7. 25 9月, 2019 3 次提交
  8. 24 9月, 2019 6 次提交
    • M
      kvm: nvmx: limit atomic switch MSRs · f0b5105a
      Marc Orr 提交于
      Allowing an unlimited number of MSRs to be specified via the VMX
      load/store MSR lists (e.g., vm-entry MSR load list) is bad for two
      reasons. First, a guest can specify an unreasonable number of MSRs,
      forcing KVM to process all of them in software. Second, the SDM bounds
      the number of MSRs allowed to be packed into the atomic switch MSR lists.
      Quoting the "Miscellaneous Data" section in the "VMX Capability
      Reporting Facility" appendix:
      
      "Bits 27:25 is used to compute the recommended maximum number of MSRs
      that should appear in the VM-exit MSR-store list, the VM-exit MSR-load
      list, or the VM-entry MSR-load list. Specifically, if the value bits
      27:25 of IA32_VMX_MISC is N, then 512 * (N + 1) is the recommended
      maximum number of MSRs to be included in each list. If the limit is
      exceeded, undefined processor behavior may result (including a machine
      check during the VMX transition)."
      
      Because KVM needs to protect itself and can't model "undefined processor
      behavior", arbitrarily force a VM-entry to fail due to MSR loading when
      the MSR load list is too large. Similarly, trigger an abort during a VM
      exit that encounters an MSR load list or MSR store list that is too large.
      
      The MSR list size is intentionally not pre-checked so as to maintain
      compatibility with hardware inasmuch as possible.
      
      Test these new checks with the kvm-unit-test "x86: nvmx: test max atomic
      switch MSRs".
      Suggested-by: NJim Mattson <jmattson@google.com>
      Reviewed-by: NJim Mattson <jmattson@google.com>
      Reviewed-by: NPeter Shier <pshier@google.com>
      Signed-off-by: NMarc Orr <marcorr@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f0b5105a
    • T
      KVM: vmx: Introduce handle_unexpected_vmexit and handle WAITPKG vmexit · bf653b78
      Tao Xu 提交于
      As the latest Intel 64 and IA-32 Architectures Software Developer's
      Manual, UMWAIT and TPAUSE instructions cause a VM exit if the
      RDTSC exiting and enable user wait and pause VM-execution
      controls are both 1.
      
      Because KVM never enable RDTSC exiting, the vm-exit for UMWAIT and TPAUSE
      should never happen. Considering EXIT_REASON_XSAVES and
      EXIT_REASON_XRSTORS is also unexpected VM-exit for KVM. Introduce a common
      exit helper handle_unexpected_vmexit() to handle these unexpected VM-exit.
      Suggested-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Co-developed-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NTao Xu <tao3.xu@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      bf653b78
    • T
      KVM: vmx: Emulate MSR IA32_UMWAIT_CONTROL · 6e3ba4ab
      Tao Xu 提交于
      UMWAIT and TPAUSE instructions use 32bit IA32_UMWAIT_CONTROL at MSR index
      E1H to determines the maximum time in TSC-quanta that the processor can
      reside in either C0.1 or C0.2.
      
      This patch emulates MSR IA32_UMWAIT_CONTROL in guest and differentiate
      IA32_UMWAIT_CONTROL between host and guest. The variable
      mwait_control_cached in arch/x86/kernel/cpu/umwait.c caches the MSR value,
      so this patch uses it to avoid frequently rdmsr of IA32_UMWAIT_CONTROL.
      Co-developed-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NTao Xu <tao3.xu@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      6e3ba4ab
    • T
      KVM: x86: Add support for user wait instructions · e69e72fa
      Tao Xu 提交于
      UMONITOR, UMWAIT and TPAUSE are a set of user wait instructions.
      This patch adds support for user wait instructions in KVM. Availability
      of the user wait instructions is indicated by the presence of the CPUID
      feature flag WAITPKG CPUID.0x07.0x0:ECX[5]. User wait instructions may
      be executed at any privilege level, and use 32bit IA32_UMWAIT_CONTROL MSR
      to set the maximum time.
      
      The behavior of user wait instructions in VMX non-root operation is
      determined first by the setting of the "enable user wait and pause"
      secondary processor-based VM-execution control bit 26.
      	If the VM-execution control is 0, UMONITOR/UMWAIT/TPAUSE cause
      an invalid-opcode exception (#UD).
      	If the VM-execution control is 1, treatment is based on the
      setting of the “RDTSC exiting†VM-execution control. Because KVM never
      enables RDTSC exiting, if the instruction causes a delay, the amount of
      time delayed is called here the physical delay. The physical delay is
      first computed by determining the virtual delay. If
      IA32_UMWAIT_CONTROL[31:2] is zero, the virtual delay is the value in
      EDX:EAX minus the value that RDTSC would return; if
      IA32_UMWAIT_CONTROL[31:2] is not zero, the virtual delay is the minimum
      of that difference and AND(IA32_UMWAIT_CONTROL,FFFFFFFCH).
      
      Because umwait and tpause can put a (psysical) CPU into a power saving
      state, by default we dont't expose it to kvm and enable it only when
      guest CPUID has it.
      
      Detailed information about user wait instructions can be found in the
      latest Intel 64 and IA-32 Architectures Software Developer's Manual.
      Co-developed-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NJingqi Liu <jingqi.liu@intel.com>
      Signed-off-by: NTao Xu <tao3.xu@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e69e72fa
    • S
      KVM: VMX: Handle single-step #DB for EMULTYPE_SKIP on EPT misconfig · 1957aa63
      Sean Christopherson 提交于
      VMX's EPT misconfig flow to handle fast-MMIO path falls back to decoding
      the instruction to determine the instruction length when running as a
      guest (Hyper-V doesn't fill VMCS.VM_EXIT_INSTRUCTION_LEN because it's
      technically not defined for EPT misconfigs).  Rather than implement the
      slow skip in VMX's generic skip_emulated_instruction(),
      handle_ept_misconfig() directly calls kvm_emulate_instruction() with
      EMULTYPE_SKIP, which intentionally doesn't do single-step detection, and
      so handle_ept_misconfig() misses a single-step #DB.
      
      Rework the EPT misconfig fallback case to route it through
      kvm_skip_emulated_instruction() so that single-step #DBs and interrupt
      shadow updates are handled automatically.  I.e. make VMX's slow skip
      logic match SVM's and have the SVM flow not intentionally avoid the
      shadow update.
      
      Alternatively, the handle_ept_misconfig() could manually handle single-
      step detection, but that results in EMULTYPE_SKIP having split logic for
      the interrupt shadow vs. single-step #DBs, and split emulator logic is
      largely what led to this mess in the first place.
      
      Modifying SVM to mirror VMX flow isn't really an option as SVM's case
      isn't limited to a specific exit reason, i.e. handling the slow skip in
      skip_emulated_instruction() is mandatory for all intents and purposes.
      
      Drop VMX's skip_emulated_instruction() wrapper since it can now fail,
      and instead WARN if it fails unexpectedly, e.g. if exit_reason somehow
      becomes corrupted.
      
      Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
      Fixes: d391f120 ("x86/kvm/vmx: do not use vm-exit instruction length for fast MMIO when running nested")
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      1957aa63
    • S
      KVM: x86: Remove emulation_result enums, EMULATE_{DONE,FAIL,USER_EXIT} · 60fc3d02
      Sean Christopherson 提交于
      Deferring emulation failure handling (in some cases) to the caller of
      x86_emulate_instruction() has proven fragile, e.g. multiple instances of
      KVM not setting run->exit_reason on EMULATE_FAIL, largely due to it
      being difficult to discern what emulation types can return what result,
      and which combination of types and results are handled where.
      
      Now that x86_emulate_instruction() always handles emulation failure,
      i.e. EMULATION_FAIL is only referenced in callers, remove the
      emulation_result enums entirely.  Per KVM's existing exit handling
      conventions, return '0' and '1' for "exit to userspace" and "resume
      guest" respectively.  Doing so cleans up many callers, e.g. they can
      return kvm_emulate_instruction() directly instead of having to interpret
      its result.
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      60fc3d02