[LTP] [PATCH 2/2] hugemmap35: add regression test for 49ccf2c3cafb
Andrea Cervesato
andrea.cervesato@suse.de
Wed Jul 15 13:39:27 CEST 2026
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add a regression test verifying that a hugetlbfs file can be mapped
with PROT_MTE even when MAP_HUGETLB is not set in the mmap() flags.
Before the referenced commit, VM_MTE_ALLOWED was not set early enough
for hugetlbfs file mappings, so such an mmap() was wrongly rejected.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c | 105 +++++++++++++++++++++
3 files changed, 107 insertions(+)
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 0896d3c941f068628f53c31197b293906c4ecba6..8ee0e6f828cb1954e03d67d40fe691d6521361bf 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -36,6 +36,7 @@ hugemmap30 hugemmap30
hugemmap31 hugemmap31
hugemmap32 hugemmap32
hugemmap34 hugemmap34
+hugemmap35 hugemmap35
hugemmap05_1 hugemmap05 -m
hugemmap05_2 hugemmap05 -s
hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index b4455de51d6d6a9cc3d8b7ff392fc3ea9e95890a..0e59035dfdcf759aa16c069575bb1f4eb58f321c 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -36,6 +36,7 @@
/hugetlb/hugemmap/hugemmap31
/hugetlb/hugemmap/hugemmap32
/hugetlb/hugemmap/hugemmap34
+/hugetlb/hugemmap/hugemmap35
/hugetlb/hugeshmat/hugeshmat01
/hugetlb/hugeshmat/hugeshmat02
/hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c
new file mode 100644
index 0000000000000000000000000000000000000000..1c11013e0de6b6dd870e3ffc48562912a44cf7f7
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap35.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test that :manpage:`mmap(2)` accepts ``PROT_MTE`` for hugetlbfs file
+ * mappings that do not specify ``MAP_HUGETLB``.
+ *
+ * On arm64, hugetlbfs file mappings must get ``VM_MTE_ALLOWED`` before mmap
+ * flag validation. This is needed because mapping a hugetlbfs file does not
+ * have to use ``MAP_HUGETLB``. The test needs root to reserve huge pages and
+ * mount hugetlbfs.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "hugetlb.h"
+#include "lapi/mman.h"
+#include "lapi/mmap.h"
+
+#define MNTPOINT "hugetlbfs/"
+
+static int fd = -1;
+static long hpage_size;
+
+#define TC(x) {x, #x}
+
+static struct tcase {
+ int flags;
+ const char *desc;
+} tcases[] = {
+ TC(MAP_SHARED),
+ TC(MAP_PRIVATE),
+};
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+ volatile char *ptr;
+
+ TESTPTR(mmap(NULL, hpage_size, PROT_READ | PROT_WRITE | PROT_MTE,
+ tc->flags, fd, 0));
+
+ if (TST_RET_PTR == MAP_FAILED) {
+ if (TST_ERR == ENOMEM)
+ tst_brk(TCONF, "Not enough huge pages");
+
+ tst_res(TFAIL | TTERRNO, "mmap(PROT_MTE, %s) without MAP_HUGETLB failed",
+ tc->desc);
+ return;
+ }
+
+ ptr = TST_RET_PTR;
+ *ptr = 1;
+
+ SAFE_MUNMAP(TST_RET_PTR, hpage_size);
+
+ tst_res(TPASS, "mmap(PROT_MTE, %s) without MAP_HUGETLB passed", tc->desc);
+}
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+ if (!hpage_size)
+ tst_brk(TCONF, "Huge pages are not supported");
+
+ TESTPTR(mmap(NULL, hpage_size, PROT_READ | PROT_MTE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0));
+
+ if (TST_RET_PTR == MAP_FAILED)
+ tst_brk(TCONF | TTERRNO, "PROT_MTE is not supported with MAP_HUGETLB");
+
+ SAFE_MUNMAP(TST_RET_PTR, hpage_size);
+
+ fd = tst_creat_unlinked(MNTPOINT, 0, 0600);
+ SAFE_FTRUNCATE(fd, hpage_size);
+}
+
+static void cleanup(void)
+{
+ if (fd != -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .hugepages = { 2, TST_NEEDS },
+ .supported_archs = (const char *const []) {
+ "aarch64",
+ NULL
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "49ccf2c3cafb"},
+ {}
+ },
+};
--
2.51.0
More information about the ltp
mailing list