linux-stable/arch/mips/kvm
James Hogan 411740f542 KVM: MIPS/MMU: Implement KVM_CAP_SYNC_MMU
Implement the SYNC_MMU capability for KVM MIPS, allowing changes in the
underlying user host virtual address (HVA) mappings to be promptly
reflected in the corresponding guest physical address (GPA) mappings.

This allows for several features to work with guest RAM which require
mappings to be altered or protected, such as copy-on-write, KSM (Kernel
Samepage Merging), idle page tracking, memory swapping, and guest memory
ballooning.

There are two main aspects of this change, described below.

The KVM MMU notifier architecture callbacks are implemented so we can be
notified of changes in the HVA mappings. These arrange for the guest
physical address (GPA) page tables to be modified and possibly for
derived mappings (GVA page tables and TLBs) to be flushed.

 - kvm_unmap_hva[_range]() - These deal with HVA mappings being removed,
   for example before a copy-on-write takes place, which requires the
   corresponding GPA page table mappings to be removed too.

 - kvm_set_spte_hva() - These update a GPA page table entry to match the
   new HVA entry, but must be careful to respect KVM specific
   configuration such as not dirtying a clean guest page which is dirty
   to the host, and write protecting writable pages in read only
   memslots (which will soon be supported).

 - kvm[_test]_age_hva() - These update GPA page table entries to be old
   (invalid) so that access can be tracked, making them young again.

The GPA page fault handling (kvm_mips_map_page) is updated to use
gfn_to_pfn_prot() (which may provide read-only pages), to handle
asynchronous page table invalidation from MMU notifier callbacks, and to
handle more cases in the fast path.

 - mmu_notifier_seq is used to detect asynchronous page table
   invalidations while we're holding a pfn from gfn_to_pfn_prot()
   outside of kvm->mmu_lock, retrying if invalidations have taken place,
   e.g. a COW or a KSM page merge.

 - The fast path (_kvm_mips_map_page_fast) now handles marking old pages
   as young / accessed, and disallowing dirtying of clean pages that
   aren't actually writable (e.g. shared pages that should COW, and
   read-only memory regions when they are enabled in a future patch).

 - Due to the use of MMU notifications we no longer need to keep the
   page references after we've updated the GPA page tables.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
2017-02-03 15:21:28 +00:00
..
00README.txt
callback.c MIPS: KVM: Convert EXPORT_SYMBOL to _GPL 2016-01-24 03:13:24 +01:00
commpage.c MIPS: kvm: Audit and remove any unnecessary uses of module.h 2016-10-05 01:31:20 +02:00
commpage.h MIPS: KVM: Rename files to remove the prefix "kvm_" and "kvm_mips_" 2014-06-30 16:52:03 +02:00
dyntrans.c KVM: MIPS/T&E: Use lockless GVA helpers for dyntrans 2017-02-03 15:21:12 +00:00
emulate.c KVM: MIPS/T&E: Handle read only GPA in TLB mod 2017-02-03 15:21:22 +00:00
entry.c KVM: MIPS: Use CP0_BadInstr[P] for emulation 2017-02-03 15:21:07 +00:00
fpu.S MIPS: KVM: Fix fpu.S misassembly with r6 2016-07-05 16:09:11 +02:00
interrupt.c MIPS: kvm: Audit and remove any unnecessary uses of module.h 2016-10-05 01:31:20 +02:00
interrupt.h MIPS; KVM: Convert exception entry to uasm 2016-07-05 16:08:46 +02:00
Kconfig KVM: MIPS/MMU: Implement KVM_CAP_SYNC_MMU 2017-02-03 15:21:28 +00:00
Makefile MIPS; KVM: Convert exception entry to uasm 2016-07-05 16:08:46 +02:00
mips.c KVM: MIPS/MMU: Implement KVM_CAP_SYNC_MMU 2017-02-03 15:21:28 +00:00
mmu.c KVM: MIPS/MMU: Implement KVM_CAP_SYNC_MMU 2017-02-03 15:21:28 +00:00
msa.S MIPS: KVM: Add base guest MSA support 2015-03-27 21:25:19 +00:00
stats.c MIPS: KVM: Clean up kvm_exit trace event 2016-06-14 11:16:23 +02:00
tlb.c KVM: MIPS/Emulate: Use lockless GVA helpers for cache emulation 2017-02-03 15:21:15 +00:00
trace.h MIPS: KVM: Combine entry trace events into class 2016-06-23 19:17:30 +02:00
trap_emul.c KVM: MIPS/T&E: Handle read only GPA in TLB mod 2017-02-03 15:21:22 +00:00