Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kho: move sanity checks to kho_restore_page()

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>

authored by

Pratyush Yadav and committed by
Andrew Morton
20571b18 0389c305

+14 -14
+14 -14
kernel/kexec_handover.c
··· 183 183 return 0; 184 184 } 185 185 186 - /* almost as free_reserved_page(), just don't free the page */ 187 - static void kho_restore_page(struct page *page, unsigned int order) 186 + static struct page *kho_restore_page(phys_addr_t phys) 188 187 { 189 - unsigned int nr_pages = (1 << order); 188 + struct page *page = pfn_to_online_page(PHYS_PFN(phys)); 189 + unsigned int nr_pages, order; 190 + 191 + if (!page) 192 + return NULL; 193 + 194 + order = page->private; 195 + if (order > MAX_PAGE_ORDER) 196 + return NULL; 197 + nr_pages = (1 << order); 190 198 191 199 /* Head page gets refcount of 1. */ 192 200 set_page_count(page, 1); ··· 207 199 prep_compound_page(page, order); 208 200 209 201 adjust_managed_page_count(page, nr_pages); 202 + return page; 210 203 } 211 204 212 205 /** ··· 218 209 */ 219 210 struct folio *kho_restore_folio(phys_addr_t phys) 220 211 { 221 - struct page *page = pfn_to_online_page(PHYS_PFN(phys)); 222 - unsigned long order; 212 + struct page *page = kho_restore_page(phys); 223 213 224 - if (!page) 225 - return NULL; 226 - 227 - order = page->private; 228 - if (order > MAX_PAGE_ORDER) 229 - return NULL; 230 - 231 - kho_restore_page(page, order); 232 - return page_folio(page); 214 + return page ? page_folio(page) : NULL; 233 215 } 234 216 EXPORT_SYMBOL_GPL(kho_restore_folio); 235 217