[PATCH v2 6/6] selftests: livepatch: Check if stack_order sysfs attribute exists

Marcos Paulo de Souza
2026-04-13T17:26:42Z

In order to run the selftests on older kernels, check if given kernel
has support for the attribute. If the attribute is not supported, skip
the checks.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
tools/testing/selftests/livepatch/test-sysfs.sh | 43 ++++++++++++++-----------
1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/tools/testing/selftests/livepatch/test-sysfs.sh b/tools/testing/selftests/livepatch/test-sysfs.sh
index 0cdaeef00983..77f515529646 100755
--- a/tools/testing/selftests/livepatch/test-sysfs.sh
+++ b/tools/testing/selftests/livepatch/test-sysfs.sh
@@ -10,6 +10,7 @@ MOD_LIVEPATCH3=test_klp_syscall

HAS_PATCH_ATTR=0
HAS_REPLACE_ATTR=0
+HAS_STACK_ORDER_ATTR=0

setup_config

@@ -23,8 +24,6 @@ check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x"
check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--"
check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1"
check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------"
-check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--"
-check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--"
check_sysfs_value "$MOD_LIVEPATCH" "transition" "0"

@@ -39,6 +38,12 @@ if does_sysfs_exists "$MOD_LIVEPATCH" "replace"; then
HAS_REPLACE_ATTR=1
fi

+if does_sysfs_exists "$MOD_LIVEPATCH" "stack_order"; then
+ check_sysfs_rights "$MOD_LIVEPATCH" "stack_order" "-r--r--r--"
+ check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
+ HAS_STACK_ORDER_ATTR=1
+fi
+
disable_lp $MOD_LIVEPATCH

unload_lp $MOD_LIVEPATCH
@@ -150,33 +155,34 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete
% rmmod $MOD_LIVEPATCH"
fi

-start_test "sysfs test stack_order value"
+if [[ "$HAS_STACK_ORDER_ATTR" == "1" ]]; then
+ start_test "sysfs test stack_order value"

-load_lp $MOD_LIVEPATCH
+ load_lp $MOD_LIVEPATCH

-check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
+ check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"

-load_lp $MOD_LIVEPATCH2
+ load_lp $MOD_LIVEPATCH2

-check_sysfs_value "$MOD_LIVEPATCH2" "stack_order" "2"
+ check_sysfs_value "$MOD_LIVEPATCH2" "stack_order" "2"

-load_lp $MOD_LIVEPATCH3
+ load_lp $MOD_LIVEPATCH3

-check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "3"
+ check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "3"

-disable_lp $MOD_LIVEPATCH2
-unload_lp $MOD_LIVEPATCH2
+ disable_lp $MOD_LIVEPATCH2
+ unload_lp $MOD_LIVEPATCH2

-check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
-check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "2"
+ check_sysfs_value "$MOD_LIVEPATCH" "stack_order" "1"
+ check_sysfs_value "$MOD_LIVEPATCH3" "stack_order" "2"

-disable_lp $MOD_LIVEPATCH3
-unload_lp $MOD_LIVEPATCH3
+ disable_lp $MOD_LIVEPATCH3
+ unload_lp $MOD_LIVEPATCH3

-disable_lp $MOD_LIVEPATCH
-unload_lp $MOD_LIVEPATCH
+ disable_lp $MOD_LIVEPATCH
+ unload_lp $MOD_LIVEPATCH

-check_result "% insmod test_modules/$MOD_LIVEPATCH.ko
+ check_result "% insmod test_modules/$MOD_LIVEPATCH.ko
livepatch: enabling patch '$MOD_LIVEPATCH'
livepatch: '$MOD_LIVEPATCH': initializing patching transition
livepatch: '$MOD_LIVEPATCH': starting patching transition
@@ -216,5 +222,6 @@ livepatch: '$MOD_LIVEPATCH': starting unpatching transition
livepatch: '$MOD_LIVEPATCH': completing unpatching transition
livepatch: '$MOD_LIVEPATCH': unpatching complete
% rmmod $MOD_LIVEPATCH"
+fi

exit 0

--
2.52.0