Skip to content

Commit 5976628

Browse files
jubalhpmladek
authored andcommitted
selftests: livepatch: save and restore kprobe state
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>
1 parent 637c730 commit 5976628

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

tools/testing/selftests/livepatch/functions.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
MAX_RETRIES=600
88
RETRY_INTERVAL=".1" # seconds
9-
SYSFS_KLP_DIR="/sys/kernel/livepatch"
9+
SYSFS_KERNEL_DIR="/sys/kernel"
10+
SYSFS_KLP_DIR="$SYSFS_KERNEL_DIR/livepatch"
11+
SYSFS_DEBUG_DIR="$SYSFS_KERNEL_DIR/debug"
12+
SYSFS_KPROBES_DIR="$SYSFS_DEBUG_DIR/kprobes"
1013

1114
# Kselftest framework requirement - SKIP code is 4
1215
ksft_skip=4
@@ -55,22 +58,26 @@ function die() {
5558
}
5659

5760
function push_config() {
58-
DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
61+
DYNAMIC_DEBUG=$(grep '^kernel/livepatch' "$SYSFS_DEBUG_DIR/dynamic_debug/control" | \
5962
awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
6063
FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
64+
KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled")
6165
}
6266

6367
function pop_config() {
6468
if [[ -n "$DYNAMIC_DEBUG" ]]; then
65-
echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
69+
echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
6670
fi
6771
if [[ -n "$FTRACE_ENABLED" ]]; then
6872
sysctl kernel.ftrace_enabled="$FTRACE_ENABLED" &> /dev/null
6973
fi
74+
if [[ -n "$KPROBE_ENABLED" ]]; then
75+
echo "$KPROBE_ENABLED" > "$SYSFS_KPROBES_DIR/enabled"
76+
fi
7077
}
7178

7279
function set_dynamic_debug() {
73-
cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
80+
cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
7481
file kernel/livepatch/* +p
7582
func klp_try_switch_task -p
7683
EOF

tools/testing/selftests/livepatch/test-syscall.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ pid_list=$(echo ${pids[@]} | tr ' ' ',')
2727
load_lp $MOD_SYSCALL klp_pids=$pid_list
2828

2929
# wait for all tasks to transition to patched state
30-
loop_until 'grep -q '^0$' /sys/kernel/test_klp_syscall/npids'
30+
loop_until 'grep -q '^0$' $SYSFS_KERNEL_DIR/$MOD_SYSCALL/npids'
3131

32-
pending_pids=$(cat /sys/kernel/test_klp_syscall/npids)
32+
pending_pids=$(cat $SYSFS_KERNEL_DIR/$MOD_SYSCALL/npids)
3333
log "$MOD_SYSCALL: Remaining not livepatched processes: $pending_pids"
3434

3535
for pid in ${pids[@]}; do

0 commit comments

Comments
 (0)