Skip to content

RFC kexec x86 purgatory cleanup

Ard Biesheuvel kexec lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest9 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9x86/purgatory: Drop function entry padding from purgatoryarch/x86/purgatory/Makefile+3 -00 replies
2/9x86/purgatory: Simplify stack handlingarch/x86/include/asm/kexec.h arch/x86/kernel/kexec-bzimage64.c arch/x86/purgatory/entry64.S +2 more+1 -364 replies
3/9x86/purgatory: Drop pointless GDT switcharch/x86/purgatory/setup-x86_64.S+0 -290 replies
4/9x86/purgatory: Avoid absolute reference to GDTarch/x86/purgatory/entry64.S+7 -33 replies
5/9x86/purgatory: Simplify GDT and drop data segmentarch/x86/purgatory/entry64.S+3 -100 replies
6/9kexec: Add support for fully linked purgatory executablesinclude/asm-generic/purgatory.lds kernel/kexec_file.c+101 -10 replies
7/9x86/purgatory: Use fully linked PIE ELF executablearch/x86/include/asm/kexec.h arch/x86/kernel/machine_kexec_64.c arch/x86/purgatory/Makefile+5 -1430 replies
8/9x86/purgatory: Simplify references to regs arrayarch/x86/purgatory/entry64.S+34 -330 replies
9/9kexec: Drop support for partially linked purgatory executableskernel/kexec_file.c+14 -2570 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/9] kexec x86 purgatory cleanup

From: Ard Biesheuvel <[email protected]>

The kexec purgatory is built like a kernel module, i.e., a partially linked ELF object where each section is allocated and placed individually, and all relocations need to be fixed up, even place relative ones.

This makes sense for kernel modules, which share the address space with the core kernel, and contain unresolved references that need to be wired up to symbols in other modules or the kernel itself.

The purgatory, however, is a fully linked binary without any external references, or any overlap with the kernel's virtual address space. So it makes much more sense to create a fully linked ELF executable that can just be loaded and run anywhere in memory.

The purgatory build on x86 has already switched over to position independent codegen, which only leaves a handful of absolute references, which can either be dropped (patch #3) or converted into a RIP-relative one (patch #4). That leaves a purgatory executable that can run at any offset in memory with applying any relocations whatsoever.

Some tweaks are needed to deal with the difference between partially (ET_REL) and fully (ET_DYN/ET_EXEC) linked ELF objects, but with those in place, a substantial amount of complicated ELF allocation, placement and patching/relocation code can simply be dropped.

The last patch in the series removes this code from the generic kexec implementation, but this can only be done once other architectures apply the same changes proposed here for x86 (powerpc, s390 and riscv all implement the purgatory using the shared logic)

Cc Arnd Bergmann <[email protected]>
Cc Eric Biederman <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Kees Cook <[email protected]>
Cc Bill Wendling <[email protected]>
Cc Justin Stitt <[email protected]>
Cc Masahiro Yamada <[email protected]>

Ard Biesheuvel (9):
x86/purgatory: Drop function entry padding from purgatory x86/purgatory: Simplify stack handling x86/purgatory: Drop pointless GDT switch x86/purgatory: Avoid absolute reference to GDT x86/purgatory: Simplify GDT and drop data segment
kexec: Add support for fully linked purgatory executables x86/purgatory: Use fully linked PIE ELF executable x86/purgatory: Simplify references to regs array
kexec: Drop support for partially linked purgatory executables

 arch/x86/include/asm/kexec.h       |   8 -
 arch/x86/kernel/kexec-bzimage64.c  |   8 -
 arch/x86/kernel/machine_kexec_64.c | 127 ----------
 arch/x86/purgatory/Makefile        |  17 +-
 arch/x86/purgatory/entry64.S       |  96 ++++----
 arch/x86/purgatory/setup-x86_64.S  |  31 +--
 arch/x86/purgatory/stack.S         |  18 --
 include/asm-generic/purgatory.lds  |  34 +++
 kernel/kexec_file.c                | 255 +++-----------------
 9 files changed, 125 insertions(+), 469 deletions(-)
 delete mode 100644 arch/x86/purgatory/stack.S
 create mode 100644 include/asm-generic/purgatory.lds
Signature · 1 line
2.44.0.769.g3c40516874-goog