1. 12 Feb, 2020 1 commit
  2. 21 Nov, 2019 1 commit
  3. 25 Jan, 2019 1 commit
  4. 21 Dec, 2018 1 commit
    • Sean Christopherson's avatar
      KVM: VMX: Move VM-Enter + VM-Exit handling to non-inline sub-routines · 453eafbe
      Sean Christopherson authored
      Transitioning to/from a VMX guest requires KVM to manually save/load
      the bulk of CPU state that the guest is allowed to direclty access,
      e.g. XSAVE state, CR2, GPRs, etc...  For obvious reasons, loading the
      guest's GPR snapshot prior to VM-Enter and saving the snapshot after
      VM-Exit is done via handcoded assembly.  The assembly blob is written
      as inline asm so that it can easily access KVM-defined structs that
      are used to hold guest state, e.g. moving the blob to a standalone
      assembly file would require generating defines for struct offsets.
      
      The other relevant aspect of VMX transitions in KVM is the handling of
      VM-Exits.  KVM doesn't employ a separate VM-Exit handler per se, but
      rather treats the VMX transition as a mega instruction (with many side
      effects), i.e. sets the VMCS.HOST_RIP to a label immediately following
      VMLAUNCH/VMRESUME.  The label is then exposed to C code via a global
      variable definition in the inline assembly.
      
      Because of the global variable, KVM takes steps to (attempt to) ensure
      only a single instance of the owning C function, e.g. vmx_vcpu_run, is
      generated by the compiler.  The earliest approach placed the inline
      assembly in a separate noinline function[1].  Later, the assembly was
      folded back into vmx_vcpu_run() and tagged with __noclone[2][3], which
      is still used today.
      
      After moving to __noclone, an edge case was encountered where GCC's
      -ftracer optimization resulted in the inline assembly blob being
      duplicated.  This was "fixed" by explicitly disabling -ftracer in the
      __noclone definition[4].
      
      Recently, it was found that disabling -ftracer causes build warnings
      for unsuspecting users of __noclone[5], and more importantly for KVM,
      prevents the compiler for properly optimizing vmx_vcpu_run()[6].  And
      perhaps most importantly of all, it was pointed out that there is no
      way to prevent duplication of a function with 100% reliability[7],
      i.e. more edge cases may be encountered in the future.
      
      So to summarize, the only way to prevent the compiler from duplicating
      the global variable definition is to move the variable out of inline
      assembly, which has been suggested several times over[1][7][8].
      
      Resolve the aforementioned issues by moving the VMLAUNCH+VRESUME and
      VM-Exit "handler" to standalone assembly sub-routines.  Moving only
      the core VMX transition codes allows the struct indexing to remain as
      inline assembly and also allows the sub-routines to be used by
      nested_vmx_check_vmentry_hw().  Reusing the sub-routines has a happy
      side-effect of eliminating two VMWRITEs in the nested_early_check path
      as there is no longer a need to dynamically change VMCS.HOST_RIP.
      
      Note that callers to vmx_vmenter() must account for the CALL modifying
      RSP, e.g. must subtract op-size from RSP when synchronizing RSP with
      VMCS.HOST_RSP and "restore" RSP prior to the CALL.  There are no great
      alternatives to fudging RSP.  Saving RSP in vmx_enter() is difficult
      because doing so requires a second register (VMWRITE does not provide
      an immediate encoding for the VMCS field and KVM supports Hyper-V's
      memory-based eVMCS ABI).  The other more drastic alternative would be
      to use eschew VMCS.HOST_RSP and manually save/load RSP using a per-cpu
      variable (which can be encoded as e.g. gs:[imm]).  But because a valid
      stack is needed at the time of VM-Exit (NMIs aren't blocked and a user
      could theoretically insert INT3/INT1ICEBRK at the VM-Exit handler), a
      dedicated per-cpu VM-Exit stack would be required.  A dedicated stack
      isn't difficult to implement, but it would require at least one page
      per CPU and knowledge of the stack in the dumpstack routines.  And in
      most cases there is essentially zero overhead in dynamically updating
      VMCS.HOST_RSP, e.g. the VMWRITE can be avoided for all but the first
      VMLAUNCH unless nested_early_check=1, which is not a fast path.  In
      other words, avoiding the VMCS.HOST_RSP by using a dedicated stack
      would only make the code marginally less ugly while requiring at least
      one page per CPU and forcing the kernel to be aware (and approve) of
      the VM-Exit stack shenanigans.
      
      [1] cea15c24ca39 ("KVM: Move KVM context switch into own function")
      [2] a3b5ba49 ("KVM: VMX: add the __noclone attribute to vmx_vcpu_run")
      [3] 104f226b ("KVM: VMX: Fold __vmx_vcpu_run() into vmx_vcpu_run()")
      [4] 95272c29 ("compiler-gcc: disable -ftracer for __noclone functions")
      [5] https://lkml.kernel.org/r/20181218140105.ajuiglkpvstt3qxs@treble
      [6] https://patchwork.kernel.org/patch/8707981/#21817015
      [7] https://lkml.kernel.org/r/ri6y38lo23g.fsf@suse.cz
      [8] https://lkml.kernel.org/r/20181218212042.GE25620@tassilo.jf.intel.com
      
      Suggested-by: default avatarAndi Kleen <ak@linux.intel.com>
      Suggested-by: default avatarMartin Jambor <mjambor@suse.cz>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: Nadav Amit <namit@vmware.com>
      Cc: Andi Kleen <ak@linux.intel.com>
      Cc: Josh Poimboeuf <jpoimboe@redhat.com>
      Cc: Martin Jambor <mjambor@suse.cz>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Miroslav Benes <mbenes@suse.cz>
      Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
      Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      453eafbe
  5. 14 Dec, 2018 4 commits
  6. 02 Nov, 2017 1 commit
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard...
      b2441318
  7. 07 Apr, 2017 1 commit
  8. 16 Sep, 2016 1 commit
  9. 03 Mar, 2016 1 commit
    • Xiao Guangrong's avatar
      KVM: page track: add the framework of guest page tracking · 21ebbeda
      Xiao Guangrong authored
      
      The array, gfn_track[mode][gfn], is introduced in memory slot for every
      guest page, this is the tracking count for the gust page on different
      modes. If the page is tracked then the count is increased, the page is
      not tracked after the count reaches zero
      
      We use 'unsigned short' as the tracking count which should be enough as
      shadow page table only can use 2^14 (2^3 for level, 2^1 for cr4_pae, 2^2
      for quadrant, 2^3 for access, 2^1 for nxe, 2^1 for cr0_wp, 2^1 for
      smep_andnot_wp, 2^1 for smap_andnot_wp, and 2^1 for smm) at most, there
      is enough room for other trackers
      
      Two callbacks, kvm_page_track_create_memslot() and
      kvm_page_track_free_memslot() are implemented in this patch, they are
      internally used to initialize and reclaim the memory of the array
      
      Currently, only write track mode is supported
      Signed-off-by: default avatarXiao Guangrong <guangrong.xiao@linux.intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      21ebbeda
  10. 23 Jul, 2015 1 commit
  11. 23 Jun, 2015 1 commit
  12. 19 Jun, 2015 1 commit
  13. 26 Mar, 2015 1 commit
  14. 23 Nov, 2014 1 commit
  15. 21 Nov, 2014 1 commit
  16. 30 Oct, 2013 1 commit
    • Alex Williamson's avatar
      kvm: Add VFIO device · ec53500f
      Alex Williamson authored
      
      So far we've succeeded at making KVM and VFIO mostly unaware of each
      other, but areas are cropping up where a connection beyond eventfds
      and irqfds needs to be made.  This patch introduces a KVM-VFIO device
      that is meant to be a gateway for such interaction.  The user creates
      the device and can add and remove VFIO groups to it via file
      descriptors.  When a group is added, KVM verifies the group is valid
      and gets a reference to it via the VFIO external user interface.
      Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      ec53500f
  17. 19 May, 2013 1 commit
  18. 28 Apr, 2013 1 commit
  19. 26 Apr, 2013 1 commit
  20. 01 Aug, 2012 1 commit
  21. 27 Dec, 2011 2 commits
  22. 12 Jan, 2011 2 commits
  23. 03 Dec, 2009 1 commit
  24. 10 Sep, 2009 5 commits
  25. 10 Jun, 2009 1 commit
  26. 03 Jan, 2009 2 commits
  27. 15 Oct, 2008 3 commits
  28. 20 Jul, 2008 1 commit