Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] perf bench mem: Add support for PROT_MTE
@ 2026-12-01 12:11 Pierre-Clément Tosi
  2026-12-01 12:11 ` [PATCH 4/4] perf bench mem: Support PROT_MTE on arm64 Pierre-Clément Tosi
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre-Clément Tosi @ 2026-12-01 12:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, James Clark
  Cc: Ankur Arora, linux-perf-users, linux-kernel,
	Pierre-Clément Tosi, Catalin Marinas, Ryan Roberts,
	linux-arm-kernel

This series extend 'perf bench' to measure the overhead of mapping MTE
Tagged Memory to userspace, which is useful when evaluating the impact
of a change to page data and tag clearing within the kernel. It adds a
new --prot flag enabling callers to pass PROT_MTE during mmap().

Note that memcpy/memset are also taught about --prot as a side-effect.

As a result, users can reliably measure page tagging through e.g.

  perf bench mem mmap -f populate --prot write,mte -s 128MB

Tested with arm64 (GCC) and x86-64 (GCC and Clang) builds.

(Applies cleanly to perf-tools-next at commit 4a7008f739a3)

Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
Pierre-Clément Tosi (4):
      perf bench mem: Report why mmap() failed
      perf bench mem: Pass bench_params to bench_mmap()
      perf bench mem: Add --prot option
      perf bench mem: Support PROT_MTE on arm64

 tools/perf/Documentation/perf-bench.txt |  21 +++++
 tools/perf/bench/mem-functions.c        | 135 ++++++++++++++++++++++++--------
 2 files changed, 123 insertions(+), 33 deletions(-)
---
base-commit: 4a7008f739a30ee4c22d9f21af362a5128f2628d
change-id: 20261201-perf-prot-mte-0ffbf9bc2f7a

Best regards,
-- 
Pierre-Clément Tosi <ptosi@google.com>



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

* [PATCH 4/4] perf bench mem: Support PROT_MTE on arm64
  2026-12-01 12:11 [PATCH 0/4] perf bench mem: Add support for PROT_MTE Pierre-Clément Tosi
@ 2026-12-01 12:11 ` Pierre-Clément Tosi
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Clément Tosi @ 2026-12-01 12:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Ian Rogers, James Clark
  Cc: Ankur Arora, linux-perf-users, linux-kernel,
	Pierre-Clément Tosi, Catalin Marinas, Ryan Roberts,
	linux-arm-kernel

Add support for '--prot mte,...' to benchmark PROT_MTE mappings.

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Pierre-Clément Tosi <ptosi@google.com>
---
 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



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

end of thread, other threads:[~2026-12-01 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:11 [PATCH 0/4] perf bench mem: Add support for PROT_MTE Pierre-Clément Tosi
2026-12-01 12:11 ` [PATCH 4/4] perf bench mem: Support PROT_MTE on arm64 Pierre-Clément Tosi

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