linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/slab: fix folio_test_{anon,ksm}() false positive on slabs
@ 2025-06-09 13:27 Harry Yoo
  2025-06-09 14:12 ` Harry Yoo
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Harry Yoo @ 2025-06-09 13:27 UTC (permalink / raw)
  To: vbabka, rientjes, cl, akpm; +Cc: roman.gushchin, willy, linux-mm, Harry Yoo

When running tools/mm/page-types (with flags, page-counts, MB omitted),
it reports that some slabs have KPF_ANON and KPF_KSM set:

  $ sudo ./page-types | grep slab
  _______S___________________________________	slab
  _______S____a________x_____________________	slab,anonymous,ksm

This is unexpected, as slab memory should never be treated as anonymous
memory. This is because slab->slabs shares the same offset as
page->mapping and setting the lower two bits of ->slabs field means
folio_test_anon() and folio_test_ksm() will return true on the slab:

  [ field ]		[ offset ] [ size ]
  page->mapping		24         8
  page->lru		8	   16

  slab->next		16	   8
  slab->slabs		24	   4

Reorder ->slabs and ->next, so that the layout will be:

  slab->slabs		16	   4
  slab->next		24	   8

After reordering, slab->slabs shares its offset with page->lru.prev,
which is not a problem. slab->next now shares the offset with
page->mapping, but that's fine, as a slab is double-word aligned.

With the change, the nonsense slab pages disappear:

  $ sudo ./page-types | grep slab
  _______S___________________________________	slab

Fixes: 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to allow larger rcu_head")
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---

No Cc: stable because we don't usually check folio_test_anon() on slabs.

 mm/slab.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/slab.h b/mm/slab.h
index 05a21dc796e0..2e7064f7709e 100644
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -59,8 +59,8 @@ struct slab {
 				struct list_head slab_list;
 #ifdef CONFIG_SLUB_CPU_PARTIAL
 				struct {
-					struct slab *next;
 					int slabs;	/* Nr of slabs left */
+					struct slab *next;
 				};
 #endif
 			};
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-06-12 12:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-09 13:27 [PATCH] mm/slab: fix folio_test_{anon,ksm}() false positive on slabs Harry Yoo
2025-06-09 14:12 ` Harry Yoo
2025-06-09 14:22 ` Vlastimil Babka
2025-06-10 12:38   ` Harry Yoo
2025-06-10 13:03     ` Vlastimil Babka
2025-06-10 13:17       ` Harry Yoo
2025-06-12 12:44         ` David Hildenbrand
2025-06-09 16:06 ` Christoph Lameter (Ampere)
2025-06-10 12:39   ` Harry Yoo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).