Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH v4 00/14] LoongArch: Add livepatch build (KLP) support
@ 2026-07-24 11:41 George Guo
  2026-07-24 11:41 ` [PATCH v4 01/14] objtool/LoongArch: Add arch_adjusted_addend() for KLP support George Guo
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: George Guo @ 2026-07-24 11:41 UTC (permalink / raw)
  To: chenhuacai, jpoimboe, peterz, jikos, mbenes, pmladek
  Cc: kernel, joe.lawrence, rostedt, ardb, nathan,
	nick.desaulniers+lkml, yangtiezhu, jiaxun.yang, wangrui, liukexin,
	guodongtai, xry111, wangyuli, loongarch, live-patching, llvm,
	linux-kernel

This series adds LoongArch support for the klp-build livepatch tooling,
enabling automated livepatch module generation using objtool on
LoongArch.

It is based on Josh Poimboeuf's klp-build series [1] (see base-commit
below, unchanged from v1-v3) and extends it with the LoongArch-specific
objtool and build pieces, plus the toolchain and relocation fixes
required to make livepatch modules load, generate, and run correctly
under both GCC and Clang.

Collaboration
=============

Patch 1 ("objtool/LoongArch: Add arch_adjusted_addend() for KLP support")
and patch 7 ("LoongArch: Add livepatch build (KLP) support") overlap with
WangYuli's earlier LoongArch KLP work [2]. Both now carry
Co-developed-by/Signed-off-by: WangYuli.

WangYuli, please check that the attribution is recorded correctly. If you
consider any other patch in this series to overlap your work, point it out
and I will add the tags in the final version.

Overview
========

 - Patches 1-8: the LoongArch objtool hooks, special-section marking
   (including the inline ALTERNATIVE() replacement), the combined
   -fPIC / -mno-direct-extern-access build fix, EFI linking, the syscall
   patching macro, and wiring up LoongArch klp-build.
 - Patches 9-14: objtool/klp-diff fixes found by running the full
   klp-build flow under GCC and Clang.

Testing
=======

The klp-build integration tests were run on LoongArch under both GCC and
Clang: cmdline-string, proc-version, data-new, gcc-static-local-var-6,
syscall, new-globals, new-function, and shadow-newpid. All of them now
generate a livepatch module, load it, and run.

new-function and shadow-newpid did not build under Clang before this
version; the new objtool/klp-diff patches fix the Clang-specific
failures the suite surfaced. Joe Lawrence's test case was also
reproduced end to end on a Clang-built kernel in a VM (patch load,
tracepoint toggle, clean unload).

Changes since v3 [3]
====================

 - Merged the two build-flag patches (-mno-direct-extern-access and
   -fPIC) into one. The combined patch is one complete thought: for
   LoongArch KLP builds, replace the arch's KBUILD_CFLAGS_KERNEL (dropping
   -fPIE and -mdirect-extern-access) and add -fPIC via KCFLAGS. (Joe
   Lawrence)
 - Moved the LoongArch config checks (CONFIG_RELOCATABLE,
   CONFIG_AS_HAS_EXPLICIT_RELOCS) into validate_config(). (Joe Lawrence)
 - Patch 4 (EFI): fixed the changelog wording and added the
   "/* from the EFI stub */" comment on the wildcard, matching arm64 and
   riscv. (Joe Lawrence)
 - Patch 6 (syscall macro): pad the line continuations with tabs. (Joe
   Lawrence)
 - New patch 12: enable inline ALTERNATIVE() cloning. Joe hit
   "can't find new instruction" livepatching a function that contains an
   ALTERNATIVE(). Mark the .subsection 1 replacement with
   ANNOTATE_DATA_SPECIAL (patch 2) and define ARCH_HAS_INLINE_ALTS for
   LoongArch objtool (patch 12), mirroring arm64. (Joe Lawrence)
 - New patch 13: keep the tablejump annotation table entries. klp-diff
   dropped the table-side word of each .discard.tablejump_annotate pair,
   which crashed objtool on the patch module.
 - New patch 14: rewrite PC-relative data references to GOT. File-local
   static data uses a direct pcalau12i/addi.d pair that cannot reach
   vmlinux from the far livepatch module; convert it to a GOT-indirect
   load when the klp relocation is created. This affects GCC and Clang.

On patch 11 (fold paired ADD/SUB relocations): Clang's integrated
assembler emits the ADD64/SUB64 pair for a "sym - ." whose symbol is
undefined in the current object, where GAS with -mthin-add-sub emits a
single R_LARCH_64_PCREL. Reported to LLVM as issue #210052 [4]. The fold
is kept regardless, since shipping Clang emits the pair.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=klp-build-arm64
[2] https://lore.kernel.org/loongarch/20251203091039.125259-1-wangyuli@aosc.io/
[3] https://lore.kernel.org/all/20260707072031.231066-1-dongtai.guo@linux.dev/
[4] https://github.com/llvm/llvm-project/issues/210052

George Guo (14):
  objtool/LoongArch: Add arch_adjusted_addend() for KLP support
  LoongArch: Mark special sections for KLP support
  livepatch/klp-build: use -fPIC and drop direct-extern-access on
    LoongArch
  LoongArch: Fix EFI linking with -fdata-sections
  objtool/klp: Add LoongArch jump opcode bytes support
  klp-build: Add LoongArch syscall patching macro
  LoongArch: Add livepatch build (KLP) support
  LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
  objtool/klp: Convert local label references
  objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label
    references
  objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL
  objtool/LoongArch: Enable inline alternative cloning for KLP
  objtool/klp: Keep LoongArch tablejump annotation table entries
  objtool/klp: Rewrite PC-relative data references to GOT on LoongArch

 arch/loongarch/Kconfig                        |   2 +
 arch/loongarch/include/asm/alternative-asm.h  |  10 +-
 arch/loongarch/include/asm/alternative.h      |  11 +-
 arch/loongarch/include/asm/asm-extable.h      |  10 +-
 arch/loongarch/include/asm/bug.h              |   1 +
 arch/loongarch/include/asm/jump_label.h       |   2 +
 arch/loongarch/kernel/asm-offsets.c           |  18 ++
 arch/loongarch/kernel/vmlinux.lds.S           |   2 +-
 include/linux/livepatch_helpers.h             |  22 ++
 scripts/livepatch/klp-build                   |  43 +++-
 tools/arch/loongarch/include/asm/inst.h       |  11 +
 tools/objtool/Makefile                        |   3 +-
 tools/objtool/arch/loongarch/decode.c         | 212 ++++++++++++++++++
 .../objtool/arch/loongarch/include/arch/elf.h |  35 +++
 tools/objtool/klp-diff.c                      | 105 ++++++++-
 15 files changed, 473 insertions(+), 14 deletions(-)


base-commit: 85afaba140a4b9f20fe8c8a64b24fc85f022d981
-- 
2.53.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-07-24 11:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 11:41 [PATCH v4 00/14] LoongArch: Add livepatch build (KLP) support George Guo
2026-07-24 11:41 ` [PATCH v4 01/14] objtool/LoongArch: Add arch_adjusted_addend() for KLP support George Guo
2026-07-24 11:41 ` [PATCH v4 02/14] LoongArch: Mark special sections " George Guo
2026-07-24 11:41 ` [PATCH v4 03/14] livepatch/klp-build: use -fPIC and drop direct-extern-access on LoongArch George Guo
2026-07-24 11:41 ` [PATCH v4 04/14] LoongArch: Fix EFI linking with -fdata-sections George Guo
2026-07-24 11:41 ` [PATCH v4 05/14] objtool/klp: Add LoongArch jump opcode bytes support George Guo
2026-07-24 11:41 ` [PATCH v4 06/14] klp-build: Add LoongArch syscall patching macro George Guo
2026-07-24 11:41 ` [PATCH v4 07/14] LoongArch: Add livepatch build (KLP) support George Guo
2026-07-24 11:41 ` [PATCH v4 08/14] LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY George Guo
2026-07-24 11:41 ` [PATCH v4 09/14] objtool/klp: Convert local label references George Guo
2026-07-24 11:41 ` [PATCH v4 10/14] objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for " George Guo
2026-07-24 11:41 ` [PATCH v4 11/14] objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL George Guo
2026-07-24 11:41 ` [PATCH v4 12/14] objtool/LoongArch: Enable inline alternative cloning for KLP George Guo
2026-07-24 11:41 ` [PATCH v4 13/14] objtool/klp: Keep LoongArch tablejump annotation table entries George Guo
2026-07-24 11:41 ` [PATCH v4 14/14] objtool/klp: Rewrite PC-relative data references to GOT on LoongArch George Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox