Skip to content

Commit f629766

Browse files
author
Denis Aleksandrov
committed
selftests: livepatch: save and restore kprobe state
JIRA: https://issues.redhat.com/browse/RHEL-80215 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> (cherry picked from commit 5976628) Signed-off-by: Denis Aleksandrov <daleksan@redhat.com>
1 parent 1395499 commit f629766

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
@@ -43,22 +46,26 @@ function die() {
4346
}
4447

4548
function push_config() {
46-
DYNAMIC_DEBUG=$(grep '^kernel/livepatch' /sys/kernel/debug/dynamic_debug/control | \
49+
DYNAMIC_DEBUG=$(grep '^kernel/livepatch' "$SYSFS_DEBUG_DIR/dynamic_debug/control" | \
4750
awk -F'[: ]' '{print "file " $1 " line " $2 " " $4}')
4851
FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled)
52+
KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled")
4953
}
5054

5155
function pop_config() {
5256
if [[ -n "$DYNAMIC_DEBUG" ]]; then
53-
echo -n "$DYNAMIC_DEBUG" > /sys/kernel/debug/dynamic_debug/control
57+
echo -n "$DYNAMIC_DEBUG" > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
5458
fi
5559
if [[ -n "$FTRACE_ENABLED" ]]; then
5660
sysctl kernel.ftrace_enabled="$FTRACE_ENABLED" &> /dev/null
5761
fi
62+
if [[ -n "$KPROBE_ENABLED" ]]; then
63+
echo "$KPROBE_ENABLED" > "$SYSFS_KPROBES_DIR/enabled"
64+
fi
5865
}
5966

6067
function set_dynamic_debug() {
61-
cat <<-EOF > /sys/kernel/debug/dynamic_debug/control
68+
cat <<-EOF > "$SYSFS_DEBUG_DIR/dynamic_debug/control"
6269
file kernel/livepatch/* +p
6370
func klp_try_switch_task -p
6471
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)