From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A13D359716; Fri, 9 Jan 2026 11:44:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767959085; cv=none; b=GNg4/Xs4o/bMe6EkpCpk4zjBJQWCGAdg919u5c83z5/oEtayA4XT1ZgiVPZD2P1TXnc1yfJarNOd6juGH/fzERVQayMMHnMSbUFSw/aoXZneq9HtJ2tM6ve8jkF4skDwY2hwPhKbGbrtLTUHhaMmhIJ80Cj5ICn27LDdnsq9fnI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767959085; c=relaxed/simple; bh=/xMBYw8rzxERxbETQfaB5mfH5phSHdpeBLUXYFzKsQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EwGfsJgzZan286/ZX0D6VCYvRz5n0m4g/46PUVvvZPemXYCJlyLod20uGjETSXEzYz7LGYzCOmroQ4S6CPB1C9LSeVs5tIPW6nZXN8GhR2VrUOAUdhyLI84O6dhz9aiXSST2QA6xF455aEVsPTRQqoHknrBYGZUBMQeoDctNoEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JZNqBBGE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JZNqBBGE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CD64C16AAE; Fri, 9 Jan 2026 11:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767959085; bh=/xMBYw8rzxERxbETQfaB5mfH5phSHdpeBLUXYFzKsQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZNqBBGErQnt9/mv+MFZN50byQ2Z6hY7x+4q1Xe89Ab4e+tE0fe+88iDp9JZHvyBt +SmoCHeqyyzcXFY0DKnKeBnBWBZFLGgUgvq3tnnTwK6C3dJJw4TTvsrUWvHvcE/Yv2 WG5B6YqFzAvaf4uUzhzaqCbLIVdRQ1Z7Ekr9yBOc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Hildenbrand , Zi Yan , Lorenzo Stoakes , Harry Yoo , Alistair Popple , Al Viro , Arnd Bergmann , Brendan Jackman , Byungchul Park , Chengming Zhou , Christian Brauner , Christophe Leroy , =?UTF-8?q?Eugenio=20P=C3=A9=20rez?= , Gregory Price , "Huang, Ying" , Jan Kara , Jason Gunthorpe , Jason Wang , Jerrin Shaji George , Johannes Weiner , John Hubbard , Jonathan Corbet , Joshua Hahn , Liam Howlett , Madhavan Srinivasan , Mathew Brost , "Matthew Wilcox (Oracle)" , Miaohe Lin , Michael Ellerman , "Michael S. Tsirkin" , Michal Hocko , Mike Rapoport , Minchan Kim , Naoya Horiguchi , Nicholas Piggin , Oscar Salvador , Peter Xu , Qi Zheng , Rakie Kim , Rik van Riel , Sergey Senozhatsky , Shakeel Butt , Suren Baghdasaryan , Vlastimil Babka , Xuan Zhuo , xu xin , Andrew Morton , Sasha Levin Subject: [PATCH 6.12 03/16] mm: simplify folio_expected_ref_count() Date: Fri, 9 Jan 2026 12:43:44 +0100 Message-ID: <20260109111951.548019950@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260109111951.415522519@linuxfoundation.org> References: <20260109111951.415522519@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand [ Upstream commit 78cb1a13c42a6d843e21389f74d1edb90ed07288 ] Now that PAGE_MAPPING_MOVABLE is gone, we can simplify and rely on the folio_test_anon() test only. ... but staring at the users, this function should never even have been called on movable_ops pages. E.g., * __buffer_migrate_folio() does not make sense for them * folio_migrate_mapping() does not make sense for them * migrate_huge_page_move_mapping() does not make sense for them * __migrate_folio() does not make sense for them * ... and khugepaged should never stumble over them Let's simply refuse typed pages (which includes slab) except hugetlb, and WARN. Link: https://lkml.kernel.org/r/20250704102524.326966-26-david@redhat.com Signed-off-by: David Hildenbrand Reviewed-by: Zi Yan Reviewed-by: Lorenzo Stoakes Reviewed-by: Harry Yoo Cc: Alistair Popple Cc: Al Viro Cc: Arnd Bergmann Cc: Brendan Jackman Cc: Byungchul Park Cc: Chengming Zhou Cc: Christian Brauner Cc: Christophe Leroy Cc: Eugenio Pé rez Cc: Greg Kroah-Hartman Cc: Gregory Price Cc: "Huang, Ying" Cc: Jan Kara Cc: Jason Gunthorpe Cc: Jason Wang Cc: Jerrin Shaji George Cc: Johannes Weiner Cc: John Hubbard Cc: Jonathan Corbet Cc: Joshua Hahn Cc: Liam Howlett Cc: Madhavan Srinivasan Cc: Mathew Brost Cc: Matthew Wilcox (Oracle) Cc: Miaohe Lin Cc: Michael Ellerman Cc: "Michael S. Tsirkin" Cc: Michal Hocko Cc: Mike Rapoport Cc: Minchan Kim Cc: Naoya Horiguchi Cc: Nicholas Piggin Cc: Oscar Salvador Cc: Peter Xu Cc: Qi Zheng Cc: Rakie Kim Cc: Rik van Riel Cc: Sergey Senozhatsky Cc: Shakeel Butt Cc: Suren Baghdasaryan Cc: Vlastimil Babka Cc: Xuan Zhuo Cc: xu xin Signed-off-by: Andrew Morton Stable-dep-of: f183663901f2 ("mm: consider non-anon swap cache folios in folio_expected_ref_count()") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/mm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2238,13 +2238,13 @@ static inline int folio_expected_ref_cou const int order = folio_order(folio); int ref_count = 0; - if (WARN_ON_ONCE(folio_test_slab(folio))) + if (WARN_ON_ONCE(page_has_type(&folio->page) && !folio_test_hugetlb(folio))) return 0; if (folio_test_anon(folio)) { /* One reference per page from the swapcache. */ ref_count += folio_test_swapcache(folio) << order; - } else if (!((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS)) { + } else { /* One reference per page from the pagecache. */ ref_count += !!folio->mapping << order; /* One reference from PG_private. */