xref: /linux/tools/testing/selftests/livepatch/test-syscall.sh (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Copyright (C) 2023 SUSE
4# Author: Marcos Paulo de Souza <mpdesouza@suse.com>
5
6. $(dirname $0)/functions.sh
7
8MOD_SYSCALL=test_klp_syscall
9
10setup_config
11
12# - Start _NRPROC processes calling getpid and load a livepatch to patch the
13#   getpid syscall. Check if all the processes transitioned to the livepatched
14#   state.
15
16start_test "patch getpid syscall while being heavily hammered"
17
18for i in $(seq 1 $(getconf _NPROCESSORS_ONLN)); do
19	./test_klp-call_getpid &
20	pids[$i]="$!"
21done
22
23pid_list=$(echo ${pids[@]} | tr ' ' ',')
24load_lp $MOD_SYSCALL klp_pids=$pid_list
25
26# wait for all tasks to transition to patched state
27loop_until 'grep -q '^0$' /sys/kernel/test_klp_syscall/npids'
28
29pending_pids=$(cat /sys/kernel/test_klp_syscall/npids)
30log "$MOD_SYSCALL: Remaining not livepatched processes: $pending_pids"
31
32for pid in ${pids[@]}; do
33	kill $pid || true
34done
35
36disable_lp $MOD_SYSCALL
37unload_lp $MOD_SYSCALL
38
39check_result "% insmod test_modules/$MOD_SYSCALL.ko klp_pids=$pid_list
40livepatch: enabling patch '$MOD_SYSCALL'
41livepatch: '$MOD_SYSCALL': initializing patching transition
42livepatch: '$MOD_SYSCALL': starting patching transition
43livepatch: '$MOD_SYSCALL': completing patching transition
44livepatch: '$MOD_SYSCALL': patching complete
45$MOD_SYSCALL: Remaining not livepatched processes: 0
46% echo 0 > /sys/kernel/livepatch/$MOD_SYSCALL/enabled
47livepatch: '$MOD_SYSCALL': initializing unpatching transition
48livepatch: '$MOD_SYSCALL': starting unpatching transition
49livepatch: '$MOD_SYSCALL': completing unpatching transition
50livepatch: '$MOD_SYSCALL': unpatching complete
51% rmmod $MOD_SYSCALL"
52
53exit 0
54