[PATCH v2 8/9] kho: test: support read-only KHO mode in test_kho
Pasha Tatashin
pasha.tatashin at soleen.com
Sun Oct 25 10:40:15 PDT 2026
test_kho currently depends on CONFIG_KEXEC_HANDOVER and restores
preserved folios via phys_to_virt() and kho_restore_folio(), which
prevents testing preserved KHO state when booted in read-only KHO mode.
Allow CONFIG_TEST_KEXEC_HANDOVER to be enabled with
CONFIG_KEXEC_HANDOVER_READONLY and update test_kho to verify preserved
state when kho_is_ro() is active. In read-only mode, retrieve the test
FDT subtree, map the FDT folio via kho_ro_map_folio(...,
PAGE_KERNEL_RO), map the preserved vmalloc folio descriptor array via
kho_ro_map_vmalloc(), verify each folio's preserved order in the KHO
radix tree via kho_ro_lookup_folio_order(), map each folio via
kho_ro_map_folio(), and verify the checksum over all preserved pages.
Also guard kho_test_exit() when no outgoing test FDT was allocated.
Signed-off-by: Pasha Tatashin <pasha.tatashin at soleen.com>
---
lib/Kconfig.debug | 2 +-
lib/test_kho.c | 71 ++++++++++++++++++++++++++++++++++-------------
2 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 134b15a44625..74223ef8bd1c 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -3381,7 +3381,7 @@ config TEST_OBJPOOL
config TEST_KEXEC_HANDOVER
bool "Test for Kexec HandOver"
default n
- depends on KEXEC_HANDOVER
+ depends on KEXEC_HANDOVER || KEXEC_HANDOVER_READONLY
help
This option enables test for Kexec HandOver (KHO).
The test consists of two parts: saving kernel data before kexec and
diff --git a/lib/test_kho.c b/lib/test_kho.c
index aa6a0956bb8b..29029dcf5815 100644
--- a/lib/test_kho.c
+++ b/lib/test_kho.c
@@ -236,10 +236,10 @@ static int kho_test_restore_data(const void *fdt, int node)
{
const struct kho_vmalloc *folios_info_phys;
const unsigned int *nr_folios;
- phys_addr_t *folios_info;
+ const phys_addr_t *folios_info;
const __wsum *old_csum;
__wsum csum = 0;
- int len;
+ int len, i;
node = fdt_path_offset(fdt, "/data");
@@ -255,15 +255,34 @@ static int kho_test_restore_data(const void *fdt, int node)
if (!folios_info_phys || len != sizeof(*folios_info_phys))
return -EINVAL;
- folios_info = kho_restore_vmalloc(folios_info_phys);
+ if (kho_is_ro())
+ folios_info = kho_ro_map_vmalloc(folios_info_phys);
+ else
+ folios_info = kho_restore_vmalloc(folios_info_phys);
if (!folios_info)
return -EINVAL;
- for (int i = 0; i < *nr_folios; i++) {
+ for (i = 0; i < *nr_folios; i++) {
unsigned int order = folios_info[i] & ~PAGE_MASK;
phys_addr_t phys = folios_info[i] & PAGE_MASK;
- unsigned int size = PAGE_SIZE << order;
struct folio *folio;
+ size_t size;
+
+ if (order > MAX_PAGE_ORDER)
+ break;
+ size = PAGE_SIZE << order;
+
+ if (kho_is_ro()) {
+ void *addr;
+
+ if (kho_ro_lookup_folio_order(phys) != order)
+ break;
+ addr = kho_ro_map_folio(phys, PAGE_KERNEL_RO);
+ if (!addr)
+ break;
+ csum = csum_partial(addr, size, csum);
+ continue;
+ }
folio = kho_restore_folio(phys);
if (!folio)
@@ -276,19 +295,33 @@ static int kho_test_restore_data(const void *fdt, int node)
folio_put(folio);
}
- vfree(folios_info);
+ if (!kho_is_ro())
+ vfree(folios_info);
- if (csum != *old_csum)
+ if (i != *nr_folios || csum != *old_csum)
return -EINVAL;
return 0;
}
-static int kho_test_restore(phys_addr_t fdt_phys)
+static int kho_test_restore(phys_addr_t fdt_phys, size_t fdt_size)
{
- void *fdt = phys_to_virt(fdt_phys);
const unsigned int *magic;
- int node, len, err;
+ int node, len;
+ void *fdt;
+
+ if (!fdt_size)
+ return -EINVAL;
+
+ if (kho_is_ro()) {
+ if (kho_ro_lookup_folio_order(fdt_phys) < get_order(fdt_size))
+ return -EINVAL;
+ fdt = kho_ro_map_folio(fdt_phys, PAGE_KERNEL_RO);
+ if (!fdt)
+ return -EINVAL;
+ } else {
+ fdt = phys_to_virt(fdt_phys);
+ }
node = fdt_path_offset(fdt, "/");
if (node < 0)
@@ -304,24 +337,21 @@ static int kho_test_restore(phys_addr_t fdt_phys)
if (*magic != KHO_TEST_MAGIC)
return -EINVAL;
- err = kho_test_restore_data(fdt, node);
- if (err)
- return err;
-
- return 0;
+ return kho_test_restore_data(fdt, node);
}
static int __init kho_test_init(void)
{
phys_addr_t fdt_phys;
+ size_t fdt_size;
int err;
- if (!kho_is_enabled())
+ if (!kho_is_enabled() && !kho_is_ro())
return 0;
- err = kho_retrieve_subtree(KHO_TEST_FDT, &fdt_phys, NULL);
+ err = kho_retrieve_subtree(KHO_TEST_FDT, &fdt_phys, &fdt_size);
if (!err) {
- err = kho_test_restore(fdt_phys);
+ err = kho_test_restore(fdt_phys, fdt_size);
if (err)
pr_err("KHO restore failed\n");
else
@@ -330,7 +360,7 @@ static int __init kho_test_init(void)
return err;
}
- if (err != -ENOENT) {
+ if (err != -ENOENT || kho_is_ro()) {
pr_warn("failed to retrieve %s FDT: %d\n", KHO_TEST_FDT, err);
return err;
}
@@ -355,6 +385,9 @@ static void kho_test_cleanup(void)
static void __exit kho_test_exit(void)
{
+ if (!kho_test_state.fdt)
+ return;
+
kho_remove_subtree(folio_address(kho_test_state.fdt));
kho_test_cleanup();
}
--
2.56.0.307.g5fe7bd680c-goog
More information about the kexec
mailing list