Commit 4677a3b6 authored by Avi Kivity's avatar Avi Kivity
Browse files

KVM: MMU: Optimize page unshadowing



Using kvm_mmu_lookup_page() will result in multiple scans of the hash chains;
use hlist_for_each_entry_safe() to achieve a single scan instead.

Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent c8a73f18
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -1471,13 +1471,22 @@ static int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn)

static void mmu_unshadow(struct kvm *kvm, gfn_t gfn)
{
	unsigned index;
	struct hlist_head *bucket;
	struct kvm_mmu_page *sp;
	struct hlist_node *node, *nn;

	while ((sp = kvm_mmu_lookup_page(kvm, gfn)) != NULL) {
		pgprintk("%s: zap %lx %x\n", __func__, gfn, sp->role.word);
	index = kvm_page_table_hashfn(gfn);
	bucket = &kvm->arch.mmu_page_hash[index];
	hlist_for_each_entry_safe(sp, node, nn, bucket, hash_link) {
		if (sp->gfn == gfn && !sp->role.metaphysical
		    && !sp->role.invalid) {
			pgprintk("%s: zap %lx %x\n",
				 __func__, gfn, sp->role.word);
			kvm_mmu_zap_page(kvm, sp);
		}
	}
}

static void page_header_update_slot(struct kvm *kvm, void *pte, gfn_t gfn)
{