Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jinjie Ruan" <ruanjinjie@huawei.com>,
	catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
	chenhuacai@kernel.org, kernel@xen0n.name, maddy@linux.ibm.com,
	mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org,
	ritesh.list@gmail.com, sshegde@linux.ibm.com, pjw@kernel.org,
	palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr,
	tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, hpa@zytor.com,
	akpm@linux-foundation.org, baoquan.he@linux.dev, rppt@kernel.org,
	pasha.tatashin@soleen.com, pratyush@kernel.org,
	leitao@debian.org, yeoreum.yun@arm.com, mpilaniy@redhat.com,
	robh@kernel.org, coiby.xu@gmail.com, Yeking@Red54.com,
	prudo@redhat.com, brads@mainlining.org,
	sourabhjain@linux.ibm.com, mkchauras@gmail.com, blum@kernel.org,
	adityag@linux.ibm.com, qirui.001@bytedance.com,
	hui.wang@canonical.com, sohammetha01@gmail.com,
	guoren@kernel.org, gaohan@iscas.ac.cn,
	ionut.nechita@windriver.com, vishal.l.verma@intel.com,
	seanjc@google.com, ardb@kernel. org, richard.lyu@suse.com,
	arnd@arndb.de, tzimmermann@suse.de, rick.p.edgecombe@intel.com,
	kai.huang@intel.com, kas@kernel.org, piliu@redhat.com,
	thuth@redhat.com, shradhagupta@linux.microsoft.com,
	ebiggers@kernel.org, jbouron@amazon.com, me@linux.beauty,
	mclapinski@google.com, graf@amazon.com, tangyouling@kylinos.cn,
	x86@kernel.org, kexec@lists.infradead.org
Subject: Re: [PATCH v8 09/11] kexec: Add kexec_rollback_segments() helper
Date: Thu, 12 Nov 2026 14:15:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-211284@kernel.org> (raw)
In-Reply-To: <20261112133418.4044428-10-ruanjinjie@huawei.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] kexec: missing elfcorehdr_index invalidation in
  kexec_rollback_segments()
--

commit 67c30192060172d9e9af6c0433ce26a5bea934f3
Author: Jinjie Ruan <ruanjinjie@huawei.com>

kexec: Add kexec_rollback_segments() helper

This commit adds a kexec_rollback_segments() helper to release CMA pages
and truncate image->nr_segments when rolling back a partial load attempt.

> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
> index 25c9bef639d27..b4fe5c4188421 100644
> --- a/kernel/kexec_file.c
> +++ b/kernel/kexec_file.c
> @@ -1419,3 +1419,15 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
>  	return 0;
>  }
>  #endif /* CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY */
> +
> +/*
> + * Undo a partial load attempt: release the CMA pages backing
> + * the segments above @nr_segments and drop them from the image.
> + */
> +void kexec_rollback_segments(struct kimage *image, unsigned long nr_segments)
> +{
> +	while (image->nr_segments > nr_segments) {
> +		kexec_free_segment_cma(image, image->nr_segments - 1);
> +		image->nr_segments--;
> +	}
> +}

[Severity: Medium]
Does kexec_rollback_segments() leave a stale image->elfcorehdr_index when
the ELF core header segment is among the dropped segments?

The commit message notes that the helper invalidates the recorded
elfcorehdr segment index when dropped, but the implementation does not
reset image->elfcorehdr_index to -1.  Moreover, kexec_add_elf_core_header()
only records image->elfcorehdr_index when memsz > image->elf_headers_sz
and updates image->elf_headers_sz on the first attempt:

kernel/kexec_file.c:kexec_add_elf_core_header() {
	...
	if (memsz > image->elf_headers_sz) {
		image->elf_headers_sz = memsz;
#ifdef CONFIG_CRASH_HOTPLUG
		image->elfcorehdr_index = image->nr_segments - 1;
#endif
	}
	...
}

If a rollback drops the ELF core header segment, a retry sees
memsz == image->elf_headers_sz and leaves the old index in place, causing
kexec_calculate_store_digests() and handle_hotplug_event() to skip or
reference the wrong segment.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261112133418.4044428-1-ruanjinjie@huawei.com?part=9


  reply	other threads:[~2026-11-12 14:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 13:34 [PATCH v8 00/11] kexec: Rework segment loading and fix CMA retries Jinjie Ruan
2026-11-12 13:34 ` [PATCH v8 01/11] kexec: Free the elf core header in kimage_file_post_load_cleanup() Jinjie Ruan
2026-11-12 13:47   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 02/11] kexec: Add helpers to load the elf core header, initrd and FDT Jinjie Ruan
2026-11-12 13:59   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 03/11] arm64: kexec_file: Load the other segments with common helpers Jinjie Ruan
2026-11-12 13:45   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 04/11] LoongArch: " Jinjie Ruan
2026-11-12 13:52   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 05/11] riscv: kexec_file: Load the extra " Jinjie Ruan
2026-11-12 13:53   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 06/11] x86: kexec_file: Use the common segment helpers Jinjie Ruan
2026-11-12 14:08   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 07/11] powerpc: " Jinjie Ruan
2026-11-12 14:01   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 08/11] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
2026-11-12 14:07   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 09/11] kexec: Add kexec_rollback_segments() helper Jinjie Ruan
2026-11-12 14:15   ` sashiko-bot [this message]
2026-11-12 13:34 ` [PATCH v8 10/11] arm64: kexec_file: Fix CMA segment placement retries Jinjie Ruan
2026-11-12 14:14   ` sashiko-bot
2026-11-12 13:34 ` [PATCH v8 11/11] LoongArch: " Jinjie Ruan
2026-11-12 14:21   ` sashiko-bot

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-211284@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Yeking@Red54.com \
    --cc=adityag@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=baoquan.he@linux.dev \
    --cc=blum@kernel.org \
    --cc=bp@alien8.de \
    --cc=brads@mainlining.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=chleroy@kernel.org \
    --cc=coiby.xu@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiggers@kernel.org \
    --cc=gaohan@iscas.ac.cn \
    --cc=graf@amazon.com \
    --cc=guoren@kernel.org \
    --cc=hpa@zytor.com \
    --cc=hui.wang@canonical.com \
    --cc=ionut.nechita@windriver.com \
    --cc=jbouron@amazon.com \
    --cc=kai.huang@intel.com \
    --cc=kas@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=maddy@linux.ibm.com \
    --cc=mark.rutland@arm.com \
    --cc=mclapinski@google.com \
    --cc=me@linux.beauty \
    --cc=mingo@redhat.com \
    --cc=mkchauras@gmail.com \
    --cc=mpe@ellerman.id.au \
    --cc=mpilaniy@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=piliu@redhat.com \
    --cc=pjw@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=prudo@redhat.com \
    --cc=qirui.001@bytedance.com \
    --cc=richard.lyu@suse.com \
    --cc=rick.p.edgecombe@intel.com \
    --cc=ritesh.list@gmail.com \
    --cc=robh@kernel.org \
    --cc=rppt@kernel.org \
    --cc=ruanjinjie@huawei.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.com \
    --cc=shradhagupta@linux.microsoft.com \
    --cc=sohammetha01@gmail.com \
    --cc=sourabhjain@linux.ibm.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tangyouling@kylinos.cn \
    --cc=tglx@kernel.org \
    --cc=thuth@redhat.com \
    --cc=tzimmermann@suse.de \
    --cc=vishal.l.verma@intel.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    --cc=yeoreum.yun@arm.com \
    /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