Debugging kexec failures is painful, as anything going wrong in execution of the critical relocate_kernel() function tends to just lead to a triple fault. Thus leading to *weeks* of my life that I won't get back. Having hacked something up for my own use, I figured I should share it... Add a CONFIG_KEXEC_DEBUG option which sets up a trivial exception handler in that environment, and outputs to the early_printk serial console if configured. Currently only 8250-compatible serial ports are supported, but that could be extended. I had to hack up QEMU support for a PCI serial port which matches what the existing early_printk code can drive, and the *real* 8250_pci driver doesn't seem to cope with that setup at all, but whatever... the kexec code now drives the same 32-bit stride which is all that earlyprintk supports. We can always add more later, if anyone cares. Someone who cares might want to bring the i386 version into line with this, although the lack of rip-based addressing makes all the PIC code a bit harder. David Woodhouse (7): x86/kexec: Add CONFIG_KEXEC_DEBUG option x86/kexec: Debugging support: load a GDT x86/kexec: Debugging support: Load an IDT and basic exception entry points x86/kexec: Debugging support: Dump registers on exception x86/kexec: Add 8250 serial port output x86/kexec: Add 8250 MMIO serial port output [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing arch/x86/Kconfig.debug | 1 + arch/x86/include/asm/kexec.h | 7 + arch/x86/kernel/early_printk.c | 9 ++ arch/x86/kernel/machine_kexec_64.c | 45 +++++++ arch/x86/kernel/relocate_kernel_64.S | 248 +++++++++++++++++++++++++++++++++++ kernel/Kconfig.kexec | 11 ++ 6 files changed, 321 insertions(+) v6: • Rebase onto already-merged fixes in tip/x86/boot. • Move CONFIG_KEXEC_DEBUG to generic kernel/Kconfig.kexec as Bartosz is working on an Arm64 version. v5: https://lore.kernel.org/kexec/20241205153343.3275139-1-dwmw2@xxxxxxxxxxxxx/T/ • Drop [RFC]. • Drop _PAGE_NOPTISHADOW fix, which Ingo already took into tip/x86/urgent. • Add memory-mapped serial port support (32-bit MMIO spacing only). v4 (RFC): https://lore.kernel.org/kexec/20241127190343.44916-1-dwmw2@xxxxxxxxxxxxx/T/ • Add _PAGE_NOPTISHADOW fix for the identmap code. • Drop explicit map of control page, which was masking the identmap bug. v3 (RFC): https://lore.kernel.org/kexec/20241125100815.2512-1-dwmw2@xxxxxxxxxxxxx/T/ • Add CONFIG_KEXEC_DEBUG option and use earlyprintk config. • Allocate PGD separately from control page. • Explicitly map control page into identmap. V2 (RFC): https://lore.kernel.org/kexec/20241122224715.171751-1-dwmw2@xxxxxxxxxxxxx/T/ • Introduce linker script, start to clean up data access. V1 (RFC): https://lore.kernel.org/kexec/20241103054019.3795299-1-dwmw2@xxxxxxxxxxxxx/T/ • Initial proof-of-concept hacks.