From nobody Tue Sep 9 21:31:46 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78818202C2B for ; Sun, 7 Sep 2025 07:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757228447; cv=none; b=hCkxlu1LfDqSgkwyCfTRjZsyT4BCgCAtH6DRLP6h1ym6YMwjKq3BgEPquOSesu/Qsf1mBn/qcdPYi8EMGGmnomR1mjTgEm+ndhMFNkzQCBR1NJgDaQpYIdb8nqD3S4hL5sLkVCZ9uUVspLR46KFlI1lom57BQyHT9FGEScmuoL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757228447; c=relaxed/simple; bh=S6cq5Fd+Tt7edEdfLD7ze+ZKtAEEGtzWPj0q1zSXPO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7aH7QP+47AOtBi+VdxV+w59DIrWe8yBuv6C2sxBb4DRTsqp8oySU5ZgM/FaffbDgP4x8wHHuabKeSwh7k9xm3F2STeX9GumQYvYBPSWQLeEK2Ilo9dSdtMOIiTy+VldsmstU33DZZeRr2uJkgbJ7sEA1CTmsb1c1VW5QHQHCoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HEZKwHsm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HEZKwHsm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2ADDC4CEFB; Sun, 7 Sep 2025 07:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757228447; bh=S6cq5Fd+Tt7edEdfLD7ze+ZKtAEEGtzWPj0q1zSXPO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HEZKwHsmg+QtBW5UFiuYs26fucUIr6wGXLeddggrTHC9Qgqatmc8T374QZ/+Eg7eN 3Cp2tnZpsbMiwBTqNfFboEAuvBqaFsEi2cwjiokLUKJf+eiR/hyZKhyERzjaRZiqKO qWcUlZigxroFfPXhC2aRs9Liyf/KGq+idNdgxbi4uUL7csesh9HXkeB1uckoUz3h3N oXUjzf1vww1oWvfB9l4KyHTe1abGjyAtQxaTXgFwnA3jM3KpdfipijBM6BFPCW5uo0 Asp36UxHGNj9ZisfH32xiFhzIDbj06EjDDQfURoMxacHCdyPXEaApf5f8glSSLDeCf Lsnk/dTM0xRVg== From: Mike Rapoport To: Andrew Morton Cc: Alexander Graf , Baoquan He , Changyuan Lyu , Chris Li , Jason Gunthorpe , Mike Rapoport , Pasha Tatashin , Pratyush Yadav , kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] lib/test_kho: use kho_preserve_vmalloc instead of storing addresses in fdt Date: Sun, 7 Sep 2025 10:00:22 +0300 Message-ID: <20250907070022.2177974-6-rppt@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250907070022.2177974-1-rppt@kernel.org> References: <20250907070022.2177974-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" 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) --- lib/test_kho.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/test_kho.c b/lib/test_kho.c index fe8504e3407b..c46f577b6aee 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,18 +68,15 @@ static struct notifier_block kho_test_nb =3D { =20 static int kho_test_save_data(struct kho_test_state *state, void *fdt) { - phys_addr_t *folios_info; + phys_addr_t *folios_info __free(kvfree) =3D NULL; + phys_addr_t folios_info_phys; int err =3D 0; =20 - err |=3D fdt_begin_node(fdt, "data"); - err |=3D fdt_property(fdt, "nr_folios", &state->nr_folios, - sizeof(state->nr_folios)); - err |=3D fdt_property_placeholder(fdt, "folios_info", - state->nr_folios * sizeof(*folios_info), - (void **)&folios_info); - err |=3D fdt_property(fdt, "csum", &state->csum, sizeof(state->csum)); - err |=3D fdt_end_node(fdt); + folios_info =3D vmalloc_array(state->nr_folios, sizeof(*folios_info)); + if (!folios_info) + return -ENOMEM; =20 + err =3D kho_preserve_vmalloc(folios_info, &folios_info_phys); if (err) return err; =20 @@ -93,6 +91,17 @@ static int kho_test_save_data(struct kho_test_state *sta= te, void *fdt) break; } =20 + err |=3D fdt_begin_node(fdt, "data"); + err |=3D fdt_property(fdt, "nr_folios", &state->nr_folios, + sizeof(state->nr_folios)); + err |=3D fdt_property(fdt, "folios_info", &folios_info_phys, + sizeof(folios_info_phys)); + err |=3D fdt_property(fdt, "csum", &state->csum, sizeof(state->csum)); + err |=3D fdt_end_node(fdt); + + if (!err) + state->folios_info =3D no_free_ptr(folios_info); + return err; } =20 @@ -210,7 +219,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 phys_addr_t *folios_info_phys; + phys_addr_t *folios_info; const __wsum *old_csum; __wsum csum =3D 0; int len; @@ -225,8 +235,12 @@ static int kho_test_restore_data(const void *fdt, int = node) if (!old_csum || len !=3D sizeof(*old_csum)) return -EINVAL; =20 - folios_info =3D fdt_getprop(fdt, node, "folios_info", &len); - if (!folios_info || len !=3D sizeof(*folios_info) * *nr_folios) + folios_info_phys =3D fdt_getprop(fdt, node, "folios_info", &len); + if (!folios_info_phys || len !=3D sizeof(*folios_info_phys)) + return -EINVAL; + + folios_info =3D kho_restore_vmalloc(*folios_info_phys); + if (!folios_info) return -EINVAL; =20 for (int i =3D 0; i < *nr_folios; i++) { @@ -246,6 +260,8 @@ static int kho_test_restore_data(const void *fdt, int n= ode) folio_put(folio); } =20 + vfree(folios_info); + if (csum !=3D *old_csum) return -EINVAL; =20 @@ -304,6 +320,7 @@ static void kho_test_cleanup(void) folio_put(kho_test_state.folios[i]); =20 kvfree(kho_test_state.folios); + vfree(kho_test_state.folios_info); folio_put(kho_test_state.fdt); } =20 --=20 2.50.1