18c2ecf20Sopenharmony_ci#!/bin/bash
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci# Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci. $(dirname $0)/functions.sh
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ciMOD_LIVEPATCH=test_klp_livepatch
88c2ecf20Sopenharmony_ciMOD_REPLACE=test_klp_atomic_replace
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cisetup_config
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci# - load a livepatch that modifies the output from /proc/cmdline and
148c2ecf20Sopenharmony_ci#   verify correct behavior
158c2ecf20Sopenharmony_ci# - unload the livepatch and make sure the patch was removed
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistart_test "basic function patching"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciload_lp $MOD_LIVEPATCH
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciif [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
228c2ecf20Sopenharmony_ci	echo -e "FAIL\n\n"
238c2ecf20Sopenharmony_ci	die "livepatch kselftest(s) failed"
248c2ecf20Sopenharmony_cifi
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cidisable_lp $MOD_LIVEPATCH
278c2ecf20Sopenharmony_ciunload_lp $MOD_LIVEPATCH
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciif [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then
308c2ecf20Sopenharmony_ci	echo -e "FAIL\n\n"
318c2ecf20Sopenharmony_ci	die "livepatch kselftest(s) failed"
328c2ecf20Sopenharmony_cifi
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cicheck_result "% modprobe $MOD_LIVEPATCH
358c2ecf20Sopenharmony_cilivepatch: enabling patch '$MOD_LIVEPATCH'
368c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': initializing patching transition
378c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': starting patching transition
388c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': completing patching transition
398c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': patching complete
408c2ecf20Sopenharmony_ci% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
418c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
428c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': starting unpatching transition
438c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': completing unpatching transition
448c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': unpatching complete
458c2ecf20Sopenharmony_ci% rmmod $MOD_LIVEPATCH"
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci# - load a livepatch that modifies the output from /proc/cmdline and
498c2ecf20Sopenharmony_ci#   verify correct behavior
508c2ecf20Sopenharmony_ci# - load another livepatch and verify that both livepatches are active
518c2ecf20Sopenharmony_ci# - unload the second livepatch and verify that the first is still active
528c2ecf20Sopenharmony_ci# - unload the first livepatch and verify none are active
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistart_test "multiple livepatches"
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciload_lp $MOD_LIVEPATCH
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
598c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciload_lp $MOD_REPLACE replace=0
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
648c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cidisable_lp $MOD_REPLACE
678c2ecf20Sopenharmony_ciunload_lp $MOD_REPLACE
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
708c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cidisable_lp $MOD_LIVEPATCH
738c2ecf20Sopenharmony_ciunload_lp $MOD_LIVEPATCH
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
768c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cicheck_result "% modprobe $MOD_LIVEPATCH
798c2ecf20Sopenharmony_cilivepatch: enabling patch '$MOD_LIVEPATCH'
808c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': initializing patching transition
818c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': starting patching transition
828c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': completing patching transition
838c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': patching complete
848c2ecf20Sopenharmony_ci$MOD_LIVEPATCH: this has been live patched
858c2ecf20Sopenharmony_ci% modprobe $MOD_REPLACE replace=0
868c2ecf20Sopenharmony_cilivepatch: enabling patch '$MOD_REPLACE'
878c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': initializing patching transition
888c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': starting patching transition
898c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': completing patching transition
908c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': patching complete
918c2ecf20Sopenharmony_ci$MOD_LIVEPATCH: this has been live patched
928c2ecf20Sopenharmony_ci$MOD_REPLACE: this has been live patched
938c2ecf20Sopenharmony_ci% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE/enabled
948c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': initializing unpatching transition
958c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': starting unpatching transition
968c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': completing unpatching transition
978c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': unpatching complete
988c2ecf20Sopenharmony_ci% rmmod $MOD_REPLACE
998c2ecf20Sopenharmony_ci$MOD_LIVEPATCH: this has been live patched
1008c2ecf20Sopenharmony_ci% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
1018c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': initializing unpatching transition
1028c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': starting unpatching transition
1038c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': completing unpatching transition
1048c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': unpatching complete
1058c2ecf20Sopenharmony_ci% rmmod $MOD_LIVEPATCH"
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci# - load a livepatch that modifies the output from /proc/cmdline and
1098c2ecf20Sopenharmony_ci#   verify correct behavior
1108c2ecf20Sopenharmony_ci# - load an atomic replace livepatch and verify that only the second is active
1118c2ecf20Sopenharmony_ci# - remove the first livepatch and verify that the atomic replace livepatch
1128c2ecf20Sopenharmony_ci#   is still active
1138c2ecf20Sopenharmony_ci# - remove the atomic replace livepatch and verify that none are active
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistart_test "atomic replace livepatch"
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ciload_lp $MOD_LIVEPATCH
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
1208c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ciload_lp $MOD_REPLACE replace=1
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
1258c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciunload_lp $MOD_LIVEPATCH
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
1308c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cidisable_lp $MOD_REPLACE
1338c2ecf20Sopenharmony_ciunload_lp $MOD_REPLACE
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_cigrep 'live patched' /proc/cmdline > /dev/kmsg
1368c2ecf20Sopenharmony_cigrep 'live patched' /proc/meminfo > /dev/kmsg
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cicheck_result "% modprobe $MOD_LIVEPATCH
1398c2ecf20Sopenharmony_cilivepatch: enabling patch '$MOD_LIVEPATCH'
1408c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': initializing patching transition
1418c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': starting patching transition
1428c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': completing patching transition
1438c2ecf20Sopenharmony_cilivepatch: '$MOD_LIVEPATCH': patching complete
1448c2ecf20Sopenharmony_ci$MOD_LIVEPATCH: this has been live patched
1458c2ecf20Sopenharmony_ci% modprobe $MOD_REPLACE replace=1
1468c2ecf20Sopenharmony_cilivepatch: enabling patch '$MOD_REPLACE'
1478c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': initializing patching transition
1488c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': starting patching transition
1498c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': completing patching transition
1508c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': patching complete
1518c2ecf20Sopenharmony_ci$MOD_REPLACE: this has been live patched
1528c2ecf20Sopenharmony_ci% rmmod $MOD_LIVEPATCH
1538c2ecf20Sopenharmony_ci$MOD_REPLACE: this has been live patched
1548c2ecf20Sopenharmony_ci% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE/enabled
1558c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': initializing unpatching transition
1568c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': starting unpatching transition
1578c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': completing unpatching transition
1588c2ecf20Sopenharmony_cilivepatch: '$MOD_REPLACE': unpatching complete
1598c2ecf20Sopenharmony_ci% rmmod $MOD_REPLACE"
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ciexit 0
163