[PATCH] selftests: prctl: skip anon VMA naming test when unsupported

From: Eva Kurchatova

Date: Wed Sep 16 2026 - 16:50:39 EST


PR_SET_VMA_ANON_NAME returns EINVAL on a kernel built without
CONFIG_ANON_VMA_NAME, and every case in the renaming test then fails on
a feature that is not there.

Probe once in the fixture setup with a throwaway mapping and skip when
the kernel answers EINVAL. Only that error means the feature is
missing; the test still checks that an invalid name is refused with
EINVAL later, on a kernel that has it.

Signed-off-by: Eva Kurchatova <eva.kurchatova@xxxxxxxxxxxxx>
---
.../testing/selftests/prctl/set-anon-vma-name-test.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/prctl/set-anon-vma-name-test.c b/tools/testing/selftests/prctl/set-anon-vma-name-test.c
index 5f9589534da8..2d49a5114497 100644
--- a/tools/testing/selftests/prctl/set-anon-vma-name-test.c
+++ b/tools/testing/selftests/prctl/set-anon-vma-name-test.c
@@ -80,6 +80,17 @@ FIXTURE(vma) {

FIXTURE_SETUP(vma) {
char template[] = "./set-anon-vma-test-XXXXXX";
+ void *probe;
+ int res;
+
+ /* Naming anonymous VMAs needs CONFIG_ANON_VMA_NAME. */
+ probe = mmap(NULL, AREA_SIZE, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ ASSERT_NE(probe, MAP_FAILED);
+ res = rename_vma((unsigned long)probe, AREA_SIZE, GOOD_NAME);
+ munmap(probe, AREA_SIZE);
+ if (res == -EINVAL)
+ SKIP(return, "CONFIG_ANON_VMA_NAME is not enabled");

self->ptr_anon = mmap(NULL, AREA_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
--
2.55.0