kho: add test for kexec handover
Subsystems (5)
Mike Rapoport
maintainerPATCH 1/1 kho: add test for kexec handover
From: "Mike Rapoport (Microsoft)" <[email protected]>
Testing kexec handover requires a kernel driver that will generate some data and preserve it with KHO on the first boot and then restore that data and verify it was preserved properly after kexec.
To facilitate such test, along with the kernel driver responsible for data generation, preservation and restoration add a script that runs a kernel in a VM with a minimal /init. The /init enables KHO, loads a kernel image for kexec and runs kexec reboot. After the boot of the kexeced kernel, the driver verifies that the data was properly preserved.
--- MAINTAINERS | 1 + lib/Kconfig.debug | 21 ++ lib/Makefile | 1 + lib/test_kho.c | 305 +++++++++++++++++++++++++ tools/testing/selftests/kho/arm64.conf | 9 + tools/testing/selftests/kho/init.c | 100 ++++++++ tools/testing/selftests/kho/vmtest.sh | 183 +++++++++++++++ tools/testing/selftests/kho/x86.conf | 7 + 8 files changed, 627 insertions(+) create mode 100644 lib/test_kho.c create mode 100644 tools/testing/selftests/kho/arm64.conf create mode 100644 tools/testing/selftests/kho/init.c create mode 100755 tools/testing/selftests/kho/vmtest.sh create mode 100644 tools/testing/selftests/kho/x86.conf
MAINTAINERS +1 -0
@@ -13356,6 +13356,7 @@ F: Documentation/admin-guide/mm/kho.rst F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h F: kernel/kexec_handover.c +F: tools/testing/selftests/kho/ KEYS-ENCRYPTED M: Mimi Zohar <[email protected]>
lib/Kconfig.debug +21 -0
@@ -3225,6 +3225,27 @@ config TEST_OBJPOOL If unsure, say N. +config TEST_KEXEC_HANDOVER + bool "Test for Kexec HandOver" + default n + depends on KEXEC_HANDOVER + help + This option enables test for Kexec HandOver (KHO). + The test consists of two parts: saving kernel data before kexec and + restoring the data after kexec and verifying that it was properly + handed over. This test module creates and saves data on the boot of + the first kernel and restores and verifies the data on the boot of + kexec'ed kernel. + + For detailed documentation about KHO, see Documentation/core-api/kho. + + To run the test run: + + tools/testing/selftests/kho/vmtest.sh -h + + If unsure, say N. + + config INT_POW_KUNIT_TEST tristate "Integer exponentiation (int_pow) test" if !KUNIT_ALL_TESTS depends on KUNIT
lib/Makefile +1 -0
@@ -102,6 +102,7 @@ obj-$(CONFIG_TEST_HMM) += test_hmm.o obj-$(CONFIG_TEST_FREE_PAGES) += test_free_pages.o obj-$(CONFIG_TEST_REF_TRACKER) += test_ref_tracker.o obj-$(CONFIG_TEST_OBJPOOL) += test_objpool.o +obj-$(CONFIG_TEST_KEXEC_HANDOVER) += test_kho.o obj-$(CONFIG_TEST_FPU) += test_fpu.o test_fpu-y := test_fpu_glue.o test_fpu_impl.o
lib/test_kho.c new file +305 -0
305 lines not on this page · raw message
tools/testing/selftests/kho/arm64.conf new file +9 -0
@@ -0,0 +1,9 @@ +QEMU_CMD="qemu-system-aarch64 -M virt -cpu max" +QEMU_KCONFIG=" +CONFIG_SERIAL_AMBA_PL010=y +CONFIG_SERIAL_AMBA_PL010_CONSOLE=y +CONFIG_SERIAL_AMBA_PL011=y +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y +" +KERNEL_IMAGE="Image" +KERNEL_CMDLINE="console=ttyAMA0"
tools/testing/selftests/kho/init.c new file +100 -0
100 lines not on this page · raw message
tools/testing/selftests/kho/vmtest.sh new file +183 -0
183 lines not on this page · raw message
tools/testing/selftests/kho/x86.conf new file +7 -0
@@ -0,0 +1,7 @@ +QEMU_CMD=qemu-system-x86_64 +QEMU_KCONFIG=" +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +" +KERNEL_IMAGE="bzImage" +KERNEL_CMDLINE="console=ttyS0"
base-commit: 89be9a83ccf1f88522317ce02f854f30d6115c41
Signature · 1 line
2.47.2
Hi Mike,
Quoted 14 lines · Mike Rapoport
From: "Mike Rapoport (Microsoft)" <[email protected]>
Testing kexec handover requires a kernel driver that will generate some data and preserve it with KHO on the first boot and then restore that data and verify it was preserved properly after kexec.
To facilitate such test, along with the kernel driver responsible for data generation, preservation and restoration add a script that runs a kernel in a VM with a minimal /init. The /init enables KHO, loads a kernel image for kexec and runs kexec reboot. After the boot of the kexeced kernel, the driver verifies that the data was properly preserved.
Signed-off-by Mike Rapoport (Microsoft) <[email protected]>
(...)
tools/testing/selftests/kho/init.c line 3
Quoted 6 lines
tools/testing/selftests/kho/init.c new file +3
-0@@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef NOLIBC
This is not necessary anymore, nolibc now provides these headers. You can keep it if you want, though.
tools/testing/selftests/kho/init.c line 8
Quoted 5 lines
tools/testing/selftests/kho/init.c new file +5
-0+#include <errno.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <syscall.h>
This should be <sys/syscall.h>.
Quoted 4 lines
tools/testing/selftests/kho/init.c new file +4
-0+#include <sys/mount.h> +#include <sys/reboot.h> +#endif +
(...)
Quoted 3 lines
tools/testing/selftests/kho/vmtest.sh new file +0
-0@@ -0,0 +1,183 @@
(...)
tools/testing/selftests/kho/vmtest.sh line 85
Quoted 6 lines
tools/testing/selftests/kho/vmtest.sh new file +6
-0+ +function mkinitrd() { + local kernel=$1 + + mkdir -p "$initrd_dir"/{dev,debugfs,proc} + sudo mknod "$initrd_dir/dev/console" c 5 1
You could generate the initrd with usr/gen_init_cpio or usr/gen_initramfs.sh which would remove the need to use sudo. Especially as I think the mknod should fail if $TMP is mounted 'nodev'.
tools/testing/selftests/kho/vmtest.sh line 89
Quoted 4 lines
tools/testing/selftests/kho/vmtest.sh new file +4
-0+ + "$CROSS_COMPILE"gcc -s -static -Os -nostdinc -I"$headers_dir/include" \ + -fno-asynchronous-unwind-tables -fno-ident -nostdlib \ + -include "$test_dir/../../../include/nolibc/nolibc.h" \
If you drop the #ifdef NOLIBC, use '-I "$test_dir/../../../include/nolibc/' here instead. Or better, $kernel_dir/tools/include/nolibc/.
tools/testing/selftests/kho/vmtest.sh line 97
Quoted 8 lines
tools/testing/selftests/kho/vmtest.sh new file +8
-0+ -o "$initrd_dir/init" "$test_dir/init.c" \ + + cp "$kernel" "$initrd_dir/kernel" + + pushd "$initrd_dir" &>/dev/null + find . | cpio -H newc --create > "$initrd" 2>/dev/null + popd &>/dev/null +}
(...)
Thomas