Skip to content

KVM: MMU: Cache shadow page tables

Avi Kivity kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest33 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/33KVM: MMU: Implement simple reverse mappingdrivers/kvm/kvm.h drivers/kvm/kvm_main.c drivers/kvm/mmu.c +1 more+142 -130 replies
2/33KVM: MMU: Teach the page table walker to track guest page table gfnsdrivers/kvm/paging_tmpl.h+5 -20 replies
3/33KVM: MMU: Load the pae pdptrs on cr3 change like the processor doesdrivers/kvm/kvm.h drivers/kvm/kvm_main.c+20 -100 replies
4/33KVM: MMU: Fold fetch_guest() into init_walker()drivers/kvm/paging_tmpl.h+47 -580 replies
5/33KVM: MU: Special treatment for shadow pae root pagesdrivers/kvm/kvm.h drivers/kvm/mmu.c+82 -450 replies
6/33KVM: MMU: Use the guest pdptrs instead of mapping cr3 in pae modedrivers/kvm/kvm_main.c drivers/kvm/paging_tmpl.h+20 -100 replies
7/33KVM: MMU: Make the shadow page tables also special-case paedrivers/kvm/paging_tmpl.h+7 -40 replies
8/33KVM: MMU: Make kvm_mmu_alloc_page() return a kvm_mmu_page pointerdrivers/kvm/mmu.c drivers/kvm/paging_tmpl.h+15 -150 replies
9/33KVM: MMU: Shadow page table cachingdrivers/kvm/kvm.h drivers/kvm/mmu.c drivers/kvm/paging_tmpl.h+280 -340 replies
10/33KVM: MMU: Write protect guest pages when a shadow is created for themdrivers/kvm/mmu.c drivers/kvm/paging_tmpl.h+55 -180 replies
11/33KVM: MMU: Let the walker extract the target page gfn from the ptedrivers/kvm/mmu.c drivers/kvm/paging_tmpl.h+31 -170 replies
12/33KVM: MMU: Support emulated writes into RAMdrivers/kvm/kvm.h drivers/kvm/kvm_main.c drivers/kvm/mmu.c+36 -00 replies
13/33KVM: MMU: Zap shadow page table entries on writes to guest page tablesdrivers/kvm/mmu.c+36 -00 replies
14/33KVM: MMU: If emulating an instruction fails, try unprotecting the pagedrivers/kvm/kvm.h drivers/kvm/kvm_main.c drivers/kvm/mmu.c+61 -00 replies
15/33KVM: MMU: Implement child shadow unlinkingdrivers/kvm/mmu.c+38 -40 replies
16/33KVM: MMU: kvm_mmu_put_page() only removes one link to the pagedrivers/kvm/mmu.c+4 -40 replies
17/33KVM: MMU: oom handlingdrivers/kvm/kvm.h drivers/kvm/mmu.c drivers/kvm/paging_tmpl.h +2 more+37 -430 replies
18/33KVM: MMU: Remove invlpg interceptiondrivers/kvm/kvm.h drivers/kvm/kvm_main.c drivers/kvm/mmu.c +2 more+0 -620 replies
19/33KVM: MMU: Remove release_pt_page_64()drivers/kvm/mmu.c+0 -290 replies
20/33KVM: MMU: Handle misaligned accesses to write protected guest page tablesdrivers/kvm/mmu.c+17 -20 replies
21/33KVM: MMU: <ove is_empty_shadow_page() above kvm_mmu_free_page()drivers/kvm/mmu.c+10 -100 replies
22/33KVM: MMU: Ensure freed shadow pages are cleandrivers/kvm/mmu.c+1 -00 replies
23/33KVM: MMU: If an empty shadow page is not empty, report more infodrivers/kvm/mmu.c+8 -40 replies
24/33KVM: MMU: Page table write flood protectiondrivers/kvm/kvm.h drivers/kvm/mmu.c+18 -10 replies
25/33KVM: MMU: Never free a shadow page actively serving as a rootdrivers/kvm/kvm.h drivers/kvm/mmu.c+19 -20 replies
26/33KVM: MMU: Fix cmpxchg8b emulationdrivers/kvm/kvm_main.c drivers/kvm/x86_emulate.c+28 -10 replies
27/33KVM: MMU: Treat user-mode faults as a hint that a page is no longer a page tabledrivers/kvm/paging_tmpl.h+12 -10 replies
28/33KVM: MMU: Free pages on kvm destructiondrivers/kvm/mmu.c+7 -20 replies
29/33KVM: MMU: Replace atomic allocations by preallocated objectsdrivers/kvm/kvm.h drivers/kvm/kvm_main.c drivers/kvm/mmu.c +1 more+153 -370 replies
30/33KVM: MMU: Detect oom conditions and propagate error to userspacedrivers/kvm/mmu.c drivers/kvm/paging_tmpl.h drivers/kvm/svm.c +1 more+50 -190 replies
31/33KVM: MMU: Flush guest tlb when reducing permissions on a ptedrivers/kvm/mmu.c+6 -10 replies
32/33KVM: MMU: Destroy mmu while we still have a vcpu leftdrivers/kvm/kvm_main.c+1 -10 replies
33/33KVM: MMU: add audit code to check mappings, etc are correctdrivers/kvm/mmu.c drivers/kvm/paging_tmpl.h+189 -20 replies

Reviews trailers per patch

None of the 33 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchIngo Molnar
SeriesA-b
1/33
2/33
3/33
4/33
5/33
6/33
7/33
8/33
9/33
10/33
11/33
12/33
13/33
14/33
15/33
16/33
17/33
18/33
19/33
20/33
21/33
22/33
23/33
24/33
25/33
26/33
27/33
28/33
29/33
30/33
31/33
32/33
33/33

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/33] KVM: MMU: Cache shadow page tables

The current kvm shadow page table implementation does not cache shadow page tables (except for global translations, used for kernel addresses) across context switches. This means that after a context switch, every memory access will trap into the host. After a while, the shadow page tables will be rebuild, and the guest can proceed at native speed until the next context switch.

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.

Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV