From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Joe Lawrence <joe.lawrence@redhat.com>,
Song Liu <song@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org,
Mark Rutland <mark.rutland@arm.com>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH v2 05/12] objtool: Extricate checksum calculation from validate_branch()
Date: Tue, 17 Mar 2026 15:51:05 -0700 [thread overview]
Message-ID: <fe1ee04d49913643d0e653ecb19731a361b863e5.1773787568.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1773787568.git.jpoimboe@kernel.org>
In preparation for porting the checksum code to other arches, make its
functionality independent from the CFG reverse engineering code.
Now that it's no longer called by validate_insn(),
checksum_update_insn() has to manually iterate the alternatives.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/check.c | 71 +++++++++++++++++-------
tools/objtool/include/objtool/checksum.h | 6 +-
2 files changed, 53 insertions(+), 24 deletions(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 2301fb7ff3c8..d428d63b29c6 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2633,8 +2633,7 @@ static bool validate_branch_enabled(void)
{
return opts.stackval ||
opts.orc ||
- opts.uaccess ||
- opts.checksum;
+ opts.uaccess;
}
static int decode_sections(struct objtool_file *file)
@@ -3663,6 +3662,7 @@ static bool skip_alt_group(struct instruction *insn)
return alt_insn->type == INSN_CLAC || alt_insn->type == INSN_STAC;
}
+#ifdef BUILD_KLP
static int checksum_debug_init(struct objtool_file *file)
{
char *dup, *s;
@@ -3705,9 +3705,30 @@ static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
struct instruction *insn)
{
struct reloc *reloc = insn_reloc(file, insn);
+ struct alternative *alt;
unsigned long offset;
struct symbol *sym;
+ for (alt = insn->alts; alt; alt = alt->next) {
+ struct alt_group *alt_group = alt->insn->alt_group;
+
+ checksum_update(func, insn, &alt->type, sizeof(alt->type));
+
+ if (alt_group && alt_group->orig_group) {
+ struct instruction *alt_insn;
+
+ checksum_update(func, insn, &alt_group->feature, sizeof(alt_group->feature));
+
+ for (alt_insn = alt->insn; alt_insn; alt_insn = next_insn_same_sec(file, alt_insn)) {
+ checksum_update_insn(file, func, alt_insn);
+ if (alt_insn == alt_group->last_insn)
+ break;
+ }
+ } else {
+ checksum_update(func, insn, &alt->insn->offset, sizeof(alt->insn->offset));
+ }
+ }
+
if (insn->fake)
return;
@@ -3716,9 +3737,11 @@ static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
if (!reloc) {
struct symbol *call_dest = insn_call_dest(insn);
- if (call_dest)
+ if (call_dest) {
+ /* intra-TU call without reloc */
checksum_update(func, insn, call_dest->demangled_name,
strlen(call_dest->demangled_name));
+ }
return;
}
@@ -3745,6 +3768,29 @@ static void checksum_update_insn(struct objtool_file *file, struct symbol *func,
checksum_update(func, insn, &offset, sizeof(offset));
}
+static int calculate_checksums(struct objtool_file *file)
+{
+ struct instruction *insn;
+ struct symbol *func;
+
+ if (checksum_debug_init(file))
+ return -1;
+
+ for_each_sym(file->elf, func) {
+ if (!is_func_sym(func))
+ continue;
+
+ checksum_init(func);
+
+ func_for_each_insn(file, func, insn)
+ checksum_update_insn(file, func, insn);
+
+ checksum_finish(func);
+ }
+ return 0;
+}
+#endif /* BUILD_KLP */
+
static int validate_branch(struct objtool_file *file, struct symbol *func,
struct instruction *insn, struct insn_state state);
static int do_validate_branch(struct objtool_file *file, struct symbol *func,
@@ -4026,9 +4072,6 @@ static int do_validate_branch(struct objtool_file *file, struct symbol *func,
insn->trace = 0;
next_insn = next_insn_to_validate(file, insn);
- if (opts.checksum && func && insn->sec)
- checksum_update_insn(file, func, insn);
-
if (func && insn_func(insn) && func != insn_func(insn)->pfunc) {
/* Ignore KCFI type preambles, which always fall through */
if (is_prefix_func(func))
@@ -4094,9 +4137,6 @@ static int validate_unwind_hint(struct objtool_file *file,
struct symbol *func = insn_func(insn);
int ret;
- if (opts.checksum)
- checksum_init(func);
-
ret = validate_branch(file, func, insn, *state);
if (ret)
BT_INSN(insn, "<=== (hint)");
@@ -4539,9 +4579,6 @@ static int validate_symbol(struct objtool_file *file, struct section *sec,
func = insn_func(insn);
- if (opts.checksum)
- checksum_init(func);
-
if (opts.trace && !fnmatch(opts.trace, sym->name, 0)) {
trace_enable();
TRACE("%s: validation begin\n", sym->name);
@@ -4554,9 +4591,6 @@ static int validate_symbol(struct objtool_file *file, struct section *sec,
TRACE("%s: validation %s\n\n", sym->name, ret ? "failed" : "end");
trace_disable();
- if (opts.checksum)
- checksum_finish(func);
-
return ret;
}
@@ -5011,10 +5045,6 @@ int check(struct objtool_file *file)
cfi_hash_add(&init_cfi);
cfi_hash_add(&func_cfi);
- ret = checksum_debug_init(file);
- if (ret)
- goto out;
-
ret = decode_sections(file);
if (ret)
goto out;
@@ -5105,6 +5135,9 @@ int check(struct objtool_file *file)
warnings += check_abs_references(file);
if (opts.checksum) {
+ ret = calculate_checksums(file);
+ if (ret)
+ goto out;
ret = create_sym_checksum_section(file);
if (ret)
goto out;
diff --git a/tools/objtool/include/objtool/checksum.h b/tools/objtool/include/objtool/checksum.h
index 7fe21608722a..36a17688c716 100644
--- a/tools/objtool/include/objtool/checksum.h
+++ b/tools/objtool/include/objtool/checksum.h
@@ -32,11 +32,7 @@ static inline void checksum_finish(struct symbol *func)
#else /* !BUILD_KLP */
-static inline void checksum_init(struct symbol *func) {}
-static inline void checksum_update(struct symbol *func,
- struct instruction *insn,
- const void *data, size_t size) {}
-static inline void checksum_finish(struct symbol *func) {}
+static inline int calculate_checksums(struct objtool_file *file) { return -ENOSYS; }
#endif /* !BUILD_KLP */
--
2.53.0
next prev parent reply other threads:[~2026-03-17 22:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 22:51 [PATCH v2 00/12] objtool/arm64: Port klp-build to arm64 Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 01/12] arm64: Annotate intra-function calls Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 02/12] arm64: head: Move boot header to .head.data Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 03/12] arm64: Fix EFI linking with -fdata-sections Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 04/12] crypto: arm64: Move data to .rodata Josh Poimboeuf
2026-03-17 22:51 ` Josh Poimboeuf [this message]
2026-03-17 22:51 ` [PATCH v2 06/12] objtool: Allow setting --mnop without --mcount Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 07/12] kbuild: Only run objtool if there is at least one command Josh Poimboeuf
2026-03-18 19:54 ` Nicolas Schier
2026-03-19 0:49 ` Josh Poimboeuf
2026-03-30 18:49 ` Nicolas Schier
2026-03-17 22:51 ` [PATCH v2 08/12] objtool: Ignore jumps to the end of the function for non-CFG arches Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 09/12] objtool: Allow empty alternatives Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 10/12] objtool: Reuse consecutive string references Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 11/12] objtool: Introduce objtool for arm64 Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 12/12] klp-build: Support cross-compilation Josh Poimboeuf
2026-03-19 4:13 ` [PATCH v2 00/12] objtool/arm64: Port klp-build to arm64 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=fe1ee04d49913643d0e653ecb19731a361b863e5.1773787568.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=herbert@gondor.apana.org.au \
--cc=joe.lawrence@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=will@kernel.org \
--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
all inboxes | Powered by JetHome®