From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ACAA582B88; Wed, 9 Sep 2026 14:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963893; cv=none; b=uihLn0uP01c7lTCo/Hs/6WtfxZWkUYUQN2DTCZE7AdA3GAaCacjZBolxGleGl4x3Ys+zp0p+oMeJtj6e+2j8Dh0rLx0b7LqKEX5VkIm9xZf7WyI6ODAGTaJ1JU63m8Ch/kpMtfuWFUYXSZfXo3kMgOPdn7TwiG/8i/JSz0RMBjg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963893; c=relaxed/simple; bh=4K6/G6ia9OO+iaLfvM68GM7BMTkzJf1BzIeNljiM0+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Td2TgJqSfgfdZnCbiE/8M3Tusf8HjiBWYA5+S1L0QyZ2RcElNx2VS9HYUNs8huX4rR/cCISrwEfgE/FvKv+jNz1eaRmcdzYCiKefUB/WCqqjPILvgkX4W1bA6h/MGIEkuZvaX7z3H0xV9MeniWdp/D9iW7SV2hRL7tXAMNPHv1A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jWd7Myo0; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jWd7Myo0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 837D31F00A3A; Wed, 9 Sep 2026 14:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788963892; bh=M/aVtcFNZnIyk4s2Jdcy687zycEZrXUGK69DB+bivgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jWd7Myo0uLmcpQ+Mz6yG2fpZZttxJoKZuWsyjaVjEWBvBJ6TMw37KZowuGUAwwwrQ zKYdbGYz+QVKGmT737+9yjbOBSJOEwJIka1g6BFyHA3YJBx3OcNCMXnimjYslJzC+f Dte+/+uEIn5wpSipJVJyy7EFBV0lpNLObaykGmTE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Roth , Sean Christopherson Subject: [PATCH 6.18 236/583] KVM: x86/mmu: Split kvm_mmu_zap_all_fast() into "front" and "back" halves Date: Wed, 9 Sep 2026 15:38:41 +0200 Message-ID: <20260909134246.330130179@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit b27622c4eeb125814081baaefe9175191be5b94d upstream. Split kvm_mmu_zap_all_fast() into a "front half" and a "back half", where the front half is everything that runs with mmu_lock held for write, and the back half is the code that runs outside of mmu_lock. This will allow putting more code inside kvm_arch_flush_shadow_memslot()'s critical section without having to take mmu_lock twice in quick succession. No functional change intended. Cc: stable@vger.kernel.org # 6.12.x Reviewed-by: Michael Roth Link: https://patch.msgid.link/20260709204948.1988414-9-seanjc@google.com Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/mmu/mmu.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6696,20 +6696,11 @@ restart: kvm_mmu_commit_zap_page(kvm, &invalid_list); } -/* - * Fast invalidate all shadow pages and use lock-break technique - * to zap obsolete pages. - * - * It's required when memslot is being deleted or VM is being - * destroyed, in these cases, we should ensure that KVM MMU does - * not use any resource of the being-deleted slot or all slots - * after calling the function. - */ -static void kvm_mmu_zap_all_fast(struct kvm *kvm) +static void __kvm_mmu_zap_all_fast_front_half(struct kvm *kvm) { lockdep_assert_held(&kvm->slots_lock); + lockdep_assert_held_write(&kvm->mmu_lock); - write_lock(&kvm->mmu_lock); trace_kvm_mmu_zap_all_fast(kvm); /* @@ -6746,8 +6737,12 @@ static void kvm_mmu_zap_all_fast(struct kvm_make_all_cpus_request(kvm, KVM_REQ_MMU_FREE_OBSOLETE_ROOTS); kvm_zap_obsolete_pages(kvm); +} - write_unlock(&kvm->mmu_lock); +static void __kvm_mmu_zap_all_fast_back_half(struct kvm *kvm) +{ + lockdep_assert_held(&kvm->slots_lock); + lockdep_assert_not_held(&kvm->mmu_lock); /* * Zap the invalidated TDP MMU roots, all SPTEs must be dropped before @@ -6761,6 +6756,24 @@ static void kvm_mmu_zap_all_fast(struct kvm_tdp_mmu_zap_invalidated_roots(kvm, true); } +/* + * Fast invalidate all shadow pages and use lock-break technique + * to zap obsolete pages. + * + * It's required when memslot is being deleted or VM is being + * destroyed, in these cases, we should ensure that KVM MMU does + * not use any resource of the being-deleted slot or all slots + * after calling the function. + */ +static void kvm_mmu_zap_all_fast(struct kvm *kvm) +{ + write_lock(&kvm->mmu_lock); + __kvm_mmu_zap_all_fast_front_half(kvm); + write_unlock(&kvm->mmu_lock); + + __kvm_mmu_zap_all_fast_back_half(kvm); +} + int kvm_mmu_init_vm(struct kvm *kvm) { int r, i;