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 NPROC=$(getconf _NPROCESSORS_ONLN) 19 MAXPROC=128 19 MAXPROC=128 20 20 21 for i in $(seq 1 $(($NPROC < $MAXPROC ? $NPROC 21 for i in $(seq 1 $(($NPROC < $MAXPROC ? $NPROC : $MAXPROC))); do 22 ./test_klp-call_getpid & 22 ./test_klp-call_getpid & 23 pids[$i]="$!" 23 pids[$i]="$!" 24 done 24 done 25 25 26 pid_list=$(echo ${pids[@]} | tr ' ' ',') 26 pid_list=$(echo ${pids[@]} | tr ' ' ',') 27 load_lp $MOD_SYSCALL klp_pids=$pid_list 27 load_lp $MOD_SYSCALL klp_pids=$pid_list 28 28 29 # wait for all tasks to transition to patched 29 # wait for all tasks to transition to patched state 30 loop_until 'grep -q '^0$' /sys/kernel/test_klp 30 loop_until 'grep -q '^0$' /sys/kernel/test_klp_syscall/npids' 31 31 32 pending_pids=$(cat /sys/kernel/test_klp_syscal 32 pending_pids=$(cat /sys/kernel/test_klp_syscall/npids) 33 log "$MOD_SYSCALL: Remaining not livepatched p 33 log "$MOD_SYSCALL: Remaining not livepatched processes: $pending_pids" 34 34 35 for pid in ${pids[@]}; do 35 for pid in ${pids[@]}; do 36 kill $pid || true 36 kill $pid || true 37 done 37 done 38 38 39 disable_lp $MOD_SYSCALL 39 disable_lp $MOD_SYSCALL 40 unload_lp $MOD_SYSCALL 40 unload_lp $MOD_SYSCALL 41 41 42 check_result "% insmod test_modules/$MOD_SYSCA 42 check_result "% insmod test_modules/$MOD_SYSCALL.ko klp_pids=$pid_list 43 livepatch: enabling patch '$MOD_SYSCALL' 43 livepatch: enabling patch '$MOD_SYSCALL' 44 livepatch: '$MOD_SYSCALL': initializing patchi 44 livepatch: '$MOD_SYSCALL': initializing patching transition 45 livepatch: '$MOD_SYSCALL': starting patching t 45 livepatch: '$MOD_SYSCALL': starting patching transition 46 livepatch: '$MOD_SYSCALL': completing patching 46 livepatch: '$MOD_SYSCALL': completing patching transition 47 livepatch: '$MOD_SYSCALL': patching complete 47 livepatch: '$MOD_SYSCALL': patching complete 48 $MOD_SYSCALL: Remaining not livepatched proces 48 $MOD_SYSCALL: Remaining not livepatched processes: 0 49 % echo 0 > /sys/kernel/livepatch/$MOD_SYSCALL/ 49 % echo 0 > /sys/kernel/livepatch/$MOD_SYSCALL/enabled 50 livepatch: '$MOD_SYSCALL': initializing unpatc 50 livepatch: '$MOD_SYSCALL': initializing unpatching transition 51 livepatch: '$MOD_SYSCALL': starting unpatching 51 livepatch: '$MOD_SYSCALL': starting unpatching transition 52 livepatch: '$MOD_SYSCALL': completing unpatchi 52 livepatch: '$MOD_SYSCALL': completing unpatching transition 53 livepatch: '$MOD_SYSCALL': unpatching complete 53 livepatch: '$MOD_SYSCALL': unpatching complete 54 % rmmod $MOD_SYSCALL" 54 % rmmod $MOD_SYSCALL" 55 55 56 exit 0 56 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.