Skip to content

Commit 8375b76

Browse files
rpptakpm00
authored andcommitted
kho: replace kho_preserve_phys() with kho_preserve_pages()
to make it clear that KHO operates on pages rather than on a random physical address. The kho_preserve_pages() will be also used in upcoming support for vmalloc preservation. Link: https://lkml.kernel.org/r/20250921054458.4043761-3-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> 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: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 469661d commit 8375b76

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

include/linux/kexec_handover.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum kho_event {
1818

1919
struct folio;
2020
struct notifier_block;
21+
struct page;
2122

2223
#define DECLARE_KHOSER_PTR(name, type) \
2324
union { \
@@ -43,7 +44,7 @@ bool kho_is_enabled(void);
4344
bool is_kho_boot(void);
4445

4546
int kho_preserve_folio(struct folio *folio);
46-
int kho_preserve_phys(phys_addr_t phys, size_t size);
47+
int kho_preserve_pages(struct page *page, unsigned int nr_pages);
4748
struct folio *kho_restore_folio(phys_addr_t phys);
4849
int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt);
4950
int kho_retrieve_subtree(const char *name, phys_addr_t *phys);
@@ -71,7 +72,7 @@ static inline int kho_preserve_folio(struct folio *folio)
7172
return -EOPNOTSUPP;
7273
}
7374

74-
static inline int kho_preserve_phys(phys_addr_t phys, size_t size)
75+
static inline int kho_preserve_pages(struct page *page, unsigned int nr_pages)
7576
{
7677
return -EOPNOTSUPP;
7778
}

kernel/kexec_handover.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -725,26 +725,23 @@ int kho_preserve_folio(struct folio *folio)
725725
EXPORT_SYMBOL_GPL(kho_preserve_folio);
726726

727727
/**
728-
* kho_preserve_phys - preserve a physically contiguous range across kexec.
729-
* @phys: physical address of the range.
730-
* @size: size of the range.
728+
* kho_preserve_pages - preserve contiguous pages across kexec
729+
* @page: first page in the list.
730+
* @nr_pages: number of pages.
731731
*
732-
* Instructs KHO to preserve the memory range from @phys to @phys + @size
733-
* across kexec.
732+
* Preserve a contiguous list of order 0 pages. Must be restored using
733+
* kho_restore_pages() to ensure the pages are restored properly as order 0.
734734
*
735735
* Return: 0 on success, error code on failure
736736
*/
737-
int kho_preserve_phys(phys_addr_t phys, size_t size)
737+
int kho_preserve_pages(struct page *page, unsigned int nr_pages)
738738
{
739-
unsigned long pfn = PHYS_PFN(phys);
739+
struct kho_mem_track *track = &kho_out.ser.track;
740+
const unsigned long start_pfn = page_to_pfn(page);
741+
const unsigned long end_pfn = start_pfn + nr_pages;
742+
unsigned long pfn = start_pfn;
740743
unsigned long failed_pfn = 0;
741-
const unsigned long start_pfn = pfn;
742-
const unsigned long end_pfn = PHYS_PFN(phys + size);
743744
int err = 0;
744-
struct kho_mem_track *track = &kho_out.ser.track;
745-
746-
if (!PAGE_ALIGNED(phys) || !PAGE_ALIGNED(size))
747-
return -EINVAL;
748745

749746
while (pfn < end_pfn) {
750747
const unsigned int order =
@@ -764,7 +761,7 @@ int kho_preserve_phys(phys_addr_t phys, size_t size)
764761

765762
return err;
766763
}
767-
EXPORT_SYMBOL_GPL(kho_preserve_phys);
764+
EXPORT_SYMBOL_GPL(kho_preserve_pages);
768765

769766
/* Handling for debug/kho/out */
770767

mm/memblock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2452,8 +2452,10 @@ static int reserve_mem_kho_finalize(struct kho_serialization *ser)
24522452

24532453
for (i = 0; i < reserved_mem_count; i++) {
24542454
struct reserve_mem_table *map = &reserved_mem_table[i];
2455+
struct page *page = phys_to_page(map->start);
2456+
unsigned int nr_pages = map->size >> PAGE_SHIFT;
24552457

2456-
err |= kho_preserve_phys(map->start, map->size);
2458+
err |= kho_preserve_pages(page, nr_pages);
24572459
}
24582460

24592461
err |= kho_preserve_folio(page_folio(kho_fdt));

0 commit comments

Comments
 (0)