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