From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, jpoimboe@kernel.org, peterz@infradead.org,
jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com
Cc: kernel@xen0n.name, joe.lawrence@redhat.com, rostedt@goodmis.org,
ardb@kernel.org, nathan@kernel.org,
nick.desaulniers+lkml@gmail.com, yangtiezhu@loongson.cn,
jiaxun.yang@flygoat.com, liukexin@kylinos.cn,
guodongtai@kylinos.cn, xry111@xry111.site, wangyuli@aosc.io,
loongarch@lists.linux.dev, live-patching@vger.kernel.org,
llvm@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH v3 00/12] LoongArch: Add livepatch build (KLP) support
Date: Tue, 7 Jul 2026 15:20:19 +0800 [thread overview]
Message-ID: <20260707072031.231066-1-dongtai.guo@linux.dev> (raw)
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/v2) and extends it with the LoongArch-specific
objtool and build pieces, plus toolchain/relocation fixes required to
make livepatch modules load, generate, and run correctly under both GCC
and Clang.
Overview:
- Patches 1-8 are unchanged from v2 [3]: the LoongArch objtool hooks,
special-section marking, the -fPIC/-mdirect-extern-access fixes,
EFI linking, KLP_SYSCALL_DEFINEx() support, and finally wiring up
LoongArch klp-build (kept last so the series stays bisectable).
- Patches 9-12 are new in v3, fixing issues Joe Lawrence found across
two rounds of review by actually running the full klp-build flow
(see Changes since v2 below for details).
All new patches (9-12) fix bugs in objtool/klp-diff.c and the LoongArch
Kconfig; none of them touch other architectures.
Testing:
GCC on LoongArch hardware: livepatch modules generated, loaded, and
exercised (unchanged from v2).
Clang 21.1.8 on LoongArch hardware, reproduced end to end with Joe's
exact test case (test-joe.patch below), since it happens to exercise
patches 10-12 together: netif_rx_internal() has __ex_table entries,
a __bug_table entry, and three __jump_table static keys, one of which
(a tracepoint's key) is unexported and not defined in the same
translation unit -- exactly the case patch 12 fixes.
$ cat test-joe.patch
diff --git a/net/core/dev.c b/net/core/dev.c
index 06c195906231..14fd3d5f351a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5717,6 +5717,7 @@ static int netif_rx_internal(struct sk_buff *skb)
unsigned int qtail;
ret = enqueue_to_backlog(skb, smp_processor_id(), &qtail);
+ pr_info("test");
}
return ret;
}
$ LLVM=/path/to/clang-21/bin/ ./scripts/livepatch/klp-build -T test-joe.patch
...
$ ls livepatch-test-joe.ko
klp-build completes cleanly: no "duplicate reloc" (patch 12), no
"Cannot find symbol for section" (patch 9), and the __ex_table/
__jump_table entries for netif_rx_internal are present in the output
module (patches 10-11). The module was then loaded into a VM running
a matching Clang-built kernel:
# insmod livepatch-test-joe.ko
[ 105.584252] livepatch: enabling patch 'livepatch_test_joe'
[ 105.586141] livepatch: 'livepatch_test_joe': starting patching transition
[ 106.824310] livepatch: 'livepatch_test_joe': patching complete
[ 120.036530] test
# cat /sys/kernel/livepatch/livepatch_test_joe/{enabled,transition}
1
0
Toggling the netif_rx tracepoint exercises the jump-table relocation
patch 12 folds for the unexported __tracepoint_netif_rx key, and lets
us cross-check the patch's own pr_info() against independent evidence
that the static branch actually flipped:
# echo 1 > /sys/kernel/debug/tracing/events/net/netif_rx/enable
# ping -c2 127.0.0.1
# cat /sys/kernel/debug/tracing/trace | tail -4
ping-1267 [001] b.... 472.753651: netif_rx: dev=lo skbaddr=... len=84
ping-1267 [001] b.s2. 472.753671: netif_rx: dev=lo skbaddr=... len=84
ping-1267 [001] b.... 473.762993: netif_rx: dev=lo skbaddr=... len=84
ping-1267 [001] b.s2. 473.763096: netif_rx: dev=lo skbaddr=... len=84
# dmesg | tail -4
[ 472.753653] test
[ 472.753671] test
[ 473.762994] test
[ 473.763096] test
Each traced packet has a matching "test" line at the same timestamp
(microsecond-aligned), confirming the tracepoint's static-key
relocation and the patch's own code path are both live at once.
Disabling and unloading works cleanly:
# echo 0 > /sys/kernel/livepatch/livepatch_test_joe/enabled
[ 557.922932] livepatch: 'livepatch_test_joe': starting unpatching transition
[ 558.905248] livepatch: 'livepatch_test_joe': unpatching complete
# rmmod livepatch_test_joe
Changes since v2 [3]:
- Patches 1-8 are unchanged.
- New patch 9: select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY.
arch/loongarch/Makefile already builds with
-fpatchable-function-entry=2, but nothing selected this, so kbuild
ran a pointless recordmcount pass on every object. Harmless under
GCC (GAS always emits a section symbol for recordmcount to anchor
on), but it fails under Clang with -ffunction-sections (as klp-build
uses) for any __weak function that ends up alone in its section,
e.g. sched_clock. (Joe Lawrence)
- New patch 10: convert local-label references in special sections.
GCC/GAS on LoongArch reference __ex_table/__bug_table/__jump_table
entries via a local text label instead of the usual "section symbol
+ offset" that objtool's klp-diff.c assumes; the label is never
cloned into the livepatch module, so such entries were silently
dropped from GCC-built modules with no error at build or load time.
(Joe Lawrence)
- New patch 11: fix ANNOTATE_DATA_SPECIAL parsing for the same local
label references. create_fake_symbols() computed each annotated
entry's offset from the relocation's addend alone, which is only
correct for the section-symbol form; with local labels, every entry
in a special section got offset 0, producing a single fake symbol
that covered (and pulled into the output module) the section's
entire contents instead of just the patched function's entries.
Found while verifying patch 10 with a real special-section entry.
- New patch 12: fold LoongArch's paired ADD/SUB relocations into a
single PC-relative one. The "key - ." field of a __jump_table entry
can come out as two relocations at the same offset (R_LARCH_ADD64 +
R_LARCH_SUB64) when Clang's integrated assembler encounters a key
that isn't defined in the same translation unit (e.g. a tracepoint's
static key); objtool only allows one relocation per offset, so
cloning such an entry failed with "duplicate reloc". (Joe Lawrence)
[1] https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=klp-build-arm64
[2] https://lore.kernel.org/all/20260604065317.219777-1-dongtai.guo@linux.dev/
[3] https://lore.kernel.org/all/20260608100852.325413-1-dongtai.guo@linux.dev/
George Guo (12):
objtool/LoongArch: Add arch_adjusted_addend() for KLP support
LoongArch: Mark special sections for KLP support
livepatch/klp-build: disable direct-extern-access for LoongArch to fix
kernel panic
livepatch/klp-build: build LoongArch with -fPIC to keep GOT-indirect
symbol references
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 in special sections
objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label
references
objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL
arch/loongarch/Kconfig | 2 +
arch/loongarch/include/asm/alternative-asm.h | 5 +-
arch/loongarch/include/asm/alternative.h | 6 +-
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 | 20 ++++
arch/loongarch/kernel/vmlinux.lds.S | 2 +-
include/linux/livepatch_helpers.h | 22 ++++
scripts/livepatch/klp-build | 36 +++++-
tools/objtool/Makefile | 3 +-
tools/objtool/arch/loongarch/decode.c | 108 ++++++++++++++++++
.../objtool/arch/loongarch/include/arch/elf.h | 18 +++
tools/objtool/klp-diff.c | 57 ++++++++-
14 files changed, 280 insertions(+), 12 deletions(-)
base-commit: 85afaba140a4b9f20fe8c8a64b24fc85f022d981
--
2.25.1
next reply other threads:[~2026-07-07 7:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 7:20 George Guo [this message]
2026-07-07 7:20 ` [PATCH v3 01/12] objtool/LoongArch: Add arch_adjusted_addend() for KLP support George Guo
2026-07-07 7:20 ` [PATCH v3 02/12] LoongArch: Mark special sections " George Guo
2026-07-07 7:20 ` [PATCH v3 03/12] livepatch/klp-build: disable direct-extern-access for LoongArch to fix kernel panic George Guo
2026-07-07 7:20 ` [PATCH v3 04/12] livepatch/klp-build: build LoongArch with -fPIC to keep GOT-indirect symbol references George Guo
2026-07-08 15:05 ` Joe Lawrence
2026-07-07 7:20 ` [PATCH v3 05/12] LoongArch: Fix EFI linking with -fdata-sections George Guo
2026-07-08 13:54 ` Joe Lawrence
2026-07-08 16:07 ` Joe Lawrence
2026-07-07 7:20 ` [PATCH v3 06/12] objtool/klp: Add LoongArch jump opcode bytes support George Guo
2026-07-07 7:20 ` [PATCH v3 07/12] klp-build: Add LoongArch syscall patching macro George Guo
2026-07-08 19:18 ` Joe Lawrence
2026-07-07 7:20 ` [PATCH v3 08/12] LoongArch: Add livepatch build (KLP) support George Guo
2026-07-07 7:20 ` [PATCH v3 09/12] LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY George Guo
2026-07-07 7:20 ` [PATCH v3 10/12] objtool/klp: Convert local label references in special sections George Guo
2026-07-07 7:20 ` [PATCH v3 11/12] objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label references George Guo
2026-07-07 7:20 ` [PATCH v3 12/12] objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL George Guo
2026-07-08 13:29 ` Xi Ruoyao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260707072031.231066-1-dongtai.guo@linux.dev \
--to=dongtai.guo@linux.dev \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=guodongtai@kylinos.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=liukexin@kylinos.cn \
--cc=live-patching@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=loongarch@lists.linux.dev \
--cc=mbenes@suse.cz \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=wangyuli@aosc.io \
--cc=xry111@xry111.site \
--cc=yangtiezhu@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox