1. 01 6月, 2020 17 次提交
  2. 28 5月, 2020 7 次提交
    • P
      KVM: SVM: always update CR3 in VMCB · 978ce583
      Paolo Bonzini 提交于
      svm_load_mmu_pgd is delaying the write of GUEST_CR3 to prepare_vmcs02 as
      an optimization, but this is only correct before the nested vmentry.
      If userspace is modifying CR3 with KVM_SET_SREGS after the VM has
      already been put in guest mode, the value of CR3 will not be updated.
      Remove the optimization, which almost never triggers anyway.
      This was was added in commit 689f3bf2 ("KVM: x86: unify callbacks
      to load paging root", 2020-03-16) just to keep the two vendor-specific
      modules closer, but we'll fix VMX too.
      
      Fixes: 689f3bf2 ("KVM: x86: unify callbacks to load paging root")
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      978ce583
    • P
      KVM: nSVM: correctly inject INIT vmexits · 5b672408
      Paolo Bonzini 提交于
      The usual drill at this point, except there is no code to remove because this
      case was not handled at all.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      5b672408
    • P
      KVM: nSVM: remove exit_required · bd279629
      Paolo Bonzini 提交于
      All events now inject vmexits before vmentry rather than after vmexit.  Therefore,
      exit_required is not set anymore and we can remove it.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      bd279629
    • P
      KVM: nSVM: inject exceptions via svm_check_nested_events · 7c86663b
      Paolo Bonzini 提交于
      This allows exceptions injected by the emulator to be properly delivered
      as vmexits.  The code also becomes simpler, because we can just let all
      L0-intercepted exceptions go through the usual path.  In particular, our
      emulation of the VMX #DB exit qualification is very much simplified,
      because the vmexit injection path can use kvm_deliver_exception_payload
      to update DR6.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      7c86663b
    • V
      KVM: nSVM: Preserve registers modifications done before nested_svm_vmexit() · b6162e82
      Vitaly Kuznetsov 提交于
      L2 guest hang is observed after 'exit_required' was dropped and nSVM
      switched to check_nested_events() completely. The hang is a busy loop when
      e.g. KVM is emulating an instruction (e.g. L2 is accessing MMIO space and
      we drop to userspace). After nested_svm_vmexit() and when L1 is doing VMRUN
      nested guest's RIP is not advanced so KVM goes into emulating the same
      instruction which caused nested_svm_vmexit() and the loop continues.
      
      nested_svm_vmexit() is not new, however, with check_nested_events() we're
      now calling it later than before. In case by that time KVM has modified
      register state we may pick stale values from VMCB when trying to save
      nested guest state to nested VMCB.
      
      nVMX code handles this case correctly: sync_vmcs02_to_vmcs12() called from
      nested_vmx_vmexit() does e.g 'vmcs12->guest_rip = kvm_rip_read(vcpu)' and
      this ensures KVM-made modifications are preserved. Do the same for nSVM.
      
      Generally, nested_vmx_vmexit()/nested_svm_vmexit() need to pick up all
      nested guest state modifications done by KVM after vmexit. It would be
      great to find a way to express this in a way which would not require to
      manually track these changes, e.g. nested_{vmcb,vmcs}_get_field().
      
      Co-debugged-with: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Message-Id: <20200527090102.220647-1-vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b6162e82
    • P
      KVM: nSVM: leave ASID aside in copy_vmcb_control_area · 6c0238c4
      Paolo Bonzini 提交于
      Restoring the ASID from the hsave area on VMEXIT is wrong, because its
      value depends on the handling of TLB flushes.  Just skipping the field in
      copy_vmcb_control_area will do.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      6c0238c4
    • P
      KVM: nSVM: fix condition for filtering async PF · a3535be7
      Paolo Bonzini 提交于
      Async page faults have to be trapped in the host (L1 in this case),
      since the APF reason was passed from L0 to L1 and stored in the L1 APF
      data page.  This was completely reversed: the page faults were passed
      to the guest, a L2 hypervisor.
      
      Cc: stable@vger.kernel.org
      Reviewed-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      a3535be7
  3. 14 5月, 2020 9 次提交
  4. 08 5月, 2020 2 次提交
    • P
      KVM: x86, SVM: isolate vcpu->arch.dr6 from vmcb->save.dr6 · d67668e9
      Paolo Bonzini 提交于
      There are two issues with KVM_EXIT_DEBUG on AMD, whose root cause is the
      different handling of DR6 on intercepted #DB exceptions on Intel and AMD.
      
      On Intel, #DB exceptions transmit the DR6 value via the exit qualification
      field of the VMCS, and the exit qualification only contains the description
      of the precise event that caused a vmexit.
      
      On AMD, instead the DR6 field of the VMCB is filled in as if the #DB exception
      was to be injected into the guest.  This has two effects when guest debugging
      is in use:
      
      * the guest DR6 is clobbered
      
      * the kvm_run->debug.arch.dr6 field can accumulate more debug events, rather
      than just the last one that happened (the testcase in the next patch covers
      this issue).
      
      This patch fixes both issues by emulating, so to speak, the Intel behavior
      on AMD processors.  The important observation is that (after the previous
      patches) the VMCB value of DR6 is only ever observable from the guest is
      KVM_DEBUGREG_WONT_EXIT is set.  Therefore we can actually set vmcb->save.dr6
      to any value we want as long as KVM_DEBUGREG_WONT_EXIT is clear, which it
      will be if guest debugging is enabled.
      
      Therefore it is possible to enter the guest with an all-zero DR6,
      reconstruct the #DB payload from the DR6 we get at exit time, and let
      kvm_deliver_exception_payload move the newly set bits into vcpu->arch.dr6.
      Some extra bits may be included in the payload if KVM_DEBUGREG_WONT_EXIT
      is set, but this is harmless.
      
      This may not be the most optimized way to deal with this, but it is
      simple and, being confined within SVM code, it gets rid of the set_dr6
      callback and kvm_update_dr6.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      d67668e9
    • P
      KVM: SVM: keep DR6 synchronized with vcpu->arch.dr6 · 5679b803
      Paolo Bonzini 提交于
      kvm_x86_ops.set_dr6 is only ever called with vcpu->arch.dr6 as the
      second argument.  Ensure that the VMCB value is synchronized to
      vcpu->arch.dr6 on #DB (both "normal" and nested) and nested vmentry, so
      that the current value of DR6 is always available in vcpu->arch.dr6.
      The get_dr6 callback can just access vcpu->arch.dr6 and becomes redundant.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      5679b803
  5. 07 5月, 2020 1 次提交
  6. 25 4月, 2020 1 次提交
  7. 23 4月, 2020 1 次提交
    • P
      KVM: x86: move nested-related kvm_x86_ops to a separate struct · 33b22172
      Paolo Bonzini 提交于
      Clean up some of the patching of kvm_x86_ops, by moving kvm_x86_ops related to
      nested virtualization into a separate struct.
      
      As a result, these ops will always be non-NULL on VMX.  This is not a problem:
      
      * check_nested_events is only called if is_guest_mode(vcpu) returns true
      
      * get_nested_state treats VMXOFF state the same as nested being disabled
      
      * set_nested_state fails if you attempt to set nested state while
        nesting is disabled
      
      * nested_enable_evmcs could already be called on a CPU without VMX enabled
        in CPUID.
      
      * nested_get_evmcs_version was fixed in the previous patch
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      33b22172
  8. 21 4月, 2020 2 次提交