KVM: x86: reintroduce pte_list_remove, but including mmu_spte_clear_track_bits
authorWei Yang <richard.weiyang@gmail.com>
Thu, 4 Oct 2018 02:04:23 +0000 (10:04 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 16 Oct 2018 22:30:12 +0000 (00:30 +0200)
rmap_remove() removes the sptep after locating the correct rmap_head but,
in several cases, the caller has already known the correct rmap_head.

This patch introduces a new pte_list_remove(); because it is known that
the spte is present (or it would not have an rmap_head), it is safe
to remove the tracking bits without any previous check.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu.c

index 175bfb6..4cf43ce 100644 (file)
@@ -1301,6 +1301,12 @@ static void __pte_list_remove(u64 *spte, struct kvm_rmap_head *rmap_head)
        }
 }
 
+static void pte_list_remove(struct kvm_rmap_head *rmap_head, u64 *sptep)
+{
+       mmu_spte_clear_track_bits(sptep);
+       __pte_list_remove(sptep, rmap_head);
+}
+
 static struct kvm_rmap_head *__gfn_to_rmap(gfn_t gfn, int level,
                                           struct kvm_memory_slot *slot)
 {
@@ -1685,7 +1691,7 @@ static bool kvm_zap_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head)
        while ((sptep = rmap_get_first(rmap_head, &iter))) {
                rmap_printk("%s: spte %p %llx.\n", __func__, sptep, *sptep);
 
-               drop_spte(kvm, sptep);
+               pte_list_remove(rmap_head, sptep);
                flush = true;
        }
 
@@ -1721,7 +1727,7 @@ restart:
                need_flush = 1;
 
                if (pte_write(*ptep)) {
-                       drop_spte(kvm, sptep);
+                       pte_list_remove(rmap_head, sptep);
                        goto restart;
                } else {
                        new_spte = *sptep & ~PT64_BASE_ADDR_MASK;
@@ -5682,7 +5688,7 @@ restart:
                if (sp->role.direct &&
                        !kvm_is_reserved_pfn(pfn) &&
                        PageTransCompoundMap(pfn_to_page(pfn))) {
-                       drop_spte(kvm, sptep);
+                       pte_list_remove(rmap_head, sptep);
                        need_tlb_flush = 1;
                        goto restart;
                }