Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/mm: split_huge_page_test: fix occasional is_backed_by_folio() wrong results

Patch series "selftests/mm: split_huge_page_test: split_pte_mapped_thp
improvements", v2.

One fix for occasional failures I found while testing and a bunch of
cleanups that should make that test easier to digest.


This patch (of 2):

When checking for actual tail or head pages of a folio, we must make sure
that the KPF_COMPOUND_HEAD/KPF_COMPOUND_TAIL flag is paired with KPF_THP.

For example, if we have another large folio after our large folio in
physical memory, our "pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL)" would
trigger even though it's actually a head page of the next folio.

If is_backed_by_folio() returns a wrong result, split_pte_mapped_thp() can
fail with "Some THPs are missing during mremap".

Fix it by checking for head/tail pages of folios properly. Add
folio_tail_flags/folio_head_flags to improve readability and use these
masks also when just testing for any compound page.

Link: https://lkml.kernel.org/r/20250903070253.34556-1-david@redhat.com
Link: https://lkml.kernel.org/r/20250903070253.34556-2-david@redhat.com
Fixes: 169b456b0162 ("selftests/mm: reimplement is_backed_by_thp() with more precise check")
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
0d0e03d5 69e0a3b4

+7 -8
+7 -8
tools/testing/selftests/mm/split_huge_page_test.c
··· 44 44 static bool is_backed_by_folio(char *vaddr, int order, int pagemap_fd, 45 45 int kpageflags_fd) 46 46 { 47 + const uint64_t folio_head_flags = KPF_THP | KPF_COMPOUND_HEAD; 48 + const uint64_t folio_tail_flags = KPF_THP | KPF_COMPOUND_TAIL; 47 49 const unsigned long nr_pages = 1UL << order; 48 50 unsigned long pfn_head; 49 51 uint64_t pfn_flags; ··· 63 61 64 62 /* check for order-0 pages */ 65 63 if (!order) { 66 - if (pfn_flags & (KPF_THP | KPF_COMPOUND_HEAD | KPF_COMPOUND_TAIL)) 64 + if (pfn_flags & (folio_head_flags | folio_tail_flags)) 67 65 return false; 68 66 return true; 69 67 } ··· 78 76 goto fail; 79 77 80 78 /* head PFN has no compound_head flag set */ 81 - if (!(pfn_flags & (KPF_THP | KPF_COMPOUND_HEAD))) 79 + if ((pfn_flags & folio_head_flags) != folio_head_flags) 82 80 return false; 83 81 84 82 /* check all tail PFN flags */ 85 83 for (i = 1; i < nr_pages; i++) { 86 84 if (pageflags_get(pfn_head + i, kpageflags_fd, &pfn_flags)) 87 85 goto fail; 88 - if (!(pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL))) 86 + if ((pfn_flags & folio_tail_flags) != folio_tail_flags) 89 87 return false; 90 88 } 91 89 ··· 96 94 if (pageflags_get(pfn_head + nr_pages, kpageflags_fd, &pfn_flags)) 97 95 return true; 98 96 99 - /* this folio is bigger than the given order */ 100 - if (pfn_flags & (KPF_THP | KPF_COMPOUND_TAIL)) 101 - return false; 102 - 103 - return true; 97 + /* If we find another tail page, then the folio is larger. */ 98 + return (pfn_flags & folio_tail_flags) != folio_tail_flags; 104 99 fail: 105 100 ksft_exit_fail_msg("Failed to get folio info\n"); 106 101 return false;