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 842314C97 for ; Wed, 7 Jan 2026 00:36:33 +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=1767746193; cv=none; b=dX7paoV1bKSMTYBkIiB8Fx7NE3LyTEZoFaDFkuk+uSi8C6Rof6omHxPA8n+UVJKU0IaBJeE0wqkvg/xZZs7M+y7FXsabW/c8UXBK6k2phxs4VfkQAdqoENacBRoPNHKJ2B+cxCpumWyd4c9dIyOKG2RBiITmelHOgOehBbDFhvo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767746193; c=relaxed/simple; bh=M7mrN6NlbeG4+DuRToSTazMe+VfOrf49zloLcLtxNvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bgOR1k170kdcncauzqd8Zc6T/xy3fng885hjfAiQ64Fi0B0mE0cZQBqtR6mf4L2c838CWCx/dUr+gvf95OuWG1MCC5U56axpCPR2fgr7p4fWtB5Pi047CXZdnC/tKSYrt3H3hZVZar/6drvES1SnLAdq7SmgJWsE1SvEyF6oz38= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fuI5CBlk; 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="fuI5CBlk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A593C116C6; Wed, 7 Jan 2026 00:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767746193; bh=M7mrN6NlbeG4+DuRToSTazMe+VfOrf49zloLcLtxNvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fuI5CBlkagwvDGFAjpx4El19pnzucn7yCmAOb3pEApe3fGpGIdupjEdi3pR1oSPTY bS7YETy3zYEA0+TayADJyETmqw/2yYJPxVubgZ4sQhHM6BEEoLAJHG2pw8S2gOZTv2 vPe/AQRLnTse15IYHpbbLaFtIySo0oyA/wkJqL/xH86pp61o+U4WNYPlcuBK6xo8xZ H3GMvXlg2CvmtUkDTR5qVdXAG3BILufg+ok4/6XJQhMX3TCDzzpLM1RQDw5nCcIZZX UktaIPmqKZ6trGAf3I71Vr2DJ+8Qt1duVX6MEZVRItgDLEYYB8Nvd3Pc0Vcnt/tMZ8 o+ZDRc8kq0Yeg== 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.1.y 1/2] mm: simplify folio_expected_ref_count() Date: Tue, 6 Jan 2026 19:36:26 -0500 Message-ID: <20260107003627.3469728-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026010547-early-outnumber-a575@gregkh> References: <2026010547-early-outnumber-a575@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 44381ffaf34b..61efff50eb67 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1820,13 +1820,13 @@ static inline int folio_expected_ref_count(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