From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796407447; b=MaxTqQB0lftOJHlKQifDVZ1Fay5uml8hxiZmDlJvhUwmBvVwcYP47Ur2ZCiwjoaKxwWz 64GmmCq37yQ+XUWA+CG1h8+tqNy/id6X8GEd/0DOiemse9PQcSp5PwoAZx55Y+VqxDXJn gx4R7NMP0HOzZefGN+mXdCcdPua7BCGLSMn0cJgIWi7lVE2kFdqy3/1KmO81saVcGqpW+ ZG0A9mUpCAoP9bnCysVtADKimzrYM5UKt3tA7sOhlAustiYMsFIaw0UdEqfBAQ7fioPEa xdSo0K4pEwuJqLKUdXHUhi+lKgGemyaw6ykMz7MeN7AQN81Ha8qfdBJzXz3HGUjYcng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407447; 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=uo6XjRcAm+BEODTbTZhILS9Qp7tXaPWGRZ2gcZjnqdI=; b=IDmG2VINzsAMlYUjALNF1g3IVGMWDzmUMUcByWTo8itHcl8qhIaUpJupS8R10nOAGh8a 2HhmEUwSfsqptSyuCcaojcJnCKGefRm+p4WFZzTDf/xWC5iC5Np/08Rz5hdJItMjdktiY JUwH7rihaW6nL2WoO0KFoCBAisif4dH3Di5lWYQHzYjP6HppRktWGb7wqOWAe48ooGj0y kj7oX8MitcTpG7c4+82oJ0g6SKowK7fbC+0ROhvk+SB7FiE2zHOrcIJoWlPOF7OB4ZSiT 5FCTABaUcDoWyFtinGL7rmP9EA3G04Y7XEqgUHZel7R2GQ8omPAldxP+0bGa4aJ4cDg== 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=FVfrzl5w; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 7ADD5606A6B5 for ; Fri, 4 Dec 2026 18:04:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7ADD5606A6B5 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=FVfrzl5w DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796407446; 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=uo6XjRcAm+BEODTbTZhILS9Qp7tXaPWGRZ2gcZjnqdI=; b=FVfrzl5wt3XvxYeRiqTiPYqh5ojv/KJ8lFAj+iol9XvRzX4OVWKJTspoXc3/kamg5Q8qcP zwo21DyeiRKrGNZPTwzGwuoGu6IHFjOua+ZzuBiSc4onmkTWm+ICWQxGgPv6RPLEq4CTgg zMGTlAbMmRU7VKI3ICZ+wiHWE4pgS4E= 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-183--ai_2Xd-PSiqqdaPuZmZQQ-1; Fri, 4 Dec 2026 18:04:02 +0000 X-MC-Unique: -ai_2Xd-PSiqqdaPuZmZQQ-1 X-Mimecast-MFC-AGG-ID: -ai_2Xd-PSiqqdaPuZmZQQ_1796407441 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 EBDC218FFAF9; Fri, 4 Dec 2026 18:04:00 +0000 (UTC) Received: from pbonzini-thinkpadx1carbon6th.rmtit.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB55218019CE; Fri, 4 Dec 2026 18:03:59 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , stable@vger.kernel.org Subject: [PATCH 6.6.y 11/17] KVM: WARN if there are in-flight memslot updates when a VM's process exits Date: Fri, 4 Dec 2026 19:03:31 +0100 Message-ID: <20261204180337.2168031-12-pbonzini@redhat.com> In-Reply-To: <20261204180337.2168031-1-pbonzini@redhat.com> References: <20261204180337.2168031-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.4.1 on 10.30.177.93 From: Sean Christopherson [ 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 Link: https://patch.msgid.link/20261120195742.55768-4-seanjc@google.com Signed-off-by: Paolo Bonzini 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 c726e6469bf5..42e147975795 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -915,6 +915,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); @@ -1338,7 +1346,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