Commit 636deed6 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull KVM updates from Paolo Bonzini:
 "ARM:
   - some cleanups
   - direct physical timer assignment
   - cache sanitization for 32-bit guests

  s390:
   - interrupt cleanup
   - introduction of the Guest Information Block
   - preparation for processor subfunctions in cpu models

  PPC:
   - bug fixes and improvements, especially related to machine checks
     and protection keys

  x86:
   - many, many cleanups, including removing a bunch of MMU code for
     unnecessary optimizations
   - AVIC fixes

  Generic:
   - memcg accounting"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (147 commits)
  kvm: vmx: fix formatting of a comment
  KVM: doc: Document the life cycle of a VM and its resources
  MAINTAINERS: Add KVM selftests to existing KVM entry
  Revert "KVM/MMU: Flush tlb directly in the kvm_zap_gfn_range()"
  KVM: PPC: Book3S: Add count cache flush parameters to kvmppc_get_cpu_char()
  KVM: PPC: Fix compilation when KVM is not enabled
  KVM: Minor cleanups for kvm_main.c
  KVM: s390: add debug logging for cpu model subfunctions
  KVM: s390: implement subfunction processor calls
  arm64: KVM: Fix architecturally invalid reset value for FPEXC32_EL2
  KVM: arm/arm64: Remove unused timer variable
  KVM: PPC: Book3S: Improve KVM reference counting
  KVM: PPC: Book3S HV: Fix build failure without IOMMU support
  Revert "KVM: Eliminate extra function calls in kvm_get_dirty_log_protect()"
  x86: kvmguest: use TSC clocksource if invariant TSC is exposed
  KVM: Never start grow vCPU halt_poll_ns from value below halt_poll_ns_grow_start
  KVM: Expose the initial start value in grow_halt_poll_ns() as a module parameter
  KVM: grow_halt_poll_ns() should never shrink vCPU halt_poll_ns
  KVM: x86/mmu: Consolidate kvm_mmu_zap_all() and kvm_mmu_zap_mmio_sptes()
  KVM: x86/mmu: WARN if zapping a MMIO spte results in zapping children
  ...
parents aa2e3ac6 4a605bc0
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -45,6 +45,23 @@ the API. The only supported use is one virtual machine per process,
and one vcpu per thread.


It is important to note that althought VM ioctls may only be issued from
the process that created the VM, a VM's lifecycle is associated with its
file descriptor, not its creator (process).  In other words, the VM and
its resources, *including the associated address space*, are not freed
until the last reference to the VM's file descriptor has been released.
For example, if fork() is issued after ioctl(KVM_CREATE_VM), the VM will
not be freed until both the parent (original) process and its child have
put their references to the VM's file descriptor.

Because a VM's resources are not freed until the last reference to its
file descriptor is released, creating additional references to a VM via
via fork(), dup(), etc... without careful consideration is strongly
discouraged and may have unwanted side effects, e.g. memory allocated
by and on behalf of the VM's process may not be freed/unaccounted when
the VM is shut down.


3. Extensions
-------------

+23 −14
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ the global max polling interval then the polling interval can be increased in
the hope that next time during the longer polling interval the wake up source
will be received while the host is polling and the latency benefits will be
received. The polling interval is grown in the function grow_halt_poll_ns() and
is multiplied by the module parameter halt_poll_ns_grow.
is multiplied by the module parameters halt_poll_ns_grow and
halt_poll_ns_grow_start.

In the event that the total block time was greater than the global max polling
interval then the host will never poll for long enough (limited by the global
@@ -82,19 +83,27 @@ powerpc kvm-hv case.

Module Parameter	|   Description		    |	     Default Value
--------------------------------------------------------------------------------
halt_poll_ns	    | The global max polling interval | KVM_HALT_POLL_NS_DEFAULT
		    | which defines the ceiling value |
		    | of the polling interval for     | (per arch value)
halt_poll_ns		| The global max polling    | KVM_HALT_POLL_NS_DEFAULT
			| interval which defines    |
			| the ceiling value of the  |
			| polling interval for      | (per arch value)
			| each vcpu.		    |
--------------------------------------------------------------------------------
halt_poll_ns_grow   | The value by which the halt     |	2
		    | polling interval is multiplied  |
		    | in the grow_halt_poll_ns()      |
halt_poll_ns_grow	| The value by which the    | 2
			| halt polling interval is  |
			| multiplied in the	    |
			| grow_halt_poll_ns()	    |
			| function.		    |
--------------------------------------------------------------------------------
halt_poll_ns_shrink | The value by which the halt     |	0
		    | polling interval is divided in  |
		    | the shrink_halt_poll_ns()	      |
halt_poll_ns_grow_start | The initial value to grow | 10000
			| to from zero in the	    |
			| grow_halt_poll_ns()	    |
			| function.		    |
--------------------------------------------------------------------------------
halt_poll_ns_shrink	| The value by which the    | 0
			| halt polling interval is  |
			| divided in the	    |
			| shrink_halt_poll_ns()	    |
			| function.		    |
--------------------------------------------------------------------------------

+9 −32
Original line number Diff line number Diff line
@@ -224,10 +224,6 @@ Shadow pages contain the following information:
    A bitmap indicating which sptes in spt point (directly or indirectly) at
    pages that may be unsynchronized.  Used to quickly locate all unsychronized
    pages reachable from a given page.
  mmu_valid_gen:
    Generation number of the page.  It is compared with kvm->arch.mmu_valid_gen
    during hash table lookup, and used to skip invalidated shadow pages (see
    "Zapping all pages" below.)
  clear_spte_count:
    Only present on 32-bit hosts, where a 64-bit spte cannot be written
    atomically.  The reader uses this while running out of the MMU lock
@@ -402,27 +398,6 @@ causes its disallow_lpage to be incremented, thus preventing instantiation of
a large spte.  The frames at the end of an unaligned memory slot have
artificially inflated ->disallow_lpages so they can never be instantiated.

Zapping all pages (page generation count)
=========================================

For the large memory guests, walking and zapping all pages is really slow
(because there are a lot of pages), and also blocks memory accesses of
all VCPUs because it needs to hold the MMU lock.

To make it be more scalable, kvm maintains a global generation number
which is stored in kvm->arch.mmu_valid_gen.  Every shadow page stores
the current global generation-number into sp->mmu_valid_gen when it
is created.  Pages with a mismatching generation number are "obsolete".

When KVM need zap all shadow pages sptes, it just simply increases the global
generation-number then reload root shadow pages on all vcpus.  As the VCPUs
create new shadow page tables, the old pages are not used because of the
mismatching generation number.

KVM then walks through all pages and zaps obsolete pages.  While the zap
operation needs to take the MMU lock, the lock can be released periodically
so that the VCPUs can make progress.

Fast invalidation of MMIO sptes
===============================

@@ -435,8 +410,7 @@ shadow pages, and is made more scalable with a similar technique.
MMIO sptes have a few spare bits, which are used to store a
generation number.  The global generation number is stored in
kvm_memslots(kvm)->generation, and increased whenever guest memory info
changes.  This generation number is distinct from the one described in
the previous section.
changes.

When KVM finds an MMIO spte, it checks the generation number of the spte.
If the generation number of the spte does not equal the global generation
@@ -452,13 +426,16 @@ stored into the MMIO spte. Thus, the MMIO spte might be created based on
out-of-date information, but with an up-to-date generation number.

To avoid this, the generation number is incremented again after synchronize_srcu
returns; thus, the low bit of kvm_memslots(kvm)->generation is only 1 during a
returns; thus, bit 63 of kvm_memslots(kvm)->generation set to 1 only during a
memslot update, while some SRCU readers might be using the old copy.  We do not
want to use an MMIO sptes created with an odd generation number, and we can do
this without losing a bit in the MMIO spte.  The low bit of the generation
is not stored in MMIO spte, and presumed zero when it is extracted out of the
spte.  If KVM is unlucky and creates an MMIO spte while the low bit is 1,
the next access to the spte will always be a cache miss.
this without losing a bit in the MMIO spte.  The "update in-progress" bit of the
generation is not stored in MMIO spte, and is so is implicitly zero when the
generation is extracted out of the spte.  If KVM is unlucky and creates an MMIO
spte while an update is in-progress, the next access to the spte will always be
a cache miss.  For example, a subsequent access during the update window will
miss due to the in-progress flag diverging, while an access after the update
window closes will have a higher generation number (as compared to the spte).


Further reading
+8 −11
Original line number Diff line number Diff line
@@ -8461,6 +8461,7 @@ F: include/linux/kvm*
F:	include/kvm/iodev.h
F:	virt/kvm/*
F:	tools/kvm/
F:	tools/testing/selftests/kvm/

KERNEL VIRTUAL MACHINE FOR AMD-V (KVM/amd)
M:	Joerg Roedel <joro@8bytes.org>
@@ -8470,29 +8471,25 @@ S: Maintained
F:	arch/x86/include/asm/svm.h
F:	arch/x86/kvm/svm.c

KERNEL VIRTUAL MACHINE FOR ARM (KVM/arm)
KERNEL VIRTUAL MACHINE FOR ARM/ARM64 (KVM/arm, KVM/arm64)
M:	Christoffer Dall <christoffer.dall@arm.com>
M:	Marc Zyngier <marc.zyngier@arm.com>
R:	James Morse <james.morse@arm.com>
R:	Julien Thierry <julien.thierry@arm.com>
R:	Suzuki K Pouloze <suzuki.poulose@arm.com>
L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
L:	kvmarm@lists.cs.columbia.edu
W:	http://systems.cs.columbia.edu/projects/kvm-arm
T:	git git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git
S:	Supported
S:	Maintained
F:	arch/arm/include/uapi/asm/kvm*
F:	arch/arm/include/asm/kvm*
F:	arch/arm/kvm/
F:	virt/kvm/arm/
F:	include/kvm/arm_*

KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)
M:	Christoffer Dall <christoffer.dall@arm.com>
M:	Marc Zyngier <marc.zyngier@arm.com>
L:	linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
L:	kvmarm@lists.cs.columbia.edu
S:	Maintained
F:	arch/arm64/include/uapi/asm/kvm*
F:	arch/arm64/include/asm/kvm*
F:	arch/arm64/kvm/
F:	virt/kvm/arm/
F:	include/kvm/arm_*

KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips)
M:	James Hogan <jhogan@kernel.org>
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@
#define ICH_VTR				__ACCESS_CP15(c12, 4, c11, 1)
#define ICH_MISR			__ACCESS_CP15(c12, 4, c11, 2)
#define ICH_EISR			__ACCESS_CP15(c12, 4, c11, 3)
#define ICH_ELSR			__ACCESS_CP15(c12, 4, c11, 5)
#define ICH_ELRSR			__ACCESS_CP15(c12, 4, c11, 5)
#define ICH_VMCR			__ACCESS_CP15(c12, 4, c11, 7)

#define __LR0(x)			__ACCESS_CP15(c12, 4, c12, x)
@@ -152,7 +152,7 @@ CPUIF_MAP(ICH_HCR, ICH_HCR_EL2)
CPUIF_MAP(ICH_VTR, ICH_VTR_EL2)
CPUIF_MAP(ICH_MISR, ICH_MISR_EL2)
CPUIF_MAP(ICH_EISR, ICH_EISR_EL2)
CPUIF_MAP(ICH_ELSR, ICH_ELSR_EL2)
CPUIF_MAP(ICH_ELRSR, ICH_ELRSR_EL2)
CPUIF_MAP(ICH_VMCR, ICH_VMCR_EL2)
CPUIF_MAP(ICH_AP0R3, ICH_AP0R3_EL2)
CPUIF_MAP(ICH_AP0R2, ICH_AP0R2_EL2)
Loading