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=1796407504; b=CQG/JOrTnOnGwps5ePxGX68lGE604xywGOukTEncgANoIdvtiKeIUZgGjxzHHZhTWSI9 zEDNPYxQNIYlAlA8/R9zRFORLI6B0CarCpLsfEKNgPwBJnIFjS5asLCS15I2PXrpx9rBj xtlitN5vdo25XMSkmvh/8ZvvI6Wl7+1aK9xQ2NlsCOVqarAg30CiaFIcaqmiig40iggg4 jlKkXVBVBDKLE4O8grqyocmXgAQ/+m0v7B47mZeJJwGG+K6xAEbb+q6IzytUlzYDnbaY7 1o+QdjDyuebZOlFXFM3vHt90jNIRWcDQJ48qlVZmHLW0E2Ayp7FKLrkGzG3kG8zxswA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407504; 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=sE78jfz+nNUFM1+t3rNfEZvnVxT6uOCVS73o5Qyn92Q=; b=Z2yP3cjcxnzwTX3zqIHaEQxSw8vsYsNxEOrGfeerujHRw9D/kkvwoYRXUNkIbHqK71A+ /SOPde5Xs937Yh7oH4chYbFjjDJLzjrbxx6zKZTc+8Z6/9nGsG8ZmqBJiebKvZLYSf3AA lpGeGIMyZ4BCLx1beKf4+5wrQgwiHJR3tmKvQkOn3Lj6ToINOGRsTSh0WMTtwuaXl53ag dNwP2na3n/5KhUjVAJ1vWGRU1M/O1ueUgRnFA9Q8BNcMIT+ge7IW6tQje/XYyh0vkkrRm mJr5syYAwo7iNndysuODd5qHoNU76N6frDaAwxZIM9lg8GMcBbbLZyOwoSy8I9IIAMw== 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=hlux2XX4; 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 228366073133 for ; Fri, 4 Dec 2026 18:05:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 228366073133 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=hlux2XX4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796407504; 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=sE78jfz+nNUFM1+t3rNfEZvnVxT6uOCVS73o5Qyn92Q=; b=hlux2XX42XvFP8PPaYZxuq6l5C+Zr8QeX5+SdgbV0jtjgwjWu1JO95/icxKZSpufbFwpGS R0Uv02HhSgEszdEd71ELi/DNL1LkdLR0QYZCCtbX7hngb4RfrjLrgDP6vZChz2SwuEnsZT Z/CxxHFAp9ZU6SHlTlHXH9iX9WMkhLU= Received: from mx-prod-mc-01.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-248-iY-ZzFZZNe-vo_mFsUUb7w-1; Fri, 4 Dec 2026 18:04:59 +0000 X-MC-Unique: iY-ZzFZZNe-vo_mFsUUb7w-1 X-Mimecast-MFC-AGG-ID: iY-ZzFZZNe-vo_mFsUUb7w_1796407498 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 290EB18F5F39; Fri, 4 Dec 2026 18:04:58 +0000 (UTC) Received: from pbonzini-thinkpadx1carbon6th.rmtit.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5E883003EA7; Fri, 4 Dec 2026 18:04:56 +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.1.y 17/24] KVM: WARN if there are in-flight memslot updates when a VM's process exits Date: Fri, 4 Dec 2026 19:04:16 +0100 Message-ID: <20261204180423.2168641-18-pbonzini@redhat.com> In-Reply-To: <20261204180423.2168641-1-pbonzini@redhat.com> References: <20261204180423.2168641-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.4 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 7ffe1900ffaf..9845e6a734f3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -894,6 +894,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); @@ -1317,7 +1325,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