summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2026-07-01 08:23:21 +0200
committerNamhyung Kim <namhyung@kernel.org>2026-07-04 09:24:02 -0700
commite34006e7435fdd2c8d15e89d2137a4bf22c16401 (patch)
treea2957ff22b3d65f4a057cfb7b953fb43035c1321
parentca0e19074bd6afcb9c7b23aa474ca17238cdb241 (diff)
downloadlinux-stable-e34006e7435fdd2c8d15e89d2137a4bf22c16401.tar.gz
linux-stable-e34006e7435fdd2c8d15e89d2137a4bf22c16401.zip
perf test amd ibs: avoid using executable heap
Making [parts of] the heap executable is dangerous and is blocked by SELinux on Fedora/RHEL even for an unconfined user. Replace the malloc() + mprotect() combo with just mmap(), creating a private anonymous rwx mapping, which only requires the more commonly allowed "execmem" permission under SELinux (things like JIT or regex compilation need it as well). mmap() with MAP_ANONYMOUS will give us a zeroed mapping that begins on a page boundary, so the result is equivalent to the original code even without a memset() or the page-alignment dance. Verified that the test still passes on a machine with an AMD CPU that has the "ibs" CPU flag. Fixes: 35db59fa8ea2 ("perf test amd ibs: Add sample period unit test") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Ravi Bangoria <ravi.bangoria@amd.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
-rw-r--r--tools/perf/arch/x86/tests/amd-ibs-period.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/tools/perf/arch/x86/tests/amd-ibs-period.c b/tools/perf/arch/x86/tests/amd-ibs-period.c
index 6a92b3a23ed7..32713f8fcd5c 100644
--- a/tools/perf/arch/x86/tests/amd-ibs-period.c
+++ b/tools/perf/arch/x86/tests/amd-ibs-period.c
@@ -46,7 +46,6 @@ static int dummy_workload_1(unsigned long count)
{
int (*func)(void);
int ret = 0;
- char *p;
char insn1[] = {
0xb8, 0x01, 0x00, 0x00, 0x00, /* mov 1,%eax */
0xc3, /* ret */
@@ -59,18 +58,11 @@ static int dummy_workload_1(unsigned long count)
0xcc, /* int 3 */
};
- p = calloc(2, page_size);
- if (!p) {
- printf("malloc() failed. %m");
- return 1;
- }
-
- func = (void *)((unsigned long)(p + page_size - 1) & ~(page_size - 1));
-
- ret = mprotect(func, page_size, PROT_READ | PROT_WRITE | PROT_EXEC);
- if (ret) {
- printf("mprotect() failed. %m");
- goto out;
+ func = mmap(NULL, page_size, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (func == MAP_FAILED) {
+ pr_debug("mmap() failed. %m\n");
+ return -1;
}
if (count < 100000)
@@ -93,7 +85,7 @@ static int dummy_workload_1(unsigned long count)
}
out:
- free(p);
+ munmap(func, page_size);
return ret;
}