Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Valentin Schneider" <vschneid@redhat.com>,
	linux-mm@kvack.org, x86@kernel.org
Cc: "Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	"Jason Baron" <jbaron@akamai.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ard Biesheuvel" <ardb@kernel.org>,
	"Sami Tolvanen" <samitolvanen@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Josh Triplett" <josh@joshtriplett.org>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Mel Gorman" <mgorman@suse.de>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Masahiro Yamada" <masahiroy@kernel.org>,
	"Han Shen" <shenhan@google.com>,
	"Rik van Riel" <riel@surriel.com>, "Jann Horn" <jannh@google.com>,
	"Dan Carpenter" <dan.carpenter@linaro.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Clark Williams" <williams@redhat.com>,
	"Tomas Glozar" <tglozar@redhat.com>,
	"Yair Podemsky" <ypodemsk@redhat.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Daniel Wagner" <dwagner@suse.de>,
	"Petr Tesarik" <ptesarik@suse.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Dan Beimborn" <Dan.Beimborn@qube-rt.com>,
	"Pak Hung Vincent Chiu" <pak-hung.chiu@qube-rt.com>
Subject: Re: [PATCH v10 06/10] objtool: Add .entry.text validation for static branches
Date: Sat, 28 Nov 2026 20:15:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-239011@kernel.org> (raw)
In-Reply-To: <20261127201221.434876-7-vschneid@redhat.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] objtool: broken jump_label NOP patching for embedded keys in
  get_alt_entry()
- [Medium] objtool: missing state.entry update on cross-section jumps
  into .entry.text
- [Low] objtool: stray vmlinux.o warning line in
  Documentation/objtool.txt
- [Low] objtool: rebase leftovers in objtool.h and read_entry_allowed()
--

commit 4d5983578f6c402f752685ea2eda9b0819f6691d
Author: Josh Poimboeuf <jpoimboe@kernel.org>

objtool: Add .entry.text validation for static branches

This commit adds objtool validation to warn when a static branch in
.entry.text uses a static key that has not been annotated with
ANNOTATE_ENTRY_ALLOWED().

> diff --git a/include/linux/objtool.h b/include/linux/objtool.h
> index af2e68e496e5d..e3d240a03e4c5 100644
> --- a/include/linux/objtool.h
> +++ b/include/linux/objtool.h
> @@ -34,6 +34,19 @@
>  	static void __used __section(".discard.func_stack_frame_non_standard") \
>  		*__func_stack_frame_non_standard_##func = func
>  
> +#define __ANNOTATE_ENTRY_ALLOWED(key) \
> +	static void __used __section(".discard.entry_allowed") \
> +		*__annotate_entry_allowed_##key = &key
> +
> +/*
> + * This is used to tell objtool that a given static key is safe to be used
> + * within .noinstr code, and it doesn't need to generate a warning about it.
> + *
> + * For more information, see tools/objtool/Documentation/objtool.txt,
> + * "non-RO static key usage in entry code"
> + */
> +#define ANNOTATE_ENTRY_ALLOWED(key) __ANNOTATE_ENTRY_ALLOWED(key)
> +
>  /*
>   * STACK_FRAME_NON_STANDARD_FP() is a frame-pointer-specific function ignore
>   * for the case where a function is intentionally missing frame pointer setup,
> @@ -111,6 +124,9 @@
>  #define UNWIND_HINT(type, sp_reg, sp_offset, signal) "\n\t"
>  #define STACK_FRAME_NON_STANDARD(func)
>  #define STACK_FRAME_NON_STANDARD_FP(func)
> +#define __ASM_ANNOTATE(label, type) ""
> +#define ASM_ANNOTATE(type)
> +#define ANNOTATE_ENTRY_ALLOWED(key)
>  #else
>  .macro UNWIND_HINT type:req sp_reg=0 sp_offset=0 signal=0
>  .endm

[Severity: Low]
This isn't a bug, but the !CONFIG_OBJTOOL block re-introduces a dead
two-argument __ASM_ANNOTATE(label, type) macro and a duplicate
ASM_ANNOTATE(type) definition that were moved to include/linux/annotate.h in
d2c60bde1c0f ("objtool: Move ANNOTATE* macros to annotate.h") and updated in
305c8dc47717 ("objtool: Consolidate annotation macros").

Also, the comment above ANNOTATE_ENTRY_ALLOWED() still refers to .noinstr
code rather than .entry.text, and the fatal return -1 paths in
read_entry_allowed() in tools/objtool/check.c use WARN_FUNC() and WARN()
instead of ERROR_FUNC() and ERROR() per 3e7be635937d ("objtool: Change
"warning:" to "error: " for fatal errors").

> diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt
> index 9e97fc25b2d8a..bb35a422c9a80 100644
> --- a/tools/objtool/Documentation/objtool.txt
> +++ b/tools/objtool/Documentation/objtool.txt
> @@ -456,6 +456,21 @@ the objtool maintainers.
>      these special names and does not use module_init() / module_exit()
>      macros to create them.
>  
> +vmlinux.o: warning: objtool: entry_SYSCALL_64+0x108: housekeeping_overridden: non-RO static key usage in entry code
> +
> +13. file.o: warning: func()+0x2a: key: non-RO static key usage in entry code

[Severity: Low]
Was the raw vmlinux.o warning line above item 13 left in by mistake?

> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 1b6fab9334566..2e1ad2247446c 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -327,8 +327,10 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
>  	memset(state, 0, sizeof(*state));
>  	init_cfi_state(&state->cfi);
>  
> -	if (opts.noinstr && sec)
> +	if (opts.noinstr && sec) {
>  		state->noinstr = sec->noinstr;
> +		state->entry = sec->entry;
> +	}
>  }

[ ... ]

> @@ -3579,6 +3628,17 @@ static int validate_return(struct symbol *func, struct instruction *insn, struct
>  	return 0;
>  }
>  
> +static int validate_static_key(struct instruction *insn, struct insn_state *state)
> +{
> +	if (state->entry && !insn->key->entry_allowed) {
> +		WARN_INSN(insn, "%s: non-RO static key usage in entry code",
> +			  insn->key->name);
> +		return 1;
> +	}
> +
> +	return 0;
> +}

[Severity: Medium]
Can a cross-section jump from .text into .entry.text cause
validate_static_key() to miss static keys in .entry.text?

init_insn_state() sets state->entry from the section where validation starts,
and state->entry is never updated when following an intra-file jump into
another section.  On vmlinux.o builds, validate_file_unwind_hints() validates
.text before .entry.text: in arch/x86/entry/entry_64.S, ret_from_fork_asm in
.text starts with an unwind hint and jumps to
swapgs_restore_regs_and_return_to_usermode (an inner label of
common_interrupt_return) in .entry.text.  Because that path is first
traversed from .text with state.entry == false and marked visited, the later
pass over .entry.text sees insn->visited already set and returns early
without checking static keys along that shared return path.

Could validate_static_key() check insn->sec->entry (or update state->entry on
cross-section jumps) so .entry.text instructions are still validated?

[ ... ]

> diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> index 2a533afbc69aa..adec1d0d8a5fe 100644
> --- a/tools/objtool/special.c
> +++ b/tools/objtool/special.c
> @@ -111,13 +111,26 @@ static int get_alt_entry(struct elf *elf, const struct special_entry *entry,
>  
>  	if (entry->key) {
>  		struct reloc *key_reloc;
> +		struct symbol *key;
> +		s64 key_addend;
>  
>  		key_reloc = find_reloc_by_dest(elf, sec, offset + entry->key);
>  		if (!key_reloc) {
>  			ERROR_FUNC(sec, offset + entry->key, "can't find key reloc");
>  			return -1;
>  		}
> -		alt->key_addend = reloc_addend(key_reloc);
> +
> +		key = key_reloc->sym;
> +		key_addend = reloc_addend(key_reloc);
> +
> +		if (key->type == STT_SECTION)
> +			key = find_symbol_by_offset(key->sec, key_addend & ~3);
> +
> +		/* embedded keys not supported */
> +		if (key) {
> +			alt->key = key;
> +			alt->key_addend = key_addend;
> +		}
>  	}
>  
>  	return 0;

[Severity: High]
Does guarding alt->key_addend = key_addend with if (key) break jump_label
NOP patching for embedded static keys?

When a static key is embedded at a non-zero offset inside a static struct
(such as key.dd_key_false inside static struct _ddebug for every pr_debug()
and dev_dbg() site under CONFIG_DYNAMIC_DEBUG=y), the __jump_table key
relocation uses STT_SECTION and find_symbol_by_offset(key->sec,
key_addend & ~3) returns NULL.  Leaving alt->key_addend as 0 causes
handle_jump_alt() to skip the opts.hack_jump_label &&
special_alt->key_addend & 2 rewrite from an initial jmp to a NOP.  As a
result, all such initially-disabled static branches execute as unconditional
jumps from boot, and toggling one at runtime triggers a BUG() in
__jump_label_patch() when the instruction bytes do not match the expected
NOP.

Setting alt->key_addend = key_addend unconditionally outside if (key) would
preserve the jump_label hack rewrite even when the symbol cannot be resolved.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=6


  reply	other threads:[~2026-11-28 20:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 01/10] objtool: Make validate_call() recognize indirect calls to pv_ops[] Valentin Schneider
2026-11-28 20:15   ` sashiko-bot
2026-11-27 20:12 ` [PATCH v10 02/10] objtool: Flesh out warning related to pv_ops[] calls Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints() Valentin Schneider
2026-11-28 20:15   ` sashiko-bot
2026-11-27 20:12 ` [PATCH v10 04/10] x86/retpoline: Make warn_thunk_thunk .noinstr Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 05/10] jump_label: Add annotations for validating .entry.text key usage Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 06/10] objtool: Add .entry.text validation for static branches Valentin Schneider
2026-11-28 20:15   ` sashiko-bot [this message]
2026-11-27 20:12 ` [PATCH v10 07/10] x86/jump_label: Add ASM support for static_branch_likely() Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded Valentin Schneider
2026-11-28 20:15   ` sashiko-bot
2026-11-27 20:12 ` [PATCH v10 09/10] x86/mm/pti: Drive kernel_cr3_loaded Valentin Schneider
2026-11-28 20:15   ` sashiko-bot
2026-11-27 20:12 ` [PATCH v10 10/10] context_tracking,x86: Quiesce kernel text patching IPIs when tracking CR3 switches Valentin Schneider
2026-11-28 20:15   ` sashiko-bot

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=sashiko-outbox-239011@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Dan.Beimborn@qube-rt.com \
    --cc=acme@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=boqun.feng@gmail.com \
    --cc=bp@alien8.de \
    --cc=dan.carpenter@linaro.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dwagner@suse.de \
    --cc=frederic@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=jbaron@akamai.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=jpoimboe@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=oleg@redhat.com \
    --cc=pak-hung.chiu@qube-rt.com \
    --cc=paulmck@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ptesarik@suse.com \
    --cc=riel@surriel.com \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shenhan@google.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tglozar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=urezki@gmail.com \
    --cc=vschneid@redhat.com \
    --cc=williams@redhat.com \
    --cc=x86@kernel.org \
    --cc=ypodemsk@redhat.com \
    /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