* [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework
@ 2026-10-26 7:51 Jinjie Ruan
2026-10-26 7:51 ` [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset Jinjie Ruan
` (14 more replies)
0 siblings, 15 replies; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
ARM64, LoongArch and RISC-V load the elf core header, initrd, DTB
and cmdline parameters with almost identical code. This series fixes
the bugs in that path. And as Mike suggested, rework the common part
into a helper.
Patch 1 stops using the Image text_offset for arm64, which breaks CMA
segments in both the load and release paths, and rejects images with
a non-zero value.
Patches 2-7 fix the CMA page and elf core header leaks in the retry
loops in arm64 and LoongArch, also fix a modified_cmdline leak
in LoongArch.
Patches 8-10 pass the kbuf fields to crash_prepare_headers() to
simplfy code.
Patch 11 frees the elf core header from the generic post-load cleanup.
Patches 12-15 add kexec_load_other_segments() and convert the three
architectures, and arch_kexec_setup_other_segments() builds
the architecture specific boot parameters (a DTB or a command line).
Tested with kexec_file_load() and kdump on arm64, RISC-V and LoongArch
under QEMU, including the non-zero text_offset rejection.
This series is also available at:
https://github.com/ruanjinjie-eng/linux/tree/kexec_cleanup_v7
Changes in v7:
- Rework the kexec_file load code to avoid code duplication
as Mike suggested.
- Add Acked-by.
- Drop the two non-zero text_offset fix patches
and deprecate .text_offset in arm64 as Mike suggested.
- Drop the x86-32 fix patch.
- Drop the TOCTOU race fix patches.
- Link to v6: https://lore.kernel.org/all/20260921090450.807575-1-ruanjinjie@huawei.com/
Previous Versions are as below:
- v5: https://lore.kernel.org/all/20260918100442.3841135-1-ruanjinjie@huawei.com/
- v4: https://lore.kernel.org/all/20260907125404.922123-1-ruanjinjie@huawei.com/
- v3: https://lore.kernel.org/all/20260826092541.3905933-1-ruanjinjie@huawei.com/
- v2: https://lore.kernel.org/all/20260729031235.2840255-1-ruanjinjie@huawei.com/
- v1: https://lore.kernel.org/all/20260723131242.1537633-1-ruanjinjie@huawei.com/#t
Jinjie Ruan (15):
arm64: kexec_file: Stop using the Image text_offset
kexec: Extract kexec_free_segment_cma() from kimage_free_cma()
arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
arm64: kexec_file: Fix elf_headers memory leak in retry loop
LoongArch: kexec_file: Fix CMA page leaks in segment placement retry
loops
LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
LoongArch: kexec_file: Fix a modified_cmdline leak
arm64: kexec_file: Simplify load_other_segments()
LoongArch: kexec_file: Simplify load_other_segments()
riscv: kexec_file: Simplify load_extra_segments()
kexec: Free the elf core header in kimage_file_post_load_cleanup()
kexec: Add kexec_load_other_segments() helper
arm64: kexec_file: Use kexec_load_other_segments() to simplify code
LoongArch: kexec_file: Use kexec_load_other_segments() to simplify
code
riscv: kexec_file: Use kexec_load_other_segments() to simplify code
arch/arm64/include/asm/kexec.h | 5 -
arch/arm64/kernel/kexec_image.c | 33 +++++--
arch/arm64/kernel/machine_kexec_file.c | 103 ++++-----------------
arch/loongarch/include/asm/kexec.h | 4 -
arch/loongarch/kernel/kexec_efi.c | 20 +++-
arch/loongarch/kernel/kexec_elf.c | 11 ++-
arch/loongarch/kernel/machine_kexec.c | 2 +
arch/loongarch/kernel/machine_kexec_file.c | 96 +++----------------
arch/powerpc/kexec/file_load_64.c | 4 -
arch/riscv/include/asm/kexec.h | 4 -
arch/riscv/kernel/kexec_elf.c | 11 ++-
arch/riscv/kernel/kexec_image.c | 11 ++-
arch/riscv/kernel/machine_kexec_file.c | 79 ++++------------
arch/x86/kernel/machine_kexec_64.c | 4 -
include/linux/kexec.h | 17 ++++
kernel/kexec_core.c | 25 ++---
kernel/kexec_file.c | 99 ++++++++++++++++++++
17 files changed, 248 insertions(+), 280 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 31+ messages in thread
* [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 9:32 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
` (13 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
image_load() adds text_offset to kernel_segment->mem and subtracts it
from kernel_segment->memsz. For CMA backed segments this breaks the
load path: the payload is copied to page_address(cma), which is the CMA
base, while image->start is set to the adjusted address, so kexec jumps
into the middle of the kernel. kimage_map_segment() has the same
mismatch when a segment has been moved.
The adjusted memsz also breaks the release path: the CMA pages are
freed using segment->memsz >> PAGE_SHIFT, which is fewer than were
allocated, leaking the tail of the allocation.
Since commit 751c263bb74f ("arm64: remove TEXT_OFFSET randomization")
TEXT_OFFSET is always zero. This has been upstream since v5.8, so no
LTS kernel carries a non-zero text_offset. Drop the adjustment and
reject images with a non-zero value instead of booting them from a
wrong address. With the adjustment gone, segments stay at their CMA
base and the release size matches the allocation.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Link: https://lore.kernel.org/all/20260921090450.807575-2-ruanjinjie@huawei.com/
Link: https://lore.kernel.org/all/20260921090450.807575-3-ruanjinjie@huawei.com/
Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/kexec_image.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index b8d0fb0a9daf..74d24c8aa2fa 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -80,12 +80,17 @@ static void *image_load(struct kimage *image,
kbuf.bufsz = kernel_len;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
kbuf.memsz = le64_to_cpu(h->image_size);
+ /*
+ * Pre-v5.8 images carry a non-zero text_offset, which is no longer
+ * honored; reject them instead of loading them at a wrong address.
+ */
text_offset = le64_to_cpu(h->text_offset);
+ if (text_offset) {
+ pr_err("Unsupported Image text_offset 0x%lx\n", text_offset);
+ return ERR_PTR(-ENOEXEC);
+ }
kbuf.buf_align = MIN_KIMG_ALIGN;
- /* Adjust kernel segment with TEXT_OFFSET */
- kbuf.memsz += text_offset;
-
kernel_segment_number = image->nr_segments;
/*
@@ -117,8 +122,6 @@ static void *image_load(struct kimage *image,
}
kernel_segment = &image->segment[kernel_segment_number];
- kernel_segment->mem += text_offset;
- kernel_segment->memsz -= text_offset;
image->start = kernel_segment->mem;
kexec_dprintk("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma()
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
2026-10-26 7:51 ` [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 9:41 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
` (12 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Arch loaders truncate nr_segments when a placement fails, so the CMA
pages of the dropped segments become unreachable. Export a per-segment
helper so they can be released first.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Breno Leitao <leitao@debian.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
include/linux/kexec.h | 2 ++
kernel/kexec_core.c | 25 ++++++++++++++-----------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 0af8ae4fdd08..faba26f871a4 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -532,6 +532,7 @@ extern bool kexec_file_dbg_print;
extern void *kimage_map_segment(struct kimage *image, int idx);
extern void kimage_unmap_segment(void *buffer);
+void kexec_free_segment_cma(struct kimage *image, unsigned long idx);
#else /* !CONFIG_KEXEC_CORE */
struct pt_regs;
struct task_struct;
@@ -543,6 +544,7 @@ static inline int kexec_crash_loaded(void) { return 0; }
static inline void *kimage_map_segment(struct kimage *image, int idx)
{ return NULL; }
static inline void kimage_unmap_segment(void *buffer) { }
+static inline void kexec_free_segment_cma(struct kimage *image, unsigned long idx) { }
#define kexec_in_progress false
#endif /* CONFIG_KEXEC_CORE */
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index dc770b9a6d05..03c666ffe18d 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -554,22 +554,25 @@ static void kimage_free_entry(kimage_entry_t entry)
kimage_free_pages(page);
}
-static void kimage_free_cma(struct kimage *image)
+void kexec_free_segment_cma(struct kimage *image, unsigned long idx)
{
- unsigned long i;
+ struct page *cma = image->segment_cma[idx];
+ u32 nr_pages = image->segment[idx].memsz >> PAGE_SHIFT;
- for (i = 0; i < image->nr_segments; i++) {
- struct page *cma = image->segment_cma[i];
- u32 nr_pages = image->segment[i].memsz >> PAGE_SHIFT;
+ if (!cma)
+ return;
- if (!cma)
- continue;
+ arch_kexec_pre_free_pages(page_address(cma), nr_pages);
+ dma_release_from_contiguous(NULL, cma, nr_pages);
+ image->segment_cma[idx] = NULL;
+}
- arch_kexec_pre_free_pages(page_address(cma), nr_pages);
- dma_release_from_contiguous(NULL, cma, nr_pages);
- image->segment_cma[i] = NULL;
- }
+static void kimage_free_cma(struct kimage *image)
+{
+ unsigned long i;
+ for (i = 0; i < image->nr_segments; i++)
+ kexec_free_segment_cma(image, i);
}
void kimage_free(struct kimage *image)
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
2026-10-26 7:51 ` [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset Jinjie Ruan
2026-10-26 7:51 ` [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 9:53 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
` (11 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
The retry loop drops nr_segments, leaking the CMA pages of the failed
segments. Release them first, and disable CMA for the retry: it
ignores buf_min and would hand out the same region forever.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Breno Leitao <leitao@debian.org>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/kexec_image.c | 8 ++++++++
arch/arm64/kernel/machine_kexec_file.c | 5 ++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 74d24c8aa2fa..6ed1991e3142 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -111,6 +111,14 @@ static void *image_load(struct kimage *image,
* We couldn't find space for the other segments; erase the
* kernel segment and try the next available hole.
*/
+ /*
+ * kexec_alloc_contig() ignores buf_min, so disable CMA to
+ * let the retry make progress.
+ */
+ if (image->segment_cma[kernel_segment_number])
+ image->no_cma = true;
+
+ kexec_free_segment_cma(image, kernel_segment_number);
image->nr_segments -= 1;
kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 854d872dfd0f..e48f29167b38 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -179,7 +179,10 @@ int load_other_segments(struct kimage *image,
return 0;
out_err:
- image->nr_segments = orig_segments;
+ while (image->nr_segments > orig_segments) {
+ kexec_free_segment_cma(image, image->nr_segments - 1);
+ image->nr_segments--;
+ }
kvfree(dtb);
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (2 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:00 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
` (10 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
A retry allocates new elf headers and overwrites image->elf_headers,
leaking the previous buffer. Free it before assigning.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/machine_kexec_file.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index e48f29167b38..2f750e5f4fcc 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -112,6 +112,10 @@ int load_other_segments(struct kimage *image,
vfree(headers);
goto out_err;
}
+
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (3 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:13 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
` (9 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
The retry loop drops nr_segments, leaking the CMA pages of the failed
segments. Release them first, and disable CMA for the retry: it
ignores buf_min and would hand out the same region forever.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Youling Tang <tangyouling@kylinos.cn>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Kees Cook <kees@kernel.org>
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
Fixes: 55d990f0084c ("LoongArch: Add EFI binary support for kexec_file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/kexec_efi.c | 8 ++++++++
arch/loongarch/kernel/machine_kexec_file.c | 6 +++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c
index 5ee78ebb1546..d42711b895a2 100644
--- a/arch/loongarch/kernel/kexec_efi.c
+++ b/arch/loongarch/kernel/kexec_efi.c
@@ -86,6 +86,14 @@ static void *efi_kexec_load(struct kimage *image,
* We couldn't find space for the other segments; erase the
* kernel segment and try the next available hole.
*/
+ /*
+ * kexec_alloc_contig() ignores buf_min, so disable CMA to
+ * let the retry make progress.
+ */
+ if (image->segment_cma[kernel_segment_number])
+ image->no_cma = true;
+
+ kexec_free_segment_cma(image, kernel_segment_number);
image->nr_segments -= 1;
kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 5412aa9f3568..62a5be102065 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -217,7 +217,11 @@ int load_other_segments(struct kimage *image,
return 0;
out_err:
- image->nr_segments = orig_segments;
+ while (image->nr_segments > orig_segments) {
+ kexec_free_segment_cma(image, image->nr_segments - 1);
+ image->nr_segments--;
+ }
+
kfree(modified_cmdline);
return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (4 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:21 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak Jinjie Ruan
` (8 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
A retry allocates new elf headers and overwrites image->elf_headers,
leaking the previous buffer. Free it before assigning.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Youling Tang <tangyouling@kylinos.cn>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
Cc: Kees Cook <kees@kernel.org>
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
Fixes: 55d990f0084c ("LoongArch: Add EFI binary support for kexec_file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/machine_kexec_file.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 62a5be102065..3beb6977ecc6 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -166,6 +166,10 @@ int load_other_segments(struct kimage *image,
vfree(headers);
goto out_err;
}
+
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (5 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:28 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
` (7 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
machine_kexec_prepare() copies it to KEXEC_CMDLINE_ADDR and overwrites
the pointer, so free the heap buffer after the copy.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Kexin Liu <liukexin@kylinos.cn>
Cc: Youling Tang <tangyouling@kylinos.cn>
Cc: Qiang Ma <maqianga@uniontech.com>
Cc: Tianyang Zhang <zhangtianyang@loongson.cn>
Cc: George Guo <guodongtai@kylinos.cn>
Cc: stable@vger.kernel.org
Fixes: d162feec6b6e ("LoongArch: Add preparatory infrastructure for kexec_file")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/machine_kexec.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/machine_kexec.c
index 1883cae93bc3..19ccc91b6f2a 100644
--- a/arch/loongarch/kernel/machine_kexec.c
+++ b/arch/loongarch/kernel/machine_kexec.c
@@ -14,6 +14,7 @@
#include <linux/mm.h>
#include <linux/of_fdt.h>
#include <linux/reboot.h>
+#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/sched/task_stack.h>
@@ -56,6 +57,7 @@ int machine_kexec_prepare(struct kimage *kimage)
*/
memcpy((void *)KEXEC_CMDLINE_ADDR, (void *)kimage->arch.cmdline_ptr,
strlen((char *)kimage->arch.cmdline_ptr) + 1);
+ kfree((void *)kimage->arch.cmdline_ptr);
kimage->arch.cmdline_ptr = (unsigned long)KEXEC_CMDLINE_ADDR;
} else {
/* Find the command line */
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments()
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (6 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:32 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 09/15] LoongArch: " Jinjie Ruan
` (6 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Pass the kbuf fields to crash_prepare_headers() and set elf_headers
before kexec_add_buffer(), so the error path needs no vfree()
because arch_kimage_file_post_load_cleanup() will do it.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Breno Leitao <leitao@debian.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/machine_kexec_file.c | 35 +++++++++++---------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index 2f750e5f4fcc..d3d191a5ac89 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -78,47 +78,42 @@ int load_other_segments(struct kimage *image,
char *initrd, unsigned long initrd_len,
char *cmdline)
{
- struct kexec_buf kbuf = {};
+ struct kexec_buf kbuf = {
+ .image = image,
+ /* not allocate anything below the kernel */
+ .buf_min = kernel_load_addr + kernel_size,
+ .buf_max = ULONG_MAX,
+ };
void *dtb = NULL;
unsigned long initrd_load_addr = 0, dtb_len,
orig_segments = image->nr_segments;
int ret = 0;
- kbuf.image = image;
- /* not allocate anything below the kernel */
- kbuf.buf_min = kernel_load_addr + kernel_size;
-
#ifdef CONFIG_CRASH_DUMP
/* load elf core header */
- void *headers;
- unsigned long headers_sz;
if (image->type == KEXEC_TYPE_CRASH) {
- ret = crash_prepare_headers(true, &headers, &headers_sz, NULL);
+ ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
if (ret) {
pr_err("Preparing elf core header failed\n");
goto out_err;
}
- kbuf.buffer = headers;
- kbuf.bufsz = headers_sz;
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
+ image->elf_headers = kbuf.buffer;
+ image->elf_headers_sz = kbuf.bufsz;
+
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = headers_sz;
+ kbuf.memsz = kbuf.bufsz;
kbuf.buf_align = SZ_64K; /* largest supported page size */
- kbuf.buf_max = ULONG_MAX;
kbuf.top_down = true;
ret = kexec_add_buffer(&kbuf);
- if (ret) {
- vfree(headers);
+ if (ret)
goto out_err;
- }
-
- if (unlikely(image->elf_headers))
- vfree(image->elf_headers);
- image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
- image->elf_headers_sz = headers_sz;
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 09/15] LoongArch: kexec_file: Simplify load_other_segments()
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (7 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:40 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments() Jinjie Ruan
` (5 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Pass the kbuf fields to crash_prepare_headers() and set
elf_headers before kexec_add_buffer(), so the error path needs
no vfree() because arch_kimage_file_post_load_cleanup() will do it.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/kernel/machine_kexec_file.c | 38 +++++++++-------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 3beb6977ecc6..6ea60e0faa2c 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -127,11 +127,12 @@ int load_other_segments(struct kimage *image,
unsigned long initrd_load_addr = 0;
unsigned long orig_segments = image->nr_segments;
char *modified_cmdline = NULL;
- struct kexec_buf kbuf = {};
-
- kbuf.image = image;
- /* Don't allocate anything below the kernel */
- kbuf.buf_min = kernel_load_addr + kernel_size;
+ struct kexec_buf kbuf = {
+ .image = image,
+ /* Don't allocate anything below the kernel */
+ .buf_min = kernel_load_addr + kernel_size,
+ .buf_max = ULONG_MAX,
+ };
modified_cmdline = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
if (!modified_cmdline)
@@ -144,35 +145,28 @@ int load_other_segments(struct kimage *image,
#ifdef CONFIG_CRASH_DUMP
/* Load elf core header */
if (image->type == KEXEC_TYPE_CRASH) {
- void *headers;
- unsigned long headers_sz;
-
- ret = crash_prepare_headers(true, &headers, &headers_sz, NULL);
+ ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
if (ret < 0) {
pr_err("Preparing elf core header failed\n");
goto out_err;
}
- kbuf.buffer = headers;
- kbuf.bufsz = headers_sz;
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
+ image->elf_headers = kbuf.buffer;
+ image->elf_headers_sz = kbuf.bufsz;
+
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = headers_sz;
+ kbuf.memsz = kbuf.bufsz;
kbuf.buf_align = SZ_64K; /* largest supported page size */
- kbuf.buf_max = ULONG_MAX;
kbuf.top_down = true;
ret = kexec_add_buffer(&kbuf);
- if (ret < 0) {
- vfree(headers);
+ if (ret < 0)
goto out_err;
- }
-
- if (unlikely(image->elf_headers))
- vfree(image->elf_headers);
- image->elf_headers = headers;
image->elf_load_addr = kbuf.mem;
- image->elf_headers_sz = headers_sz;
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
@@ -181,7 +175,7 @@ int load_other_segments(struct kimage *image,
cmdline_add_mem(&cmdline_tmplen, modified_cmdline);
/* Add the elfcorehdr=size@start parameter to the command line */
- cmdline_add_elfcorehdr(image, &cmdline_tmplen, modified_cmdline, headers_sz);
+ cmdline_add_elfcorehdr(image, &cmdline_tmplen, modified_cmdline, kbuf.bufsz);
}
#endif
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments()
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (8 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 09/15] LoongArch: " Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:42 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup() Jinjie Ruan
` (4 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Pass the kbuf fields to crash_prepare_headers() and set elf_headers
before kexec_add_buffer(), so the error path needs no vfree()
because arch_kimage_file_post_load_cleanup() will do it.
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/riscv/kernel/machine_kexec_file.c | 28 +++++++++++---------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index 26cd2a8bd0cd..ca921b063920 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -247,39 +247,35 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
int ret;
void *fdt;
unsigned long initrd_pbase = 0UL;
- struct kexec_buf kbuf = {};
char *modified_cmdline = NULL;
-
- kbuf.image = image;
- kbuf.buf_min = kernel_start + kernel_len;
- kbuf.buf_max = PFN_PHYS(max_low_pfn);
+ struct kexec_buf kbuf = {
+ .image = image,
+ .buf_min = kernel_start + kernel_len,
+ .buf_max = PFN_PHYS(max_low_pfn),
+ };
#ifdef CONFIG_CRASH_DUMP
/* Add elfcorehdr */
if (image->type == KEXEC_TYPE_CRASH) {
- void *headers;
- unsigned long headers_sz;
- ret = crash_prepare_headers(true, &headers, &headers_sz, NULL);
+ ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
if (ret) {
pr_err("Preparing elf core header failed\n");
goto out;
}
- kbuf.buffer = headers;
- kbuf.bufsz = headers_sz;
+ image->elf_headers = kbuf.buffer;
+ image->elf_headers_sz = kbuf.bufsz;
+
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = headers_sz;
+ kbuf.memsz = kbuf.bufsz;
kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
kbuf.top_down = true;
ret = kexec_add_buffer(&kbuf);
- if (ret) {
- vfree(headers);
+ if (ret)
goto out;
- }
- image->elf_headers = headers;
+
image->elf_load_addr = kbuf.mem;
- image->elf_headers_sz = headers_sz;
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup()
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (9 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments() Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:47 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper Jinjie Ruan
` (3 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
The elf core header buffer is generic state, but arm64, LoongArch,
RISC-V, x86 and powerpc each free it in their post-load cleanup. Move
it into the generic cleanup, which also gives the loader a helper to
release it on error.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/kernel/machine_kexec_file.c | 4 ----
arch/loongarch/kernel/machine_kexec_file.c | 4 ----
arch/powerpc/kexec/file_load_64.c | 4 ----
arch/riscv/kernel/machine_kexec_file.c | 4 ----
arch/x86/kernel/machine_kexec_64.c | 4 ----
kernel/kexec_file.c | 9 +++++++++
6 files changed, 9 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index d3d191a5ac89..e7f280915e8d 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -32,10 +32,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
kvfree(image->arch.dtb);
image->arch.dtb = NULL;
- vfree(image->elf_headers);
- image->elf_headers = NULL;
- image->elf_headers_sz = 0;
-
return kexec_image_post_load_cleanup_default(image);
}
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index 6ea60e0faa2c..c0a799f0d240 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -28,10 +28,6 @@ const struct kexec_file_ops * const kexec_file_loaders[] = {
int arch_kimage_file_post_load_cleanup(struct kimage *image)
{
- vfree(image->elf_headers);
- image->elf_headers = NULL;
- image->elf_headers_sz = 0;
-
return kexec_image_post_load_cleanup_default(image);
}
diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index bd80c5fb1b1f..0cf03cee35a7 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -841,10 +841,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
vfree(image->arch.backup_buf);
image->arch.backup_buf = NULL;
- vfree(image->elf_headers);
- image->elf_headers = NULL;
- image->elf_headers_sz = 0;
-
kvfree(image->arch.fdt);
image->arch.fdt = NULL;
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index ca921b063920..d191351c6055 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -29,10 +29,6 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
kvfree(image->arch.fdt);
image->arch.fdt = NULL;
- vfree(image->elf_headers);
- image->elf_headers = NULL;
- image->elf_headers_sz = 0;
-
return kexec_image_post_load_cleanup_default(image);
}
diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index c3f4a389992d..0a66cc268ee7 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -600,10 +600,6 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
int arch_kimage_file_post_load_cleanup(struct kimage *image)
{
- vfree(image->elf_headers);
- image->elf_headers = NULL;
- image->elf_headers_sz = 0;
-
return kexec_image_post_load_cleanup_default(image);
}
#endif /* CONFIG_KEXEC_FILE */
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 59fb9d71e9d8..62d4cba278a5 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -100,6 +100,13 @@ int kexec_image_post_load_cleanup_default(struct kimage *image)
return image->fops->cleanup(image->image_loader_data);
}
+static void kexec_free_elf_headers(struct kimage *image)
+{
+ vfree(image->elf_headers);
+ image->elf_headers = NULL;
+ image->elf_headers_sz = 0;
+}
+
/*
* Free up memory used by kernel, initrd, and command line. This is temporary
* memory allocation which is not needed any more after these buffers have
@@ -118,6 +125,8 @@ void kimage_file_post_load_cleanup(struct kimage *image)
kfree(image->cmdline_buf);
image->cmdline_buf = NULL;
+ kexec_free_elf_headers(image);
+
vfree(pi->purgatory_buf);
pi->purgatory_buf = NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (10 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup() Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 10:56 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code Jinjie Ruan
` (2 subsequent siblings)
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
arm64, LoongArch and RISC-V duplicate the elf core header and initrd
loading. Move it into a common helper with one arch hook for the boot
parameters; a failure releases everything added for the attempt.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
include/linux/kexec.h | 15 ++++++++
kernel/kexec_file.c | 90 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+)
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index faba26f871a4..de1d83ddc38b 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -259,6 +259,21 @@ int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len);
extern int kexec_add_buffer(struct kexec_buf *kbuf);
int kexec_locate_mem_hole(struct kexec_buf *kbuf);
+struct kexec_load_params {
+ unsigned long kernel_load_addr;
+ unsigned long kernel_size;
+ char *initrd;
+ unsigned long initrd_len;
+ char *cmdline;
+ unsigned long cmdline_len;
+};
+
+int arch_kexec_setup_other_segments(struct kimage *image,
+ struct kexec_load_params *params,
+ unsigned long initrd_load_addr);
+int kexec_load_other_segments(struct kimage *image,
+ struct kexec_load_params *params, bool top_down);
+
#ifndef arch_kexec_locate_mem_hole
/**
* arch_kexec_locate_mem_hole - Find free memory to place the segments.
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index 62d4cba278a5..8b80f1186875 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -1295,3 +1295,93 @@ int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
return 0;
}
#endif /* CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY */
+
+int __weak arch_kexec_setup_other_segments(struct kimage *image,
+ struct kexec_load_params *params,
+ unsigned long initrd_load_addr)
+{
+ return 0;
+}
+
+int kexec_load_other_segments(struct kimage *image,
+ struct kexec_load_params *params, bool top_down)
+{
+ struct kexec_buf kbuf = {
+ .image = image,
+ /* Do not allocate anything below the kernel */
+ .buf_min = params->kernel_load_addr + params->kernel_size,
+ .buf_max = top_down ? PFN_PHYS(max_low_pfn) : ULONG_MAX,
+ };
+
+ unsigned long orig_segments = image->nr_segments;
+ unsigned long initrd_load_addr = 0;
+ int ret = 0;
+
+#ifdef CONFIG_CRASH_DUMP
+ if (image->type == KEXEC_TYPE_CRASH) {
+ ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
+ if (ret) {
+ pr_err("Preparing elf core header failed\n");
+ goto out_err;
+ }
+
+ if (unlikely(image->elf_headers))
+ vfree(image->elf_headers);
+
+ image->elf_headers = kbuf.buffer;
+ image->elf_headers_sz = kbuf.bufsz;
+
+ kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+ kbuf.memsz = kbuf.bufsz;
+ kbuf.buf_align = SZ_64K; /* largest supported page size */
+ kbuf.top_down = true;
+
+ ret = kexec_add_buffer(&kbuf);
+ if (ret)
+ goto out_err;
+
+ image->elf_load_addr = kbuf.mem;
+
+ kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+ image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
+ }
+#endif
+
+ if (params->initrd) {
+ kbuf.buffer = params->initrd;
+ kbuf.bufsz = params->initrd_len;
+ kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+ kbuf.memsz = params->initrd_len;
+ kbuf.buf_align = 0;
+ /* within 1GB-aligned window of up to 32GB in size */
+ if (!top_down)
+ kbuf.buf_max = round_down(params->kernel_load_addr, SZ_1G) +
+ (unsigned long)SZ_1G * 32;
+ kbuf.top_down = top_down;
+
+ ret = kexec_add_buffer(&kbuf);
+ if (ret)
+ goto out_err;
+ initrd_load_addr = kbuf.mem;
+
+ kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+ initrd_load_addr, kbuf.bufsz, kbuf.memsz);
+ }
+
+ ret = arch_kexec_setup_other_segments(image, params,
+ initrd_load_addr);
+ if (ret)
+ goto out_err;
+
+ return 0;
+
+out_err:
+ while (image->nr_segments > orig_segments) {
+ kexec_free_segment_cma(image, image->nr_segments - 1);
+ image->nr_segments--;
+ }
+
+ kexec_free_elf_headers(image);
+
+ return ret;
+}
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (11 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper Jinjie Ruan
@ 2026-10-26 7:51 ` Jinjie Ruan
2026-10-26 11:01 ` sashiko-bot
2026-10-26 7:52 ` [PATCH v7 14/15] LoongArch: " Jinjie Ruan
2026-10-26 7:52 ` [PATCH v7 15/15] riscv: " Jinjie Ruan
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:51 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Replace the local copy with the common helper.
The retry loop stays. And the DTB and the dm-crypt keys move to the setup
hook and the keys are loaded after the initrd now.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/arm64/include/asm/kexec.h | 5 --
arch/arm64/kernel/kexec_image.c | 12 +++-
arch/arm64/kernel/machine_kexec_file.c | 95 ++++----------------------
3 files changed, 23 insertions(+), 89 deletions(-)
diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index 892e5bebda95..8fc04e0e7dad 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -123,11 +123,6 @@ extern const struct kexec_file_ops kexec_image_ops;
int arch_kimage_file_post_load_cleanup(struct kimage *image);
#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
-
-extern int load_other_segments(struct kimage *image,
- unsigned long kernel_load_addr, unsigned long kernel_size,
- char *initrd, unsigned long initrd_len,
- char *cmdline);
#endif
#endif /* __ASSEMBLER__ */
diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
index 6ed1991e3142..f5a7f1f92afc 100644
--- a/arch/arm64/kernel/kexec_image.c
+++ b/arch/arm64/kernel/kexec_image.c
@@ -44,6 +44,12 @@ static void *image_load(struct kimage *image,
struct kexec_buf kbuf = {};
unsigned long text_offset, kernel_segment_number;
struct kexec_segment *kernel_segment;
+ struct kexec_load_params params = {
+ .initrd = initrd,
+ .initrd_len = initrd_len,
+ .cmdline = cmdline,
+ .cmdline_len = cmdline_len,
+ };
int ret;
/*
@@ -101,9 +107,9 @@ static void *image_load(struct kimage *image,
while ((ret = kexec_add_buffer(&kbuf)) == 0) {
/* Try to load additional data */
kernel_segment = &image->segment[kernel_segment_number];
- ret = load_other_segments(image, kernel_segment->mem,
- kernel_segment->memsz, initrd,
- initrd_len, cmdline);
+ params.kernel_load_addr = kernel_segment->mem;
+ params.kernel_size = kernel_segment->memsz;
+ ret = kexec_load_other_segments(image, ¶ms, false);
if (!ret)
break;
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index e7f280915e8d..44754b380bf1 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -63,91 +63,30 @@ int arch_crash_populate_cmem(struct crash_mem *cmem)
}
#endif
-/*
- * Tries to add the initrd and DTB to the image. If it is not possible to find
- * valid locations, this function will undo changes to the image and return non
- * zero.
- */
-int load_other_segments(struct kimage *image,
- unsigned long kernel_load_addr,
- unsigned long kernel_size,
- char *initrd, unsigned long initrd_len,
- char *cmdline)
+int arch_kexec_setup_other_segments(struct kimage *image,
+ struct kexec_load_params *params,
+ unsigned long initrd_load_addr)
{
struct kexec_buf kbuf = {
.image = image,
- /* not allocate anything below the kernel */
- .buf_min = kernel_load_addr + kernel_size,
- .buf_max = ULONG_MAX,
+ .buf_min = params->kernel_load_addr + params->kernel_size,
};
- void *dtb = NULL;
- unsigned long initrd_load_addr = 0, dtb_len,
- orig_segments = image->nr_segments;
- int ret = 0;
+ unsigned long dtb_len;
+ void *dtb;
+ int ret;
-#ifdef CONFIG_CRASH_DUMP
- /* load elf core header */
if (image->type == KEXEC_TYPE_CRASH) {
- ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
- if (ret) {
- pr_err("Preparing elf core header failed\n");
- goto out_err;
- }
-
- if (unlikely(image->elf_headers))
- vfree(image->elf_headers);
-
- image->elf_headers = kbuf.buffer;
- image->elf_headers_sz = kbuf.bufsz;
-
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = kbuf.bufsz;
- kbuf.buf_align = SZ_64K; /* largest supported page size */
- kbuf.top_down = true;
-
- ret = kexec_add_buffer(&kbuf);
- if (ret)
- goto out_err;
-
- image->elf_load_addr = kbuf.mem;
-
- kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
- image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
-
ret = crash_load_dm_crypt_keys(image);
if (ret)
- goto out_err;
- }
-#endif
-
- /* load initrd */
- if (initrd) {
- kbuf.buffer = initrd;
- kbuf.bufsz = initrd_len;
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = initrd_len;
- kbuf.buf_align = 0;
- /* within 1GB-aligned window of up to 32GB in size */
- kbuf.buf_max = round_down(kernel_load_addr, SZ_1G)
- + (unsigned long)SZ_1G * 32;
- kbuf.top_down = false;
-
- ret = kexec_add_buffer(&kbuf);
- if (ret)
- goto out_err;
- initrd_load_addr = kbuf.mem;
-
- kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
- initrd_load_addr, kbuf.bufsz, kbuf.memsz);
+ return ret;
}
/* load dtb */
dtb = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
- initrd_len, cmdline, 0);
+ params->initrd_len, params->cmdline, 0);
if (!dtb) {
pr_err("Preparing for new dtb failed\n");
- ret = -EINVAL;
- goto out_err;
+ return -EINVAL;
}
/* trim it */
@@ -163,8 +102,10 @@ int load_other_segments(struct kimage *image,
kbuf.top_down = true;
ret = kexec_add_buffer(&kbuf);
- if (ret)
- goto out_err;
+ if (ret) {
+ kvfree(dtb);
+ return ret;
+ }
image->arch.dtb = dtb;
image->arch.dtb_mem = kbuf.mem;
@@ -172,12 +113,4 @@ int load_other_segments(struct kimage *image,
kbuf.mem, kbuf.bufsz, kbuf.memsz);
return 0;
-
-out_err:
- while (image->nr_segments > orig_segments) {
- kexec_free_segment_cma(image, image->nr_segments - 1);
- image->nr_segments--;
- }
- kvfree(dtb);
- return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 14/15] LoongArch: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (12 preceding siblings ...)
2026-10-26 7:51 ` [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code Jinjie Ruan
@ 2026-10-26 7:52 ` Jinjie Ruan
2026-10-26 11:12 ` sashiko-bot
2026-10-26 7:52 ` [PATCH v7 15/15] riscv: " Jinjie Ruan
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:52 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Replace the local copy with the common helper. The retry loop stays
and the command line is built in the setup hook.
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/loongarch/include/asm/kexec.h | 4 -
arch/loongarch/kernel/kexec_efi.c | 12 ++-
arch/loongarch/kernel/kexec_elf.c | 11 ++-
arch/loongarch/kernel/machine_kexec_file.c | 94 ++++------------------
4 files changed, 32 insertions(+), 89 deletions(-)
diff --git a/arch/loongarch/include/asm/kexec.h b/arch/loongarch/include/asm/kexec.h
index 6be136e9f0a0..e58cf7e282a9 100644
--- a/arch/loongarch/include/asm/kexec.h
+++ b/arch/loongarch/include/asm/kexec.h
@@ -49,10 +49,6 @@ extern const struct kexec_file_ops kexec_elf_ops;
int arch_kimage_file_post_load_cleanup(struct kimage *image);
#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
-
-extern int load_other_segments(struct kimage *image,
- unsigned long kernel_load_addr, unsigned long kernel_size,
- char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len);
#endif
typedef void (*do_kexec_t)(unsigned long efi_boot,
diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c
index d42711b895a2..1362e51e9171 100644
--- a/arch/loongarch/kernel/kexec_efi.c
+++ b/arch/loongarch/kernel/kexec_efi.c
@@ -44,6 +44,12 @@ static void *efi_kexec_load(struct kimage *image,
unsigned long text_offset, kernel_segment_number;
struct kexec_buf kbuf = {};
struct kexec_segment *kernel_segment;
+ struct kexec_load_params params = {
+ .initrd = initrd,
+ .initrd_len = initrd_len,
+ .cmdline = cmdline,
+ .cmdline_len = cmdline_len,
+ };
struct loongarch_image_header *h;
h = (struct loongarch_image_header *)kernel;
@@ -76,9 +82,9 @@ static void *efi_kexec_load(struct kimage *image,
while ((ret = kexec_add_buffer(&kbuf)) == 0) {
/* Try to load additional data */
kernel_segment = &image->segment[kernel_segment_number];
- ret = load_other_segments(image, kernel_segment->mem,
- kernel_segment->memsz, initrd,
- initrd_len, cmdline, cmdline_len);
+ params.kernel_load_addr = kernel_segment->mem;
+ params.kernel_size = kernel_segment->memsz;
+ ret = kexec_load_other_segments(image, ¶ms, false);
if (!ret)
break;
diff --git a/arch/loongarch/kernel/kexec_elf.c b/arch/loongarch/kernel/kexec_elf.c
index 1b6b64744c7f..47272cfa990d 100644
--- a/arch/loongarch/kernel/kexec_elf.c
+++ b/arch/loongarch/kernel/kexec_elf.c
@@ -62,6 +62,12 @@ static void *elf_kexec_load(struct kimage *image,
struct kexec_buf kbuf = {};
struct kexec_elf_info elf_info;
struct kexec_segment *kernel_segment;
+ struct kexec_load_params params = {
+ .initrd = initrd,
+ .initrd_len = initrd_len,
+ .cmdline = cmdline,
+ .cmdline_len = cmdline_len,
+ };
ret = kexec_build_elf_info(kernel, kernel_len, &ehdr, &elf_info);
if (ret < 0)
@@ -83,8 +89,9 @@ static void *elf_kexec_load(struct kimage *image,
/* Load additional data */
kernel_segment = &image->segment[kernel_segment_number];
- ret = load_other_segments(image, kernel_segment->mem, kernel_segment->memsz,
- initrd, initrd_len, cmdline, cmdline_len);
+ params.kernel_load_addr = kernel_segment->mem;
+ params.kernel_size = kernel_segment->memsz;
+ ret = kexec_load_other_segments(image, ¶ms, false);
if (ret < 0)
goto out;
diff --git a/arch/loongarch/kernel/machine_kexec_file.c b/arch/loongarch/kernel/machine_kexec_file.c
index c0a799f0d240..d65cb40ef047 100644
--- a/arch/loongarch/kernel/machine_kexec_file.c
+++ b/arch/loongarch/kernel/machine_kexec_file.c
@@ -110,112 +110,46 @@ static void cmdline_add_elfcorehdr(struct kimage *image, unsigned long *cmdline_
#endif
-/*
- * Try to add the initrd to the image. If it is not possible to find valid
- * locations, this function will undo changes to the image and return non zero.
- */
-int load_other_segments(struct kimage *image,
- unsigned long kernel_load_addr, unsigned long kernel_size,
- char *initrd, unsigned long initrd_len, char *cmdline, unsigned long cmdline_len)
+int arch_kexec_setup_other_segments(struct kimage *image,
+ struct kexec_load_params *params,
+ unsigned long initrd_load_addr)
{
- int ret = 0;
unsigned long cmdline_tmplen = 0;
- unsigned long initrd_load_addr = 0;
- unsigned long orig_segments = image->nr_segments;
- char *modified_cmdline = NULL;
- struct kexec_buf kbuf = {
- .image = image,
- /* Don't allocate anything below the kernel */
- .buf_min = kernel_load_addr + kernel_size,
- .buf_max = ULONG_MAX,
- };
+ unsigned long cmdline_len = params->cmdline_len;
+ const char *cmdline = params->cmdline;
+ char *modified_cmdline;
modified_cmdline = kzalloc(COMMAND_LINE_SIZE, GFP_KERNEL);
if (!modified_cmdline)
- return -EINVAL;
+ return -ENOMEM;
cmdline_add_loader(&cmdline_tmplen, modified_cmdline);
/* Ensure it's null terminated */
modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0';
#ifdef CONFIG_CRASH_DUMP
- /* Load elf core header */
if (image->type == KEXEC_TYPE_CRASH) {
- ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
- if (ret < 0) {
- pr_err("Preparing elf core header failed\n");
- goto out_err;
- }
-
- if (unlikely(image->elf_headers))
- vfree(image->elf_headers);
-
- image->elf_headers = kbuf.buffer;
- image->elf_headers_sz = kbuf.bufsz;
-
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = kbuf.bufsz;
- kbuf.buf_align = SZ_64K; /* largest supported page size */
- kbuf.top_down = true;
-
- ret = kexec_add_buffer(&kbuf);
- if (ret < 0)
- goto out_err;
-
- image->elf_load_addr = kbuf.mem;
-
- kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
- image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
-
/* Add the mem=size@start parameter to the command line */
cmdline_add_mem(&cmdline_tmplen, modified_cmdline);
/* Add the elfcorehdr=size@start parameter to the command line */
- cmdline_add_elfcorehdr(image, &cmdline_tmplen, modified_cmdline, kbuf.bufsz);
+ cmdline_add_elfcorehdr(image, &cmdline_tmplen, modified_cmdline,
+ image->elf_headers_sz);
}
#endif
- /* Load initrd */
- if (initrd) {
- kbuf.buffer = initrd;
- kbuf.bufsz = initrd_len;
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = initrd_len;
- kbuf.buf_align = 0;
- /* within 1GB-aligned window of up to 32GB in size */
- kbuf.buf_max = round_down(kernel_load_addr, SZ_1G) + (unsigned long)SZ_1G * 32;
- kbuf.top_down = false;
-
- ret = kexec_add_buffer(&kbuf);
- if (ret < 0)
- goto out_err;
- initrd_load_addr = kbuf.mem;
-
- kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
- initrd_load_addr, kbuf.bufsz, kbuf.memsz);
-
- /* Add the initrd=start,size parameter to the command line */
+ /* Add the initrd=start,size parameter to the command line */
+ if (initrd_load_addr)
cmdline_add_initrd(image, &cmdline_tmplen, modified_cmdline, initrd_load_addr);
- }
if (cmdline_len + cmdline_tmplen > COMMAND_LINE_SIZE) {
pr_err("Appending command line exceeds COMMAND_LINE_SIZE\n");
- ret = -EINVAL;
- goto out_err;
+ kfree(modified_cmdline);
+ return -EINVAL;
}
memcpy(modified_cmdline + cmdline_tmplen, cmdline, cmdline_len);
- cmdline = modified_cmdline;
- image->arch.cmdline_ptr = (unsigned long)cmdline;
+ image->arch.cmdline_ptr = (unsigned long)modified_cmdline;
return 0;
-
-out_err:
- while (image->nr_segments > orig_segments) {
- kexec_free_segment_cma(image, image->nr_segments - 1);
- image->nr_segments--;
- }
-
- kfree(modified_cmdline);
- return ret;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* [PATCH v7 15/15] riscv: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
` (13 preceding siblings ...)
2026-10-26 7:52 ` [PATCH v7 14/15] LoongArch: " Jinjie Ruan
@ 2026-10-26 7:52 ` Jinjie Ruan
2026-10-26 11:21 ` sashiko-bot
14 siblings, 1 reply; 31+ messages in thread
From: Jinjie Ruan @ 2026-10-26 7:52 UTC (permalink / raw)
To: catalin.marinas, will, mark.rutland, chenhuacai, kernel, maddy,
mpe, npiggin, chleroy, ritesh.list, sshegde, pjw, palmer, aou,
alex, tglx, mingo, bp, dave.hansen, hpa, akpm, baoquan.he, rppt,
pasha.tatashin, pratyush, thuth, ruanjinjie, leitao, yeoreum.yun,
robh, sourabhjain, kees, coiby.xu, Yeking, tangyouling, maqianga,
zhangtianyang, guodongtai, blum, adityag, hui.wang, sohammetha01,
guoren, gaohan, kai.huang, kas, vishal.l.verma, piliu, jbouron,
mclapinski, me, graf, bgwin, x86, linux-arm-kernel, linux-kernel,
loongarch, linuxppc-dev, linux-riscv, kexec
Replace load_extra_segments() with the common helper.
The purgatory, DTB and kdump command line move to the setup hook. And the elf
core header is now 64K aligned.
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
arch/riscv/include/asm/kexec.h | 4 --
arch/riscv/kernel/kexec_elf.c | 11 ++++-
arch/riscv/kernel/kexec_image.c | 11 ++++-
arch/riscv/kernel/machine_kexec_file.c | 65 ++++++--------------------
4 files changed, 31 insertions(+), 60 deletions(-)
diff --git a/arch/riscv/include/asm/kexec.h b/arch/riscv/include/asm/kexec.h
index b9ee8346cc8c..b0400de9acfd 100644
--- a/arch/riscv/include/asm/kexec.h
+++ b/arch/riscv/include/asm/kexec.h
@@ -69,10 +69,6 @@ struct kimage;
int arch_kimage_file_post_load_cleanup(struct kimage *image);
#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
-int load_extra_segments(struct kimage *image, unsigned long kernel_start,
- unsigned long kernel_len, char *initrd,
- unsigned long initrd_len, char *cmdline,
- unsigned long cmdline_len);
#endif
#endif
diff --git a/arch/riscv/kernel/kexec_elf.c b/arch/riscv/kernel/kexec_elf.c
index 3e9a32acb8f2..202600760f91 100644
--- a/arch/riscv/kernel/kexec_elf.c
+++ b/arch/riscv/kernel/kexec_elf.c
@@ -110,6 +110,12 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
unsigned long new_kernel_pbase = 0UL;
struct elfhdr ehdr;
struct kexec_elf_info elf_info;
+ struct kexec_load_params params = {
+ .initrd = initrd,
+ .initrd_len = initrd_len,
+ .cmdline = cmdline,
+ .cmdline_len = cmdline_len,
+ };
ret = kexec_build_elf_info(kernel_buf, kernel_len, &ehdr, &elf_info);
if (ret)
@@ -126,8 +132,9 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;
- ret = load_extra_segments(image, image->start, kernel_len,
- initrd, initrd_len, cmdline, cmdline_len);
+ params.kernel_load_addr = image->start;
+ params.kernel_size = kernel_len;
+ ret = kexec_load_other_segments(image, ¶ms, true);
out:
kexec_free_elf_info(&elf_info);
return ret ? ERR_PTR(ret) : NULL;
diff --git a/arch/riscv/kernel/kexec_image.c b/arch/riscv/kernel/kexec_image.c
index 51dc89259f16..e0d0aa912a76 100644
--- a/arch/riscv/kernel/kexec_image.c
+++ b/arch/riscv/kernel/kexec_image.c
@@ -42,6 +42,12 @@ static void *image_load(struct kimage *image,
u64 flags;
bool be_image, be_kernel;
struct kexec_buf kbuf = {};
+ struct kexec_load_params params = {
+ .initrd = initrd,
+ .initrd_len = initrd_len,
+ .cmdline = cmdline,
+ .cmdline_len = cmdline_len,
+ };
int ret;
/* Check Image header */
@@ -83,8 +89,9 @@ static void *image_load(struct kimage *image,
pr_info("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kbuf.mem, kbuf.bufsz, kbuf.memsz);
- ret = load_extra_segments(image, kbuf.mem, kbuf.memsz,
- initrd, initrd_len, cmdline, cmdline_len);
+ params.kernel_load_addr = kbuf.mem;
+ params.kernel_size = kbuf.memsz;
+ ret = kexec_load_other_segments(image, ¶ms, true);
out:
return ret ? ERR_PTR(ret) : NULL;
diff --git a/arch/riscv/kernel/machine_kexec_file.c b/arch/riscv/kernel/machine_kexec_file.c
index d191351c6055..e79b71a8b7aa 100644
--- a/arch/riscv/kernel/machine_kexec_file.c
+++ b/arch/riscv/kernel/machine_kexec_file.c
@@ -234,51 +234,26 @@ int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
return 0;
}
-
-int load_extra_segments(struct kimage *image, unsigned long kernel_start,
- unsigned long kernel_len, char *initrd,
- unsigned long initrd_len, char *cmdline,
- unsigned long cmdline_len)
+int arch_kexec_setup_other_segments(struct kimage *image,
+ struct kexec_load_params *params,
+ unsigned long initrd_load_addr)
{
- int ret;
- void *fdt;
- unsigned long initrd_pbase = 0UL;
- char *modified_cmdline = NULL;
+ unsigned long kernel_start = params->kernel_load_addr;
+ char *cmdline = params->cmdline;
struct kexec_buf kbuf = {
.image = image,
- .buf_min = kernel_start + kernel_len,
+ .buf_min = kernel_start + params->kernel_size,
.buf_max = PFN_PHYS(max_low_pfn),
};
+ char *modified_cmdline = NULL;
+ void *fdt;
+ int ret;
#ifdef CONFIG_CRASH_DUMP
- /* Add elfcorehdr */
+ /* Setup cmdline for kdump kernel case */
if (image->type == KEXEC_TYPE_CRASH) {
- ret = crash_prepare_headers(true, &kbuf.buffer, &kbuf.bufsz, NULL);
- if (ret) {
- pr_err("Preparing elf core header failed\n");
- goto out;
- }
-
- image->elf_headers = kbuf.buffer;
- image->elf_headers_sz = kbuf.bufsz;
-
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- kbuf.memsz = kbuf.bufsz;
- kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
- kbuf.top_down = true;
-
- ret = kexec_add_buffer(&kbuf);
- if (ret)
- goto out;
-
- image->elf_load_addr = kbuf.mem;
-
- kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
- image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
-
- /* Setup cmdline for kdump kernel case */
modified_cmdline = setup_kdump_cmdline(image, cmdline,
- cmdline_len);
+ params->cmdline_len);
if (!modified_cmdline) {
pr_err("Setting up cmdline for kdump kernel failed\n");
ret = -EINVAL;
@@ -306,23 +281,9 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,
pr_err("Error update purgatory ret=%d\n", ret);
#endif /* CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY */
- /* Add the initrd to the image */
- if (initrd != NULL) {
- kbuf.buffer = initrd;
- kbuf.bufsz = kbuf.memsz = initrd_len;
- kbuf.buf_align = PAGE_SIZE;
- kbuf.top_down = true;
- kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
- ret = kexec_add_buffer(&kbuf);
- if (ret)
- goto out;
- initrd_pbase = kbuf.mem;
- kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_pbase);
- }
-
/* Add the DTB to the image */
- fdt = of_kexec_alloc_and_setup_fdt(image, initrd_pbase,
- initrd_len, cmdline, 0);
+ fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
+ params->initrd_len, cmdline, 0);
if (!fdt) {
pr_err("Error setting up the new device tree.\n");
ret = -EINVAL;
--
2.34.1
^ permalink raw reply related [flat|nested] 31+ messages in thread
* Re: [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset
2026-10-26 7:51 ` [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset Jinjie Ruan
@ 2026-10-26 9:32 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 9:32 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> image_load() adds text_offset to kernel_segment->mem and subtracts it
> from kernel_segment->memsz. For CMA backed segments this breaks the
> load path: the payload is copied to page_address(cma), which is the CMA
> base, while image->start is set to the adjusted address, so kexec jumps
> into the middle of the kernel. kimage_map_segment() has the same
> mismatch when a segment has been moved.
>
> The adjusted memsz also breaks the release path: the CMA pages are
> freed using segment->memsz >> PAGE_SHIFT, which is fewer than were
> allocated, leaking the tail of the allocation.
>
> Since commit 751c263bb74f ("arm64: remove TEXT_OFFSET randomization")
> TEXT_OFFSET is always zero. This has been upstream since v5.8, so no
> LTS kernel carries a non-zero text_offset. Drop the adjustment and
> reject images with a non-zero value instead of booting them from a
> wrong address. With the adjustment gone, segments stay at their CMA
> base and the release size matches the allocation.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mike Rapoport <rppt@kernel.org>
> Link: https://lore.kernel.org/all/20260921090450.807575-2-ruanjinjie@huawei.com/
> Link: https://lore.kernel.org/all/20260921090450.807575-3-ruanjinjie@huawei.com/
> Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=1
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma()
2026-10-26 7:51 ` [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
@ 2026-10-26 9:41 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 9:41 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Arch loaders truncate nr_segments when a placement fails, so the CMA
> pages of the dropped segments become unreachable. Export a per-segment
> helper so they can be released first.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
> Cc: Pratyush Yadav <pratyush@kernel.org>
> Cc: Breno Leitao <leitao@debian.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=2
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
2026-10-26 7:51 ` [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
@ 2026-10-26 9:53 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 9:53 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] arm64: kexec_file: image_load() skips RAM below CMA on non-CMA retry
--
commit a177040c2457cfc0cd78f4ced8850ba0e9322a44
Author: Jinjie Ruan <ruanjinjie@huawei.com>
arm64: kexec_file: Fix CMA page leaks in segment placement retry loops
This commit frees CMA-backed segments when rewinding image->nr_segments in
image_load() and load_other_segments(), and sets image->no_cma when a
CMA-allocated kernel segment placement retry occurs.
> diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c
> index 74d24c8aa2fad..6ed1991e31429 100644
> --- a/arch/arm64/kernel/kexec_image.c
> +++ b/arch/arm64/kernel/kexec_image.c
> @@ -111,6 +111,14 @@ static void *image_load(struct kimage *image,
> * We couldn't find space for the other segments; erase the
> * kernel segment and try the next available hole.
> */
> + /*
> + * kexec_alloc_contig() ignores buf_min, so disable CMA to
> + * let the retry make progress.
> + */
> + if (image->segment_cma[kernel_segment_number])
> + image->no_cma = true;
> +
> + kexec_free_segment_cma(image, kernel_segment_number);
> image->nr_segments -= 1;
> kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
> kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
[Severity: Medium]
When falling back from a CMA allocation to a non-CMA search in image_load(),
does unconditionally advancing kbuf.buf_min to kernel_segment->mem +
kernel_segment->memsz skip all free RAM below the CMA region?
In image_load(), kbuf.buf_min starts at 0 with kbuf.top_down set to false:
arch/arm64/kernel/kexec_image.c:image_load() {
kbuf.image = image;
kbuf.buf_min = 0;
kbuf.buf_max = ULONG_MAX;
kbuf.top_down = false;
...
while ((ret = kexec_add_buffer(&kbuf)) == 0) {
On the first iteration, kexec_add_buffer() -> kexec_locate_mem_hole() calls
kexec_alloc_contig() before walking memblock:
kernel/kexec_file.c:kexec_locate_mem_hole() {
if (!kexec_alloc_contig(kbuf))
return 0;
if (!IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK))
ret = kexec_walk_resources(kbuf, locate_mem_hole_callback);
else
ret = kexec_walk_memblock(kbuf, locate_mem_hole_callback);
Because kexec_alloc_contig() allocates from the CMA area without consulting
kbuf.buf_min, the bottom-up walk starting from 0 has not run yet.
If load_other_segments() then fails to place initrd or dtb above
kernel_segment->mem + kernel_segment->memsz (for example, when CMA is near
the top of RAM and lacks space for the remaining segments), setting
image->no_cma = true and advancing kbuf.buf_min to kernel_segment->mem +
kernel_segment->memsz causes the next iteration's kexec_walk_memblock() to
search only above the CMA region, where load_other_segments() already failed
to find space.
Should kbuf.buf_min only be updated to kernel_segment->mem +
kernel_segment->memsz when the failed kernel segment was not allocated from
CMA?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=3
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop
2026-10-26 7:51 ` [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
@ 2026-10-26 10:00 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:00 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> A retry allocates new elf headers and overwrites image->elf_headers,
> leaking the previous buffer. Free it before assigning.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Breno Leitao <leitao@debian.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Yeoreum Yun <yeoreum.yun@arm.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: stable@vger.kernel.org
> Fixes: 108aa503657e ("arm64: kexec_file: try more regions if loading segments fails")
> Acked-by: Catalin Marinas <catalin.marinas@arm.com>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=4
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops
2026-10-26 7:51 ` [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
@ 2026-10-26 10:13 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:13 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] LoongArch: kexec_file: efi_kexec_load() skips RAM below CMA on retry
--
commit f502069414c135fd39705a4caf6f9bdd9bb1a976
Author: Jinjie Ruan <ruanjinjie@huawei.com>
LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops
This commit fixes CMA page leaks in efi_kexec_load() and
load_other_segments() when segment placement fails, and disables CMA on
retry so kexec_add_buffer() does not repeatedly allocate the same CMA
region.
Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
> diff --git a/arch/loongarch/kernel/kexec_efi.c b/arch/loongarch/kernel/kexec_efi.c
> index 5ee78ebb1546e..d42711b895a2c 100644
> --- a/arch/loongarch/kernel/kexec_efi.c
> +++ b/arch/loongarch/kernel/kexec_efi.c
> @@ -86,6 +86,14 @@ static void *efi_kexec_load(struct kimage *image,
> * We couldn't find space for the other segments; erase the
> * kernel segment and try the next available hole.
> */
> + /*
> + * kexec_alloc_contig() ignores buf_min, so disable CMA to
> + * let the retry make progress.
> + */
> + if (image->segment_cma[kernel_segment_number])
> + image->no_cma = true;
> +
> + kexec_free_segment_cma(image, kernel_segment_number);
> image->nr_segments -= 1;
> kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
> kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
[Severity: Medium]
When falling back from a CMA allocation to a normal bottom-up System RAM
search in efi_kexec_load(), does advancing kbuf.buf_min skip valid System
RAM located below the CMA region?
Before the retry loop in efi_kexec_load(), kbuf is set up for a bottom-up
search starting at text_offset:
kbuf.top_down = false;
...
kbuf.buf_min = text_offset;
On the first iteration, kexec_add_buffer() -> kexec_locate_mem_hole() ->
kexec_alloc_contig() allocates the kernel segment from CMA, which ignores
kbuf.buf_min and may place the kernel high in physical memory (for example,
near the top of DRAM or above 4GB).
If load_other_segments() then fails to place the initrd because there is
not enough space above the CMA kernel segment, the retry path sets
image->no_cma = true so the next iteration falls back to
kexec_walk_memblock(). However, it still updates kbuf.buf_min:
kbuf.buf_min = kernel_segment->mem + kernel_segment->memsz;
Because the first attempt came from CMA rather than a bottom-up walk from
text_offset, won't advancing kbuf.buf_min past the CMA allocation skip all
System RAM in [text_offset, kernel_segment->mem + kernel_segment->memsz)
and cause kexec_file_load() to fail with -EADDRNOTAVAIL?
Should kbuf.buf_min only be advanced when the failed kernel segment was not
allocated from CMA?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=5
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop
2026-10-26 7:51 ` [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
@ 2026-10-26 10:21 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:21 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> A retry allocates new elf headers and overwrites image->elf_headers,
> leaking the previous buffer. Free it before assigning.
>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: WANG Xuerui <kernel@xen0n.name>
> Cc: Youling Tang <tangyouling@kylinos.cn>
> Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Cc: Sourabh Jain <sourabhjain@linux.ibm.com>
> Cc: Kees Cook <kees@kernel.org>
> Cc: stable@vger.kernel.org
> Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
> Fixes: 55d990f0084c ("LoongArch: Add EFI binary support for kexec_file")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=6
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak
2026-10-26 7:51 ` [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak Jinjie Ruan
@ 2026-10-26 10:28 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:28 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> machine_kexec_prepare() copies it to KEXEC_CMDLINE_ADDR and overwrites
> the pointer, so free the heap buffer after the copy.
>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: WANG Xuerui <kernel@xen0n.name>
> Cc: Kexin Liu <liukexin@kylinos.cn>
> Cc: Youling Tang <tangyouling@kylinos.cn>
> Cc: Qiang Ma <maqianga@uniontech.com>
> Cc: Tianyang Zhang <zhangtianyang@loongson.cn>
> Cc: George Guo <guodongtai@kylinos.cn>
> Cc: stable@vger.kernel.org
> Fixes: d162feec6b6e ("LoongArch: Add preparatory infrastructure for kexec_file")
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=7
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments()
2026-10-26 7:51 ` [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
@ 2026-10-26 10:32 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:32 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Pass the kbuf fields to crash_prepare_headers() and set elf_headers
> before kexec_add_buffer(), so the error path needs no vfree()
> because arch_kimage_file_post_load_cleanup() will do it.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Breno Leitao <leitao@debian.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=8
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 09/15] LoongArch: kexec_file: Simplify load_other_segments()
2026-10-26 7:51 ` [PATCH v7 09/15] LoongArch: " Jinjie Ruan
@ 2026-10-26 10:40 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:40 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Pass the kbuf fields to crash_prepare_headers() and set
> elf_headers before kexec_add_buffer(), so the error path needs
> no vfree() because arch_kimage_file_post_load_cleanup() will do it.
>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=9
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments()
2026-10-26 7:51 ` [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments() Jinjie Ruan
@ 2026-10-26 10:42 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:42 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Pass the kbuf fields to crash_prepare_headers() and set elf_headers
> before kexec_add_buffer(), so the error path needs no vfree()
> because arch_kimage_file_post_load_cleanup() will do it.
>
> Cc: Palmer Dabbelt <palmer@rivosinc.com>
> Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=10
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup()
2026-10-26 7:51 ` [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup() Jinjie Ruan
@ 2026-10-26 10:47 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:47 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> The elf core header buffer is generic state, but arm64, LoongArch,
> RISC-V, x86 and powerpc each free it in their post-load cleanup. Move
> it into the generic cleanup, which also gives the loader a helper to
> release it on error.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: Palmer Dabbelt <palmer@rivosinc.com>
> Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=11
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper
2026-10-26 7:51 ` [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper Jinjie Ruan
@ 2026-10-26 10:56 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 10:56 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> arm64, LoongArch and RISC-V duplicate the elf core header and initrd
> loading. Move it into a common helper with one arch hook for the boot
> parameters; a failure releases everything added for the attempt.
>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=12
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:51 ` [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code Jinjie Ruan
@ 2026-10-26 11:01 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 11:01 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Replace the local copy with the common helper.
>
> The retry loop stays. And the DTB and the dm-crypt keys move to the setup
> hook and the keys are loaded after the initrd now.
>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=13
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 14/15] LoongArch: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:52 ` [PATCH v7 14/15] LoongArch: " Jinjie Ruan
@ 2026-10-26 11:12 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 11:12 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Replace the local copy with the common helper. The retry loop stays
> and the command line is built in the setup hook.
>
> Cc: Huacai Chen <chenhuacai@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=14
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: [PATCH v7 15/15] riscv: kexec_file: Use kexec_load_other_segments() to simplify code
2026-10-26 7:52 ` [PATCH v7 15/15] riscv: " Jinjie Ruan
@ 2026-10-26 11:21 ` sashiko-bot
0 siblings, 0 replies; 31+ messages in thread
From: sashiko-bot @ 2026-10-26 11:21 UTC (permalink / raw)
To: Jinjie Ruan, catalin.marinas, will, mark.rutland, chenhuacai,
kernel, maddy, mpe, npiggin, chleroy, ritesh.list, sshegde, pjw,
palmer, aou, alex, tglx, mingo, bp, dave.hansen, hpa, akpm,
baoquan.he, rppt, pasha.tatashin, pratyush, thuth, leitao,
yeoreum.yun, robh, sourabhjain, kees, coiby.xu, Yeking,
tangyouling, maqianga, zhangtianyang, guodongtai, blum, adityag,
hui.wang, sohammetha01, guoren, gaohan, kai.huang, kas,
vishal.l.verma
> Replace load_extra_segments() with the common helper.
>
> The purgatory, DTB and kdump command line move to the setup hook. And the elf
> core header is now 64K aligned.
>
> Cc: Palmer Dabbelt <palmer@rivosinc.com>
> Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Baoquan He <baoquan.he@linux.dev>
> Cc: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026075201.699550-1-ruanjinjie@huawei.com?part=15
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2026-10-26 11:21 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26 7:51 [PATCH v7 00/15] kexec: Fix CMA and elf header leaks and rework Jinjie Ruan
2026-10-26 7:51 ` [PATCH v7 01/15] arm64: kexec_file: Stop using the Image text_offset Jinjie Ruan
2026-10-26 9:32 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 02/15] kexec: Extract kexec_free_segment_cma() from kimage_free_cma() Jinjie Ruan
2026-10-26 9:41 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 03/15] arm64: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
2026-10-26 9:53 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 04/15] arm64: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
2026-10-26 10:00 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 05/15] LoongArch: kexec_file: Fix CMA page leaks in segment placement retry loops Jinjie Ruan
2026-10-26 10:13 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 06/15] LoongArch: kexec_file: Fix elf_headers memory leak in retry loop Jinjie Ruan
2026-10-26 10:21 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 07/15] LoongArch: kexec_file: Fix a modified_cmdline leak Jinjie Ruan
2026-10-26 10:28 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 08/15] arm64: kexec_file: Simplify load_other_segments() Jinjie Ruan
2026-10-26 10:32 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 09/15] LoongArch: " Jinjie Ruan
2026-10-26 10:40 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 10/15] riscv: kexec_file: Simplify load_extra_segments() Jinjie Ruan
2026-10-26 10:42 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 11/15] kexec: Free the elf core header in kimage_file_post_load_cleanup() Jinjie Ruan
2026-10-26 10:47 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 12/15] kexec: Add kexec_load_other_segments() helper Jinjie Ruan
2026-10-26 10:56 ` sashiko-bot
2026-10-26 7:51 ` [PATCH v7 13/15] arm64: kexec_file: Use kexec_load_other_segments() to simplify code Jinjie Ruan
2026-10-26 11:01 ` sashiko-bot
2026-10-26 7:52 ` [PATCH v7 14/15] LoongArch: " Jinjie Ruan
2026-10-26 11:12 ` sashiko-bot
2026-10-26 7:52 ` [PATCH v7 15/15] riscv: " Jinjie Ruan
2026-10-26 11:21 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox