* [PATCH v3 1/3] kho: init new_physxa->phys_bits to fix lockdep
2025-08-08 20:18 [PATCH v3 0/3] Several KHO Hotfixes Pasha Tatashin
@ 2025-08-08 20:18 ` Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 2/3] kho: mm: Don't allow deferred struct page with KHO Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 3/3] kho: warn if KHO is disabled due to an error Pasha Tatashin
2 siblings, 0 replies; 4+ messages in thread
From: Pasha Tatashin @ 2025-08-08 20:18 UTC (permalink / raw)
To: akpm, bhe, pasha.tatashin, rppt, arnd, coxu, dave, ebiggers,
graf, changyuanl, kees, linux-kernel, kexec, linux-mm
Lockdep shows the following warning:
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe
you didn't initialize this object before use?
turning off the locking correctness validator.
[<ffffffff810133a6>] dump_stack_lvl+0x66/0xa0
[<ffffffff8136012c>] assign_lock_key+0x10c/0x120
[<ffffffff81358bb4>] register_lock_class+0xf4/0x2f0
[<ffffffff813597ff>] __lock_acquire+0x7f/0x2c40
[<ffffffff81360cb0>] ? __pfx_hlock_conflict+0x10/0x10
[<ffffffff811707be>] ? native_flush_tlb_global+0x8e/0xa0
[<ffffffff8117096e>] ? __flush_tlb_all+0x4e/0xa0
[<ffffffff81172fc2>] ? __kernel_map_pages+0x112/0x140
[<ffffffff813ec327>] ? xa_load_or_alloc+0x67/0xe0
[<ffffffff81359556>] lock_acquire+0xe6/0x280
[<ffffffff813ec327>] ? xa_load_or_alloc+0x67/0xe0
[<ffffffff8100b9e0>] _raw_spin_lock+0x30/0x40
[<ffffffff813ec327>] ? xa_load_or_alloc+0x67/0xe0
[<ffffffff813ec327>] xa_load_or_alloc+0x67/0xe0
[<ffffffff813eb4c0>] kho_preserve_folio+0x90/0x100
[<ffffffff813ebb7f>] __kho_finalize+0xcf/0x400
[<ffffffff813ebef4>] kho_finalize+0x34/0x70
This is becase xa has its own lock, that is not initialized in
xa_load_or_alloc.
Modifiy __kho_preserve_order(), to properly call
xa_init(&new_physxa->phys_bits);
Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation")
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: stable@vger.kernel.org
---
kernel/kexec_handover.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
index e49743ae52c5..65145972d6d6 100644
--- a/kernel/kexec_handover.c
+++ b/kernel/kexec_handover.c
@@ -144,14 +144,34 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn,
unsigned int order)
{
struct kho_mem_phys_bits *bits;
- struct kho_mem_phys *physxa;
+ struct kho_mem_phys *physxa, *new_physxa;
const unsigned long pfn_high = pfn >> order;
might_sleep();
- physxa = xa_load_or_alloc(&track->orders, order, sizeof(*physxa));
- if (IS_ERR(physxa))
- return PTR_ERR(physxa);
+ physxa = xa_load(&track->orders, order);
+ if (!physxa) {
+ int err;
+
+ new_physxa = kzalloc(sizeof(*physxa), GFP_KERNEL);
+ if (!new_physxa)
+ return -ENOMEM;
+
+ xa_init(&new_physxa->phys_bits);
+ physxa = xa_cmpxchg(&track->orders, order, NULL, new_physxa,
+ GFP_KERNEL);
+
+ err = xa_err(physxa);
+ if (err || physxa) {
+ xa_destroy(&new_physxa->phys_bits);
+ kfree(new_physxa);
+
+ if (err)
+ return err;
+ } else {
+ physxa = new_physxa;
+ }
+ }
bits = xa_load_or_alloc(&physxa->phys_bits, pfn_high / PRESERVE_BITS,
sizeof(*bits));
--
2.50.1.703.g449372360f-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 2/3] kho: mm: Don't allow deferred struct page with KHO
2025-08-08 20:18 [PATCH v3 0/3] Several KHO Hotfixes Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 1/3] kho: init new_physxa->phys_bits to fix lockdep Pasha Tatashin
@ 2025-08-08 20:18 ` Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 3/3] kho: warn if KHO is disabled due to an error Pasha Tatashin
2 siblings, 0 replies; 4+ messages in thread
From: Pasha Tatashin @ 2025-08-08 20:18 UTC (permalink / raw)
To: akpm, bhe, pasha.tatashin, rppt, arnd, coxu, dave, ebiggers,
graf, changyuanl, kees, linux-kernel, kexec, linux-mm
KHO uses struct pages for the preserved memory early in boot, however,
with deferred struct page initialization, only a small portion of
memory has properly initialized struct pages.
This problem was detected where vmemmap is poisoned, and illegal flag
combinations are detected.
Don't allow them to be enabled together, and later we will have to
teach KHO to work properly with deferred struct page init kernel
feature.
Fixes: 990a950fe8fd ("kexec: add config option for KHO")
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Pratyush Yadav <pratyush@kernel.org>
Cc: stable@vger.kernel.org
---
kernel/Kconfig.kexec | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/Kconfig.kexec b/kernel/Kconfig.kexec
index 2ee603a98813..1224dd937df0 100644
--- a/kernel/Kconfig.kexec
+++ b/kernel/Kconfig.kexec
@@ -97,6 +97,7 @@ config KEXEC_JUMP
config KEXEC_HANDOVER
bool "kexec handover"
depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE
+ depends on !DEFERRED_STRUCT_PAGE_INIT
select MEMBLOCK_KHO_SCRATCH
select KEXEC_FILE
select DEBUG_FS
--
2.50.1.703.g449372360f-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v3 3/3] kho: warn if KHO is disabled due to an error
2025-08-08 20:18 [PATCH v3 0/3] Several KHO Hotfixes Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 1/3] kho: init new_physxa->phys_bits to fix lockdep Pasha Tatashin
2025-08-08 20:18 ` [PATCH v3 2/3] kho: mm: Don't allow deferred struct page with KHO Pasha Tatashin
@ 2025-08-08 20:18 ` Pasha Tatashin
2 siblings, 0 replies; 4+ messages in thread
From: Pasha Tatashin @ 2025-08-08 20:18 UTC (permalink / raw)
To: akpm, bhe, pasha.tatashin, rppt, arnd, coxu, dave, ebiggers,
graf, changyuanl, kees, linux-kernel, kexec, linux-mm
During boot scratch area is allocated based on command line
parameters or auto calculated. However, scratch area may fail
to allocate, and in that case KHO is disabled. Currently,
no warning is printed that KHO is disabled, which makes it
confusing for the end user to figure out why KHO is not
available. Add the missing warning message.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Pratyush Yadav <pratyush@kernel.org>
Cc: stable@vger.kernel.org
---
kernel/kexec_handover.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
index 65145972d6d6..ecd1ac210dbd 100644
--- a/kernel/kexec_handover.c
+++ b/kernel/kexec_handover.c
@@ -564,6 +564,7 @@ static void __init kho_reserve_scratch(void)
err_free_scratch_desc:
memblock_free(kho_scratch, kho_scratch_cnt * sizeof(*kho_scratch));
err_disable_kho:
+ pr_warn("Failed to reserve scratch area, disabling kexec handover\n");
kho_enable = false;
}
--
2.50.1.703.g449372360f-goog
^ permalink raw reply [flat|nested] 4+ messages in thread