Skip to content

Commit c607374

Browse files
vpetrogrppt
authored andcommitted
kho: make preserved pages compatible with deferred struct page init
When CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, struct page initialization is deferred to parallel kthreads that run later in the boot process. During KHO restoration, kho_preserved_memory_reserve() writes metadata for each preserved memory region. However, if the struct page has not been initialized, this write targets uninitialized memory, potentially leading to errors like: BUG: unable to handle page fault for address: ... Fix this by introducing kho_get_preserved_page(), which ensures all struct pages in a preserved region are initialized by calling init_deferred_page() which is a no-op when the struct page is already initialized. Signed-off-by: Evangelos Petrongonas <epetron@amazon.de> Co-developed-by: Michal Clapinski <mclapinski@google.com> Signed-off-by: Michal Clapinski <mclapinski@google.com> Reviewed-by: Pratyush Yadav (Google) <pratyush@kernel.org> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Link: https://patch.msgid.link/20260423122538.140993-3-mclapinski@google.com Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent bf480c6 commit c607374

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

kernel/liveupdate/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

33
menu "Live Update and Kexec HandOver"
4-
depends on !DEFERRED_STRUCT_PAGE_INIT
54

65
config KEXEC_HANDOVER
76
bool "kexec handover"
87
depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE
9-
depends on !DEFERRED_STRUCT_PAGE_INIT
108
select MEMBLOCK_KHO_SCRATCH
119
select KEXEC_FILE
1210
select LIBFDT

kernel/liveupdate/kexec_handover.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ struct page *kho_restore_pages(phys_addr_t phys, unsigned long nr_pages)
459459
}
460460
EXPORT_SYMBOL_GPL(kho_restore_pages);
461461

462+
/*
463+
* With CONFIG_DEFERRED_STRUCT_PAGE_INIT, struct pages in higher memory regions
464+
* may not be initialized yet at the time KHO deserializes preserved memory.
465+
* KHO uses the struct page to store metadata and a later initialization would
466+
* overwrite it.
467+
* Ensure all the struct pages in the preservation are
468+
* initialized. kho_preserved_memory_reserve() marks the reservation as noinit
469+
* to make sure they don't get re-initialized later.
470+
*/
471+
static struct page *__init kho_get_preserved_page(phys_addr_t phys,
472+
unsigned int order)
473+
{
474+
unsigned long pfn = PHYS_PFN(phys);
475+
int nid;
476+
477+
if (!IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT))
478+
return pfn_to_page(pfn);
479+
480+
nid = early_pfn_to_nid(pfn);
481+
for (unsigned long i = 0; i < (1UL << order); i++)
482+
init_deferred_page(pfn + i, nid);
483+
484+
return pfn_to_page(pfn);
485+
}
486+
462487
static int __init kho_preserved_memory_reserve(phys_addr_t phys,
463488
unsigned int order)
464489
{
@@ -467,7 +492,7 @@ static int __init kho_preserved_memory_reserve(phys_addr_t phys,
467492
u64 sz;
468493

469494
sz = 1 << (order + PAGE_SHIFT);
470-
page = phys_to_page(phys);
495+
page = kho_get_preserved_page(phys, order);
471496

472497
/* Reserve the memory preserved in KHO in memblock */
473498
memblock_reserve(phys, sz);

0 commit comments

Comments
 (0)