linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, hugetlb: Reset mapping to TAIL_MAPPING before restoring vmemmap
@ 2025-04-15  5:47 Oscar Salvador
  2025-04-15  7:23 ` David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Oscar Salvador @ 2025-04-15  5:47 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Muchun Song, David Hildenbrand, linux-mm, linux-kernel,
	Vlastimil Babka, Matthew Wilcox, Oscar Salvador

commit 4eeec8c89a0c ("mm: move hugetlb specific things in folio to page[3]")
shifted hugetlb specific stuff, and now mapping overlaps _hugetlb_cgroup field.

_hugetlb_cgroup is set to NULL when preparing the hugetlb page in
init_new_hugetlb_folio().
For a better picture, this is page->mapping before and after the comming
for the first three tail pages:

before:
page: fffff51a44358040  0000000000000000
page: fffff51a44358080  0000000000000000
page: fffff51a443580c0  dead000000000400

after:
page: fffff1f0042b0040  0000000000000000
page: fffff1f0042b0080  fffff1f0042b0090
page: fffff1f0042b00c0  0000000000000000

Tail#2 has fffff1f0042b0090 because of the _deferred_list initialization,
which was also shifted, but that is not a problem.

For HVO, upon restoring that gets copied in some tail pages (reset_struct_pages)
and so those tail pages will not have TAIL_MAPPING set and the check
in free_tail_page_prepare() will fail:

 kernel: BUG: Bad page state in process kworker/0:3  pfn:10ac40
 kernel: page does not match folio
 kernel: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10ac40
 kernel: flags: 0x17ffffc0000000(node=0|zone=2|lastcpupid=0x1fffff)
 kernel: raw: 0017ffffc0000000 fffff1f0042b0000 0000000000000000 0000000000000000
 kernel: raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
 kernel: page dumped because: corrupted mapping in tail page

Reset _hugetlb_cgroup to TAIL_MAPPING before restoring so tail pages have the
right value.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
---
Hi guys,

Although I can no longer reproduce the issue with this patch, I'm not entirely
sure this is the right way to fix the problem, so I'm open to
suggestions.
---
 mm/hugetlb_vmemmap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 9a99dfa3c495..3d763182c834 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -498,6 +498,12 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,
  */
 int hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio)
 {
+	/*
+	 * Before restoring vmemmap, make sure to reset mapping to TAIL_MAPPING,
+	 * so tail pages that were reset will have the right thing after being
+	 * restored, and the checks in free_tail_page_prepare() will pass.
+	 */
+	set_hugetlb_cgroup(folio, TAIL_MAPPING);
 	return __hugetlb_vmemmap_restore_folio(h, folio, VMEMMAP_SYNCHRONIZE_RCU);
 }
 
-- 
2.49.0



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

end of thread, other threads:[~2025-04-16  7:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-15  5:47 [PATCH] mm, hugetlb: Reset mapping to TAIL_MAPPING before restoring vmemmap Oscar Salvador
2025-04-15  7:23 ` David Hildenbrand
2025-04-15  7:32   ` David Hildenbrand
2025-04-15  7:48     ` Muchun Song
2025-04-15  8:02     ` Oscar Salvador
2025-04-15  8:36       ` David Hildenbrand
2025-04-16  7:21 ` kernel test robot
2025-04-16  7:53 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox