From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794591193; b=q0Q00Gxl5cjhUT1I259FT/PAVOE7I4lD9fzZcQzidUviB1hEYr/wJrbBRPK4z/iW5dr0 5XE14+sc40Uin5g45dXyz+pOgL327J0OVWv0kJeGKh4CedaEy/PFruWB2Kod/1LpLosuw G1+8WxZB0PTLCl9PMZrTcBDmGng3vxXieM1GVb9PgIp9fImYojYTp/xF1OMcehx/N942Z USIFG0+5qj3veHdE2z3C2U3++jKHx2NIy+RNYCTLARei1Y/jI77AFJXfm9XpEO0SjhknI j9DDKB5RouivYzTwAFIxbpI4/fNY+3bRDByKH1kC3p5wGkJOxpfjMQi193yR2SUo99A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794591193; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ZmGs/YLnL469sK/nFsuOv+kuFaKLq4BfXUhWjHNK4o8=; b=3EFZouOwSUoJ/Awjz/EESjpwlkp+MCBbl02Yaz2FW1//CcWTKYGNBYx+oqGOxE/VZHc8 LHV76XVUWLFT/4UE+xqfM/DOlMxBhebXDr6z655OassrSjYmiIeSC+skqIagbf76NkVrC w9AHlSzZBrZC0qDNaaHtVtfc6XyTveUo/e85U5L+y8hHiHmlmxojxtWFFXka4C2rpZF3J rDwuCkhwRaz2iNYCCPG0LT2l+CMUosrT7p1L3fOcCGG3ymg2k8b3BFLU1mYGlR2BswXrp 7BIS3gtKjdyVhvGDVGOVs4PGmrTKRJQbmnFVmgxmw1v8S6K9+X7UjOUfv5Bnqk4MWcg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WR8O9DOw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E25C6075E03; Fri, 13 Nov 2026 17:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WR8O9DOw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E0911F000C5; Fri, 13 Nov 2026 17:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794591192; bh=ZmGs/YLnL469sK/nFsuOv+kuFaKLq4BfXUhWjHNK4o8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WR8O9DOwa8o2Id64A5cLLssa+K6rB1tgcOXbzNsocr8BEYwUaE8VwIqPDJBBEy1OG k5r/Hu4HVbxFax9mjN+qJ3n4D/PacJihiVTnfiSuOBUeJ3TzbY6x/1fsHe1jrbGI+N B/9ra9eIAj4FfCKtb7pl3K33ng8frPpB9XpKCxM0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , "Gregory Price (Meta)" , "Lorenzo Stoakes (ARM)" , Muhammad Usama Anjum , "David Hildenbrand (Arm)" , Sasha Levin Subject: [PATCH 6.12 328/670] mm/mmu_notifier: set ->mm only after mmgrab() Date: Fri, 13 Nov 2026 10:48:12 -0500 Message-ID: <20261113153822.994069268@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153811.177190860@linuxfoundation.org> References: <20261113153811.177190860@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 5ad9e4b0f1104f5dbfb41125c34bb30ea6dc7a94 ] Radeon uses a non-NULL notifier->mm to decide whether to call mmu_interval_notifier_remove() when freeing a buffer object. __mmu_interval_notifier_insert() sets ->mm before validating the range, so a wrapping userptr range can leave ->mm set after insertion fails. Cleanup then tries to remove an unregistered notifier for which no mm reference was acquired. Set ->mm only after mmgrab(), once insertion can no longer fail. While we could fix radeon's code instead, setting ->mm on success only makes the code more robust. Fix generated by an LLM and sent by Chris Mason in private. Fixes: 3506ff69c3ec ("drm/radeon: use mmu_interval_notifier_insert") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ david: simplify description ] Reviewed-by: Gregory Price (Meta) Tested-by: Gregory Price (Meta) Reviewed-by: Lorenzo Stoakes (ARM) Tested-by: Muhammad Usama Anjum Link: https://patch.msgid.link/20261031-fixes_core-v3-29-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Sasha Levin --- mm/mmu_notifier.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index e614ecafb8817..1c2707a8ed76b 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -901,7 +901,6 @@ static int __mmu_interval_notifier_insert( struct mmu_notifier_subscriptions *subscriptions, unsigned long start, unsigned long length, const struct mmu_interval_notifier_ops *ops) { - interval_sub->mm = mm; interval_sub->ops = ops; RB_CLEAR_NODE(&interval_sub->interval_tree.rb); interval_sub->interval_tree.start = start; @@ -918,8 +917,12 @@ static int __mmu_interval_notifier_insert( if (WARN_ON(atomic_read(&mm->mm_users) <= 0)) return -EINVAL; - /* pairs with mmdrop in mmu_interval_notifier_remove() */ + /* + * Pairs with mmdrop in mmu_interval_notifier_remove(). Drivers take a + * non-NULL ->mm for "registered", so set it only with the reference. + */ mmgrab(mm); + interval_sub->mm = mm; /* * If some invalidate_range_start/end region is going on in parallel -- 2.53.0