Skip to content

Commit 469661d

Browse files
rpptakpm00
authored andcommitted
kho: check if kho is finalized in __kho_preserve_order()
Patch series "kho: add support for preserving vmalloc allocations", v5. Following the discussion about preservation of memfd with LUO [1] these patches add support for preserving vmalloc allocations. Any KHO uses case presumes that there's a data structure that lists physical addresses of preserved folios (and potentially some additional metadata). Allowing vmalloc preservations with KHO allows scalable preservation of such data structures. For instance, instead of allocating array describing preserved folios in the fdt, memfd preservation can use vmalloc: preserved_folios = vmalloc_array(nr_folios, sizeof(*preserved_folios)); memfd_luo_preserve_folios(preserved_folios, folios, nr_folios); kho_preserve_vmalloc(preserved_folios, &folios_info); This patch (of 4): Instead of checking if kho is finalized in each caller of __kho_preserve_order(), do it in the core function itself. Link: https://lkml.kernel.org/r/20250921054458.4043761-1-rppt@kernel.org Link: https://lkml.kernel.org/r/20250921054458.4043761-2-rppt@kernel.org Link: https://lore.kernel.org/all/20250807014442.3829950-30-pasha.tatashin@soleen.com [1] Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Cc: Alexander Graf <graf@amazon.com> Cc: Baoquan He <bhe@redhat.com> Cc: Changyuan Lyu <changyuanl@google.com> Cc: Chris Li <chrisl@kernel.org> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent fa02d50 commit 469661d

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

kernel/kexec_handover.c

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ struct kho_serialization {
107107
struct khoser_mem_chunk *preserved_mem_map;
108108
};
109109

110+
struct kho_out {
111+
struct blocking_notifier_head chain_head;
112+
113+
struct dentry *dir;
114+
115+
struct mutex lock; /* protects KHO FDT finalization */
116+
117+
struct kho_serialization ser;
118+
bool finalized;
119+
};
120+
121+
static struct kho_out kho_out = {
122+
.chain_head = BLOCKING_NOTIFIER_INIT(kho_out.chain_head),
123+
.lock = __MUTEX_INITIALIZER(kho_out.lock),
124+
.ser = {
125+
.fdt_list = LIST_HEAD_INIT(kho_out.ser.fdt_list),
126+
.track = {
127+
.orders = XARRAY_INIT(kho_out.ser.track.orders, 0),
128+
},
129+
},
130+
.finalized = false,
131+
};
132+
110133
static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size_t sz)
111134
{
112135
void *elm, *res;
@@ -165,6 +188,9 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn,
165188

166189
might_sleep();
167190

191+
if (kho_out.finalized)
192+
return -EBUSY;
193+
168194
physxa = xa_load(&track->orders, order);
169195
if (!physxa) {
170196
int err;
@@ -667,29 +693,6 @@ int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt)
667693
}
668694
EXPORT_SYMBOL_GPL(kho_add_subtree);
669695

670-
struct kho_out {
671-
struct blocking_notifier_head chain_head;
672-
673-
struct dentry *dir;
674-
675-
struct mutex lock; /* protects KHO FDT finalization */
676-
677-
struct kho_serialization ser;
678-
bool finalized;
679-
};
680-
681-
static struct kho_out kho_out = {
682-
.chain_head = BLOCKING_NOTIFIER_INIT(kho_out.chain_head),
683-
.lock = __MUTEX_INITIALIZER(kho_out.lock),
684-
.ser = {
685-
.fdt_list = LIST_HEAD_INIT(kho_out.ser.fdt_list),
686-
.track = {
687-
.orders = XARRAY_INIT(kho_out.ser.track.orders, 0),
688-
},
689-
},
690-
.finalized = false,
691-
};
692-
693696
int register_kho_notifier(struct notifier_block *nb)
694697
{
695698
return blocking_notifier_chain_register(&kho_out.chain_head, nb);
@@ -717,9 +720,6 @@ int kho_preserve_folio(struct folio *folio)
717720
const unsigned int order = folio_order(folio);
718721
struct kho_mem_track *track = &kho_out.ser.track;
719722

720-
if (kho_out.finalized)
721-
return -EBUSY;
722-
723723
return __kho_preserve_order(track, pfn, order);
724724
}
725725
EXPORT_SYMBOL_GPL(kho_preserve_folio);
@@ -743,9 +743,6 @@ int kho_preserve_phys(phys_addr_t phys, size_t size)
743743
int err = 0;
744744
struct kho_mem_track *track = &kho_out.ser.track;
745745

746-
if (kho_out.finalized)
747-
return -EBUSY;
748-
749746
if (!PAGE_ALIGNED(phys) || !PAGE_ALIGNED(size))
750747
return -EINVAL;
751748

0 commit comments

Comments
 (0)