mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] selftests: riscv: vector: Fix the checks of the child's exit status
@ 2026-09-26 15:55 Danish Khateeb
  2026-09-26 15:55 ` [PATCH 1/2] selftests: riscv: vstate_exec_nolibc: Check the return value of waitpid() Danish Khateeb
  2026-09-26 15:55 ` [PATCH 2/2] selftests: riscv: vector: Fix the check for children exiting with -1 Danish Khateeb
  0 siblings, 2 replies; 3+ messages in thread
From: Danish Khateeb @ 2026-09-26 15:55 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: Shuah Khan, Andy Chiu, Sergey Matyukevich, Thomas Weißschuh,
	linux-riscv, linux-kselftest, linux-kernel, Danish Khateeb

Two fixes for vstate_exec_nolibc, found through a kernel test robot
warning [1]. Patch 1 checks the return value of waitpid(), which GCC
warns about. Patch 2 fixes a check which never matches, so that a child
reporting a failure no longer lets the tests pass.

Tested in QEMU (virt, rv64 with and without V) on a v7.3-rc1 defconfig
kernel, running vstate_prctl as init:

- vstate_prctl passes 13/13 with and without the series.
- With the child's vstate_ctrl check forced to fail, it still passes
  13/13 without patch 2, and fails the 6 affected tests with it.
- The warning is gone with GCC 14.2 and 16.2.

[1] https://lore.kernel.org/r/202609250003.hvssJlRZ-lkp@intel.com/

Danish Khateeb (2):
  selftests: riscv: vstate_exec_nolibc: Check the return value of
    waitpid()
  selftests: riscv: vector: Fix the check for children exiting with -1

 tools/testing/selftests/riscv/vector/v_helpers.c          | 2 +-
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)


base-commit: a06776565b9e73512e880a95b66c198ae8e7e24a
-- 
2.55.0


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

* [PATCH 1/2] selftests: riscv: vstate_exec_nolibc: Check the return value of waitpid()
  2026-09-26 15:55 [PATCH 0/2] selftests: riscv: vector: Fix the checks of the child's exit status Danish Khateeb
@ 2026-09-26 15:55 ` Danish Khateeb
  2026-09-26 15:55 ` [PATCH 2/2] selftests: riscv: vector: Fix the check for children exiting with -1 Danish Khateeb
  1 sibling, 0 replies; 3+ messages in thread
From: Danish Khateeb @ 2026-09-26 15:55 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: Shuah Khan, Andy Chiu, Sergey Matyukevich, Thomas Weißschuh,
	linux-riscv, linux-kselftest, linux-kernel, Danish Khateeb,
	kernel test robot

vstate_exec_nolibc does not check whether waitpid() succeeds, so status
is used uninitialized if it fails. Since nolibc implements waitpid() on
top of waitid(), GCC can see this, and warns:

  vstate_exec_nolibc.c:78:12: warning: 'status' may be used uninitialized [-Wmaybe-uninitialized]

Fail if waitpid() fails, as launch_test() does for the same call.

Fixes: 7cf6198ce22d ("selftests: Test RISC-V Vector prctl interface")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202609250003.hvssJlRZ-lkp@intel.com/
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
index 12f1b1b1c7aa..5f53e5e8ac52 100644
--- a/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
+++ b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
@@ -69,6 +69,10 @@ int main(int argc, char **argv)
 	}
 
 	rc = waitpid(-1, &status, 0);
+	if (rc == -1) {
+		puts("waitpid failed\n");
+		exit(-1);
+	}
 
 	if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
 		puts("child exited abnormally\n");
-- 
2.55.0


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

* [PATCH 2/2] selftests: riscv: vector: Fix the check for children exiting with -1
  2026-09-26 15:55 [PATCH 0/2] selftests: riscv: vector: Fix the checks of the child's exit status Danish Khateeb
  2026-09-26 15:55 ` [PATCH 1/2] selftests: riscv: vstate_exec_nolibc: Check the return value of waitpid() Danish Khateeb
@ 2026-09-26 15:55 ` Danish Khateeb
  1 sibling, 0 replies; 3+ messages in thread
From: Danish Khateeb @ 2026-09-26 15:55 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti
  Cc: Shuah Khan, Andy Chiu, Sergey Matyukevich, Thomas Weißschuh,
	linux-riscv, linux-kselftest, linux-kernel, Danish Khateeb

vstate_exec_nolibc and launch_test() look for a child which failed with
exit(-1) by checking WEXITSTATUS(status) == -1. But WEXITSTATUS() only
returns the low 8 bits of the exit code, so the check never matches.

vstate_exec_nolibc then returns ctrl as if the child had succeeded,
which is the value the harness expects. So when a child finds that its
vstate_ctrl differs from its parent's, it prints an error, but the test
still passes.

Compare the exit status with 255 instead. A successful child exits with
its vstate_ctrl, which is at most 0x1f. launch_test() already failed
the test on 255, but now reports it as an abnormal exit.

Fixes: 7cf6198ce22d ("selftests: Test RISC-V Vector prctl interface")
Assisted-by: LLM
Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
---
 tools/testing/selftests/riscv/vector/v_helpers.c          | 2 +-
 tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/riscv/vector/v_helpers.c b/tools/testing/selftests/riscv/vector/v_helpers.c
index de6da7c8d2f1..8942ddf2b52b 100644
--- a/tools/testing/selftests/riscv/vector/v_helpers.c
+++ b/tools/testing/selftests/riscv/vector/v_helpers.c
@@ -81,7 +81,7 @@ int launch_test(char *next_program, int test_inherit, int xtheadvector)
 		return -3;
 	}
 
-	if ((WIFEXITED(status) && WEXITSTATUS(status) == -1) ||
+	if ((WIFEXITED(status) && WEXITSTATUS(status) == 255) ||
 	    WIFSIGNALED(status)) {
 		printf("child exited abnormally\n");
 		return -4;
diff --git a/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
index 5f53e5e8ac52..05f18b13a36a 100644
--- a/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
+++ b/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
 		exit(-1);
 	}
 
-	if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 255) {
 		puts("child exited abnormally\n");
 		exit(-1);
 	}
-- 
2.55.0


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

end of thread, other threads:[~2026-09-26 15:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26 15:55 [PATCH 0/2] selftests: riscv: vector: Fix the checks of the child's exit status Danish Khateeb
2026-09-26 15:55 ` [PATCH 1/2] selftests: riscv: vstate_exec_nolibc: Check the return value of waitpid() Danish Khateeb
2026-09-26 15:55 ` [PATCH 2/2] selftests: riscv: vector: Fix the check for children exiting with -1 Danish Khateeb

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

all inboxes | Powered by JetHome®