c4bbe83d27
The modules are being moved from lib/livepatch to tools/testing/selftests/livepatch/test_modules. This code moving will allow writing more complex tests, like for example an userspace C code that will call a livepatched kernel function. The modules are now built as out-of-tree modules, but being part of the kernel source means they will be maintained. Another advantage of the code moving is to be able to easily change, debug and rebuild the tests by running make on the selftests/livepatch directory, which is not currently possible since the modules on lib/livepatch are build and installed using the "modules" target. The current approach also keeps the ability to execute the tests manually by executing the scripts inside selftests/livepatch directory, as it's currently supported. If the modules are modified, they needed to be rebuilt before running the scripts though. The modules are built before running the selftests when using the kselftest invocations: make kselftest TARGETS=livepatch or make -C tools/testing/selftests/livepatch run_tests Having the modules being built as out-of-modules requires changing the currently used 'modprobe' by 'insmod' and adapt the test scripts that check for the kernel message buffer. Now it is possible to only compile the modules by running: make -C tools/testing/selftests/livepatch/ This way the test modules and other test program can be built in order to be packaged if so desired. As there aren't any modules being built on lib/livepatch, remove the TEST_LIVEPATCH Kconfig and it's references. Note: "make gen_tar" packages the pre-built binaries into the tarball. It means that it will store the test modules pre-built for the kernel running on the build host. Note that these modules need not binary compatible with the kernel built from the same sources. But the same is true for other packaged selftest binaries. The entire kernel sources are needed for rebuilding the selftests on another system. Reviewed-by: Joe Lawrence <joe.lawrence@redhat.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
65 lines
2.3 KiB
Bash
Executable File
65 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (C) 2019 Joe Lawrence <joe.lawrence@redhat.com>
|
|
|
|
. $(dirname $0)/functions.sh
|
|
|
|
MOD_LIVEPATCH=test_klp_livepatch
|
|
|
|
setup_config
|
|
|
|
|
|
# - turn ftrace_enabled OFF and verify livepatches can't load
|
|
# - turn ftrace_enabled ON and verify livepatch can load
|
|
# - verify that ftrace_enabled can't be turned OFF while a livepatch is loaded
|
|
|
|
start_test "livepatch interaction with ftrace_enabled sysctl"
|
|
|
|
set_ftrace_enabled 0
|
|
load_failing_mod $MOD_LIVEPATCH
|
|
|
|
set_ftrace_enabled 1
|
|
load_lp $MOD_LIVEPATCH
|
|
if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
|
|
echo -e "FAIL\n\n"
|
|
die "livepatch kselftest(s) failed"
|
|
fi
|
|
|
|
# Check that ftrace could not get disabled when a livepatch is enabled
|
|
set_ftrace_enabled --fail 0
|
|
if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
|
|
echo -e "FAIL\n\n"
|
|
die "livepatch kselftest(s) failed"
|
|
fi
|
|
disable_lp $MOD_LIVEPATCH
|
|
unload_lp $MOD_LIVEPATCH
|
|
|
|
check_result "livepatch: kernel.ftrace_enabled = 0
|
|
% insmod test_modules/$MOD_LIVEPATCH.ko
|
|
livepatch: enabling patch '$MOD_LIVEPATCH'
|
|
livepatch: '$MOD_LIVEPATCH': initializing patching transition
|
|
livepatch: failed to register ftrace handler for function 'cmdline_proc_show' (-16)
|
|
livepatch: failed to patch object 'vmlinux'
|
|
livepatch: failed to enable patch '$MOD_LIVEPATCH'
|
|
livepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch
|
|
livepatch: '$MOD_LIVEPATCH': completing unpatching transition
|
|
livepatch: '$MOD_LIVEPATCH': unpatching complete
|
|
insmod: ERROR: could not insert module test_modules/$MOD_LIVEPATCH.ko: Device or resource busy
|
|
livepatch: kernel.ftrace_enabled = 1
|
|
% insmod test_modules/$MOD_LIVEPATCH.ko
|
|
livepatch: enabling patch '$MOD_LIVEPATCH'
|
|
livepatch: '$MOD_LIVEPATCH': initializing patching transition
|
|
livepatch: '$MOD_LIVEPATCH': starting patching transition
|
|
livepatch: '$MOD_LIVEPATCH': completing patching transition
|
|
livepatch: '$MOD_LIVEPATCH': patching complete
|
|
livepatch: sysctl: setting key \"kernel.ftrace_enabled\": Device or resource busy
|
|
% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
|
|
livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
|
|
livepatch: '$MOD_LIVEPATCH': starting unpatching transition
|
|
livepatch: '$MOD_LIVEPATCH': completing unpatching transition
|
|
livepatch: '$MOD_LIVEPATCH': unpatching complete
|
|
% rmmod $MOD_LIVEPATCH"
|
|
|
|
|
|
exit 0
|