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=1793217048; b=OgctWE+UtxpL2MyZNT8t/HrhMDO4hVav/svPk/IQIKrranxYmvX4arKTMYS4DGZZ80XX EorVBQXUMTU1SEGGFX5PZdF8TUkq4jKUq/tGbsAOktm83jjyPbJR9sFJSl6BukuGOkQ7p xsoFvQb4gUa2EU5XVpACraL0D4QR7S8rWuNJ0deRK4fgEVg9ZLNtElSKiRU/uB3tkuoo1 SAG0M78HUCO7gKFDzVv1ULTxYOqlzeO3nns0x12D1Y/MRCumNAbjmXkHNTbt9WbMFdy76 7mJ5/g9BHkOGCEc2vW7YxNWnx5H7y4Z/lb7EeVdGVdDIwpjEYlIfQTYsWNTZ7/pPWlA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793217048; 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=XSUdkgSDfH4R5akaUwLA/RLz6vDfVWZVLldPkKw0HRc=; b=ZBhjzefYnmKOjEFDN91WCIAiNbP5P4TI8WpF36+IKkgF13BptRnW52QSzwFEny8TeksN KBrd+JzPqfQzQdwYzCBm9xCtx5frhTKU5FiQauVfZ1UAqJhMbopE6EjjZ/9Gnu6gftwAt dpwd7wqfk9fuPCF2FlQj5Gq30brYvdpOSGia0XM0x+ncCcD+k3OVLuiOMavbKpX5w8WXi +FQ3Azf63DFvqbnaOs8hLHuSKVXovpioBtSITzantj1BDgWNRdnTYjoFGg2JHeogpi2Gu p6ss2ZYMKo+3jcfnuvadrLauY7u+bh2qe8TAKsn0hhhVjiQ7IkPGHheJ0yKGrSYj+qw== 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=wy+vSC1M; 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 9B685606A320; Wed, 28 Oct 2026 19:50:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wy+vSC1M Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7D2F1F01825; Wed, 28 Oct 2026 19:50:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793217048; bh=XSUdkgSDfH4R5akaUwLA/RLz6vDfVWZVLldPkKw0HRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wy+vSC1MScjL4eeRD1PJx2Ar8KIIZs8hjz2GAtVG1eH9Bj8A1jacwTEvYQUUchBZN 7BDpB/jGfHpsHjK/4A+GOC/6/9rrS9x10dgF5OZ37xQ0pV+oh4E26HvIM0v4Sdeq3n 8HbeAO/XE2aspHy2avNltpQWk5vKl4i4HmWBkJSY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+38a0cbd267eff2d286ff@syzkaller.appspotmail.com, Kairui Song , Chengming Zhou , Johannes Weiner , "Matthew Wilcox (Oracle)" , Michal Hocko , Muchun Song , Qi Zheng , Roman Gushchin , Sasha Levin , Shakeel Butt , Yu Zhao , Andrew Morton Subject: [PATCH 6.1 1769/1887] mm, madvise: fix potential workingset node list_lru leaks Date: Wed, 28 Oct 2026 18:04:25 +0100 Message-ID: <20261028170539.710439546@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@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.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kairui Song [ Upstream commit 62e72d2cf702a5e2fb53d9c46ed900d9384e4a06 ] Since commit 5abc1e37afa0 ("mm: list_lru: allocate list_lru_one only when needed"), all list_lru users need to allocate the items using the new infrastructure that provides list_lru info for slab allocation, ensuring that the corresponding memcg list_lru is allocated before use. For workingset shadow nodes (which are xa_node), users are converted to use the new infrastructure by commit 9bbdc0f32409 ("xarray: use kmem_cache_alloc_lru to allocate xa_node"). The xas->xa_lru will be set correctly for filemap users. However, there is a missing case: xa_node allocations caused by madvise(..., MADV_COLLAPSE). madvise(..., MADV_COLLAPSE) will also read in the absent parts of file map, and there will be xa_nodes allocated for the caller's memcg (assuming it's not rootcg). However, these allocations won't trigger memcg list_lru allocation because the proper xas info was not set. If nothing else has allocated other xa_nodes for that memcg to trigger list_lru creation, and memory pressure starts to evict file pages, workingset_update_node will try to add these xa_nodes to their corresponding memcg list_lru, and it does not exist (NULL). So they will be added to rootcg's list_lru instead. This shouldn't be a significant issue in practice, but it is indeed unexpected behavior, and these xa_nodes will not be reclaimed effectively. And may lead to incorrect counting of the list_lru->nr_items counter. This problem wasn't exposed until recent commit 28e98022b31ef ("mm/list_lru: simplify reparenting and initial allocation") added a sanity check: only dying memcg could have a NULL list_lru when list_lru_{add,del} is called. This problem triggered this WARNING. So make madvise(..., MADV_COLLAPSE) also call xas_set_lru() to pass the list_lru which we may want to insert xa_node into later. And move mapping_set_update to mm/internal.h, and turn into a macro to avoid including extra headers in mm/internal.h. Link: https://lkml.kernel.org/r/20241222122936.67501-1-ryncsn@gmail.com Fixes: 9bbdc0f32409 ("xarray: use kmem_cache_alloc_lru to allocate xa_node") Reported-by: syzbot+38a0cbd267eff2d286ff@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/675d01e9.050a0220.37aaf.00be.GAE@google.com/ Signed-off-by: Kairui Song Cc: Chengming Zhou Cc: Johannes Weiner Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Muchun Song Cc: Qi Zheng Cc: Roman Gushchin Cc: Sasha Levin Cc: Shakeel Butt Cc: Yu Zhao Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/khugepaged.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ded9a00b20b58..4c3581364cb28 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1788,6 +1789,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, if (result != SCAN_SUCCEED) goto out; + mapping_set_update(&xas, mapping); + /* * Ensure we have slots for all the pages in the range. This is * almost certainly a no-op because most of the pages must be present -- 2.53.0