]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
kho: move sanity checks to kho_restore_page()
authorPratyush Yadav <pratyush@kernel.org>
Wed, 17 Sep 2025 12:56:53 +0000 (14:56 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 23 Sep 2025 21:14:17 +0000 (14:14 -0700)
While KHO exposes folio as the primitive externally, internally its
restoration machinery operates on pages.  This can be seen with
kho_restore_folio() for example.  It performs some sanity checks and hands
it over to kho_restore_page() to do the heavy lifting of page restoration.
After the work done by kho_restore_page(), kho_restore_folio() only
converts the head page to folio and returns it.  Similarly,
deserialize_bitmap() operates on the head page directly to store the
order.

Move the sanity checks for valid phys and order from the public-facing
kho_restore_folio() to the private-facing kho_restore_page().  This makes
the boundary between page and folio clearer from KHO's perspective.

While at it, drop the comment above kho_restore_page().  The comment is
misleading now.  The function stopped looking like free_reserved_page()
since 12b9a2c05d1b4 ("kho: initialize tail pages for higher order folios
properly"), and now looks even more different.

Link: https://lkml.kernel.org/r/20250917125725.665-1-pratyush@kernel.org
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: 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>
kernel/kexec_handover.c

index 8079fc4b918979731e54569f24ce3f7d80634f65..c006a75446647cf800159e2d8f0d3ca66deeb0ab 100644 (file)
@@ -183,10 +183,18 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn,
        return 0;
 }
 
-/* almost as free_reserved_page(), just don't free the page */
-static void kho_restore_page(struct page *page, unsigned int order)
+static struct page *kho_restore_page(phys_addr_t phys)
 {
-       unsigned int nr_pages = (1 << order);
+       struct page *page = pfn_to_online_page(PHYS_PFN(phys));
+       unsigned int nr_pages, order;
+
+       if (!page)
+               return NULL;
+
+       order = page->private;
+       if (order > MAX_PAGE_ORDER)
+               return NULL;
+       nr_pages = (1 << order);
 
        /* Head page gets refcount of 1. */
        set_page_count(page, 1);
@@ -199,6 +207,7 @@ static void kho_restore_page(struct page *page, unsigned int order)
                prep_compound_page(page, order);
 
        adjust_managed_page_count(page, nr_pages);
+       return page;
 }
 
 /**
@@ -209,18 +218,9 @@ static void kho_restore_page(struct page *page, unsigned int order)
  */
 struct folio *kho_restore_folio(phys_addr_t phys)
 {
-       struct page *page = pfn_to_online_page(PHYS_PFN(phys));
-       unsigned long order;
-
-       if (!page)
-               return NULL;
-
-       order = page->private;
-       if (order > MAX_PAGE_ORDER)
-               return NULL;
+       struct page *page = kho_restore_page(phys);
 
-       kho_restore_page(page, order);
-       return page_folio(page);
+       return page ? page_folio(page) : NULL;
 }
 EXPORT_SYMBOL_GPL(kho_restore_folio);