diff options
author | Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> | 2013-06-19 05:09:24 -0400 |
---|---|---|
committer | Gleb Natapov <gleb@redhat.com> | 2013-06-27 07:20:47 -0400 |
commit | f6f8adeef542a18b1cb26a0b772c9781a10bb477 (patch) | |
tree | 60399cfb430de99e170e68bb2a1c7be596e680c0 | |
parent | 2d49c47f350b939b395cd2d1abaa8c3bb6c54326 (diff) |
KVM: MMU: document fast invalidate all pages
Document it to Documentation/virtual/kvm/mmu.txt
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | Documentation/virtual/kvm/mmu.txt | 25 | ||||
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/Documentation/virtual/kvm/mmu.txt b/Documentation/virtual/kvm/mmu.txt index 42193f206602..89c8a4caf51e 100644 --- a/Documentation/virtual/kvm/mmu.txt +++ b/Documentation/virtual/kvm/mmu.txt | |||
@@ -210,6 +210,10 @@ Shadow pages contain the following information: | |||
210 | A bitmap indicating which sptes in spt point (directly or indirectly) at | 210 | A bitmap indicating which sptes in spt point (directly or indirectly) at |
211 | pages that may be unsynchronized. Used to quickly locate all unsychronized | 211 | pages that may be unsynchronized. Used to quickly locate all unsychronized |
212 | pages reachable from a given page. | 212 | pages reachable from a given page. |
213 | mmu_valid_gen: | ||
214 | Generation number of the page. It is compared with kvm->arch.mmu_valid_gen | ||
215 | during hash table lookup, and used to skip invalidated shadow pages (see | ||
216 | "Zapping all pages" below.) | ||
213 | clear_spte_count: | 217 | clear_spte_count: |
214 | Only present on 32-bit hosts, where a 64-bit spte cannot be written | 218 | Only present on 32-bit hosts, where a 64-bit spte cannot be written |
215 | atomically. The reader uses this while running out of the MMU lock | 219 | atomically. The reader uses this while running out of the MMU lock |
@@ -375,6 +379,27 @@ causes its write_count to be incremented, thus preventing instantiation of | |||
375 | a large spte. The frames at the end of an unaligned memory slot have | 379 | a large spte. The frames at the end of an unaligned memory slot have |
376 | artificially inflated ->write_counts so they can never be instantiated. | 380 | artificially inflated ->write_counts so they can never be instantiated. |
377 | 381 | ||
382 | Zapping all pages (page generation count) | ||
383 | ========================================= | ||
384 | |||
385 | For the large memory guests, walking and zapping all pages is really slow | ||
386 | (because there are a lot of pages), and also blocks memory accesses of | ||
387 | all VCPUs because it needs to hold the MMU lock. | ||
388 | |||
389 | To make it be more scalable, kvm maintains a global generation number | ||
390 | which is stored in kvm->arch.mmu_valid_gen. Every shadow page stores | ||
391 | the current global generation-number into sp->mmu_valid_gen when it | ||
392 | is created. Pages with a mismatching generation number are "obsolete". | ||
393 | |||
394 | When KVM need zap all shadow pages sptes, it just simply increases the global | ||
395 | generation-number then reload root shadow pages on all vcpus. As the VCPUs | ||
396 | create new shadow page tables, the old pages are not used because of the | ||
397 | mismatching generation number. | ||
398 | |||
399 | KVM then walks through all pages and zaps obsolete pages. While the zap | ||
400 | operation needs to take the MMU lock, the lock can be released periodically | ||
401 | so that the VCPUs can make progress. | ||
402 | |||
378 | Further reading | 403 | Further reading |
379 | =============== | 404 | =============== |
380 | 405 | ||
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 6b636fd8582f..280e3271b027 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -222,7 +222,10 @@ struct kvm_mmu_page { | |||
222 | int root_count; /* Currently serving as active root */ | 222 | int root_count; /* Currently serving as active root */ |
223 | unsigned int unsync_children; | 223 | unsigned int unsync_children; |
224 | unsigned long parent_ptes; /* Reverse mapping for parent_pte */ | 224 | unsigned long parent_ptes; /* Reverse mapping for parent_pte */ |
225 | |||
226 | /* The page is obsolete if mmu_valid_gen != kvm->arch.mmu_valid_gen. */ | ||
225 | unsigned long mmu_valid_gen; | 227 | unsigned long mmu_valid_gen; |
228 | |||
226 | DECLARE_BITMAP(unsync_child_bitmap, 512); | 229 | DECLARE_BITMAP(unsync_child_bitmap, 512); |
227 | 230 | ||
228 | #ifdef CONFIG_X86_32 | 231 | #ifdef CONFIG_X86_32 |