[PATCH v3] selftests: x86: test_shadow_stack: return KSFT_SKIP when test is skipped

From: Aleksei Oladko

Date: Mon Mar 23 2026 - 06:53:26 EST


test_shadow_stack prints a message indicating that the test is
skipped in some cases, but still returns 1. This causes the test
to be reported as failed instead of skipped.

Return KSFT_SKIP in the skip path so the result is reported
correctly.

Signed-off-by: Aleksei Oladko <aleksey.oladko@xxxxxxxxxxxxx>

---
Changes in v3:
- Fixed incorrect return values in test_userfaultfd and test_uretprobe
- Link to v1: https://lore.kernel.org/linux-kselftest/20260322233938.190526-1-aleksey.oladko@xxxxxxxxxxxxx/T/

Changes in v2:
- return SKIP only for "Could not enable Shadow stack" case
- Changed message from SKIP to FAIL for remaining cases
- Link to v1: https://lore.kernel.org/linux-kselftest/20260301014733.454260-1-aleksey.oladko@xxxxxxxxxxxxx/T/

Signed-off-by: Aleksei Oladko <aleksey.oladko@xxxxxxxxxxxxx>
---
.../testing/selftests/x86/test_shadow_stack.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
index 21af54d5f4ea..d52c8c2f7800 100644
--- a/tools/testing/selftests/x86/test_shadow_stack.c
+++ b/tools/testing/selftests/x86/test_shadow_stack.c
@@ -35,6 +35,7 @@
#include <sys/signal.h>
#include <linux/elf.h>
#include <linux/perf_event.h>
+#include "kselftest.h"

/*
* Define the ABI defines if needed, so people can run the tests
@@ -64,7 +65,7 @@
int main(int argc, char *argv[])
{
printf("[SKIP]\tCompiler does not support CET.\n");
- return 0;
+ return KSFT_SKIP;
}
#else
void write_shstk(unsigned long *addr, unsigned long val)
@@ -820,9 +821,11 @@ static int test_uretprobe(void)

type = determine_uprobe_perf_type();
if (type < 0) {
- if (type == -ENOENT)
+ if (type == -ENOENT) {
printf("[SKIP]\tUretprobe test, uprobes are not available\n");
- return 0;
+ return 0;
+ }
+ return 1;
}

offset = get_uprobe_offset(uretprobe_trigger);
@@ -981,21 +984,21 @@ int main(int argc, char *argv[])

if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
printf("[SKIP]\tCould not enable Shadow stack\n");
- return 1;
+ return KSFT_SKIP;
}

if (ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK)) {
- ret = 1;
printf("[FAIL]\tDisabling shadow stack failed\n");
+ return 1;
}

if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) {
- printf("[SKIP]\tCould not re-enable Shadow stack\n");
+ printf("[FAIL]\tCould not re-enable Shadow stack\n");
return 1;
}

if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_WRSS)) {
- printf("[SKIP]\tCould not enable WRSS\n");
+ printf("[FAIL]\tCould not enable WRSS\n");
ret = 1;
goto out;
}
@@ -1057,6 +1060,7 @@ int main(int argc, char *argv[])
if (test_ptrace()) {
ret = 1;
printf("[FAIL]\tptrace test\n");
+ goto out;
}

if (test_32bit()) {
--
2.43.0