]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: livepatch: save and restore kprobe state
authorMichael Vetter <mvetter@suse.com>
Thu, 17 Oct 2024 20:01:31 +0000 (22:01 +0200)
committerPetr Mladek <pmladek@suse.com>
Tue, 22 Oct 2024 15:13:11 +0000 (17:13 +0200)
Save the state of /sys/kernel/debug/kprobes/enabled
during setup_config() and restore it during cleanup().

This is in preparation for a future commit that will add a test
that should confirm that we cannot livepatch a kprobed function
if that kprobe has a post handler.

Signed-off-by: Michael Vetter <mvetter@suse.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com>
Tested-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Reviewed-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20241017200132.21946-3-mvetter@suse.com
[pmladek@suse.com: Added few more substitutions in test-syscall.sh]
Signed-off-by: Petr Mladek <pmladek@suse.com>
tools/testing/selftests/livepatch/functions.sh
tools/testing/selftests/livepatch/test-syscall.sh

index 7bdfe668127b90c69d8147886aac02533c82c6a6..e5d06fb402335d85959bafe099087effc6ddce12 100644 (file)
@@ -6,7 +6,10 @@
 
 MAX_RETRIES=600
 RETRY_INTERVAL=".1"    # seconds
-SYSFS_KLP_DIR="/sys/kernel/livepatch"
+SYSFS_KERNEL_DIR="/sys/kernel"
+SYSFS_KLP_DIR="$SYSFS_KERNEL_DIR/livepatch"
+SYSFS_DEBUG_DIR="$SYSFS_KERNEL_DIR/debug"
+SYSFS_KPROBES_DIR="$SYSFS_DEBUG_DIR/kprobes"
 
 # Kselftest framework requirement - SKIP code is 4
 ksft_skip=4
@@ -55,22 +58,26 @@ function die() {
 }
 
 function push_config() {
-       DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
+       DYNAMIC_DEBUG=$(grep '^kernel/livepatch' "$SYSFS_DEBUG_DIR/dynamic_debug/control" | \
                        awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
        FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
+       KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled")
 }
 
 function pop_config() {
        if [[ -n "$DYNAMIC_DEBUG" ]]; then
-               echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
+               echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
        fi
        if [[ -n "$FTRACE_ENABLED" ]]; then
                sysctl kernel.ftrace_enabled="$FTRACE_ENABLED" &> /dev/null
        fi
+       if [[ -n "$KPROBE_ENABLED" ]]; then
+               echo "$KPROBE_ENABLED" > "$SYSFS_KPROBES_DIR/enabled"
+       fi
 }
 
 function set_dynamic_debug() {
-        cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
+        cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
                file kernel/livepatch/* +p
                func klp_try_switch_task -p
                EOF
index 9347464a89a045acf27b4080e42f807907293ff6..5f9344277b62f360f7fdacc956f35fa3b154fc0c 100755 (executable)
@@ -27,9 +27,9 @@ pid_list=$(echo ${pids[@]} | tr ' ' ',')
 load_lp $MOD_SYSCALL klp_pids=$pid_list
 
 # wait for all tasks to transition to patched state
-loop_until 'grep -q '^0$' /sys/kernel/test_klp_syscall/npids'
+loop_until 'grep -q '^0$' $SYSFS_KERNEL_DIR/$MOD_SYSCALL/npids'
 
-pending_pids=$(cat /sys/kernel/test_klp_syscall/npids)
+pending_pids=$(cat $SYSFS_KERNEL_DIR/$MOD_SYSCALL/npids)
 log "$MOD_SYSCALL: Remaining not livepatched processes: $pending_pids"
 
 for pid in ${pids[@]}; do