[PATCH v2] kselftest/arm64: Check that PR_SVE_VL_INHERIT survives a second exec
From: Abdalla Eldoumani
Date: Thu Dec 03 2026 - 12:06:17 EST
From: Abdalla Eldoumani <abdalla.eldoumani@xxxxxxxxxxx>
The prctl_set_for_child test sets a vector length with
PR_SVE_VL_INHERIT and checks that a forked and exec()ed child sees it.
That only covers the first exec(). The kernel keeps the inherit flag
and the on-exec VL across exec() so that later descendants keep the VL
too, and nothing checks that part, which the fp TODO list notes as
testing PR_SVE_VL_INHERIT after a double fork.
Extend the test to also read the VL in a grandchild. Add a small
fork-exec helper next to rdvl-sve and rdvl-sme that forks, execs the
program it is given and passes on its exit status. The child execs
fork-exec with the rdvl helper, so the VL is read after two fork() and
exec() generations. Both SVE and SME are covered since the test runs
for each vector type.
With a kernel modified to clear the inherit flag on exec() the existing
check still passes and the new check fails for both vector types, with
the grandchild getting the default VL. Drop the item from the TODO list.
Assisted-by: LLM
Signed-off-by: Abdalla Eldoumani <abdalla.eldoumani@xxxxxxxxxxx>
---
Changes in v2:
- Move the middle generation into a fork-exec helper next to rdvl-sve
and rdvl-sme, instead of re-running vec-syscfg through /proc/self/exe,
so main() is left alone (Mark Brown).
tools/testing/selftests/arm64/fp/.gitignore | 1 +
tools/testing/selftests/arm64/fp/Makefile | 4 +-
tools/testing/selftests/arm64/fp/TODO | 1 -
tools/testing/selftests/arm64/fp/fork-exec.c | 43 +++++++++++++++++++
tools/testing/selftests/arm64/fp/vec-syscfg.c | 32 +++++++++++++-
5 files changed, 77 insertions(+), 4 deletions(-)
create mode 100644 tools/testing/selftests/arm64/fp/fork-exec.c
diff --git a/tools/testing/selftests/arm64/fp/.gitignore b/tools/testing/selftests/arm64/fp/.gitignore
index 8362e7e..535c6d8 100644
--- a/tools/testing/selftests/arm64/fp/.gitignore
+++ b/tools/testing/selftests/arm64/fp/.gitignore
@@ -1,3 +1,4 @@
+fork-exec
fp-pidbench
fp-ptrace
fp-stress
diff --git a/tools/testing/selftests/arm64/fp/Makefile b/tools/testing/selftests/arm64/fp/Makefile
index d171021..e194cd4 100644
--- a/tools/testing/selftests/arm64/fp/Makefile
+++ b/tools/testing/selftests/arm64/fp/Makefile
@@ -11,7 +11,8 @@ TEST_GEN_PROGS := \
sve-ptrace sve-probe-vls \
vec-syscfg \
za-fork za-ptrace
-TEST_GEN_PROGS_EXTENDED := fp-pidbench fpsimd-test \
+TEST_GEN_PROGS_EXTENDED := fork-exec \
+ fp-pidbench fpsimd-test \
kernel-test \
rdvl-sme rdvl-sve \
sve-test \
@@ -24,6 +25,7 @@ TEST_PROGS_EXTENDED := fpsimd-stress sve-stress ssve-stress za-stress
EXTRA_CLEAN += $(OUTPUT)/asm-utils.o $(OUTPUT)/rdvl.o $(OUTPUT)/za-fork-asm.o
+$(OUTPUT)/fork-exec: fork-exec.c
# Build with nolibc to avoid effects due to libc's clone() support
$(OUTPUT)/fp-pidbench: fp-pidbench.S $(OUTPUT)/asm-utils.o
$(CC) -nostdlib $^ -o $@
diff --git a/tools/testing/selftests/arm64/fp/TODO b/tools/testing/selftests/arm64/fp/TODO
index 44004e5..90ee128 100644
--- a/tools/testing/selftests/arm64/fp/TODO
+++ b/tools/testing/selftests/arm64/fp/TODO
@@ -4,4 +4,3 @@
- Ensure ptraced processes actually see the register state visible through
the ptrace interface.
- Big endian.
-- Test PR_SVE_VL_INHERIT after a double fork.
diff --git a/tools/testing/selftests/arm64/fp/fork-exec.c b/tools/testing/selftests/arm64/fp/fork-exec.c
new file mode 100644
index 0000000..e758c0d
--- /dev/null
+++ b/tools/testing/selftests/arm64/fp/fork-exec.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Fork, exec the program named on the command line and exit with its
+ * status, so a test can read state two exec() generations down.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int main(int argc, char **argv)
+{
+ pid_t child;
+ int status;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s program\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ child = fork();
+ if (child == -1) {
+ fprintf(stderr, "fork() failed: %d (%s)\n",
+ errno, strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ if (child == 0) {
+ execl(argv[1], argv[1], NULL);
+ fprintf(stderr, "execl(%s) failed: %d (%s)\n",
+ argv[1], errno, strerror(errno));
+ _exit(EXIT_FAILURE);
+ }
+
+ if (waitpid(child, &status, 0) != child || !WIFEXITED(status))
+ return EXIT_FAILURE;
+
+ return WEXITSTATUS(status);
+}
diff --git a/tools/testing/selftests/arm64/fp/vec-syscfg.c b/tools/testing/selftests/arm64/fp/vec-syscfg.c
index 2c8ccbe..63b8f52 100644
--- a/tools/testing/selftests/arm64/fp/vec-syscfg.c
+++ b/tools/testing/selftests/arm64/fp/vec-syscfg.c
@@ -24,6 +24,8 @@
#define ARCH_MIN_VL SVE_VL_MIN
+#define FORK_EXEC_BINARY "./fork-exec"
+
struct vec_data {
const char *name;
unsigned long hwcap_type;
@@ -85,8 +87,13 @@ static int stdio_read_integer(FILE *f, const char *what, int *val)
return 0;
}
-/* Start a new process and return the vector length it sees */
-static int get_child_rdvl(struct vec_data *data)
+/*
+ * Start a new process and return the vector length it sees. With
+ * grandchild set the child execs the fork-exec helper, which forks and
+ * execs the rdvl binary, so the VL is read two fork()/exec() generations
+ * down.
+ */
+static int get_descendant_rdvl(struct vec_data *data, bool grandchild)
{
FILE *out;
int pipefd[2];
@@ -123,6 +130,14 @@ static int get_child_rdvl(struct vec_data *data)
exit(EXIT_FAILURE);
}
+ if (grandchild) {
+ execl(FORK_EXEC_BINARY, FORK_EXEC_BINARY,
+ data->rdvl_binary, NULL);
+ fprintf(stderr, "execl(%s) failed: %d (%s)\n",
+ FORK_EXEC_BINARY, errno, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
/* exec() a new binary which puts the VL on stdout */
ret = execl(data->rdvl_binary, data->rdvl_binary, NULL);
fprintf(stderr, "execl(%s) failed: %d (%s)\n",
@@ -174,6 +189,11 @@ static int get_child_rdvl(struct vec_data *data)
return read_vl;
}
+static int get_child_rdvl(struct vec_data *data)
+{
+ return get_descendant_rdvl(data, false);
+}
+
static int file_read_integer(const char *name, int *val)
{
FILE *f;
@@ -498,6 +518,14 @@ static void prctl_set_for_child(struct vec_data *data)
return;
}
+ /* _INHERIT must survive the child's exec(), check a grandchild */
+ child_vl = get_descendant_rdvl(data, true);
+ if (child_vl != data->min_vl) {
+ ksft_test_result_fail("%s set %d _INHERIT but grandchild VL is %d\n",
+ data->name, data->min_vl, child_vl);
+ return;
+ }
+
ksft_test_result_pass("%s vector length was inherited\n", data->name);
file_write_integer(data->default_vl_file, data->default_vl);
base-commit: efded46f0a94d8e2cd7fb61aaf01be3ba1e9ee7d
--
2.43.0