[PATCH 0/7] LoongArch: add KHO support and selftests

George Guo posted 7 patches 2 weeks ago
There is a newer version of this series
arch/loongarch/Kconfig                     |  3 ++
arch/loongarch/include/asm/io.h            |  1 +
arch/loongarch/kernel/machine_kexec.c      |  9 +++-
arch/loongarch/kernel/machine_kexec_file.c | 57 ++++++++++++++++++++++
arch/loongarch/kernel/setup.c              | 27 ++++++++++
tools/testing/selftests/kho/loongarch.conf | 10 ++++
tools/testing/selftests/kho/vmtest.sh      | 38 ++++++++++++---
7 files changed, 135 insertions(+), 10 deletions(-)
create mode 100644 tools/testing/selftests/kho/loongarch.conf
[PATCH 0/7] LoongArch: add KHO support and selftests
Posted by George Guo 2 weeks ago
From: George Guo <guodongtai@kylinos.cn>>

This series adds Kexec Handover (KHO) support for LoongArch64 and
extends the KHO selftest infrastructure to run on LoongArch under QEMU.

KHO support (patches 1-2)
--------------------------
Patch 1 wires up the three pieces needed for KHO on LoongArch:
 - Kconfig: select ARCH_SUPPORTS_KEXEC_HANDOVER for 64BIT
 - machine_kexec_file: call cmdline_add_kho() to pass the KHO FDT and
   scratch buffer addresses via "kho_handover=" on the kernel cmdline
 - setup: parse "kho_handover=" early and call kho_populate()

Patch 2 fixes a duplicate-parameter bug when kexec is invoked with
--reuse-cmdline: the running kernel's cmdline already contains a stale
kho_handover= from the previous load.  load_other_segments() prepends a
fresh entry but appends the original cmdline verbatim, so early_param()
calls kho_populate() twice and the second call overwrites the first with
a stale FDT pointer, panicking early in mm_core_init().

Bug fixes (patches 3-4)
------------------------
Patch 3 fixes a build failure with CONFIG_KFENCE=y: virt_to_phys() and
phys_to_virt() in asm/io.h expand to use offset_in_page() and
page_address(), which require <linux/mm.h> that was not included.

Patch 4 moves KEXEC_CONTROL_CODE from 0x100000 to 0x180000.  QEMU
places its machine FDT at 0x100000 when booting with '-kernel'; the
previous placement silently overwrote the FDT with the relocation
trampoline, breaking earlycon in the kexec'd kernel.

Selftest support (patches 5-7)
-------------------------------
Patch 5 adds loongarch.conf and extends vmtest.sh to recognise
loongarch64 as a build target.  QEMU's LoongArch virt machine is
FDT-only (no ACPI), so 'earlycon' must appear on the kernel cmdline or
the console UART is never discovered and the test log stays empty.

Patch 6 disables SERIO_I8042 and its dependents in the QEMU_KCONFIG
fragment.  QEMU's LoongArch virt machine has no i8042 controller; the
fallback port probe hits a page fault on the memory-mapped I/O range and
panics before reaching userspace.

Patch 7 polls the serial output for the test verdict and kills QEMU once
it appears.  QEMU provides no EFI runtime services on LoongArch, so
machine_restart() falls through to an infinite idle loop and QEMU never
exits after kexec.


George Guo (7):
  LoongArch: Add KHO basic support
  LoongArch: kho: strip stale kho_handover= from reused cmdline
  LoongArch: Add missing linux/mm.h include in asm/io.h
  LoongArch: kexec: avoid overwriting QEMU's machine FDT at 0x100000
  selftests/kho: add LoongArch vmtest support
  selftests/kho: LoongArch: disable PS/2 input devices for QEMU virt
  selftests/kho: handle QEMU not exiting after kexec on LoongArch

 arch/loongarch/Kconfig                     |  3 ++
 arch/loongarch/include/asm/io.h            |  1 +
 arch/loongarch/kernel/machine_kexec.c      |  9 +++-
 arch/loongarch/kernel/machine_kexec_file.c | 57 ++++++++++++++++++++++
 arch/loongarch/kernel/setup.c              | 27 ++++++++++
 tools/testing/selftests/kho/loongarch.conf | 10 ++++
 tools/testing/selftests/kho/vmtest.sh      | 38 ++++++++++++---
 7 files changed, 135 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/kho/loongarch.conf

-- 
2.25.1
Re: [PATCH 0/7] LoongArch: add KHO support and selftests
Posted by Mike Rapoport 2 weeks ago
On Mon, 25 May 2026 14:28:03 +0800, George Guo <dongtai.guo@linux.dev> wrote:

Hi,

> [...]
> 
> Bug fixes (patches 3-4)
> ------------------------
> Patch 3 fixes a build failure with CONFIG_KFENCE=y: virt_to_phys() and
> phys_to_virt() in asm/io.h expand to use offset_in_page() and
> page_address(), which require <linux/mm.h> that was not included.

This fix looks unrelated to KHO, it makes sense to send it as a separate
patch.

> 
> Patch 4 moves KEXEC_CONTROL_CODE from 0x100000 to 0x180000.  QEMU
> places its machine FDT at 0x100000 when booting with '-kernel'; the
> previous placement silently overwrote the FDT with the relocation

And I believe that patch 2 and patch 4 can be folded into patch 1 so
that addition of KHO support will be a single patch.

> trampoline, breaking earlycon in the kexec'd kernel.
> 
> Selftest support (patches 5-7)
> -------------------------------
> Patch 5 adds loongarch.conf and extends vmtest.sh to recognise
> loongarch64 as a build target.  QEMU's LoongArch virt machine is
> FDT-only (no ACPI), so 'earlycon' must appear on the kernel cmdline or
> the console UART is never discovered and the test log stays empty.
> 
> Patch 6 disables SERIO_I8042 and its dependents in the QEMU_KCONFIG
> fragment.  QEMU's LoongArch virt machine has no i8042 controller; the
> fallback port probe hits a page fault on the memory-mapped I/O range and
> panics before reaching userspace.

This should be folded into patch 5 for sure.

> 
> Patch 7 polls the serial output for the test verdict and kills QEMU once
> it appears.  QEMU provides no EFI runtime services on LoongArch, so
> machine_restart() falls through to an infinite idle loop and QEMU never
> exits after kexec.

And since without this selftest would hang on loongarch, the timeout
handing should be folded into patch 5.

In general, the rationale when adding new features is to make sure that
after each patch there are no regressions and the new functionality
either works or cannot be enabled until completely implemented.

-- 
Sincerely yours,
Mike.
Re: [PATCH 0/7] LoongArch: add KHO support and selftests
Posted by Huacai Chen 2 weeks ago
Hi, Mike,

On Mon, May 25, 2026 at 3:48 PM Mike Rapoport <rppt@kernel.org> wrote:
>
> On Mon, 25 May 2026 14:28:03 +0800, George Guo <dongtai.guo@linux.dev> wrote:
>
> Hi,
>
> > [...]
> >
> > Bug fixes (patches 3-4)
> > ------------------------
> > Patch 3 fixes a build failure with CONFIG_KFENCE=y: virt_to_phys() and
> > phys_to_virt() in asm/io.h expand to use offset_in_page() and
> > page_address(), which require <linux/mm.h> that was not included.
>
> This fix looks unrelated to KHO, it makes sense to send it as a separate
> patch.
He tried, but it causes new problems, but I agree this patch has
nothing to do with KHO.
https://lore.kernel.org/loongarch/202605211925.DbDvQ6ii-lkp@intel.com/T/#t

>
> >
> > Patch 4 moves KEXEC_CONTROL_CODE from 0x100000 to 0x180000.  QEMU
> > places its machine FDT at 0x100000 when booting with '-kernel'; the
> > previous placement silently overwrote the FDT with the relocation
>
> And I believe that patch 2 and patch 4 can be folded into patch 1 so
> that addition of KHO support will be a single patch.
Patch 2 should be folded, but Patch 4 can be separate, because it
should be backported.

>
> > trampoline, breaking earlycon in the kexec'd kernel.
> >
> > Selftest support (patches 5-7)
> > -------------------------------
> > Patch 5 adds loongarch.conf and extends vmtest.sh to recognise
> > loongarch64 as a build target.  QEMU's LoongArch virt machine is
> > FDT-only (no ACPI), so 'earlycon' must appear on the kernel cmdline or
> > the console UART is never discovered and the test log stays empty.
> >
> > Patch 6 disables SERIO_I8042 and its dependents in the QEMU_KCONFIG
> > fragment.  QEMU's LoongArch virt machine has no i8042 controller; the
> > fallback port probe hits a page fault on the memory-mapped I/O range and
> > panics before reaching userspace.
>
> This should be folded into patch 5 for sure.
I completely don't know why Patch 6 is needed, for normal use I8042
doesn't cause problems in virtual machines.

Huacai

>
> >
> > Patch 7 polls the serial output for the test verdict and kills QEMU once
> > it appears.  QEMU provides no EFI runtime services on LoongArch, so
> > machine_restart() falls through to an infinite idle loop and QEMU never
> > exits after kexec.
>
> And since without this selftest would hang on loongarch, the timeout
> handing should be folded into patch 5.
>
> In general, the rationale when adding new features is to make sure that
> after each patch there are no regressions and the new functionality
> either works or cannot be enabled until completely implemented.
>
> --
> Sincerely yours,
> Mike.
>
Re: [PATCH 0/7] LoongArch: add KHO support and selftests
Posted by Mike Rapoport 2 weeks ago
Hi,

On 2026-05-25 18:25:08+08:00, Huacai Chen wrote:
> Hi, Mike,
> 
> On Mon, May 25, 2026 at 3:48 PM Mike Rapoport <rppt@kernel.org> wrote:
> 
> > On Mon, 25 May 2026 14:28:03 +0800, George Guo <dongtai.guo@linux.dev> wrote:
> >
> > This fix looks unrelated to KHO, it makes sense to send it as a separate
> > patch.
> 
> He tried, but it causes new problems, but I agree this patch has
> nothing to do with KHO.
> https://lore.kernel.org/loongarch/202605211925.DbDvQ6ii-lkp@intel.com/T/#t
> 
> > And I believe that patch 2 and patch 4 can be folded into patch 1 so
> > that addition of KHO support will be a single patch.
> 
> Patch 2 should be folded, but Patch 4 can be separate, because it
> should be backported.

Fair enough. 
I'd suggest to move the fixes to be the first patches in the series, but
presuming this is going via loongarch tree it's up to you :)

> > This should be folded into patch 5 for sure.
> 
> I completely don't know why Patch 6 is needed, for normal use I8042
> doesn't cause problems in virtual machines.
> 
> Huacai