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=1796407288; b=qZSFP4HmGg4p3E9SeVXzaAq+d0cWYKVpTu+MqKxJ7EDmJWXjRH9Eq+DoGqIpr5VXKs4n 97EwwV3Y9wDf7e5cOZzxcEIE5pPi0G7JdY4Hty/YtfNNZaUVpswX2tZSr/WqwTyiSw+0f SN6vMR79P59+S/RcpT9PeFza0qDa2X3pKfo0m9LmZ0INl90gV0ciCmHMYHuNecURsigpM xUlbQyJqAE+g+JtN4tMrzHA8/OGiz+4lz3263Ye18vDXr73wnXZRHwX9IyxQL4wEqyfS2 pJ/ayNzXKpFxrEvMhv+koNXsQFQymR9Al2EycU5toFhlCscD/KvK+p0lrrsXMHjrSlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407288; 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=0RXIqSbmgZqQUtvNuGLGK+xuRaSTFLeHQ915piMRJQU=; b=jIf+ItsKZLLu/SYk4qekaLS74hUBkFgPj94Ed4O4kDDMFuxlVmc9/kMaZs0C0u7AVv98 1QeHiyCtRdXQWj6zzA0yfI624P6KZSJ677EEwK9yex/4aC3koCsvUjBraAUtDCpjlu2XN ixsXl/WgIKpqk6Jl8cOSRLXKYAWYyM1CQqy1Ym3S9i5TskdhLd8N5o5hXxIOtyuP0ELEP iPy6LmfkGMpMylgQFXAe8lMuNMbU4RClns5Lgfsghs5q++oEty06wim2gR7U2U+a08pH/ Fy2Nv0mluc2t6Qtv4O5dhVSasC3GUGtInYaV5qaSwCCVruRyKyO+m69mv/Ne+DzxvHQ== 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=f6M6ySSF; 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 7A28D60A380E for ; Fri, 4 Dec 2026 18:01:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7A28D60A380E 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=f6M6ySSF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796407287; 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=0RXIqSbmgZqQUtvNuGLGK+xuRaSTFLeHQ915piMRJQU=; b=f6M6ySSFA02+p13P8gVL5SPDFqyp4kI9I3xkMm1LBqIysihlQtiWZWWTioyLPSkp1J54JH BlZdCmcsdZXev5f16llbNmpF5hj4o4Jqp1yyweRBukbmQeyBDT9Ev9zA9CsP5blQXKCvnG C3I6bFRMbs8P/0VZg1mWCNFqyhvQbDM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS with 8BITMIME (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-NAkwHblrO3avXLnECA4Q9w-1; Fri, 4 Dec 2026 18:01:24 +0000 X-MC-Unique: NAkwHblrO3avXLnECA4Q9w-1 X-Mimecast-MFC-AGG-ID: NAkwHblrO3avXLnECA4Q9w_1796407283 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 224B418BD484; Fri, 4 Dec 2026 18:01:23 +0000 (UTC) Received: from pbonzini-thinkpadx1carbon6th.rmtit.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8A9B1955E80; Fri, 4 Dec 2026 18:01:21 +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.18.y 11/17] KVM: WARN if there are in-flight memslot updates when a VM's process exits Date: Fri, 4 Dec 2026 19:00:53 +0100 Message-ID: <20261204180059.2165490-12-pbonzini@redhat.com> In-Reply-To: <20261204180059.2165490-1-pbonzini@redhat.com> References: <20261204180059.2165490-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.0 on 10.30.177.12 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 eadd20efad5f..7972d8dd2d55 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); @@ -1308,7 +1316,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