]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kho: don't unpreserve memory during abort
authorPasha Tatashin <pasha.tatashin@soleen.com>
Sat, 1 Nov 2025 14:23:22 +0000 (10:23 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 27 Nov 2025 22:24:33 +0000 (14:24 -0800)
KHO allows clients to preserve memory regions at any point before the KHO
state is finalized.  The finalization process itself involves KHO
performing its own actions, such as serializing the overall preserved
memory map.

If this finalization process is aborted, the current implementation
destroys KHO's internal memory tracking structures
(`kho_out.ser.track.orders`).  This behavior effectively unpreserves all
memory from KHO's perspective, regardless of whether those preservations
were made by clients before the finalization attempt or by KHO itself
during finalization.

This premature unpreservation is incorrect.  An abort of the finalization
process should only undo actions taken by KHO as part of that specific
finalization attempt.  Individual memory regions preserved by clients
prior to finalization should remain preserved, as their lifecycle is
managed by the clients themselves.  These clients might still need to call
kho_unpreserve_folio() or kho_unpreserve_phys() based on their own logic,
even after a KHO finalization attempt is aborted.

Link: https://lkml.kernel.org/r/20251101142325.1326536-7-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Changyuan Lyu <changyuanl@google.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Simon Horman <horms@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/kexec_handover.c

index 4e033f96637d0d5f79ed6ee90586ac1b36c56d6e..0a4a058fbf0c773bc8b1eae2193e85d825a01782 100644 (file)
@@ -1119,31 +1119,12 @@ EXPORT_SYMBOL_GPL(kho_restore_vmalloc);
 
 static int __kho_abort(void)
 {
-       int err = 0;
-       unsigned long order;
-       struct kho_mem_phys *physxa;
-
-       xa_for_each(&kho_out.track.orders, order, physxa) {
-               struct kho_mem_phys_bits *bits;
-               unsigned long phys;
-
-               xa_for_each(&physxa->phys_bits, phys, bits)
-                       kfree(bits);
-
-               xa_destroy(&physxa->phys_bits);
-               kfree(physxa);
-       }
-       xa_destroy(&kho_out.track.orders);
-
        if (kho_out.preserved_mem_map) {
                kho_mem_ser_free(kho_out.preserved_mem_map);
                kho_out.preserved_mem_map = NULL;
        }
 
-       if (err)
-               pr_err("Failed to abort KHO finalization: %d\n", err);
-
-       return err;
+       return 0;
 }
 
 int kho_abort(void)