From: George Guo <dongtai.guo@linux.dev>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: maobibo@loongson.cn, loongarch@lists.linux.dev,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
George Guo <guodongtai@kylinos.cn>
Subject: [PATCH v4 1/2] LoongArch: kexec: use core control page for relocation trampoline to avoid QEMU FDT conflict
Date: Wed, 1 Jul 2026 23:59:56 +0800 [thread overview]
Message-ID: <20260701155957.534779-2-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20260701155957.534779-1-dongtai.guo@linux.dev>
From: George Guo <guodongtai@kylinos.cn>
KEXEC_CONTROL_CODE was hardcoded to TO_CACHE(0x100000). QEMU places its
machine FDT at physical 0x100000 when booting with '-kernel', so
machine_kexec_prepare() overwrote the FDT with the relocation trampoline.
The kexec'd kernel's fdt_setup() then read trampoline code instead of a
valid FDT, earlycon auto-detection failed, and the second kernel booted
silently with no console output.
The trampoline does not need a fixed address. It is executed by the
current kernel to relocate and enter the new kernel, and is dead once the
new kernel starts. Drop KEXEC_CONTROL_CODE and reuse the
control_code_page that the kexec core already allocates (as arm64 and
riscv do). That page is excluded from the relocation copy and lives
nowhere near 0x100000, so the QEMU FDT is left intact.
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
arch/loongarch/kernel/machine_kexec.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/machine_kexec.c
index ced49194d9de..7ced6ca2dadb 100644
--- a/arch/loongarch/kernel/machine_kexec.c
+++ b/arch/loongarch/kernel/machine_kexec.c
@@ -21,8 +21,6 @@
#include <asm/cacheflush.h>
#include <asm/page.h>
-/* 0x100000 ~ 0x200000 is safe */
-#define KEXEC_CONTROL_CODE TO_CACHE(0x100000UL)
#define KEXEC_CMDLINE_ADDR TO_CACHE(0x108000UL)
static unsigned long reboot_code_buffer;
@@ -76,9 +74,14 @@ int machine_kexec_prepare(struct kimage *kimage)
}
}
- /* kexec/kdump need a safe page to save reboot_code_buffer */
- kimage->control_code_page = virt_to_page((void *)KEXEC_CONTROL_CODE);
-
+ /*
+ * kexec/kdump need a safe page to save reboot_code_buffer. Reuse the
+ * control_code_page allocated by the kexec core (as arm64 and riscv
+ * do) instead of a fixed address: the trampoline is only executed by
+ * the current kernel before entering the new kernel, so it needs no
+ * fixed or reserved location. This also stops machine_kexec_prepare()
+ * from overwriting QEMU's machine FDT at 0x100000.
+ */
reboot_code_buffer = (unsigned long)page_address(kimage->control_code_page);
memcpy((void *)reboot_code_buffer, relocate_new_kernel, relocate_new_kernel_size);
--
2.25.1
next prev parent reply other threads:[~2026-07-01 16:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 15:59 [PATCH v4 0/2] LoongArch: kexec: avoid clobbering the QEMU FDT George Guo
2026-07-01 15:59 ` George Guo [this message]
2026-07-01 15:59 ` [PATCH v4 2/2] LoongArch: kexec: load the command line in its own segment George Guo
2026-07-09 9:11 ` [PATCH v4 0/2] LoongArch: kexec: avoid clobbering the QEMU FDT Huacai Chen
2026-07-09 12:48 ` George Guo
2026-07-10 14:12 ` Huacai Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260701155957.534779-2-dongtai.guo@linux.dev \
--to=dongtai.guo@linux.dev \
--cc=chenhuacai@kernel.org \
--cc=guodongtai@kylinos.cn \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox