LoongArch: Add livepatch build (KLP) support
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest14 patches 2 repliesIn review
- v312 patches 15 repliesSuperseded
- v28 patches 3 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 8 patches | 6 replies | Superseded |
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/14 | objtool/LoongArch: Add arch_adjusted_addend() for KLP supporttools/ | +5 | 0 replies | |
| 2/14 | LoongArch: Mark special sections for KLP supportarch/ arch/ arch/ +3 more | +46 | 0 replies | |
| 3/14 | livepatch/klp-build: use -fPIC and drop direct-extern-access on LoongArchscripts/ | +42 | 0 replies | |
| 4/14 | LoongArch: Fix EFI linking with -fdata-sectionsarch/ | +1 | 0 replies | |
| 5/14 | objtool/klp: Add LoongArch jump opcode bytes supporttools/ | +41 | 0 replies | |
| 6/14 | klp-build: Add LoongArch syscall patching macroinclude/ | +22 | 0 replies | |
| 7/14 | LoongArch: Add livepatch build (KLP) supportarch/ tools/ | +3 | 0 replies | |
| 8/14 | LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRYarch/ | +1 | 0 replies | |
| 9/14 | objtool/klp: Convert local label referencestools/ | +48 | 0 replies | |
| 10/14 | objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label referencestools/ | +7 | 0 replies | |
| 11/14 | objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCRELtools/ tools/ tools/ | +93 | 0 replies | |
| 12/14 | objtool/LoongArch: Enable inline alternative cloning for KLPtools/ | +1 | 0 replies | |
| 13/14 | objtool/klp: Keep LoongArch tablejump annotation table entriestools/ | +11 | 0 replies | |
| 14/14 | objtool/klp: Rewrite PC-relative data references to GOT on LoongArchtools/ tools/ tools/ +1 more | +152 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH v4 00/14] LoongArch: Add livepatch build (KLP) support
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/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[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
Signature · 1 line
2.53.0