From: Pratyush Yadav <pratyush@kernel.org>
To: "Alexander Graf" <graf@amazon.com>,
"Mike Rapoport" <rppt@kernel.org>,
"Changyuan Lyu" <changyuanl@google.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Baoquan He" <bhe@redhat.com>,
"Pratyush Yadav" <pratyush@kernel.org>,
"Pasha Tatashin" <pasha.tatashin@soleen.com>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Chris Li" <chrisl@kernel.org>, "Jason Miu" <jasonmiu@google.com>,
"David Matlack" <dmatlack@google.com>,
"David Rientjes" <rientjes@google.com>
Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
linux-mm@kvack.org
Subject: [RFC PATCH 4/4] lib/test_kho: use kho_preserve_vmalloc instead of storing addresses in fdt
Date: Tue, 9 Sep 2025 16:44:24 +0200 [thread overview]
Message-ID: <20250909144426.33274-5-pratyush@kernel.org> (raw)
In-Reply-To: <20250909144426.33274-1-pratyush@kernel.org>
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
KHO test stores physical addresses of the preserved folios directly in
fdt.
Use kho_preserve_vmalloc() instead of it and kho_restore_vmalloc() to
retrieve the addresses after kexec.
This makes the test more scalable from one side and adds tests coverage
for kho_preserve_vmalloc() from the other.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
[pratyush@kernel.org: use the KHO-array version of kho_restore_vmalloc()]
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
---
lib/test_kho.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/lib/test_kho.c b/lib/test_kho.c
index c2eb899c3b456..3f4cb39cd917e 100644
--- a/lib/test_kho.c
+++ b/lib/test_kho.c
@@ -32,6 +32,7 @@ module_param(max_mem, long, 0644);
struct kho_test_state {
unsigned int nr_folios;
struct folio **folios;
+ phys_addr_t *folios_info;
struct folio *fdt;
__wsum csum;
};
@@ -67,14 +68,18 @@ static struct notifier_block kho_test_nb = {
static int kho_test_save_data(struct kho_test_state *state, void *fdt)
{
+ struct kho_vmalloc folios_info_preservation = {};
phys_addr_t *folios_info __free(kvfree) = NULL;
int err = 0;
- folios_info = kvmalloc_array(state->nr_folios, sizeof(*folios_info),
- GFP_KERNEL);
+ folios_info = vmalloc_array(state->nr_folios, sizeof(*folios_info));
if (!folios_info)
return -ENOMEM;
+ err = kho_preserve_vmalloc(folios_info, &folios_info_preservation);
+ if (err)
+ return err;
+
for (int i = 0; i < state->nr_folios; i++) {
struct folio *folio = state->folios[i];
unsigned int order = folio_order(folio);
@@ -89,11 +94,14 @@ static int kho_test_save_data(struct kho_test_state *state, void *fdt)
err |= fdt_begin_node(fdt, "data");
err |= fdt_property(fdt, "nr_folios", &state->nr_folios,
sizeof(state->nr_folios));
- err |= fdt_property(fdt, "folios_info", folios_info,
- state->nr_folios * sizeof(*folios_info));
+ err |= fdt_property(fdt, "folios_info", &folios_info_preservation,
+ sizeof(folios_info_preservation));
err |= fdt_property(fdt, "csum", &state->csum, sizeof(state->csum));
err |= fdt_end_node(fdt);
+ if (!err)
+ state->folios_info = no_free_ptr(folios_info);
+
return err;
}
@@ -197,7 +205,8 @@ static int kho_test_save(void)
static int kho_test_restore_data(const void *fdt, int node)
{
const unsigned int *nr_folios;
- const phys_addr_t *folios_info;
+ const struct kho_vmalloc *folios_info_preservation;
+ phys_addr_t *folios_info;
const __wsum *old_csum;
__wsum csum = 0;
int len;
@@ -212,8 +221,12 @@ static int kho_test_restore_data(const void *fdt, int node)
if (!old_csum || len != sizeof(*old_csum))
return -EINVAL;
- folios_info = fdt_getprop(fdt, node, "folios_info", &len);
- if (!folios_info || len != sizeof(*folios_info) * *nr_folios)
+ folios_info_preservation = fdt_getprop(fdt, node, "folios_info", &len);
+ if (!folios_info_preservation || len != sizeof(*folios_info_preservation))
+ return -EINVAL;
+
+ folios_info = kho_restore_vmalloc((struct kho_vmalloc *)folios_info_preservation);
+ if (!folios_info)
return -EINVAL;
for (int i = 0; i < *nr_folios; i++) {
@@ -233,6 +246,8 @@ static int kho_test_restore_data(const void *fdt, int node)
folio_put(folio);
}
+ vfree(folios_info);
+
if (csum != *old_csum)
return -EINVAL;
@@ -291,6 +306,7 @@ static void kho_test_cleanup(void)
folio_put(kho_test_state.folios[i]);
kvfree(kho_test_state.folios);
+ vfree(kho_test_state.folios_info);
}
static void __exit kho_test_exit(void)
--
2.47.3
prev parent reply other threads:[~2025-09-09 14:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 14:44 [RFC PATCH 0/4] kho: introduce the KHO array Pratyush Yadav
2025-09-09 14:44 ` [RFC PATCH 1/4] " Pratyush Yadav
2025-09-09 15:28 ` Jason Gunthorpe
2025-09-09 15:40 ` Pratyush Yadav
2025-09-09 15:50 ` Jason Gunthorpe
2025-09-09 14:44 ` [RFC PATCH 2/4] kho: use KHO array for preserved memory bitmap serialization Pratyush Yadav
2025-09-09 14:44 ` [RFC PATCH 3/4] kho: add support for preserving vmalloc allocations Pratyush Yadav
2025-09-09 14:44 ` Pratyush Yadav [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250909144426.33274-5-pratyush@kernel.org \
--to=pratyush@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=changyuanl@google.com \
--cc=chrisl@kernel.org \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=jgg@nvidia.com \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox