From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>, stable@vger.kernel.org
Subject: [PATCH 6.12.y 11/17] KVM: WARN if there are in-flight memslot updates when a VM's process exits
Date: Fri, 4 Dec 2026 19:02:39 +0100 [thread overview]
Message-ID: <20261204180245.2166967-12-pbonzini@redhat.com> (raw)
In-Reply-To: <20261204180245.2166967-1-pbonzini@redhat.com>
From: Sean Christopherson <seanjc@google.com>
[ Upstream commit fd00a80aa395b803832ebaf1c494d721e9483dbb ]
Move the sanity check on there being no outstanding memslot updates from VM
destruction to kvm_mmu_notifier_release(), i.e. WARN if there are
outstanding memslot updates when the VM is dying *or* the owning process is
exiting. KVM subtly already guarantees (and relies on!) memslot updates to
be mutually exclusive with the mm dying.
If KVM unregistered its mmu_notifier between .invalidate_range_start() and
.invalidate_range_end(), then the invalidate count would be left elevated
until the VM is destroyed, but if there were an outstanding memslot update,
it would be impossible for the VM to be destroyed.
Opportunistically change the WARNs to WARN_ON_ONCE() so that a KVM bug
doesn't unintentionally DoS the host due to spamming dmesg (hanging a task
is bad enough).
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
Link: https://patch.msgid.link/20261120195742.55768-4-seanjc@google.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
virt/kvm/kvm_main.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a83772ea4cf7..02290261e64b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -911,6 +911,14 @@ static void kvm_mmu_notifier_release(struct mmu_notifier *mn,
struct kvm *kvm = mmu_notifier_to_kvm(mn);
int idx;
+ /*
+ * No threads can be waiting in kvm_swap_active_memslots() as KVM only
+ * allows KVM_SET_USER_MEMORY_REGION{,2} in process context, and only
+ * from the process that created the VM, i.e. to @mm. If @mm is dying,
+ * then there can't possibly be outstanding memslot updates.
+ */
+ WARN_ON_ONCE(rcuwait_active(&kvm->mn_memslots_update_rcuwait));
+
idx = srcu_read_lock(&kvm->srcu);
kvm_arch_flush_shadow_all(kvm);
kvm_arch_guest_memory_reclaimed(kvm);
@@ -1345,7 +1353,6 @@ static void kvm_destroy_vm(struct kvm *kvm)
* notifier between a start() and end(), then there shouldn't be any
* in-progress invalidations.
*/
- WARN_ON(rcuwait_active(&kvm->mn_memslots_update_rcuwait));
if (kvm->mn_active_invalidate_count)
kvm->mn_active_invalidate_count = 0;
else
--
2.56.1
next prev parent reply other threads:[~2026-12-04 18:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 18:02 [PATCH 6.12.y 00/17] Fixes for various (mostly x86) KVM vulnerabilities Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 01/17] KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 02/17] KVM: x86/mmu: Flush TLBs if child SPTE is zapped when splitting a huge SPTE Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 03/17] KVM: x86/mmu: Propagate the return from kvm_zap_all_rmap_sptes() out of __rmap_add() Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 04/17] KVM: x86: Disable hypervisor (VMX Preemption) timer if TSC deadline wraps Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 05/17] KVM: x86: Reset local APIC timer metadata on RESET, INIT, and KVM_SET_LAPIC Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 06/17] LoongArch: KVM: Flush TLBs *before* dropping mmu_lock Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 07/17] KVM: x86/mmu: Flush all TLB entries, not a precise range, when yielding Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 08/17] KVM: x86/mmu: Flush TLBs in kvm_unmap_gfn_range() if the unmap may block/yield Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 09/17] KVM: x86/xen: Pin kvm->mm prior to borrowing mm when setting event channel Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 10/17] KVM: Fold kvm_flush_shadow_all() into kvm_mmu_notifier_release() Paolo Bonzini
2026-12-04 18:02 ` Paolo Bonzini [this message]
2026-12-04 18:02 ` [PATCH 6.12.y 12/17] KVM: Set mn_active_invalidate_count when the VM's mm is released Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 13/17] KVM: Invalidate all GFN=>PFN caches when VM and/or its process is dying Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 14/17] x86/fpu: Bail early from guest XFD update if XFD isn't supported Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 15/17] x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state if guest FPU isn't in-use Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 16/17] x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD MSR Paolo Bonzini
2026-12-04 18:02 ` [PATCH 6.12.y 17/17] KVM: VMX: Ensure pCPU is valid before sending IPI to deliver posted IRQ Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204180245.2166967-12-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®