Skip to contentSkip to conversation

selftests/mm: hugepage-mremap: fix mapping alignment

PATCH In review Luiz Capitulino 2 participants 4 messages Sep 28 – Oct 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/mm: hugepage-mremap: fix mapping alignment

commit a914785f6349da754e1226420bf4e51961956769 upstream.

When running the HugeTLB kselftest suite on arm64 with 64K base pages, this test always fails:

# -------------------------

  # running ./hugepage-mremap
  # -------------------------
  # TAP version 13
  # 1..1
  # # Map haddr: Returned address is 0x7eaa40000000
  # # Map daddr: Returned address is 0x7daa40000000
  # # Map vaddr: Returned address is 0x7faa40000000
  # Bail out! ioctl-UFFDIO_REGISTER: Invalid argument
  # # Planned tests != run tests (1 != 0)
  # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
  # [FAIL]
  not ok 1 hugepage-mremap # exit=1
  # NOTE: These hugetlb tests provide minimal coverage.  Use
  #       https://github.com/libhugetlbfs/libhugetlbfs.git for
  #       hugetlb regression testing.
  # SKIP ./uffd-wp-mremap

The problem is that the default HugeTLB page size on such systems is 512 MiB and 'length' is not aligned to the page size. This causes uffd_register() to fail as 'length' is 10 MiB and not aligned to the HugeTLB page size.

On upstream this was fixed by a914785f6349 ("selftests/mm: hugetlb-mremap:
add setup of HugeTLB pages") as that commit aligns 'length' to the default HugeTLB page size as part of what it's doing. Since this commit is part of a 50+ patch series, we backport only the 'length' alignment bits to fix the test.

---
 tools/testing/selftests/mm/hugepage-mremap.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/mm/hugepage-mremap.c +6 -0
index 928c1045e295..0d4e1a5b185d 100644
@@ -97,6 +97,7 @@ static void register_region_with_uffd(char *addr, size_t len)
 
 int main(int argc, char *argv[])
 {
+	unsigned long hugepage_size;
 	size_t length = 0;
 	int ret = 0, fd;
 
@@ -114,7 +115,12 @@ int main(int argc, char *argv[])
 	else
 		length = DEFAULT_LENGTH_MB;
 
+	hugepage_size = default_huge_page_size();
+	if (!hugepage_size)
+		ksft_exit_skip("Could not detect default hugetlb page size\n");
+
 	length = MB_TO_BYTES(length);
+	length = (length + hugepage_size - 1) & ~(hugepage_size - 1);
 	fd = memfd_create(argv[0], MFD_HUGETLB);
 	if (fd < 0)
 		ksft_exit_fail_msg("Open failed: %s\n", strerror(errno));
Signature · 1 line
2.55.0
maintainer
#1 lore raw
Quoted 1 line

commit a914785f6349da754e1226420bf4e51961956769 upstream.

a914785f6349 ("selftests/mm: hugetlb-mremap: add setup of HugeTLB pages") is Mike's commit, but this patch has you as the author with only your Signed-off-by. Could you send a v3 that keeps Mike as the author with his Signed-off-by, followed by yours, or otherwise makes the provenance explicit?

The same applies to the 6.12.y posting.

Signature · 2 lines
Thanks,
Sasha
author Tested-by Tested-by Sarthak Sharma
#2 lore raw
Quoted 8 lines · Sasha Levin
Quoted 1 line

commit a914785f6349da754e1226420bf4e51961956769 upstream.

a914785f6349 ("selftests/mm: hugetlb-mremap: add setup of HugeTLB pages") is Mike's commit, but this patch has you as the author with only your Signed-off-by. Could you send a v3 that keeps Mike as the author with his Signed-off-by, followed by yours, or otherwise makes the provenance explicit?

The same applies to the 6.12.y posting.

My intent was to explain what was being fixed and why and, as it's a partial backport, I decided to author the change. But I'm keeping Mike's original changelog & authorship now, can you review it before I post? Note that the subject will change as a result.

"""
From: "Mike Rapoport (Microsoft)" <[email protected]>
Date: Mon, 11 May 2026 19:28:25 +0300
Subject: [PATCH v6.18.y v3] selftests/mm: hugetlb-mremap: add setup of HugeTLB pages

commit a914785f6349da754e1226420bf4e51961956769 upstream.

hugetlb-mremap test fails if there are no free huge pages prepared by a wrapper script.

Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit.

Cc Baolin Wang <[email protected]>
Cc Barry Song <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Dev Jain <[email protected]>
Cc Donet Tom <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc John Hubbard <[email protected]>
Cc Lance Yang <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Liam Howlett <[email protected]>
Cc Li Wang <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Mark Brown <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Nico Pache <[email protected]>
Cc Peter Xu <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Zi Yan <[email protected]>

[ Backport-notes: this is a partial backport containing only the aligning of 'length' to the hugepage size. The hugepage_settings.h include line and the hugetlb_setup_default() call are omitted. Without this fix, the uffd_register() call always fails on arm64 with 64K base pages and 512 MiB default HugeTLB page size causing the test to fail with the error below as 'length' is 10 MiB and not aligned to the HugeTLB page size.

# -------------------------

  # running ./hugepage-mremap
  # -------------------------
  # TAP version 13
  # 1..1
  # # Map haddr: Returned address is 0x7eaa40000000
  # # Map daddr: Returned address is 0x7daa40000000
  # # Map vaddr: Returned address is 0x7faa40000000
  # Bail out! ioctl-UFFDIO_REGISTER: Invalid argument
  # # Planned tests != run tests (1 != 0)
  # # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
  # [FAIL]
  not ok 1 hugepage-mremap # exit=1
  # NOTE: These hugetlb tests provide minimal coverage.  Use
  #       https://github.com/libhugetlbfs/libhugetlbfs.git for
  #       hugetlb regression testing.
  # SKIP ./uffd-wp-mremap
]
Signed-off-by: Luiz Capitulino <[email protected]>
"""
maintainer
#3 lore raw
Quoted 4 lines

My intent was to explain what was being fixed and why and, as it's a partial backport, I decided to author the change. But I'm keeping Mike's original changelog & authorship now, can you review it before I post? Note that the subject will change as a result.

The draft looks good to me. Please post v3 for both 6.18.y and 6.12.y.

Signature · 2 lines
Thanks,
Sasha