The natural solution, then, is to cache shadow page tables across context switches. Unfortunately, this introduces a bucketload of problems:
- the guest does not notify the processor (and hence kvm) that it modifies a page table entry if it has reason to believe that the modification will be followed by a tlb flush. It becomes necessary to write-protect guest page tables so that we can use the page fault when the access occurs as a notification. - write protecting the guest page tables means we need to keep track of which ptes map those guest page table. We need to add reverse mapping for all mapped writable guest pages. - when the guest does access the write-protected page, we need to allow it to perform the write in some way. We do that either by emulating the write, or removing all shadow page tables for that page and allowing the write to proceed, depending on circumstances.
This patchset implements the ideas above. While a lot of tuning remains to be done (for example, a sane page replacement algorithm), a guest running with this patchset applied is much faster and more responsive than with 2.6.20-rc3. Some preliminary benchmarks are available in http://article.gmane.org/gmane.comp.emulators.kvm.devel/661.
The patchset is bisectable compile-wise. -- error compiling committee.c: too many arguments to function - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH 0/33] KVM: MMU: Cache shadow page tables
- From: Andrew Morton <[email protected]>
- [PATCH 33/33] KVM: MMU: add audit code to check mappings, etc are correct
- From: Avi Kivity <[email protected]>
- [PATCH 32/33] KVM: MMU: Destroy mmu while we still have a vcpu left
- From: Avi Kivity <[email protected]>
- [PATCH 31/33] KVM: MMU: Flush guest tlb when reducing permissions on a pte
- From: Avi Kivity <[email protected]>
- [PATCH 30/33] KVM: MMU: Detect oom conditions and propagate error to userspace
- From: Avi Kivity <[email protected]>
- [PATCH 29/33] KVM: MMU: Replace atomic allocations by preallocated objects
- From: Avi Kivity <[email protected]>
- [PATCH 28/33] KVM: MMU: Free pages on kvm destruction
- From: Avi Kivity <[email protected]>
- [PATCH 27/33] KVM: MMU: Treat user-mode faults as a hint that a page is no longer a page table
- From: Avi Kivity <[email protected]>
- [PATCH 26/33] KVM: MMU: Fix cmpxchg8b emulation
- From: Avi Kivity <[email protected]>
- [PATCH 25/33] KVM: MMU: Never free a shadow page actively serving as a root
- From: Avi Kivity <[email protected]>
- [PATCH 24/33] KVM: MMU: Page table write flood protection
- From: Avi Kivity <[email protected]>
- [PATCH 23/33] KVM: MMU: If an empty shadow page is not empty, report more info
- From: Avi Kivity <[email protected]>
- [PATCH 22/33] KVM: MMU: Ensure freed shadow pages are clean
- From: Avi Kivity <[email protected]>
- [PATCH 21/33] KVM: MMU: <ove is_empty_shadow_page() above kvm_mmu_free_page()
- From: Avi Kivity <[email protected]>
- [PATCH 20/33] KVM: MMU: Handle misaligned accesses to write protected guest page tables
- From: Avi Kivity <[email protected]>
- [PATCH 19/33] KVM: MMU: Remove release_pt_page_64()
- From: Avi Kivity <[email protected]>
- [PATCH 18/33] KVM: MMU: Remove invlpg interception
- From: Avi Kivity <[email protected]>
- [PATCH 17/33] KVM: MMU: oom handling
- From: Avi Kivity <[email protected]>
- [PATCH 16/33] KVM: MMU: kvm_mmu_put_page() only removes one link to the page
- From: Avi Kivity <[email protected]>
- [PATCH 15/33] KVM: MMU: Implement child shadow unlinking
- From: Avi Kivity <[email protected]>
- [PATCH 14/33] KVM: MMU: If emulating an instruction fails, try unprotecting the page
- From: Avi Kivity <[email protected]>
- [PATCH 13/33] KVM: MMU: Zap shadow page table entries on writes to guest page tables
- From: Avi Kivity <[email protected]>
- [PATCH 12/33] KVM: MMU: Support emulated writes into RAM
- From: Avi Kivity <[email protected]>
- [PATCH 11/33] KVM: MMU: Let the walker extract the target page gfn from the pte
- From: Avi Kivity <[email protected]>
- [PATCH 10/33] KVM: MMU: Write protect guest pages when a shadow is created for them
- From: Avi Kivity <[email protected]>
- [PATCH 9/33] KVM: MMU: Shadow page table caching
- From: Avi Kivity <[email protected]>
- [PATCH 8/33] KVM: MMU: Make kvm_mmu_alloc_page() return a kvm_mmu_page pointer
- From: Avi Kivity <[email protected]>
- [PATCH 7/33] KVM: MMU: Make the shadow page tables also special-case pae
- From: Avi Kivity <[email protected]>
- [PATCH 6/33] KVM: MMU: Use the guest pdptrs instead of mapping cr3 in pae mode
- From: Avi Kivity <[email protected]>
- [PATCH 5/33] KVM: MU: Special treatment for shadow pae root pages
- From: Avi Kivity <[email protected]>
- [PATCH 4/33] KVM: MMU: Fold fetch_guest() into init_walker()
- From: Avi Kivity <[email protected]>
- [PATCH 3/33] KVM: MMU: Load the pae pdptrs on cr3 change like the processor does
- From: Avi Kivity <[email protected]>
- [PATCH 2/33] KVM: MMU: Teach the page table walker to track guest page table gfns
- From: Avi Kivity <[email protected]>
- [PATCH 1/33] KVM: MMU: Implement simple reverse mapping
- From: Avi Kivity <[email protected]>
- Re: [PATCH 0/33] KVM: MMU: Cache shadow page tables
- Prev by Date: RE: kernel + gcc 4.1 = several problems
- Next by Date: [PATCH 1/33] KVM: MMU: Implement simple reverse mapping
- Previous by thread: ACL support patch for > 2.4.29
- Next by thread: [PATCH 1/33] KVM: MMU: Implement simple reverse mapping
- Index(es):