[PATCH 01/12] mm/ksm: catch tail page abnormal in page_stable_node

From: alexs
Date: Mon Mar 18 2024 - 08:11:27 EST


From: Alex Shi <alexs@xxxxxxxxxx>

commit 19138349ed59 ("mm/migrate: Add folio_migrate_flags()") change the
meaning of func page_stable_node() to check the compound head for tail
'page' instead of tail page self.
But seems both semantics are same at results, the func always return NULL
for tail page. So adding a bug monitor here in case of abnormal.

Signed-off-by: Alex Shi <alexs@xxxxxxxxxx>
Cc: Izik Eidus <izik.eidus@xxxxxxxxxxxxxxxxxx>
Cc: Matthew Wilcox <willy@xxxxxxxxxxxxx>
Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
Cc: Hugh Dickins <hughd@xxxxxxxxxx>
Cc: Chris Wright <chrisw@xxxxxxxxxxxx>
To: linux-kernel@xxxxxxxxxxxxxxx
To: linux-mm@xxxxxxxxx
To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
mm/ksm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index 8c001819cf10..3ff469961927 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1091,7 +1091,12 @@ static inline struct ksm_stable_node *folio_stable_node(struct folio *folio)

static inline struct ksm_stable_node *page_stable_node(struct page *page)
{
- return folio_stable_node(page_folio(page));
+ struct ksm_stable_node *node;
+
+ node = folio_stable_node(page_folio(page));
+ VM_BUG_ON_PAGE(PageTail(page) && node, page);
+
+ return node;
}

static inline void set_page_stable_node(struct page *page,
--
2.43.0