• James Hogan's avatar
    KVM: MIPS/MMU: Implement KVM_CAP_SYNC_MMU · 411740f5
    James Hogan authored
    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: default avatarJames 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
    411740f5
mips.c 45.1 KB