Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chris Down" <chris@chrisdown.name>,
	rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org
Cc: graf@amazon.com, kexec@lists.infradead.org, linux-mm@kvack.org,
	kernel-team@meta.com
Subject: Re: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited
Date: Thu, 03 Dec 2026 06:32:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-247236@kernel.org> (raw)
In-Reply-To: <ac61194cf889a29d390438b68ee9fd30e28d468b.1796126791.git.chris@chrisdown.name>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] kho: err_free_bootmem in kho_init() frees active inherited
  bootmem
- [Medium] kho: kho_init() skips CMA accounting when kho_mem_retrieve()
  fails
--

commit 8ab45df6c0cc32b7be0a781a67fbb61c13c0156f
Author: Chris Down <chris@chrisdown.name>

kho: skip bootmem setup in kho_init() if bootmem was inherited

This commit changes kho_init() to check kho_in.bootmem_phys instead of fdt
when deciding whether to skip releasing bootmem areas to CMA, so inherited
bootmem is left alone even if kho_mem_retrieve() fails and clears
kho_in.fdt_phys.

> diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
> index 15fb892a4412d..43ecef317cfdf 100644
> --- a/kernel/liveupdate/kho_core.c
> +++ b/kernel/liveupdate/kho_core.c
> @@ -1928,10 +1928,16 @@ static __init int kho_init(void)
>  	if (err)
>  		goto err_free_fdt;
>  
> -	if (fdt) {
> +	if (fdt)
>  		kho_in_debugfs_init(&kho_in.dbg, fdt);
> +
> +	/*
> +	 * We've booted from the inherited bootmem. That means this kernel is
> +	 * already using it. As such, leave it alone even if the handover is
> +	 * dropped later.
> +	 */
> +	if (kho_in.bootmem_phys)
>  		return 0;
> -	}
>  
>  	for (int i = 0; i < kho_bootmem_cnt; i++) {
>  		unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr);

[Severity: Medium]
Should the err_free_bootmem unwind path in kho_init() also check
!kho_in.bootmem_phys instead of !is_kho_boot()?

kernel/liveupdate/kho_core.c:kho_init() {
	...
err_free_bootmem:
	kho_out.fdt = NULL;
	if (!is_kho_boot()) {
		for (int i = 0; i < kho_bootmem_cnt; i++) {
			void *start = __va(kho_bootmem[i].addr);
			void *end = start + kho_bootmem[i].size;

			free_reserved_area(start, end, -1, "");
		}
	}
	...
}

Because is_kho_boot() checks kho_in.fdt_phys, if kho_mem_retrieve() fails
and clears kho_in.fdt_phys, a subsequent failure in kho_init() will take
this branch and call free_reserved_area() on the inherited kho_bootmem
regions that the kernel booted out of and already released to the buddy
allocator.

[Severity: Medium]
Should the call to kho_account_incoming_bootmem() at the start of
kho_init() also test kho_in.bootmem_phys rather than is_kho_boot()?

kernel/liveupdate/kho_core.c:kho_init() {
	...
	if (is_kho_boot())
		kho_account_incoming_bootmem();
	...
}

Before kho_mem_retrieve() runs, free_area_init() marks the inherited
kho_bootmem pageblocks as MIGRATE_CMA, and memblock_free_all() releases
their free pages into the MIGRATE_CMA buddy lists.  When kho_mem_retrieve()
fails and clears kho_in.fdt_phys, gating kho_account_incoming_bootmem() on
is_kho_boot() while returning early on kho_in.bootmem_phys leaves those
pageblocks unaccounted in zone->cma_pages and totalcma_pages, causing
CmaFree to exceed CmaTotal in /proc/meminfo.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796126791.git.chris@chrisdown.name?part=1


  parent reply	other threads:[~2026-12-03  6:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down
2026-12-02  6:32 ` [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited Chris Down
2026-12-02 10:59   ` Pratyush Yadav
2026-12-03  2:58     ` Chris Down
2026-12-03  6:32   ` sashiko-bot [this message]
2026-12-02  6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down
2026-12-02 11:14   ` Pratyush Yadav
2026-12-03  2:58     ` Chris Down
2026-12-03  6:32   ` sashiko-bot
2026-12-02 11:24 ` [PATCH v2 0/2] kho: handle failures to reserve preserved memory Mike Rapoport
2026-12-03  2:58   ` Chris Down

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247236@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chris@chrisdown.name \
    --cc=graf@amazon.com \
    --cc=kernel-team@meta.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox