Commit 1b834210 authored by Sean Christopherson's avatar Sean Christopherson Committed by Yu Zhang
Browse files

KVM: x86/mmu: Coalesce TLB flushes when zapping collapsible SPTEs

mainline inclusion
from mainline-v5.13-rc1
commit 142ccde1
category: feature
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I7S3VQ
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=142ccde1f7b1b0c621c299cbcc8feb6353f7cc92



----------------------------------------------------------------------

Gather pending TLB flushes across both the legacy and TDP MMUs when
zapping collapsible SPTEs to avoid multiple flushes if both the legacy
MMU (for nested guests) and TDP MMU have mappings for the memslot.

Note, this also optimizes the TDP MMU to flush only the relevant range
when running as L1 with Hyper-V enlightenments.

Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210326021957.1424875-4-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>

conflict:
	arch/x86/kvm/mmu/tdp_mmu.h

Signed-off-by: default avatarYu Zhang <yu.c.zhang@linux.intel.com>
parent 37361e1b
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -5723,11 +5723,13 @@ void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm,

	write_lock(&kvm->mmu_lock);
	flush = slot_handle_leaf(kvm, slot, kvm_mmu_zap_collapsible_spte, true);

	if (is_tdp_mmu_enabled(kvm))
		flush = kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot, flush);

	if (flush)
		kvm_arch_flush_remote_tlbs_memslot(kvm, slot);

	if (is_tdp_mmu_enabled(kvm))
		kvm_tdp_mmu_zap_collapsible_sptes(kvm, slot);
	write_unlock(&kvm->mmu_lock);
}

+3 −5
Original line number Diff line number Diff line
@@ -1367,11 +1367,10 @@ static bool zap_collapsible_spte_range(struct kvm *kvm,
 * Clear non-leaf entries (and free associated page tables) which could
 * be replaced by large mappings, for GFNs within the slot.
 */
void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
				       struct kvm_memory_slot *slot)
bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
				       struct kvm_memory_slot *slot, bool flush)
{
	struct kvm_mmu_page *root;
	bool flush = false;
	int root_as_id;

	for_each_tdp_mmu_root_yield_safe(kvm, root) {
@@ -1382,8 +1381,7 @@ void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
		flush = zap_collapsible_spte_range(kvm, root, slot, flush);
	}

	if (flush)
		kvm_flush_remote_tlbs(kvm);
	return flush;
}

/*
+2 −2
Original line number Diff line number Diff line
@@ -50,8 +50,8 @@ void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm,
				       gfn_t gfn, unsigned long mask,
				       bool wrprot);
bool kvm_tdp_mmu_slot_set_dirty(struct kvm *kvm, struct kvm_memory_slot *slot);
void kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
				       struct kvm_memory_slot *slot);
bool kvm_tdp_mmu_zap_collapsible_sptes(struct kvm *kvm,
				       struct kvm_memory_slot *slot, bool flush);

bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm,
				   struct kvm_memory_slot *slot, gfn_t gfn);