Hi Mike,

On 2025-07-27 11:37:33+0300, Mike Rapoport wrote:
> 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]>

(...)

> --- /dev/null
> +++ b/tools/testing/selftests/kho/init.c
> @@ -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.

> +#include <errno.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <syscall.h>

This should be <sys/syscall.h>.

> +#include <sys/mount.h>
> +#include <sys/reboot.h>
> +#endif
> +

(...)

> --- /dev/null
> +++ b/tools/testing/selftests/kho/vmtest.sh
> @@ -0,0 +1,183 @@

(...)

> +
> +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'.

> +
> +     "$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/.

> +                     -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

Reply via email to