* [PATCH] kho: fix order calculation for kho_unpreserve_pages()
@ 2026-05-19 13:33 Pratyush Yadav
2026-05-19 14:13 ` Pasha Tatashin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pratyush Yadav @ 2026-05-19 13:33 UTC (permalink / raw)
To: Mike Rapoport, Pasha Tatashin, Pratyush Yadav, Alexander Graf,
Samiullah Khawaja, Andrew Morton
Cc: kexec, linux-mm, linux-kernel, stable
From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
Commit 91e74fa8b1bc ("kho: make sure preservations do not span multiple
NUMA nodes") made sure preservations from kho_preserve_pages() do not
span multiple NUMA nodes. If they do, the order is reduced and tried
again.
The same logic was not implemented for kho_unpreserve_pages(). This can
result in unpreserve calculating a different order than preserve, and
thus not actually unpreserving the pages.
Fix this by moving the order calculation logic to
__kho_preserve_pages_order() and use it from both preserve and
unpreserve paths.
Move __kho_unpreserve() down to avoid having a forward declaration. Its
users are further down in the file anyway. Also, it results in grouping
for all the page-level preservation and unpreservation functions. This
unfortunately makes the diff hard to read, but the main change in
__kho_unpreserve() is to call __kho_preserve_pages_order() instead of
open-coding the order calculation.
Fixes: 91e74fa8b1bc ("kho: make sure preservations do not span multiple NUMA nodes")
Cc: stable@vger.kernel.org
Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
---
kernel/liveupdate/kexec_handover.c | 56 +++++++++++++++++-------------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index 4fde8325c49f..11855e275397 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -357,20 +357,6 @@ int kho_radix_walk_tree(struct kho_radix_tree *tree,
}
EXPORT_SYMBOL_GPL(kho_radix_walk_tree);
-static void __kho_unpreserve(struct kho_radix_tree *tree,
- unsigned long pfn, unsigned long end_pfn)
-{
- unsigned int order;
-
- while (pfn < end_pfn) {
- order = min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn));
-
- kho_radix_del_page(tree, pfn, order);
-
- pfn += 1 << order;
- }
-}
-
/* For physically contiguous 0-order pages. */
static void kho_init_pages(struct page *page, unsigned long nr_pages)
{
@@ -855,6 +841,37 @@ void kho_unpreserve_folio(struct folio *folio)
}
EXPORT_SYMBOL_GPL(kho_unpreserve_folio);
+static unsigned int __kho_preserve_pages_order(unsigned long start_pfn,
+ unsigned long end_pfn)
+{
+ unsigned int order = min(count_trailing_zeros(start_pfn),
+ ilog2(end_pfn - start_pfn));
+
+ /*
+ * Make sure all the pages in a single preservation are in the same NUMA
+ * node. The restore machinery can not cope with a preservation spanning
+ * multiple NUMA nodes.
+ */
+ while (pfn_to_nid(start_pfn) != pfn_to_nid(start_pfn + (1UL << order) - 1))
+ order--;
+
+ return order;
+}
+
+static void __kho_unpreserve(struct kho_radix_tree *tree,
+ unsigned long pfn, unsigned long end_pfn)
+{
+ unsigned int order;
+
+ while (pfn < end_pfn) {
+ order = __kho_preserve_pages_order(pfn, end_pfn);
+
+ kho_radix_del_page(tree, pfn, order);
+
+ pfn += 1 << order;
+ }
+}
+
/**
* kho_preserve_pages - preserve contiguous pages across kexec
* @page: first page in the list.
@@ -880,16 +897,7 @@ int kho_preserve_pages(struct page *page, unsigned long nr_pages)
}
while (pfn < end_pfn) {
- unsigned int order =
- min(count_trailing_zeros(pfn), ilog2(end_pfn - pfn));
-
- /*
- * Make sure all the pages in a single preservation are in the
- * same NUMA node. The restore machinery can not cope with a
- * preservation spanning multiple NUMA nodes.
- */
- while (pfn_to_nid(pfn) != pfn_to_nid(pfn + (1UL << order) - 1))
- order--;
+ unsigned int order = __kho_preserve_pages_order(pfn, end_pfn);
err = kho_radix_add_page(tree, pfn, order);
if (err) {
base-commit: b1378127003b61930ce30064328640503ad3ef6d
--
2.54.0.563.g4f69b47b94-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: fix order calculation for kho_unpreserve_pages()
2026-05-19 13:33 [PATCH] kho: fix order calculation for kho_unpreserve_pages() Pratyush Yadav
@ 2026-05-19 14:13 ` Pasha Tatashin
2026-05-19 18:47 ` Samiullah Khawaja
2026-05-20 5:09 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: Pasha Tatashin @ 2026-05-19 14:13 UTC (permalink / raw)
To: Pratyush Yadav
Cc: Mike Rapoport, Pasha Tatashin, Alexander Graf, Samiullah Khawaja,
Andrew Morton, kexec, linux-mm, linux-kernel, stable
On 05-19 15:33, Pratyush Yadav wrote:
> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>
> Commit 91e74fa8b1bc ("kho: make sure preservations do not span multiple
> NUMA nodes") made sure preservations from kho_preserve_pages() do not
> span multiple NUMA nodes. If they do, the order is reduced and tried
> again.
>
> The same logic was not implemented for kho_unpreserve_pages(). This can
> result in unpreserve calculating a different order than preserve, and
> thus not actually unpreserving the pages.
>
> Fix this by moving the order calculation logic to
> __kho_preserve_pages_order() and use it from both preserve and
> unpreserve paths.
>
> Move __kho_unpreserve() down to avoid having a forward declaration. Its
> users are further down in the file anyway. Also, it results in grouping
> for all the page-level preservation and unpreservation functions. This
> unfortunately makes the diff hard to read, but the main change in
> __kho_unpreserve() is to call __kho_preserve_pages_order() instead of
> open-coding the order calculation.
>
> Fixes: 91e74fa8b1bc ("kho: make sure preservations do not span multiple NUMA nodes")
> Cc: stable@vger.kernel.org
> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Pasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: fix order calculation for kho_unpreserve_pages()
2026-05-19 13:33 [PATCH] kho: fix order calculation for kho_unpreserve_pages() Pratyush Yadav
2026-05-19 14:13 ` Pasha Tatashin
@ 2026-05-19 18:47 ` Samiullah Khawaja
2026-05-20 5:09 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: Samiullah Khawaja @ 2026-05-19 18:47 UTC (permalink / raw)
To: Pratyush Yadav
Cc: Mike Rapoport, Pasha Tatashin, Alexander Graf, Andrew Morton,
kexec, linux-mm, linux-kernel, stable
On Tue, May 19, 2026 at 03:33:30PM +0200, Pratyush Yadav wrote:
>From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>
>Commit 91e74fa8b1bc ("kho: make sure preservations do not span multiple
>NUMA nodes") made sure preservations from kho_preserve_pages() do not
>span multiple NUMA nodes. If they do, the order is reduced and tried
>again.
>
>The same logic was not implemented for kho_unpreserve_pages(). This can
>result in unpreserve calculating a different order than preserve, and
>thus not actually unpreserving the pages.
>
>Fix this by moving the order calculation logic to
>__kho_preserve_pages_order() and use it from both preserve and
>unpreserve paths.
>
>Move __kho_unpreserve() down to avoid having a forward declaration. Its
>users are further down in the file anyway. Also, it results in grouping
>for all the page-level preservation and unpreservation functions. This
>unfortunately makes the diff hard to read, but the main change in
>__kho_unpreserve() is to call __kho_preserve_pages_order() instead of
>open-coding the order calculation.
>
>Fixes: 91e74fa8b1bc ("kho: make sure preservations do not span multiple NUMA nodes")
>Cc: stable@vger.kernel.org
>Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Nice find, sashiko was also complaining about same on my kunit series:
https://sashiko.dev/#/patchset/20260512195135.804833-1-skhawaja%40google.com
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] kho: fix order calculation for kho_unpreserve_pages()
2026-05-19 13:33 [PATCH] kho: fix order calculation for kho_unpreserve_pages() Pratyush Yadav
2026-05-19 14:13 ` Pasha Tatashin
2026-05-19 18:47 ` Samiullah Khawaja
@ 2026-05-20 5:09 ` Mike Rapoport
2 siblings, 0 replies; 4+ messages in thread
From: Mike Rapoport @ 2026-05-20 5:09 UTC (permalink / raw)
To: Pasha Tatashin, Alexander Graf, Samiullah Khawaja, Andrew Morton,
Pratyush Yadav
Cc: Mike Rapoport, kexec, linux-mm, linux-kernel, stable
On Tue, 19 May 2026 15:33:30 +0200, Pratyush Yadav wrote:
> Commit 91e74fa8b1bc ("kho: make sure preservations do not span multiple
> NUMA nodes") made sure preservations from kho_preserve_pages() do not
> span multiple NUMA nodes. If they do, the order is reduced and tried
> again.
>
> The same logic was not implemented for kho_unpreserve_pages(). This can
> result in unpreserve calculating a different order than preserve, and
> thus not actually unpreserving the pages.
>
> [...]
Applied to fixes branch of liveupdate/linux.git tree, thanks!
[1/1] kho: fix order calculation for kho_unpreserve_pages()
commit: ec4084bc445027a52f600e30a976928be1ba1950
tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: fixes
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-20 5:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-19 13:33 [PATCH] kho: fix order calculation for kho_unpreserve_pages() Pratyush Yadav
2026-05-19 14:13 ` Pasha Tatashin
2026-05-19 18:47 ` Samiullah Khawaja
2026-05-20 5:09 ` Mike Rapoport
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox