]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86/mmu: comment on kvm_mmu_get_page's syncing of pages
authorSean Christopherson <seanjc@google.com>
Wed, 23 Jun 2021 16:49:19 +0000 (12:49 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 24 Jun 2021 22:00:37 +0000 (18:00 -0400)
Explain the usage of sync_page() in kvm_mmu_get_page(), which is
subtle in how and why it differs from mmu_sync_children().

Signed-off-by: Sean Christopherson <seanjc@google.com>
[Split out of a different patch by Sean. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c

index e4415e739807fef4d38ed91e358e5a7f27c28404..726e5b1715432a0fd8f3fbb05b2a4dd6d0ccb1b9 100644 (file)
@@ -2008,8 +2008,17 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
                        goto trace_get_page;
 
                if (sp->unsync) {
-                       /* The page is good, but __kvm_sync_page might still end
-                        * up zapping it.  If so, break in order to rebuild it.
+                       /*
+                        * The page is good, but is stale.  __kvm_sync_page does
+                        * get the latest guest state, but (unlike mmu_unsync_children)
+                        * it doesn't write-protect the page or mark it synchronized!
+                        * This way the validity of the mapping is ensured, but the
+                        * overhead of write protection is not incurred until the
+                        * guest invalidates the TLB mapping.  This allows multiple
+                        * SPs for a single gfn to be unsync.
+                        *
+                        * If the sync fails, the page is zapped.  If so, break
+                        * in order to rebuild it.
                         */
                        if (!__kvm_sync_page(vcpu, sp, &invalid_list))
                                break;