[PATCH 0/5] riscv: kexec: fix kexec_file with CMA-backed segments
From: Han Gao via B4 Relay
Date: Fri Oct 23 2026 - 03:37:56 EST
I ran into these while doing kexec_file reboots in a loop on a Zhihe
A210 board. Things mostly worked, but every few rounds the next kernel
would hang or purgatory would spin, depending on where the segments and
the DTB happened to land. Most of it goes back to segments now being
allocated from CMA, which exposed a few assumptions that no longer hold.
They are separate bugs, so each one gets its own patch.
Patch 1 lets the RISC-V relocation code turn the MMU off even when the
entry list has no indirection page, which is the normal case with CMA.
Patch 2 fixes the purgatory relocations, which assumed a PC-relative low
part always sits right after its high part. Patches 3 and 4 are in the
generic code: CMA quietly caps the alignment below what the RISC-V
kernel needs, and the tail of CMA segment pages was never cleared even
though the purgatory digest expects zeroes there. Patch 5 reserves the
DTB early enough that a CMA pool cannot be placed on top of it.
With all five applied, the board survives repeated kexec_file reboots,
including the layouts where every segment comes from CMA.
---
Han Gao (5):
riscv: kexec: Disable the MMU before walking the entry list
riscv: kexec_file: Pair PC-relative low parts with their high parts
kexec_file: Honor the segment alignment for CMA allocations
kexec_core: Clear the unused part of CMA segments
riscv: mm: Reserve the DTB before scanning reserved memory
arch/riscv/kernel/kexec_relocate.S | 29 ++++++------
arch/riscv/kernel/machine_kexec_file.c | 84 ++++++++++++++++++++++++++--------
arch/riscv/mm/init.c | 18 ++++----
kernel/kexec_core.c | 6 +--
kernel/kexec_file.c | 7 +++
5 files changed, 99 insertions(+), 45 deletions(-)
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261023-riscv-kexec-cma-fixes-9bc69798a5cf
Best regards,
--
Han Gao <gaohan@xxxxxxxxxxx>