From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>,
Miroslav Benes <mbenes@suse.cz>,
Joe Lawrence <joe.lawrence@redhat.com>,
live-patching@vger.kernel.org, Song Liu <song@kernel.org>,
laokz <laokz@foxmail.com>, Jiri Kosina <jikos@kernel.org>,
Marcos Paulo de Souza <mpdesouza@suse.com>,
Weinan Liu <wnliu@google.com>,
Fazla Mehrab <a.mehrab@bytedance.com>,
Chen Zhongjin <chenzhongjin@huawei.com>,
Puranjay Mohan <puranjay@kernel.org>
Subject: [PATCH v2 00/62] objtool,livepatch: klp-build livepatch module generation
Date: Fri, 9 May 2025 13:16:24 -0700 [thread overview]
Message-ID: <cover.1746821544.git.jpoimboe@kernel.org> (raw)
This series introduces new objtool features and a klp-build script to
generate livepatch modules using a source .patch as input.
This builds on concepts from the longstanding out-of-tree kpatch [1]
project which began in 2012 and has been used for many years to generate
livepatch modules for production kernels. However, this is a complete
rewrite which incorporates hard-earned lessons from 12+ years of
maintaining kpatch.
Key improvements compared to kpatch-build:
- Integrated with objtool: Leverages objtool's existing control-flow
graph analysis to help detect changed functions.
- Works on vmlinux.o: Supports late-linked objects, making it
compatible with LTO, IBT, and similar.
- Simplified code base: ~3k fewer lines of code.
- Upstream: No more out-of-tree #ifdef hacks, far less cruft.
- Cleaner internals: Vastly simplified logic for symbol/section/reloc
inclusion and special section extraction.
- Robust __LINE__ macro handling: Avoids false positive binary diffs
caused by the __LINE__ macro by introducing a fix-patch-lines script
which injects #line directives into the source .patch to preserve
the original line numbers at compile time.
The primary user interface is the klp-build script which does the
following:
- Builds an original kernel with -function-sections and
-fdata-sections, plus objtool function checksumming.
- Applies the .patch file and rebuilds the kernel using the same
options.
- Runs 'objtool klp diff' to detect changed functions and generate
intermediate binary diff objects.
- Builds a kernel module which links the diff objects with some
livepatch module init code (scripts/livepatch/init.c).
- Finalizes the livepatch module (aka work around linker wreckage)
using 'objtool klp post-link'.
I've tested with a variety of patches on defconfig and Fedora-config
kernels with both GCC and Clang.
These patches can also be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git klp-build-v2
Please test!
[1] https://github.com/dynup/kpatch
Changes since the RFC: https://lore.kernel.org/cover.1725334260.git.jpoimboe@kernel.org
- Too many to list. Doubled the patch count exactly ;-)
Josh Poimboeuf (62):
s390/vmlinux.lds.S: Prevent thunk functions from getting placed with
normal text
vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros
x86/module: Improve relocation error messages
x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation
compiler: Tweak __UNIQUE_ID() naming
compiler.h: Make addressable symbols less of an eyesore
elfnote: Change ELFNOTE() to use __UNIQUE_ID()
kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAME
modpost: Ignore unresolved section bounds symbols
x86/alternative: Refactor INT3 call emulation selftest
objtool: Make find_symbol_containing() less arbitrary
objtool: Speed up SHT_GROUP reindexing
objtool: Fix broken error handling in read_symbols()
objtool: Propagate elf_truncate_section() error in elf_write()
objtool: Add empty symbols to the symbol tree again
objtool: Fix interval tree insertion for zero-length symbols
objtool: Fix weak symbol detection
objtool: Fix x86 addend calculation
objtool: Fix __pa_symbol() relocation handling
objtool: Fix "unexpected end of section" warning for alternatives
objtool: Check for missing annotation entries in read_annotate()
objtool: Const string cleanup
objtool: Clean up compiler flag usage
objtool: Remove .parainstructions reference
objtool: Convert elf iterator macros to use 'struct elf'
objtool: Add section/symbol type helpers
objtool: Mark .cold subfunctions
objtool: Fix weak symbol hole detection for .cold functions
objtool: Mark prefix functions
objtool: Simplify reloc offset calculation in unwind_read_hints()
objtool: Avoid emptying lists for duplicate sections
objtool: Suppress section skipping warnings with --dryrun
objtool: Rename --Werror to --werror
objtool: Reindent check_options[]
objtool: Refactor add_jump_destinations()
objtool: Simplify special symbol handling in elf_update_symbol()
objtool: Generalize elf_create_symbol()
objtool: Generalize elf_create_section()
objtool: Add elf_create_data()
objtool: Introduce elf_create_reloc() and elf_init_reloc()
objtool: Add elf_create_file()
kbuild,x86: Fix module permissions for __jump_table and __bug_table
x86/alternative: Define ELF section entry size for alternatives
x86/jump_label: Define ELF section entry size for jump table
x86/extable: Define ELF section entry size for exception tables
x86/bug: Define ELF section entry size for the bug table
x86/orc: Define ELF section entry size for unwind hints
objtool: Make STACK_FRAME_NON_STANDARD consistent
kbuild,objtool: Defer objtool validation step for CONFIG_LIVEPATCH
objtool/klp: Add --checksum option to generate per-function checksums
objtool/klp: Add --debug-checksum=<funcs> to show per-instruction
checksums
objtool/klp: Introduce klp diff subcommand for diffing object files
objtool/klp: Add --debug option to show cloning decisions
objtool/klp: Add post-link subcommand to finalize livepatch modules
objtool: Disallow duplicate prefix symbols
objtool: Add base objtool support for livepatch modules
livepatch/klp-build: Introduce fix-patch-lines script to avoid
__LINE__ diff noise
livepatch/klp-build: Add stub init code for livepatch modules
livepatch/klp-build: Introduce klp-build script for generating
livepatch modules
livepatch/klp-build: Add --debug option to show cloning decisions
livepatch/klp-build: Add --show-first-changed option to show function
divergence
livepatch: Introduce source code helpers for livepatch modules
MAINTAINERS | 3 +-
arch/Kconfig | 3 +
arch/s390/include/asm/nospec-insn.h | 2 +-
arch/s390/kernel/vmlinux.lds.S | 2 +-
arch/x86/Kconfig | 1 +
arch/x86/include/asm/alternative.h | 7 +-
arch/x86/include/asm/asm.h | 20 +-
arch/x86/include/asm/bug.h | 44 +-
arch/x86/include/asm/jump_label.h | 32 +-
arch/x86/kernel/alternative.c | 53 +-
arch/x86/kernel/kprobes/opt.c | 4 -
arch/x86/kernel/module.c | 15 +-
arch/x86/kernel/unwind_orc.c | 2 +
include/asm-generic/vmlinux.lds.h | 40 +-
include/linux/compiler.h | 8 +-
include/linux/elfnote.h | 13 +-
include/linux/init.h | 3 +-
include/linux/jump_label.h | 20 +-
include/linux/livepatch.h | 25 +-
include/linux/livepatch_external.h | 76 +
include/linux/livepatch_helpers.h | 68 +
include/linux/objtool.h | 16 +-
kernel/extable.c | 2 +
kernel/livepatch/core.c | 8 +-
scripts/Makefile.lib | 6 +-
scripts/Makefile.modfinal | 18 +-
scripts/Makefile.vmlinux_o | 2 +-
scripts/link-vmlinux.sh | 3 +-
scripts/livepatch/fix-patch-lines | 79 +
scripts/livepatch/init.c | 108 ++
scripts/livepatch/klp-build | 781 +++++++++
scripts/mod/modpost.c | 5 +
scripts/module.lds.S | 26 +-
tools/include/linux/interval_tree_generic.h | 2 +-
tools/include/linux/livepatch_external.h | 76 +
tools/objtool/Build | 4 +-
tools/objtool/Makefile | 48 +-
tools/objtool/arch/loongarch/decode.c | 6 +-
tools/objtool/arch/powerpc/decode.c | 6 +-
tools/objtool/arch/x86/decode.c | 68 +-
tools/objtool/arch/x86/special.c | 2 +-
tools/objtool/builtin-check.c | 70 +-
tools/objtool/builtin-klp.c | 53 +
tools/objtool/check.c | 690 +++++---
tools/objtool/elf.c | 812 ++++++---
tools/objtool/include/objtool/arch.h | 5 +-
tools/objtool/include/objtool/builtin.h | 6 +-
tools/objtool/include/objtool/check.h | 6 +-
tools/objtool/include/objtool/checksum.h | 43 +
.../objtool/include/objtool/checksum_types.h | 25 +
tools/objtool/include/objtool/elf.h | 186 +-
tools/objtool/include/objtool/klp.h | 35 +
tools/objtool/include/objtool/objtool.h | 6 +-
tools/objtool/include/objtool/warn.h | 40 +
tools/objtool/klp-diff.c | 1504 +++++++++++++++++
tools/objtool/klp-post-link.c | 165 ++
tools/objtool/objtool.c | 42 +-
tools/objtool/orc_gen.c | 8 +-
tools/objtool/special.c | 4 +-
tools/objtool/sync-check.sh | 1 +
tools/objtool/weak.c | 7 +
61 files changed, 4687 insertions(+), 728 deletions(-)
create mode 100644 include/linux/livepatch_external.h
create mode 100644 include/linux/livepatch_helpers.h
create mode 100755 scripts/livepatch/fix-patch-lines
create mode 100644 scripts/livepatch/init.c
create mode 100755 scripts/livepatch/klp-build
create mode 100644 tools/include/linux/livepatch_external.h
create mode 100644 tools/objtool/builtin-klp.c
create mode 100644 tools/objtool/include/objtool/checksum.h
create mode 100644 tools/objtool/include/objtool/checksum_types.h
create mode 100644 tools/objtool/include/objtool/klp.h
create mode 100644 tools/objtool/klp-diff.c
create mode 100644 tools/objtool/klp-post-link.c
--
2.49.0
next reply other threads:[~2025-05-09 20:17 UTC|newest]
Thread overview: 134+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 20:16 Josh Poimboeuf [this message]
2025-05-09 20:16 ` [PATCH v2 01/62] s390/vmlinux.lds.S: Prevent thunk functions from getting placed with normal text Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 02/62] vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 03/62] x86/module: Improve relocation error messages Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 04/62] x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 05/62] compiler: Tweak __UNIQUE_ID() naming Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 06/62] compiler.h: Make addressable symbols less of an eyesore Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 07/62] elfnote: Change ELFNOTE() to use __UNIQUE_ID() Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 08/62] kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAME Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 09/62] modpost: Ignore unresolved section bounds symbols Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 10/62] x86/alternative: Refactor INT3 call emulation selftest Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 11/62] objtool: Make find_symbol_containing() less arbitrary Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 12/62] objtool: Speed up SHT_GROUP reindexing Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 13/62] objtool: Fix broken error handling in read_symbols() Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 14/62] objtool: Propagate elf_truncate_section() error in elf_write() Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 15/62] objtool: Add empty symbols to the symbol tree again Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 16/62] objtool: Fix interval tree insertion for zero-length symbols Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 17/62] objtool: Fix weak symbol detection Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 18/62] objtool: Fix x86 addend calculation Josh Poimboeuf
2025-05-26 10:23 ` Peter Zijlstra
2025-06-04 23:53 ` Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 19/62] objtool: Fix __pa_symbol() relocation handling Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 20/62] objtool: Fix "unexpected end of section" warning for alternatives Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 21/62] objtool: Check for missing annotation entries in read_annotate() Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 22/62] objtool: Const string cleanup Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 23/62] objtool: Clean up compiler flag usage Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 24/62] objtool: Remove .parainstructions reference Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 25/62] objtool: Convert elf iterator macros to use 'struct elf' Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 26/62] objtool: Add section/symbol type helpers Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 27/62] objtool: Mark .cold subfunctions Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 28/62] objtool: Fix weak symbol hole detection for .cold functions Josh Poimboeuf
2025-05-26 10:38 ` Peter Zijlstra
2025-06-04 23:56 ` Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 29/62] objtool: Mark prefix functions Josh Poimboeuf
2025-05-26 10:43 ` Peter Zijlstra
2025-06-05 0:04 ` Josh Poimboeuf
2025-06-26 22:43 ` Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 30/62] objtool: Simplify reloc offset calculation in unwind_read_hints() Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 31/62] objtool: Avoid emptying lists for duplicate sections Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 32/62] objtool: Suppress section skipping warnings with --dryrun Josh Poimboeuf
2025-05-26 10:52 ` Peter Zijlstra
2025-05-28 10:34 ` Peter Zijlstra
2025-06-05 0:19 ` Josh Poimboeuf
2025-06-05 7:32 ` Peter Zijlstra
2025-06-05 14:52 ` Peter Zijlstra
2025-06-05 16:18 ` Josh Poimboeuf
2025-06-05 0:14 ` Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 33/62] objtool: Rename --Werror to --werror Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 34/62] objtool: Reindent check_options[] Josh Poimboeuf
2025-05-09 20:16 ` [PATCH v2 35/62] objtool: Refactor add_jump_destinations() Josh Poimboeuf
2025-05-23 11:46 ` Joe Lawrence
2025-06-04 23:49 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 36/62] objtool: Simplify special symbol handling in elf_update_symbol() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 37/62] objtool: Generalize elf_create_symbol() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 38/62] objtool: Generalize elf_create_section() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 39/62] objtool: Add elf_create_data() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 40/62] objtool: Introduce elf_create_reloc() and elf_init_reloc() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 41/62] objtool: Add elf_create_file() Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 42/62] kbuild,x86: Fix module permissions for __jump_table and __bug_table Josh Poimboeuf
2025-05-26 11:06 ` Peter Zijlstra
2025-06-05 0:22 ` Josh Poimboeuf
2025-06-05 4:00 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 43/62] x86/alternative: Define ELF section entry size for alternatives Josh Poimboeuf
2025-05-09 21:36 ` Borislav Petkov
2025-05-09 21:54 ` Josh Poimboeuf
2025-05-09 22:12 ` Borislav Petkov
2025-05-09 20:17 ` [PATCH v2 44/62] x86/jump_label: Define ELF section entry size for jump table Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 45/62] x86/extable: Define ELF section entry size for exception tables Josh Poimboeuf
2025-05-28 14:40 ` Joe Lawrence
2025-06-05 22:14 ` Josh Poimboeuf
2025-06-06 3:58 ` Brian Gerst
2025-06-06 7:48 ` Josh Poimboeuf
2025-06-07 1:26 ` Brian Gerst
2025-06-09 17:07 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 46/62] x86/bug: Define ELF section entry size for the bug table Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 47/62] x86/orc: Define ELF section entry size for unwind hints Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 48/62] objtool: Make STACK_FRAME_NON_STANDARD consistent Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 49/62] kbuild,objtool: Defer objtool validation step for CONFIG_LIVEPATCH Josh Poimboeuf
2025-05-28 14:45 ` Joe Lawrence
2025-06-06 0:37 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 50/62] objtool/klp: Add --checksum option to generate per-function checksums Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 51/62] objtool/klp: Add --debug-checksum=<funcs> to show per-instruction checksums Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 52/62] objtool/klp: Introduce klp diff subcommand for diffing object files Josh Poimboeuf
2025-05-13 14:49 ` laokz
2025-05-13 20:45 ` Josh Poimboeuf
2025-05-14 10:32 ` laokz
2025-05-26 18:22 ` Peter Zijlstra
2025-06-05 0:36 ` Josh Poimboeuf
2025-05-26 18:25 ` Peter Zijlstra
2025-05-26 18:27 ` Peter Zijlstra
2025-06-05 7:32 ` Josh Poimboeuf
2025-05-26 18:47 ` Peter Zijlstra
2025-06-05 20:12 ` Josh Poimboeuf
2025-05-26 18:50 ` Peter Zijlstra
2025-06-05 21:17 ` Josh Poimboeuf
2025-05-26 18:57 ` Peter Zijlstra
2025-06-05 22:07 ` Josh Poimboeuf
2025-06-09 18:32 ` Joe Lawrence
2025-06-09 23:21 ` Josh Poimboeuf
2025-06-10 12:39 ` Joe Lawrence
2025-06-10 20:26 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 53/62] objtool/klp: Add --debug option to show cloning decisions Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 54/62] objtool/klp: Add post-link subcommand to finalize livepatch modules Josh Poimboeuf
2025-06-26 23:19 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 55/62] objtool: Disallow duplicate prefix symbols Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 56/62] objtool: Add base objtool support for livepatch modules Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 57/62] livepatch/klp-build: Introduce fix-patch-lines script to avoid __LINE__ diff noise Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 58/62] livepatch/klp-build: Add stub init code for livepatch modules Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 59/62] livepatch/klp-build: Introduce klp-build script for generating " Josh Poimboeuf
2025-06-06 13:05 ` Joe Lawrence
2025-06-06 19:03 ` Josh Poimboeuf
2025-06-06 20:28 ` Josh Poimboeuf
2025-06-06 20:53 ` Joe Lawrence
2025-06-06 20:58 ` Joe Lawrence
2025-06-06 21:35 ` Josh Poimboeuf
2025-06-09 21:20 ` Joe Lawrence
2025-06-09 23:59 ` Josh Poimboeuf
2025-06-10 2:05 ` Joe Lawrence
2025-06-10 2:14 ` Joe Lawrence
2025-06-10 15:41 ` Josh Poimboeuf
2025-06-10 2:34 ` Joe Lawrence
2025-06-10 16:10 ` Josh Poimboeuf
2025-06-11 18:44 ` Joe Lawrence
2025-06-11 19:08 ` Josh Poimboeuf
2025-06-11 19:21 ` Joe Lawrence
2025-06-11 21:44 ` Joe Lawrence
2025-06-11 23:12 ` Josh Poimboeuf
2025-06-12 18:25 ` Joe Lawrence
2025-06-18 22:38 ` Dylan Hatch
2025-06-26 23:27 ` Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 60/62] livepatch/klp-build: Add --debug option to show cloning decisions Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 61/62] livepatch/klp-build: Add --show-first-changed option to show function divergence Josh Poimboeuf
2025-05-09 20:17 ` [PATCH v2 62/62] livepatch: Introduce source code helpers for livepatch modules Josh Poimboeuf
2025-06-12 20:56 ` [PATCH v2 00/62] objtool,livepatch: klp-build livepatch module generation Josh Poimboeuf
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=cover.1746821544.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=a.mehrab@bytedance.com \
--cc=chenzhongjin@huawei.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=laokz@foxmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mpdesouza@suse.com \
--cc=pmladek@suse.com \
--cc=puranjay@kernel.org \
--cc=song@kernel.org \
--cc=wnliu@google.com \
--cc=x86@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).