Re: [PATCH] kho: fix order calculation for kho_unpreserve_pages()

From: Samiullah Khawaja

Date: Tue May 19 2026 - 14:48:09 EST


On Tue, May 19, 2026 at 03:33:30PM +0200, Pratyush Yadav wrote:
From: "Pratyush Yadav (Google)" <pratyush@xxxxxxxxxx>

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@xxxxxxxxxxxxxxx
Signed-off-by: Pratyush Yadav (Google) <pratyush@xxxxxxxxxx>

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@xxxxxxxxxx>