[PATCH v4 0/2] LoongArch: kexec: avoid clobbering the QEMU FDT

George Guo dongtai.guo at linux.dev
Wed Jul 1 08:59:55 PDT 2026


This series fixes two ways the LoongArch kexec path can clobber the
firmware-provided FDT that QEMU places at physical 0x100000, which made the
second kernel boot silently (earlycon auto-detection reads a corrupted FDT).

Patch 1 moves the relocation trampoline off the hardcoded 0x100000 onto the
kexec core's control_code_page (as arm64/riscv do), so machine_kexec_prepare()
no longer overwrites the FDT.

Patch 2 removes the remaining fixed command-line address (KEXEC_CMDLINE_ADDR,
0x108000).  QEMU's machine FDT declares fdt_totalsize = 1MB and thus claims the
whole [0x100000, 0x200000) upper half of the reserved 2MB, so 0x108000 lives
inside the FDT and only survives because the FDT's real content is small
(~3.6KB) and 0x108000 falls in the trailing slack.  The command line is passed
to the second kernel in register a1, not at a fixed address, so it is loaded
into its own kexec segment instead, removing the overlap regardless of FDT
size.

This addresses the two questions raised on the v3 trampoline patch [1]:
 - "how to avoid the cmdline overlapping FDT" -> patch 2.
 - "how to avoid the control page being corrupted by the new kernel" -> the
   trampoline is executed only by the current kernel and is dead once the new
   kernel starts, so being overwritten afterwards is harmless; the kexec core
   also keeps the control page outside every relocation destination, so it
   cannot be corrupted during relocation.  The command line is different (it is
   read by the new kernel), which is why only the trampoline uses the core page.

Tested with tools/testing/selftests/kho/vmtest.sh on LoongArch (QEMU,
kexec_file_load): the second kernel boots with the full command line and
earlycon, and KHO restore succeeds.

This series depends on [2] ("LoongArch: kexec: Fix address space mismatch in
command line lookup"), whose char head[] change patch 2 builds on.

[1] https://lore.kernel.org/all/20260604114106.391502-1-dongtai.guo@linux.dev/
[2] https://lore.kernel.org/all/20260701023747.56221-1-dongtai.guo@linux.dev/

Changes in v4:
 - Add patch 2: load the command line in its own kexec segment, dropping the
   fixed KEXEC_CMDLINE_ADDR that overlaps the QEMU FDT (addresses the command
   line concern from the v3 review).
 - Patch 1 (relocation trampoline): drop the KEXEC_CMDLINE_ADDR comment added
   in v3 that claimed 0x108000 does not overlap the FDT (it does; patch 2
   removes the fixed address entirely).  No functional change otherwise.

v3: https://lore.kernel.org/all/20260604114106.391502-1-dongtai.guo@linux.dev/
v2: https://lore.kernel.org/all/20260601033820.38805-1-dongtai.guo@linux.dev/
v1: https://lore.kernel.org/all/20260528135828.196953-1-dongtai.guo@linux.dev/

George Guo (2):
  LoongArch: kexec: use core control page for relocation trampoline to
    avoid QEMU FDT conflict
  LoongArch: kexec: load the command line in its own segment

 arch/loongarch/include/asm/kexec.h         |  1 +
 arch/loongarch/kernel/machine_kexec.c      | 38 ++++++++++------------
 arch/loongarch/kernel/machine_kexec_file.c | 33 +++++++++++++++++--
 3 files changed, 49 insertions(+), 23 deletions(-)

-- 
2.25.1




More information about the kexec mailing list