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

Aleksei Oladko posted 1 patch 1 week, 4 days ago
There is a newer version of this series
.../testing/selftests/x86/test_shadow_stack.c | 20 +++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
[PATCH v2] selftests: x86: test_shadow_stack: return KSFT_SKIP when test is skipped
Posted by Aleksei Oladko 1 week, 4 days ago
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@virtuozzo.com>

---
v2:
- return SKIP only for "Could not enable Shadow stack" case
- Changed message from SKIP to FAIL for remaining cases
---
 .../testing/selftests/x86/test_shadow_stack.c | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
index 21af54d5f4ea..4c5437846d26 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)
@@ -496,7 +497,7 @@ int test_userfaultfd(void)
 	uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
 	if (uffd < 0) {
 		printf("[SKIP]\tUserfaultfd unavailable.\n");
-		return 0;
+		return KSFT_SKIP;
 	}
 
 	reset_test_shstk(0);
@@ -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 KSFT_SKIP;
+		}
+		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
Re: [PATCH v2] selftests: x86: test_shadow_stack: return KSFT_SKIP when test is skipped
Posted by Pavel Tikhomirov 1 week, 4 days ago
Please don't forget to CC me on the next version.

On 3/23/26 00:39, Aleksei Oladko wrote:
> 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@virtuozzo.com>
> 
> ---
> v2:
> - return SKIP only for "Could not enable Shadow stack" case
> - Changed message from SKIP to FAIL for remaining cases
> ---
>  .../testing/selftests/x86/test_shadow_stack.c | 20 +++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
> index 21af54d5f4ea..4c5437846d26 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)
> @@ -496,7 +497,7 @@ int test_userfaultfd(void)
>  	uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
>  	if (uffd < 0) {
>  		printf("[SKIP]\tUserfaultfd unavailable.\n");
> -		return 0;
> +		return KSFT_SKIP;

This is incorrect and will lead to fail instead of skip.

>  	}
>  
>  	reset_test_shstk(0);
> @@ -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 KSFT_SKIP;

same here.

Can you please stick to https://lore.kernel.org/all/3205f6e7-bf02-4fb4-ab03-278447c17f70@virtuozzo.com/ more closely.

> +		}
> +		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()) {

-- 
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.