[PATCH 4/4] perf bench mem: Support PROT_MTE on arm64
From: Pierre-Clément Tosi
Date: Tue Dec 01 2026 - 07:12:53 EST
Add support for '--prot mte,...' to benchmark PROT_MTE mappings.
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Ryan Roberts <ryan.roberts@xxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Signed-off-by: Pierre-Clément Tosi <ptosi@xxxxxxxxxx>
---
tools/perf/Documentation/perf-bench.txt | 7 +++++--
tools/perf/bench/mem-functions.c | 11 ++++++++++-
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/tools/perf/Documentation/perf-bench.txt b/tools/perf/Documentation/perf-bench.txt
index 0a3ad2284f19..fd09f3fc206b 100644
--- a/tools/perf/Documentation/perf-bench.txt
+++ b/tools/perf/Documentation/perf-bench.txt
@@ -291,13 +291,16 @@ Create multiple threads to call mmap/munmap concurrently.
--prot=<PROT>::
Specify memory protection for mapping memory buffers (default:
-read,write). Available values are none, read, write and exec, as a
-comma-separated list.
+read,write). Available values are none, read, write, exec and, on
+arm64, mte (PROT_MTE), as a comma-separated list.
The benchmark loads from each page of a readable mapping and stores to
each page of a writable one: 'read' maps the zero page, 'write' takes a
single write fault per page, and 'read,write' maps the zero page before
breaking copy-on-write. Mappings that are neither readable nor writable
are not accessed.
+With mte, the kernel initialises the allocation tags of each page when
+it first maps it, unless the CPU doesn't support MTE, in which case
+mmap() ignores PROT_MTE.
SUITES FOR 'numa'
~~~~~~~~~~~~~~~~~
diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index 84247f83da59..722aa4189737 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -29,6 +29,11 @@
#include <linux/log2.h>
#include <pthread.h>
+/* arm64 only (asm/mman.h), but missing from older C libraries. */
+#if defined(__aarch64__) && !defined(PROT_MTE)
+#define PROT_MTE 0x20
+#endif
+
#define K 1024
#define PAGE_SHIFT_4KB 12
@@ -65,7 +70,7 @@ static const struct option bench_common_options[] = {
"Use a cycles event instead of gettimeofday() to measure performance"),
OPT_STRING(0, "prot", &prot_str, "read,write",
- "Memory protection: none, read, write, exec (comma-separated)"),
+ "Memory protection: none, read, write, exec, mte (arm64) (comma-separated)"),
OPT_END()
};
@@ -285,6 +290,10 @@ static int parse_arg_prot(const char *str)
prot |= PROT_WRITE;
else if (len == strlen("exec") && !strncmp(str, "exec", len))
prot |= PROT_EXEC;
+#ifdef PROT_MTE
+ else if (len == strlen("mte") && !strncmp(str, "mte", len))
+ prot |= PROT_MTE;
+#endif
else
return -1;
--
2.56.1.839.g22a8290db9-goog