Skip to contentSkip to conversation

kselftest/arm64: Check that PR_SVE_VL_INHERIT survives a second exec

PATCH New Abdalla Eldoumani 1 participant 1 message Dec 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kselftest/arm64: Check that PR_SVE_VL_INHERIT survives a second exec

From: Abdalla Eldoumani <[email protected]>

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

---
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
tools/testing/selftests/arm64/fp/.gitignore +1 -0
index 8362e7e..535c6d8 100644
@@ -1,3 +1,4 @@
+fork-exec
 fp-pidbench
 fp-ptrace
 fp-stress
tools/testing/selftests/arm64/fp/Makefile +3 -1
index d171021..e194cd4 100644
@@ -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 $@
tools/testing/selftests/arm64/fp/TODO +0 -1
index 44004e5..90ee128 100644
@@ -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.
tools/testing/selftests/arm64/fp/fork-exec.c new file +43 -0

43 lines not on this page · raw message

tools/testing/selftests/arm64/fp/vec-syscfg.c +30 -2
index 2c8ccbe..63b8f52 100644
@@ -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

Signature · 1 line
2.43.0