FAILED: patch "[PATCH] kho: make sure scratch size is always aligned by" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 0e39380a7316122e1b00012b3f3cd3e318b3e7d3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072031-lapping-tubby-5b19@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 0e39380a7316122e1b00012b3f3cd3e318b3e7d3 Mon Sep 17 00:00:00 2001
From: "Pratyush Yadav (Google)" <[email protected]>
Date: Tue, 19 May 2026 18:05:49 +0200
Subject: [PATCH] kho: make sure scratch size is always aligned by
CMA_MIN_ALIGNMENT_BYTES
When using scratch_scale, the scratch sizes are rounded up to CMA_MIN_ALIGNMENT_BYTES since they will be released as MIGRATE_CMA. This is not done when using fixed scratch sizes via command line. This can result in user specifying a size which is not aligned, and thus kernel releasing a pageblock that is only partially scratch.
Do the rounding up for both cases in scratch_size_update().
kernel/liveupdate/kexec_handover.c +21 -11
@@ -618,20 +618,30 @@ early_param("kho_scratch", kho_parse_scratch_size);static void __init scratch_size_update (void ) { -phys_addr_t size; +/* +* If fixed sizes are not provided via command line, calculate them +* now. +*/ +if (scratch_scale) { +phys_addr_t size; -if (!scratch_scale) -return ; + size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , +NUMA_NO_NODE ); + size = size * scratch_scale /100 ; + scratch_size_lowmem = size; - size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , -NUMA_NO_NODE ); - size = size * scratch_scale /100 ; - scratch_size_lowmem =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); + size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , +NUMA_NO_NODE ); + size = size * scratch_scale /100 - scratch_size_lowmem; + scratch_size_global = size; + } - size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , -NUMA_NO_NODE ); - size = size * scratch_scale /100 - scratch_size_lowmem; - scratch_size_global =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); +/* +* Scratch areas are released as MIGRATE_CMA. Round them up to the right +* size. +*/ + scratch_size_lowmem =round_up (scratch_size_lowmem,CMA_MIN_ALIGNMENT_BYTES ); + scratch_size_global =round_up (scratch_size_global,CMA_MIN_ALIGNMENT_BYTES ); }static phys_addr_t __init scratch_size_node (int nid)
Sasha Levin
maintainerPATCH 1/2 kho: add interfaces to unpreserve folios, page ranges, and vmalloc
From: Pasha Tatashin <[email protected]>
[ Upstream commit 36f8f7ef7fd2f238922e9d217e86c69838319d8c ]
Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio, pages, and vmallocs.
Stable-dep-of: 0e39380a7316 ("kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES")
--- include/linux/kexec_handover.h | 18 ++++++ kernel/kexec_handover.c | 104 ++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 13 deletions(-)
include/linux/kexec_handover.h +18 -0
@@ -52,8 +52,11 @@ bool kho_is_enabled(void);bool is_kho_boot (void );int kho_preserve_folio (struct folio *folio); +int kho_unpreserve_folio (struct folio *folio);int kho_preserve_pages (struct page *page,unsigned int nr_pages); +int kho_unpreserve_pages (struct page *page,unsigned int nr_pages);int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation); +int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned int nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);
@@ -83,17 +86,32 @@ static inline int kho_preserve_folio(struct folio *folio)return -EOPNOTSUPP ; } +static inline int kho_unpreserve_folio (struct folio *folio) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_pages (struct page *page,unsigned int nr_pages) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_pages (struct page *page,unsigned int nr_pages) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation) +{ +return -EOPNOTSUPP ; +} +static inline struct folio *kho_restore_folio (phys_addr_t phys) {return NULL ;
kernel/kexec_handover.c +91 -13
135 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 kho: make sure scratch size is always aligned by CMA_MIN_ALIGNMENT_BYTES
From: "Pratyush Yadav (Google)" <[email protected]>
[ Upstream commit 0e39380a7316122e1b00012b3f3cd3e318b3e7d3 ]
When using scratch_scale, the scratch sizes are rounded up to CMA_MIN_ALIGNMENT_BYTES since they will be released as MIGRATE_CMA. This is not done when using fixed scratch sizes via command line. This can result in user specifying a size which is not aligned, and thus kernel releasing a pageblock that is only partially scratch.
Do the rounding up for both cases in scratch_size_update().
--- kernel/kexec_handover.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
kernel/kexec_handover.c +21 -11
@@ -569,20 +569,30 @@ early_param("kho_scratch", kho_parse_scratch_size);static void __init scratch_size_update (void ) { -phys_addr_t size; +/* +* If fixed sizes are not provided via command line, calculate them +* now. +*/ +if (scratch_scale) { +phys_addr_t size; -if (!scratch_scale) -return ; + size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , +NUMA_NO_NODE ); + size = size * scratch_scale /100 ; + scratch_size_lowmem = size; - size =memblock_reserved_kern_size (ARCH_LOW_ADDRESS_LIMIT , -NUMA_NO_NODE ); - size = size * scratch_scale /100 ; - scratch_size_lowmem =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); + size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , +NUMA_NO_NODE ); + size = size * scratch_scale /100 - scratch_size_lowmem; + scratch_size_global = size; + } - size =memblock_reserved_kern_size (MEMBLOCK_ALLOC_ANYWHERE , -NUMA_NO_NODE ); - size = size * scratch_scale /100 - scratch_size_lowmem; - scratch_size_global =round_up (size,CMA_MIN_ALIGNMENT_BYTES ); +/* +* Scratch areas are released as MIGRATE_CMA. Round them up to the right +* size. +*/ + scratch_size_lowmem =round_up (scratch_size_lowmem,CMA_MIN_ALIGNMENT_BYTES ); + scratch_size_global =round_up (scratch_size_global,CMA_MIN_ALIGNMENT_BYTES ); }static phys_addr_t __init scratch_size_node (int nid)
Signature · 1 line
2.53.0
Re: [PATCH 6.18.y 1/2] kho: add interfaces to unpreserve folios, page ranges, and vmalloc
In reply to Sasha LevinQuoted 227 lines · Sasha Levin
From: Pasha Tatashin <[email protected]>
[ Upstream commit
36f8f7ef7fd2f238922e9d217e86c69838319d8c]Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio, pages, and vmallocs.
Signed-off-by Pasha Tatashin <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Cc Alexander Graf <[email protected]>Cc Changyuan Lyu <[email protected]>Cc Christian Brauner <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Masahiro Yamada <[email protected]>Cc Miguel Ojeda <[email protected]>Cc Randy Dunlap <[email protected]>Cc Simon Horman <[email protected]>Cc Tejun Heo <[email protected]>Cc Zhu Yanjun <[email protected]>Signed-off-by Andrew Morton <[email protected]>Stable-dep-of:
0e39380a7316("kho: make sure scratch size is always aligned byCMA_MIN_ALIGNMENT_BYTES")Signed-off-by Sasha Levin <[email protected]>--- include/linux/kexec_handover.h | 18 ++++++ kernel/kexec_handover.c | 104 ++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 13 deletions(-)include/linux/kexec_handover.h +18
-0@@ -52,8 +52,11 @@ bool kho_is_enabled(void);bool is_kho_boot (void );int kho_preserve_folio (struct folio *folio); +int kho_unpreserve_folio (struct folio *folio);int kho_preserve_pages (struct page *page,unsigned int nr_pages); +int kho_unpreserve_pages (struct page *page,unsigned int nr_pages);int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation); +int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned int nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);@@ -83,17 +86,32 @@ static inline int kho_preserve_folio(struct folio *folio)return -EOPNOTSUPP ; } +static inline int kho_unpreserve_folio (struct folio *folio) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_pages (struct page *page,unsigned int nr_pages) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_pages (struct page *page,unsigned int nr_pages) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation) +{ +return -EOPNOTSUPP ; +} +static inline struct folio *kho_restore_folio (phys_addr_t phys) {return NULL ;kernel/kexec_handover.c +91
-13@@ -153,26 +153,33 @@ static void *xa_load_or_alloc(struct xarray *xa, unsigned long index)return no_free_ptr (elm); } -static void __kho_unpreserve (struct kho_mem_track *track,unsigned long pfn, -unsigned long end_pfn) +static void __kho_unpreserve_order (struct kho_mem_track *track,unsigned long pfn, +unsigned int order) {struct kho_mem_phys_bits *bits;struct kho_mem_phys *physxa; +const unsigned long pfn_high = pfn >> order; -while (pfn < end_pfn) { -const unsigned int order = -min (count_trailing_zeros (pfn),ilog2 (end_pfn - pfn)); -const unsigned long pfn_high = pfn >> order; + physxa =xa_load (&track->orders, order); +if (WARN_ON_ONCE (!physxa)) +return ; - physxa =xa_load (&track->orders, order); -if (WARN_ON_ONCE (!physxa)) -return ; + bits =xa_load (&physxa->phys_bits, pfn_high /PRESERVE_BITS ); +if (WARN_ON_ONCE (!bits)) +return ; + +clear_bit (pfn_high %PRESERVE_BITS , bits->preserve); +} + +static void __kho_unpreserve (struct kho_mem_track *track,unsigned long pfn, +unsigned long end_pfn) +{ +unsigned int order; - bits =xa_load (&physxa->phys_bits, pfn_high /PRESERVE_BITS ); -if (WARN_ON_ONCE (!bits)) -return ; +while (pfn < end_pfn) { + order =min (count_trailing_zeros (pfn),ilog2 (end_pfn - pfn)); -clear_bit (pfn_high %PRESERVE_BITS , bits->preserve); +__kho_unpreserve_order (track, pfn, order); pfn +=1 << order; }@@ -739,6 +746,30 @@ int kho_preserve_folio(struct folio *folio) }EXPORT_SYMBOL_GPL (kho_preserve_folio); +/** +* kho_unpreserve_folio - unpreserve a folio. +* @folio: folio to unpreserve. +* +* Instructs KHO to unpreserve a folio that was preserved by +* kho_preserve_folio() before. The provided @folio (pfn and order) +* must exactly match a previously preserved folio. +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_folio (struct folio *folio) +{ +const unsigned long pfn =folio_pfn (folio); +const unsigned int order =folio_order (folio); +struct kho_mem_track *track = &kho_out.track; + +if (kho_out.finalized) +return -EBUSY ; + +__kho_unpreserve_order (track, pfn, order); +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_folio); +/** * kho_preserve_pages - preserve contiguous pages across kexec * @page: first page in the list. @@ -783,6 +814,33 @@ int kho_preserve_pages(struct page *page, unsigned int nr_pages) }EXPORT_SYMBOL_GPL (kho_preserve_pages); +/** +* kho_unpreserve_pages - unpreserve contiguous pages. +* @page: first page in the list. +* @nr_pages: number of pages. +* +* Instructs KHO to unpreserve @nr_pages contiguous pages starting from @page. +* This must be called with the same @page and @nr_pages as the corresponding +* kho_preserve_pages() call. Unpreserving arbitrary sub-ranges of larger +* preserved blocks is not supported. +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_pages (struct page *page,unsigned int nr_pages) +{ +struct kho_mem_track *track = &kho_out.track; +const unsigned long start_pfn =page_to_pfn (page); +const unsigned long end_pfn = start_pfn + nr_pages; + +if (kho_out.finalized) +return -EBUSY ; + +__kho_unpreserve (track, start_pfn, end_pfn); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_pages); +struct kho_vmalloc_hdr { DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); };@@ -944,6 +1002,26 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) }EXPORT_SYMBOL_GPL (kho_preserve_vmalloc); +/** +* kho_unpreserve_vmalloc - unpreserve memory allocated with vmalloc() +* @preservation: preservation metadata returned by kho_preserve_vmalloc() +* +* Instructs KHO to unpreserve the area in vmalloc address space that was +* previously preserved with kho_preserve_vmalloc(). +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation) +{ +if (kho_out.finalized) +return -EBUSY ; + +kho_vmalloc_free_chunks (preservation); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_vmalloc); +/** * kho_restore_vmalloc - recreates and populates an area in vmalloc address * space from the preserved memory. Signature · 1 line
2.53.0
Oops, nope, dropped this and patch 2/2 as this causes a build error :(
Re: [PATCH 6.18.y 1/2] kho: add interfaces to unpreserve folios, page ranges, and vmalloc
Quoted 222 lines · Greg KH
Quoted 221 lines · Sasha Levin
From: Pasha Tatashin <[email protected]>
[ Upstream commit
36f8f7ef7fd2f238922e9d217e86c69838319d8c]Allow users of KHO to cancel the previous preservation by adding the necessary interfaces to unpreserve folio, pages, and vmallocs.
Signed-off-by Pasha Tatashin <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Cc Alexander Graf <[email protected]>Cc Changyuan Lyu <[email protected]>Cc Christian Brauner <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Jason Gunthorpe <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Masahiro Yamada <[email protected]>Cc Miguel Ojeda <[email protected]>Cc Randy Dunlap <[email protected]>Cc Simon Horman <[email protected]>Cc Tejun Heo <[email protected]>Cc Zhu Yanjun <[email protected]>Signed-off-by Andrew Morton <[email protected]>Stable-dep-of:
0e39380a7316("kho: make sure scratch size is always aligned byCMA_MIN_ALIGNMENT_BYTES")Signed-off-by Sasha Levin <[email protected]>--- include/linux/kexec_handover.h | 18 ++++++ kernel/kexec_handover.c | 104 ++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 13 deletions(-)include/linux/kexec_handover.h +18
-0@@ -52,8 +52,11 @@ bool kho_is_enabled(void);bool is_kho_boot (void );int kho_preserve_folio (struct folio *folio); +int kho_unpreserve_folio (struct folio *folio);int kho_preserve_pages (struct page *page,unsigned int nr_pages); +int kho_unpreserve_pages (struct page *page,unsigned int nr_pages);int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation); +int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation);struct folio *kho_restore_folio (phys_addr_t phys);struct page *kho_restore_pages (phys_addr_t phys,unsigned int nr_pages);void *kho_restore_vmalloc (const struct kho_vmalloc *preservation);@@ -83,17 +86,32 @@ static inline int kho_preserve_folio(struct folio *folio)return -EOPNOTSUPP ; } +static inline int kho_unpreserve_folio (struct folio *folio) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_pages (struct page *page,unsigned int nr_pages) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_pages (struct page *page,unsigned int nr_pages) +{ +return -EOPNOTSUPP ; +} +static inline int kho_preserve_vmalloc (void *ptr,struct kho_vmalloc *preservation) {return -EOPNOTSUPP ; } +static inline int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation) +{ +return -EOPNOTSUPP ; +} +static inline struct folio *kho_restore_folio (phys_addr_t phys) {return NULL ;kernel/kexec_handover.c +91
-13@@ -153,26 +153,33 @@ static void *xa_load_or_alloc(struct xarray *xa, unsigned long index)return no_free_ptr (elm); } -static void __kho_unpreserve (struct kho_mem_track *track,unsigned long pfn, -unsigned long end_pfn) +static void __kho_unpreserve_order (struct kho_mem_track *track,unsigned long pfn, +unsigned int order) {struct kho_mem_phys_bits *bits;struct kho_mem_phys *physxa; +const unsigned long pfn_high = pfn >> order; -while (pfn < end_pfn) { -const unsigned int order = -min (count_trailing_zeros (pfn),ilog2 (end_pfn - pfn)); -const unsigned long pfn_high = pfn >> order; + physxa =xa_load (&track->orders, order); +if (WARN_ON_ONCE (!physxa)) +return ; - physxa =xa_load (&track->orders, order); -if (WARN_ON_ONCE (!physxa)) -return ; + bits =xa_load (&physxa->phys_bits, pfn_high /PRESERVE_BITS ); +if (WARN_ON_ONCE (!bits)) +return ; + +clear_bit (pfn_high %PRESERVE_BITS , bits->preserve); +} + +static void __kho_unpreserve (struct kho_mem_track *track,unsigned long pfn, +unsigned long end_pfn) +{ +unsigned int order; - bits =xa_load (&physxa->phys_bits, pfn_high /PRESERVE_BITS ); -if (WARN_ON_ONCE (!bits)) -return ; +while (pfn < end_pfn) { + order =min (count_trailing_zeros (pfn),ilog2 (end_pfn - pfn)); -clear_bit (pfn_high %PRESERVE_BITS , bits->preserve); +__kho_unpreserve_order (track, pfn, order); pfn +=1 << order; }@@ -739,6 +746,30 @@ int kho_preserve_folio(struct folio *folio) }EXPORT_SYMBOL_GPL (kho_preserve_folio); +/** +* kho_unpreserve_folio - unpreserve a folio. +* @folio: folio to unpreserve. +* +* Instructs KHO to unpreserve a folio that was preserved by +* kho_preserve_folio() before. The provided @folio (pfn and order) +* must exactly match a previously preserved folio. +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_folio (struct folio *folio) +{ +const unsigned long pfn =folio_pfn (folio); +const unsigned int order =folio_order (folio); +struct kho_mem_track *track = &kho_out.track; + +if (kho_out.finalized) +return -EBUSY ; + +__kho_unpreserve_order (track, pfn, order); +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_folio); +/** * kho_preserve_pages - preserve contiguous pages across kexec * @page: first page in the list. @@ -783,6 +814,33 @@ int kho_preserve_pages(struct page *page, unsigned int nr_pages) }EXPORT_SYMBOL_GPL (kho_preserve_pages); +/** +* kho_unpreserve_pages - unpreserve contiguous pages. +* @page: first page in the list. +* @nr_pages: number of pages. +* +* Instructs KHO to unpreserve @nr_pages contiguous pages starting from @page. +* This must be called with the same @page and @nr_pages as the corresponding +* kho_preserve_pages() call. Unpreserving arbitrary sub-ranges of larger +* preserved blocks is not supported. +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_pages (struct page *page,unsigned int nr_pages) +{ +struct kho_mem_track *track = &kho_out.track; +const unsigned long start_pfn =page_to_pfn (page); +const unsigned long end_pfn = start_pfn + nr_pages; + +if (kho_out.finalized) +return -EBUSY ; + +__kho_unpreserve (track, start_pfn, end_pfn); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_pages); +struct kho_vmalloc_hdr { DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); };@@ -944,6 +1002,26 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation) }EXPORT_SYMBOL_GPL (kho_preserve_vmalloc); +/** +* kho_unpreserve_vmalloc - unpreserve memory allocated with vmalloc() +* @preservation: preservation metadata returned by kho_preserve_vmalloc() +* +* Instructs KHO to unpreserve the area in vmalloc address space that was +* previously preserved with kho_preserve_vmalloc(). +* +* Return: 0 on success, error code on failure +*/ +int kho_unpreserve_vmalloc (struct kho_vmalloc *preservation) +{ +if (kho_out.finalized) +return -EBUSY ; + +kho_vmalloc_free_chunks (preservation); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kho_unpreserve_vmalloc); +/**
Quoted 10 lines
Quoted 6 lines
kernel/kexec_handover.c +0
-0* kho_restore_vmalloc - recreates and populates an area in vmalloc address * space from the preserved memory. Signature · 1 line
2.53.0Oops, nope, dropped this and patch 2/2 as this causes a build error :(
Actually patch 2/2 works just fine on it's own, so I've kept that.