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 CB392328B5F; Fri, 9 Jan 2026 12:51:22 +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=1767963082; cv=none; b=Oace+aUHI+15M5MJyuYFM3B9g7Hjao1lf2gGQFlmxD0knXURCaLUw3e5k1eCOBfYEVkmEkkSe91x9cJzdgHTaQELMO5vR8MhAsRVe4Y2lR3vilz159RdYZicjRYgl+Q51u5KQF6KrmCEiEbA1O1tKtYPP8YA5qLl6gE5C4Nii18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767963082; c=relaxed/simple; bh=UWzRAJYUPGz+7PFCxoRpxdGhKaWzC5cSuitwpwrva8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gsia1Lq2lb77X3qYK/iLLXcPvVpLG0F0V+c3OsWqRFhG3zjZiLwQd+BSvXQPclJFIYka5HwIt53uU3nKV3cVFhqtOH+eTtxezuRGKYQuMomn9168b11XBTDNxmP812WC3K+jttLC7LqYe9blKCgQ2HcaSLzbKc06/ZsYhBmFzyc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TEpB/a+0; 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="TEpB/a+0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62925C4CEF1; Fri, 9 Jan 2026 12:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767963082; bh=UWzRAJYUPGz+7PFCxoRpxdGhKaWzC5cSuitwpwrva8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TEpB/a+0oSe2CXjOtKfnY6ZQNLc/qT+06uk9cuKpiOv7UZyUd67MljPFBEn6W8zqf HKwgdQeO5kLqKddciK4MJt9RK9kXkV2cc/GqJrzsMyYrEPYQ+D3Ux+246N7RFpybv7 h68MnlQU3lV8nsNa0LzULd0ae83gFjF0CSnV8pPY= 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.1 589/634] mm: simplify folio_expected_ref_count() Date: Fri, 9 Jan 2026 12:44:27 +0100 Message-ID: <20260109112139.782958738@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260109112117.407257400@linuxfoundation.org> References: <20260109112117.407257400@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.1-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 @@ -1820,13 +1820,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. */