Re: [PATCH v3 07/12] KVM: x86/mmu: Fold kvm_mmu_zap_memslot() into kvm_arch_flush_shadow_memslot()
From: Michael Roth
Date: Wed Jul 01 2026 - 18:52:57 EST
On Tue, Jun 30, 2026 at 03:26:02PM -0700, Sean Christopherson wrote:
> Fold kvm_mmu_zap_memslot() into its sole caller so that its GFN range
> structure can be used to trigger guest_memfd invalidations regardless of
> whether KVM will do a partial or full zap of the MMU.
>
> No functional change intended.
>
> Cc: stable@xxxxxxxxxxxxxxx # 6.12.x
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Reviewed-by: Michael Roth <michael.roth@xxxxxxx>
> ---
> arch/x86/kvm/mmu/mmu.c | 35 +++++++++++++++--------------------
> 1 file changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 6c13da942bfc..223d80b12b9b 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -7560,8 +7560,14 @@ static void kvm_mmu_zap_memslot_pages_and_flush(struct kvm *kvm,
> kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);
> }
>
> -static void kvm_mmu_zap_memslot(struct kvm *kvm,
> - struct kvm_memory_slot *slot)
> +static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)
> +{
> + return kvm->arch.vm_type == KVM_X86_DEFAULT_VM &&
> + kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);
> +}
> +
> +void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
> + struct kvm_memory_slot *slot)
> {
> struct kvm_gfn_range range = {
> .slot = slot,
> @@ -7572,25 +7578,14 @@ static void kvm_mmu_zap_memslot(struct kvm *kvm,
> };
> bool flush;
>
> - write_lock(&kvm->mmu_lock);
> - flush = kvm_unmap_gfn_range(kvm, &range);
> - kvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);
> - write_unlock(&kvm->mmu_lock);
> -}
> -
> -static inline bool kvm_memslot_flush_zap_all(struct kvm *kvm)
> -{
> - return kvm->arch.vm_type == KVM_X86_DEFAULT_VM &&
> - kvm_check_has_quirk(kvm, KVM_X86_QUIRK_SLOT_ZAP_ALL);
> -}
> -
> -void kvm_arch_flush_shadow_memslot(struct kvm *kvm,
> - struct kvm_memory_slot *slot)
> -{
> - if (kvm_memslot_flush_zap_all(kvm))
> + if (kvm_memslot_flush_zap_all(kvm)) {
> kvm_mmu_zap_all_fast(kvm);
> - else
> - kvm_mmu_zap_memslot(kvm, slot);
> + } else {
> + write_lock(&kvm->mmu_lock);
> + flush = kvm_unmap_gfn_range(kvm, &range);
> + kvm_mmu_zap_memslot_pages_and_flush(kvm, slot, flush);
> + write_unlock(&kvm->mmu_lock);
> + }
> }
>
> void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen)
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>