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

Aleksei Oladko posted 1 patch 1 week, 4 days ago
.../testing/selftests/x86/test_shadow_stack.c  | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
[PATCH v3] 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>

---
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@virtuozzo.com/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@virtuozzo.com/T/

Signed-off-by: Aleksei Oladko <aleksey.oladko@virtuozzo.com>
---
 .../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
Re: [PATCH v3] selftests: x86: test_shadow_stack: return KSFT_SKIP when test is skipped
Posted by Pavel Tikhomirov 1 week, 4 days ago
On 3/23/26 11:45, 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.
> 

Reviewed-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

> Signed-off-by: Aleksei Oladko <aleksey.oladko@virtuozzo.com>
> 
> ---
> 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@virtuozzo.com/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@virtuozzo.com/T/
> 
> Signed-off-by: Aleksei Oladko <aleksey.oladko@virtuozzo.com>
> ---
>  .../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()) {

-- 
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.
Re: [PATCH v3] selftests: x86: test_shadow_stack: return KSFT_SKIP when test is skipped
Posted by Edgecombe, Rick P 1 week, 1 day ago
+Jiri who added this part of the test

Link:https://lore.kernel.org/lkml/20260323104536.198738-1-aleksey.oladko@virtuozzo.com/

On Mon, 2026-03-23 at 12:15 +0100, Pavel Tikhomirov wrote:
> >   	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;
> >   	}

This patch looks good and thanks for fixing up the other stuff. Except I'm not
sure if this whole < 0 scenario would be better to leave as a skip. The failure
to read the file isn't testing anything about shadow stack. So I'd leave the
existing behavior, or if you want to improve it, drop the type == -ENOENT check
and just always print SKIP and return 0.

Jiri do you recall why it only prints SKIP in the -ENOENT case?