1. 21 4月, 2020 26 次提交
  2. 16 4月, 2020 13 次提交
    • S
      KVM: x86: Export kvm_propagate_fault() (as kvm_inject_emulated_page_fault) · 53b3d8e9
      Sean Christopherson 提交于
      Export the page fault propagation helper so that VMX can use it to
      correctly emulate TLB invalidation on page faults in an upcoming patch.
      
      In the (hopefully) not-too-distant future, SGX virtualization will also
      want access to the helper for injecting page faults to the correct level
      (L1 vs. L2) when emulating ENCLS instructions.
      
      Rename the function to kvm_inject_emulated_page_fault() to clarify that
      it is (a) injecting a fault and (b) only for page faults.  WARN if it's
      invoked with an exception other than PF_VECTOR.
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200320212833.3507-6-sean.j.christopherson@intel.com>
      Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      53b3d8e9
    • J
      KVM: nVMX: Invalidate all roots when emulating INVVPID without EPT · d6e3f838
      Junaid Shahid 提交于
      Free all roots when emulating INVVPID for L1 and EPT is disabled, as
      outstanding changes to the page tables managed by L1 need to be
      recognized.  Because L1 and L2 share an MMU when EPT is disabled, and
      because VPID is not tracked by the MMU role, all roots in the current
      MMU (root_mmu) need to be freed, otherwise a future nested VM-Enter or
      VM-Exit could do a fast CR3 switch (without a flush/sync) and consume
      stale SPTEs.
      
      Fixes: 5c614b35 ("KVM: nVMX: nested VPID emulation")
      Signed-off-by: NJunaid Shahid <junaids@google.com>
      [sean: ported to upstream KVM, reworded the comment and changelog]
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200320212833.3507-5-sean.j.christopherson@intel.com>
      Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      d6e3f838
    • S
      KVM: nVMX: Invalidate all EPTP contexts when emulating INVEPT for L1 · f8aa7e39
      Sean Christopherson 提交于
      Free all L2 (guest_mmu) roots when emulating INVEPT for L1.  Outstanding
      changes to the EPT tables managed by L1 need to be recognized, and
      relying on KVM to always flush L2's EPTP context on nested VM-Enter is
      dangerous.
      
      Similar to handle_invpcid(), rely on kvm_mmu_free_roots() to do a remote
      TLB flush if necessary, e.g. if L1 has never entered L2 then there is
      nothing to be done.
      
      Nuking all L2 roots is overkill for the single-context variant, but it's
      the safe and easy bet.  A more precise zap mechanism will be added in
      the future.  Add a TODO to call out that KVM only needs to invalidate
      affected contexts.
      
      Fixes: 14c07ad8 ("x86/kvm/mmu: introduce guest_mmu")
      Reported-by: NJim Mattson <jmattson@google.com>
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200320212833.3507-4-sean.j.christopherson@intel.com>
      Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      f8aa7e39
    • S
      KVM: nVMX: Validate the EPTP when emulating INVEPT(EXTENT_CONTEXT) · eed0030e
      Sean Christopherson 提交于
      Signal VM-Fail for the single-context variant of INVEPT if the specified
      EPTP is invalid.  Per the INEVPT pseudocode in Intel's SDM, it's subject
      to the standard EPT checks:
      
        If VM entry with the "enable EPT" VM execution control set to 1 would
        fail due to the EPTP value then VMfail(Invalid operand to INVEPT/INVVPID);
      
      Fixes: bfd0a56b ("nEPT: Nested INVEPT")
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200320212833.3507-3-sean.j.christopherson@intel.com>
      Reviewed-by: NVitaly Kuznetsov <vkuznets@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      eed0030e
    • S
      KVM: VMX: Flush all EPTP/VPID contexts on remote TLB flush · e8eff282
      Sean Christopherson 提交于
      Flush all EPTP/VPID contexts if a TLB flush _may_ have been triggered by
      a remote or deferred TLB flush, i.e. by KVM_REQ_TLB_FLUSH.  Remote TLB
      flushes require all contexts to be invalidated, not just the active
      contexts, e.g. all mappings in all contexts for a given HVA need to be
      invalidated on a mmu_notifier invalidation.  Similarly, the instigator
      of the deferred TLB flush may be expecting all contexts to be flushed,
      e.g. vmx_vcpu_load_vmcs().
      
      Without nested VMX, flushing only the current EPTP/VPID context isn't
      problematic because KVM uses a constant VPID for each vCPU, and
      mmu_alloc_direct_roots() all but guarantees KVM will use a single EPTP
      for L1.  In the rare case where a different EPTP is created or reused,
      KVM (currently) unconditionally flushes the new EPTP context prior to
      entering the guest.
      
      With nested VMX, KVM conditionally uses a different VPID for L2, and
      unconditionally uses a different EPTP for L2.  Because KVM doesn't
      _intentionally_ guarantee L2's EPTP/VPID context is flushed on nested
      VM-Enter, it'd be possible for a malicious L1 to attack the host and/or
      different VMs by exploiting the lack of flushing for L2.
      
        1) Launch nested guest from malicious L1.
      
        2) Nested VM-Enter to L2.
      
        3) Access target GPA 'g'.  CPU inserts TLB entry tagged with L2's ASID
           mapping 'g' to host PFN 'x'.
      
        2) Nested VM-Exit to L1.
      
        3) L1 triggers kernel same-page merging (ksm) by duplicating/zeroing
           the page for PFN 'x'.
      
        4) Host kernel merges PFN 'x' with PFN 'y', i.e. unmaps PFN 'x' and
           remaps the page to PFN 'y'.  mmu_notifier sends invalidate command,
           KVM flushes TLB only for L1's ASID.
      
        4) Host kernel reallocates PFN 'x' to some other task/guest.
      
        5) Nested VM-Enter to L2.  KVM does not invalidate L2's EPTP or VPID.
      
        6) L2 accesses GPA 'g' and gains read/write access to PFN 'x' via its
           stale TLB entry.
      
      However, current KVM unconditionally flushes L1's EPTP/VPID context on
      nested VM-Exit.  But, that behavior is mostly unintentional, KVM doesn't
      go out of its way to flush EPTP/VPID on nested VM-Enter/VM-Exit, rather
      a TLB flush is guaranteed to occur prior to re-entering L1 due to
      __kvm_mmu_new_cr3() always being called with skip_tlb_flush=false.  On
      nested VM-Enter, this happens via kvm_init_shadow_ept_mmu() (nested EPT
      enabled) or in nested_vmx_load_cr3() (nested EPT disabled).  On nested
      VM-Exit it occurs via nested_vmx_load_cr3().
      
      This also fixes a bug where a deferred TLB flush in the context of L2,
      with EPT disabled, would flush L1's VPID instead of L2's VPID, as
      vmx_flush_tlb() flushes L1's VPID regardless of is_guest_mode().
      
      Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
      Cc: Ben Gardon <bgardon@google.com>
      Cc: Jim Mattson <jmattson@google.com>
      Cc: Junaid Shahid <junaids@google.com>
      Cc: Liran Alon <liran.alon@oracle.com>
      Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
      Cc: John Haxby <john.haxby@oracle.com>
      Reviewed-by: NLiran Alon <liran.alon@oracle.com>
      Fixes: efebf0aa ("KVM: nVMX: Do not flush TLB on L1<->L2 transitions if L1 uses VPID and EPT")
      Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
      Message-Id: <20200320212833.3507-2-sean.j.christopherson@intel.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e8eff282
    • E
      KVM: pass through CPUID(0x80000006) · 43d05de2
      Eric Northup 提交于
      Return the host's L2 cache and TLB information for CPUID.0x80000006
      instead of zeroing out the entry as part of KVM_GET_SUPPORTED_CPUID.
      This allows a userspace VMM to feed KVM_GET_SUPPORTED_CPUID's output
      directly into KVM_SET_CPUID2 (without breaking the guest).
      Signed-off-by: NEric Northup (Google) <digitaleric@gmail.com>
      Signed-off-by: NJim Mattson <jmattson@google.com>
      Signed-off-by: NJon Cargille <jcargill@google.com>
      Message-Id: <20200415012320.236065-1-jcargill@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      43d05de2
    • P
      KVM: x86: Return updated timer current count register from KVM_GET_LAPIC · 24647e0a
      Peter Shier 提交于
      kvm_vcpu_ioctl_get_lapic (implements KVM_GET_LAPIC ioctl) does a bulk copy
      of the LAPIC registers but must take into account that the one-shot and
      periodic timer current count register is computed upon reads and is not
      present in register state. When restoring LAPIC state (e.g. after
      migration), restart timers from their their current count values at time of
      save.
      
      Note: When a one-shot timer expires, the code in arch/x86/kvm/lapic.c does
      not zero the value of the LAPIC initial count register (emulating HW
      behavior). If no other timer is run and pending prior to a subsequent
      KVM_GET_LAPIC call, the returned register set will include the expired
      one-shot initial count. On a subsequent KVM_SET_LAPIC call the code will
      see a non-zero initial count and start a new one-shot timer using the
      expired timer's count. This is a prior existing bug and will be addressed
      in a separate patch. Thanks to jmattson@google.com for this find.
      Signed-off-by: NPeter Shier <pshier@google.com>
      Reviewed-by: NJim Mattson <jmattson@google.com>
      Reviewed-by: NWanpeng Li <wanpengli@tencent.com>
      Message-Id: <20181010225653.238911-1-pshier@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      24647e0a
    • U
      KVM: SVM: Fix __svm_vcpu_run declaration. · 56a87e5d
      Uros Bizjak 提交于
      The function returns no value.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Fixes: 199cd1d7 ("KVM: SVM: Split svm_vcpu_run inline assembly to separate file")
      Signed-off-by: NUros Bizjak <ubizjak@gmail.com>
      Message-Id: <20200409114926.1407442-1-ubizjak@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      56a87e5d
    • U
      KVM: SVM: Do not setup frame pointer in __svm_vcpu_run · b61f62d4
      Uros Bizjak 提交于
      __svm_vcpu_run is a leaf function and does not need
      a frame pointer.  %rbp is also destroyed a few instructions
      later when guest registers are loaded.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NUros Bizjak <ubizjak@gmail.com>
      Message-Id: <20200409120440.1427215-1-ubizjak@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b61f62d4
    • B
      KVM: SVM: Fix build error due to missing release_pages() include · b2bce0a5
      Borislav Petkov 提交于
      Fix:
      
        arch/x86/kvm/svm/sev.c: In function ‘sev_pin_memory’:
        arch/x86/kvm/svm/sev.c:360:3: error: implicit declaration of function ‘release_pages’;\
      	  did you mean ‘reclaim_pages’? [-Werror=implicit-function-declaration]
          360 |   release_pages(pages, npinned);
              |   ^~~~~~~~~~~~~
              |   reclaim_pages
      
      because svm.c includes pagemap.h but the carved out sev.c needs it too.
      Triggered by a randconfig build.
      
      Fixes: eaf78265 ("KVM: SVM: Move SEV code to separate file")
      Signed-off-by: NBorislav Petkov <bp@suse.de>
      Message-Id: <20200411160927.27954-1-bp@alien8.de>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b2bce0a5
    • U
      KVM: SVM: Do not mark svm_vcpu_run with STACK_FRAME_NON_STANDARD · b4fd6308
      Uros Bizjak 提交于
      svm_vcpu_run does not change stack or frame pointer anymore.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NUros Bizjak <ubizjak@gmail.com>
      Message-Id: <20200414113612.104501-1-ubizjak@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b4fd6308
    • O
      kvm: nVMX: match comment with return type for nested_vmx_exit_reflected · 69c09755
      Oliver Upton 提交于
      nested_vmx_exit_reflected() returns a bool, not int. As such, refer to
      the return values as true/false in the comment instead of 1/0.
      Signed-off-by: NOliver Upton <oupton@google.com>
      Message-Id: <20200414221241.134103-1-oupton@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      69c09755
    • O
      kvm: nVMX: reflect MTF VM-exits if injected by L1 · b045ae90
      Oliver Upton 提交于
      According to SDM 26.6.2, it is possible to inject an MTF VM-exit via the
      VM-entry interruption-information field regardless of the 'monitor trap
      flag' VM-execution control. KVM appropriately copies the VM-entry
      interruption-information field from vmcs12 to vmcs02. However, if L1
      has not set the 'monitor trap flag' VM-execution control, KVM fails to
      reflect the subsequent MTF VM-exit into L1.
      
      Fix this by consulting the VM-entry interruption-information field of
      vmcs12 to determine if L1 has injected the MTF VM-exit. If so, reflect
      the exit, regardless of the 'monitor trap flag' VM-execution control.
      
      Fixes: 5f3d45e7 ("kvm/x86: add support for MONITOR_TRAP_FLAG")
      Signed-off-by: NOliver Upton <oupton@google.com>
      Reviewed-by: NPeter Shier <pshier@google.com>
      Reviewed-by: NJim Mattson <jmattson@google.com>
      Message-Id: <20200414224746.240324-1-oupton@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      b045ae90
  3. 14 4月, 2020 1 次提交