From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796407201; b=aOeJjYBCyWVLimbSnlG958lKo1YBpJTVGs0nWuBQUlMx4PlEsUKzTkEgcAMvCemBT78R 8KzjOiqL724cFWKF2VH6/oGyoECVB3EhswhlpMFxsPq61tw3yx7DPKiFoRQF/uIg1vsnz vw2+hVuXIg2E63zMawS+JUHbR7M3/aBwWxnH2pU3Pa56Nu61aua0XOL3vBOEjSYw7SMX8 Hk5JoWHUSv8k8wNOMHji44QB0PvLa+mlGhDpMnoGZ6asvDk3ohzvHK/Q3oJv45G5ef/uE guHXdzzT4PWOTZoWjeedP1g/J7nOqmtUxQkhkdgVe30AHZkese2MdHbzUW1eizzNsqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407201; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=osJCEkzqNxoNru4IBmhS6DCAi7mbwCRqmtspPv99dY0=; b=RAlRKrh06KiZpJaPA3mQkPRLgbyQSey2ZGTHHKRTsxoUfrDUuCBih+vX9oe5JAJTwXVJ YuCo9Frh9bj/7u5WMdBPecGmxOY/o+k5RFAMLwD/n+k1z84l0c4a2+8q2hjIObivfrZcv kSk6dZZatDFGjh7hi3oKjkQ12pbRBvTqND45Gfl4VjcTlnNSdG8J9kXc5EPpjiYdq9JQu 2iMu2+30cYPgTIhbQBm2BKoCUCZGDn15NRoD8s/zDEOPePaJMMTqouJie3pQ0hOvG2pd1 0O8tEM0CxwMjJo4SfQQpavn1YgdviAEsL4ZJEw5xKZAdTJr+D2bZhTqKYXLyoSZgJbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ze6MX8eI; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9857D606A6BA for ; Fri, 4 Dec 2026 18:00:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9857D606A6BA Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ze6MX8eI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796407200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=osJCEkzqNxoNru4IBmhS6DCAi7mbwCRqmtspPv99dY0=; b=Ze6MX8eIfgdJ9hclFra7ta3YC0Cvc2QA1JEsjGrz0v5OF5zJ/FVHH6xmNQ4+Sulc6zQl/i wgTkrclJaq1Hm/36zaK6/SoHsOJZHVm4xG4RbrNXyPWfQON5azhyEmcxtLdfl1aiPO0zEh 8cBH0PtuJEeP5TEWqBeoHobwBlxoJoo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS with 8BITMIME (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-Tp_u9mQPNTCW-mvYwVPmqA-1; Fri, 4 Dec 2026 17:59:57 +0000 X-MC-Unique: Tp_u9mQPNTCW-mvYwVPmqA-1 X-Mimecast-MFC-AGG-ID: Tp_u9mQPNTCW-mvYwVPmqA_1796407195 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2BBA01909059; Fri, 4 Dec 2026 17:59:55 +0000 (UTC) Received: from pbonzini-thinkpadx1carbon6th.rmtit.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DBA47BAC; Fri, 4 Dec 2026 17:59:53 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , stable@vger.kernel.org Subject: [PATCH 11/17] KVM: WARN if there are in-flight memslot updates when a VM's process exits Date: Fri, 4 Dec 2026 18:59:24 +0100 Message-ID: <20261204175930.2154542-12-pbonzini@redhat.com> In-Reply-To: <20261204175930.2154542-1-pbonzini@redhat.com> References: <20261204175930.2154542-1-pbonzini@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 From: Sean Christopherson 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 Link: https://patch.msgid.link/20261120195742.55768-4-seanjc@google.com Signed-off-by: Paolo Bonzini --- 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 4f62287d4dd9..4592d2f45758 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -882,6 +882,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); @@ -1299,7 +1307,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