]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kho: warn and exit when unpreserved page wasn't preserved
authorPratyush Yadav <pratyush@kernel.org>
Mon, 3 Nov 2025 18:02:32 +0000 (19:02 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 10 Nov 2025 05:19:47 +0000 (21:19 -0800)
Calling __kho_unpreserve() on a pair of (pfn, end_pfn) that wasn't
preserved is a bug.  Currently, if that is done, the physxa or bits can be
NULL.  This results in a soft lockup since a NULL physxa or bits results
in redoing the loop without ever making any progress.

Return when physxa or bits are not found, but WARN first to loudly
indicate invalid behaviour.

Link: https://lkml.kernel.org/r/20251103180235.71409-3-pratyush@kernel.org
Fixes: fc33e4b44b27 ("kexec: enable KHO support for memory preservation")
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/kexec_handover.c

index e0bafe7c0ded794c79cc0713674c96604a2ab99a..03d12e27189fc4733bfcb20f30533ba00285f56f 100644 (file)
@@ -171,12 +171,12 @@ static void __kho_unpreserve(struct kho_mem_track *track, unsigned long pfn,
                const unsigned long pfn_high = pfn >> order;
 
                physxa = xa_load(&track->orders, order);
-               if (!physxa)
-                       continue;
+               if (WARN_ON_ONCE(!physxa))
+                       return;
 
                bits = xa_load(&physxa->phys_bits, pfn_high / PRESERVE_BITS);
-               if (!bits)
-                       continue;
+               if (WARN_ON_ONCE(!bits))
+                       return;
 
                clear_bit(pfn_high % PRESERVE_BITS, bits->preserve);