[PATCH 5/9] selftests/kho: Catch missing or zero bootmem reports before kexec
Chris Down
chris at chrisdown.name
Tue Nov 10 23:53:25 PST 2026
The KHO vmtest can pass even if the bootmem size is no longer visible to
userspace. Let's fail if /sys/kernel/kexec/kho_bootmem_size can't be
read or reports zero on the KHO-enabled boot.
Signed-off-by: Chris Down <chris at chrisdown.name>
---
tools/testing/selftests/kho/init.c | 24 ++++++++++++++++++++++++
tools/testing/selftests/kho/vmtest.sh | 1 +
2 files changed, 25 insertions(+)
diff --git a/tools/testing/selftests/kho/init.c b/tools/testing/selftests/kho/init.c
index 88a41b6eba95..ca9297d896d3 100644
--- a/tools/testing/selftests/kho/init.c
+++ b/tools/testing/selftests/kho/init.c
@@ -18,9 +18,30 @@ static int mount_filesystems(void)
if (mount("debugfs", "/debugfs", "debugfs", 0, NULL) < 0)
return -1;
+ if (mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
+ return -1;
+
return mount("proc", "/proc", "proc", 0, NULL);
}
+static int check_bootmem_size(void)
+{
+ char buf[32];
+ ssize_t len;
+ int fd;
+
+ fd = open("/sys/kernel/kexec/kho_bootmem_size", O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ len = read(fd, buf, sizeof(buf));
+ close(fd);
+ if (len <= 0)
+ return -1;
+
+ return buf[0] == '0' ? -1 : 0;
+}
+
static long kexec_file_load(int kernel_fd, int initrd_fd,
unsigned long cmdline_len, const char *cmdline,
unsigned long flags)
@@ -61,6 +82,9 @@ int main(int argc, char *argv[])
if (mount_filesystems())
goto err_reboot;
+ if (check_bootmem_size())
+ goto err_reboot;
+
if (kexec_load())
goto err_reboot;
diff --git a/tools/testing/selftests/kho/vmtest.sh b/tools/testing/selftests/kho/vmtest.sh
index 1e86ffcc3a79..e3e99cfe3ac1 100755
--- a/tools/testing/selftests/kho/vmtest.sh
+++ b/tools/testing/selftests/kho/vmtest.sh
@@ -95,6 +95,7 @@ function mkinitrd() {
dir /dev 0755 0 0
dir /proc 0755 0 0
dir /debugfs 0755 0 0
+dir /sys 0755 0 0
nod /dev/console 0600 0 0 c 5 1
file /init $tmp_dir/init 0755 0 0
file /kernel $kernel 0644 0 0
--
2.54.0
More information about the kexec
mailing list