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