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 67E752550BA for ; Tue, 6 Jan 2026 23:07:54 +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=1767740874; cv=none; b=RCdV0UCSo12Itacq8kcN44DuOA1WJAET2w9+YdlryuLwYq7NtZHfzVXic+8UdSAwkWfxeuxVjgjDg3GFoHuef7agXA8JfqTcl5OxNAC0RmX93IsbsbyexX0Y7NPa7NdNDQE06+xqWPKwRwkcoIFRhCJHMKzWrf+6dQMY+d6ZIF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767740874; c=relaxed/simple; bh=dY5jh0fDrczOegcNmRnB1RIq2GS0wAVKbPrg0jfyAuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RnLEgM9dZEnYMHc9m0rXMP7/4Qw93q+FyYX5tfXkEyWMPcNdTh1plEln1/xEXSphAH/fHddYLmg0WEKBuX9fs1M6AkQfcuL5cVMVIZwzwt/s8iXG0D5PB6lMJNWGm1Xi1cOsFHtQ7IzJswK1V5gtb/J/+Au2EqVa+eJfHgpzelA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qSYzroI2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qSYzroI2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 275D9C116C6; Tue, 6 Jan 2026 23:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767740873; bh=dY5jh0fDrczOegcNmRnB1RIq2GS0wAVKbPrg0jfyAuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qSYzroI2nTCvIlKEYnq617VXkisFLgroUJ+jNaCgTKucVwuNB3Buf6j+JNyCmGgQA EQY9Axo7kFBmdTosxgD+9zcHh3u/PEHFN1xffS1ZT/WCjMyN5pwQhbNNTc55TRwaBg g/jxQdL5WzW2jX/mTFR3dnH799RiikHCVZC13Dn9hw3fL5g/eV5MIgbfBJ8VCLVG5X aNA7nACdtmnBj2PudmgRI3gfvz+AMGKl8jmJN8aSD9ij5mqvRZwa6quGJWyA9bQEVA nqQh8Zrv3GCbg9G6/GEFosAo+R4B86IgeGMmoEgTUi1Xq6rSBveAO96cmDutKJl1pS REct3cCTsJsjQ== From: Sasha Levin To: stable@vger.kernel.org Cc: 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?= , Greg Kroah-Hartman , 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.y 1/2] mm: simplify folio_expected_ref_count() Date: Tue, 6 Jan 2026 18:07:46 -0500 Message-ID: <20260106230747.3447947-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026010544-pavestone-gloating-a829@gregkh> References: <2026010544-pavestone-gloating-a829@gregkh> 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 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 --- include/linux/mm.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 13b4bd7355c1..bbea39a8d441 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2238,13 +2238,13 @@ static inline int folio_expected_ref_count(const struct folio *folio) 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. */ -- 2.51.0