Re: [PATCH v4 1/2] kho: Introduce a helper to init high order pages

Pratyush Yadav <[email protected]>
Newsgroups org.infradead.lists.kexec,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <[email protected]>
On Mon, Aug 03 2026, Pranjal Shrivastava wrote:

> The current KHO restoration logic assumes all multi-page blocks are
> split into independent 4KB pages. Break out a helper to prepare for
> supporting high-order non-compound pages.
>
> Extract kho_init_high_order_page() to handle the refcount pattern
> where only the head page is refcounted. Use the helper for folio
> restoration that requires a similar refcount logic.
>
> Reviewed-by: Samiullah Khawaja <[email protected]>
> Signed-off-by: Pranjal Shrivastava <[email protected]>
> ---
>  kernel/liveupdate/kexec_handover.c | 29 +++++++++++++++++++----------
>  1 file changed, 19 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
> index 4834a809985a..e836efd98795 100644
> --- a/kernel/liveupdate/kexec_handover.c
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -357,6 +357,24 @@ int kho_radix_walk_tree(struct kho_radix_tree *tree,
>  }
>  EXPORT_SYMBOL_GPL(kho_radix_walk_tree);
>  
> +/* For physically contiguous pages. */
> +static void kho_init_high_order_page(struct page *page, unsigned int order)
> +{
> +	unsigned long nr_pages = (1UL << order);
> +
> +	/* Head page gets refcount of 1. */
> +	set_page_count(page, 1);
> +	/* Clear head page's codetag to avoid accounting mismatch. */
> +	clear_page_tag_ref(page);
> +
> +	/* For high-order blocks, tail pages get a page count of zero. */
> +	for (unsigned long i = 1; i < nr_pages; i++) {
> +		set_page_count(page + i, 0);
> +		/* Clear each page's codetag to avoid accounting mismatch. */
> +		clear_page_tag_ref(page + i);
> +	}

That's sneaky...

The patch _almost_ looks like pure code movement, but then adds this
little change. I'm not saying this is intentionally sneaky or anything
of the sort, but these kind of things are easy to miss during code
movement and should get a patch of their own or at least be called out
in the commit message.

I don't know how page tags work, but IIRC when the change was originally
added by Ran, he said that we don't need to clear the tag for tail
pages. That held true for folios, does it not hold true for non-compound
high-order pages?

> +}
> +
>  /* For physically contiguous 0-order pages. */
>  static void kho_init_pages(struct page *page, unsigned long nr_pages)
>  {
> @@ -369,16 +387,7 @@ static void kho_init_pages(struct page *page, unsigned long nr_pages)
>  
>  static void kho_init_folio(struct page *page, unsigned int order)
>  {
> -	unsigned long nr_pages = (1 << order);
> -
> -	/* Head page gets refcount of 1. */
> -	set_page_count(page, 1);
> -	/* Clear head page's codetag to avoid accounting mismatch. */
> -	clear_page_tag_ref(page);
> -
> -	/* For higher order folios, tail pages get a page count of zero. */
> -	for (unsigned long i = 1; i < nr_pages; i++)
> -		set_page_count(page + i, 0);
> +	kho_init_high_order_page(page, order);
>  
>  	if (order > 0)
>  		prep_compound_page(page, order);

-- 
Regards,
Pratyush Yadav
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.