* [PATCH v10 01/10] objtool: Make validate_call() recognize indirect calls to pv_ops[]
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
@ 2026-11-27 20:12 ` 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
` (11 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
call_dest_name() does not get passed the file pointer of validate_call(),
which means its invocation of insn_reloc() will always return NULL. Make it
take a file pointer.
While at it, make sure call_dest_name() uses arch_dest_reloc_offset(),
otherwise it gets the pv_ops[] offset wrong.
Fabricating an intentional warning shows the change; previously:
vmlinux.o: warning: objtool: __flush_tlb_all_noinstr+0x4: call to {dynamic}() leaves .noinstr.text section
now:
vmlinux.o: warning: objtool: __flush_tlb_all_noinstr+0x4: call to pv_ops[1]() leaves .noinstr.text section
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/check.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 464f6c9d9ff0b..7d68f8df9a848 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -3423,7 +3423,7 @@ static inline bool func_uaccess_safe(struct symbol *func)
return false;
}
-static inline const char *call_dest_name(struct instruction *insn)
+static inline const char *call_dest_name(struct objtool_file *file, struct instruction *insn)
{
static char pvname[19];
struct reloc *reloc;
@@ -3432,9 +3432,9 @@ static inline const char *call_dest_name(struct instruction *insn)
if (insn_call_dest(insn))
return insn_call_dest(insn)->name;
- reloc = insn_reloc(NULL, insn);
+ reloc = insn_reloc(file, insn);
if (reloc && !strcmp(reloc->sym->name, "pv_ops")) {
- idx = (reloc_addend(reloc) / sizeof(void *));
+ idx = arch_insn_adjusted_addend(insn, reloc) / sizeof(void *);
snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx);
return pvname;
}
@@ -3513,17 +3513,19 @@ static int validate_call(struct objtool_file *file,
{
if (state->noinstr && state->instr <= 0 &&
!noinstr_call_dest(file, insn, insn_call_dest(insn))) {
- WARN_INSN(insn, "call to %s() leaves .noinstr.text section", call_dest_name(insn));
+ WARN_INSN(insn, "call to %s() leaves .noinstr.text section", call_dest_name(file, insn));
return 1;
}
if (state->uaccess && !func_uaccess_safe(insn_call_dest(insn))) {
- WARN_INSN(insn, "call to %s() with UACCESS enabled", call_dest_name(insn));
+ WARN_INSN(insn, "call to %s() with UACCESS enabled",
+ call_dest_name(file, insn));
return 1;
}
if (state->df) {
- WARN_INSN(insn, "call to %s() with DF set", call_dest_name(insn));
+ WARN_INSN(insn, "call to %s() with DF set",
+ call_dest_name(file, insn));
return 1;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 01/10] objtool: Make validate_call() recognize indirect calls to pv_ops[]
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] objtool: stale arch_dest_reloc_offset() reference and missing
Fixes in commit log
--
commit da1902185020d224da0bb5054ffc562cddfe29e6
Author: Valentin Schneider <vschneid@redhat.com>
objtool: Make validate_call() recognize indirect calls to pv_ops[]
This commit passes the objtool_file pointer from validate_call() to
call_dest_name() and adjusts the relocation addend when computing the
pv_ops[] index.
[Severity: Low]
In tools/objtool/check.c, call_dest_name() calls
arch_insn_adjusted_addend(insn, reloc), whereas the second paragraph of the
commit message states that it uses arch_dest_reloc_offset(), which was
replaced in 41d24d785897 ("objtool: Fix x86 addend calculation").
Also, since this commit fixes call_dest_name() passing NULL to insn_reloc()
and using an unadjusted relocation addend, should it carry Fixes tags for
db2b0c5d7b6f ("objtool: Support pv_opsindirect calls for noinstr") and
0932dbe1f568 ("objtool: Remove instruction::reloc")?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=1
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH v10 02/10] objtool: Flesh out warning related to pv_ops[] calls
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-27 20:12 ` Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints() Valentin Schneider
` (10 subsequent siblings)
12 siblings, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
I had to look into objtool itself to understand what this warning was
about; make it more explicit.
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 7d68f8df9a848..6b1d0e2af00c9 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -3461,7 +3461,7 @@ static bool pv_call_dest(struct objtool_file *file, struct instruction *insn)
list_for_each_entry(target, &file->pv_ops[idx].targets, pv_target) {
if (!target->sec->noinstr) {
- WARN("pv_ops[%d]: %s", idx, target->name);
+ WARN("pv_ops[%d]: indirect call to %s() leaves .noinstr.text section", idx, target->name);
file->pv_ops[idx].clean = false;
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints()
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-27 20:12 ` [PATCH v10 02/10] objtool: Flesh out warning related to pv_ops[] calls Valentin Schneider
@ 2026-11-27 20:12 ` 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
` (9 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
When passing a NULL @sec to validate_unwind_hints(), it is unable to
properly initialize the insn_state->noinstr passed down during
validation. This means we lose noinstr validation of the hints.
That validation currently happens when 'opts.noinstr' is true but
'validate_branch_enabled()' isn't.
In other words, this will run noinstr validation of hints:
$ objtool --noinstr --link [...]
but this won't:
$ objtool --noinstr --link --uaccess [...]
Always pass a valid section to validate_unwind_hints(), so that noinstr
validation of hints happens regardless of the value of
validate_branch_enabled().
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
tools/objtool/check.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 6b1d0e2af00c9..1b6fab9334566 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4011,13 +4011,8 @@ static int validate_unwind_hints(struct objtool_file *file, struct section *sec)
init_insn_state(file, &state, sec);
- if (sec) {
- sec_for_each_insn(file, sec, insn)
- warnings += validate_unwind_hint(file, insn, &state);
- } else {
- for_each_insn(file, insn)
- warnings += validate_unwind_hint(file, insn, &state);
- }
+ sec_for_each_insn(file, sec, insn)
+ warnings += validate_unwind_hint(file, insn, &state);
return warnings;
}
@@ -4460,6 +4455,21 @@ static int validate_functions(struct objtool_file *file)
return warnings;
}
+static int validate_file_unwind_hints(struct objtool_file *file)
+{
+ struct section *sec;
+ int warnings = 0;
+
+ for_each_sec(file->elf, sec) {
+ if (!is_text_sec(sec))
+ continue;
+
+ warnings += validate_unwind_hints(file, sec);
+ }
+
+ return warnings;
+}
+
static void mark_endbr_used(struct instruction *insn)
{
if (!list_empty(&insn->call_node))
@@ -4849,7 +4859,8 @@ int check(struct objtool_file *file)
int w = 0;
w += validate_functions(file);
- w += validate_unwind_hints(file, NULL);
+ w += validate_file_unwind_hints(file);
+
if (!w)
w += validate_reachable_instructions(file);
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints()
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] objtool: missing Fixes trailer for validate_unwind_hints()
noinstr fix
--
commit 803aa4215447278a6ce511cb2e06657b8c499ad4
Author: Valentin Schneider <vschneid@redhat.com>
> objtool: Always pass a section to validate_unwind_hints()
>
> When passing a NULL @sec to validate_unwind_hints(), it is unable to
> properly initialize the insn_state->noinstr passed down during
> validation. This means we lose noinstr validation of the hints.
>
> That validation currently happens when 'opts.noinstr' is true but
> 'validate_branch_enabled()' isn't.
> In other words, this will run noinstr validation of hints:
> $ objtool --noinstr --link [...]
> but this won't:
> $ objtool --noinstr --link --uaccess [...]
>
> Always pass a valid section to validate_unwind_hints(), so that noinstr
> validation of hints happens regardless of the value of
> validate_branch_enabled().
>
> Signed-off-by: Valentin Schneider <vschneid@redhat.com>
[Severity: Low]
Passing NULL for sec from check() to validate_unwind_hints() was introduced
in 932f8e987bfd ("objtool: Add STT_NOTYPE noinstr validation"). Should this
include:
Fixes: 932f8e987bfd ("objtool: Add STT_NOTYPE noinstr validation")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=3
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH v10 04/10] x86/retpoline: Make warn_thunk_thunk .noinstr
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (2 preceding siblings ...)
2026-11-27 20:12 ` [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints() Valentin Schneider
@ 2026-11-27 20:12 ` Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 05/10] jump_label: Add annotations for validating .entry.text key usage Valentin Schneider
` (8 subsequent siblings)
12 siblings, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Objtool now warns about it:
vmlinux.o: warning: objtool: .altinstr_replacement+0x28e1: call to warn_thunk_thunk() leaves .noinstr.text section
Mark it noinstr.
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
arch/x86/entry/entry.S | 3 ++-
arch/x86/kernel/cpu/bugs.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S
index 2bc217bb5475b..4f85cdb5011fc 100644
--- a/arch/x86/entry/entry.S
+++ b/arch/x86/entry/entry.S
@@ -40,6 +40,8 @@ SYM_FUNC_START(__WARN_trap)
SYM_FUNC_END(__WARN_trap)
EXPORT_SYMBOL(__WARN_trap)
+THUNK warn_thunk_thunk, __warn_thunk
+
.popsection
/*
@@ -60,7 +62,6 @@ EXPORT_SYMBOL_FOR_KVM(x86_verw_sel);
.popsection
-THUNK warn_thunk_thunk, __warn_thunk
/*
* Clang's implementation of TLS stack cookies requires the variable in
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 56eac5611c318..caf8c3c76b544 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -3771,7 +3771,7 @@ ssize_t cpu_show_vmscape(struct device *dev, struct device_attribute *attr, char
}
#endif
-void __warn_thunk(void)
+void noinstr __warn_thunk(void)
{
WARN_ONCE(1, "Unpatched return thunk in use. This should not happen!\n");
}
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* [PATCH v10 05/10] jump_label: Add annotations for validating .entry.text key usage
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (3 preceding siblings ...)
2026-11-27 20:12 ` [PATCH v10 04/10] x86/retpoline: Make warn_thunk_thunk .noinstr Valentin Schneider
@ 2026-11-27 20:12 ` Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 06/10] objtool: Add .entry.text validation for static branches Valentin Schneider
` (7 subsequent siblings)
12 siblings, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
From: Josh Poimboeuf <jpoimboe@kernel.org>
Adding static keys to entry text needs to be done with care, as they may be
executed before a context serialization operation has been run. Add
DEFINE_STATIC_KEY_*_ENTRY() variants for those. They don't do anything
special yet; that will come later.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
[Reduced from .noinstr to .entry.text]
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
include/linux/jump_label.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index c95350a109876..36634f08d30a7 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -374,6 +374,20 @@ struct static_key_false {
#define DEFINE_STATIC_KEY_FALSE_RO(name) \
struct static_key_false name __ro_after_init = STATIC_KEY_FALSE_INIT
+/*
+ * Objtool will warn about static keys used in early entry code, as they may
+ * be unsafe if executed before any serializing operation.
+ *
+ * The _ENTRY variants are used to tell objtool the static key is safe to be
+ * used. If using one of these _ENTRY variants, please add a comment above the
+ * definition with the rationale.
+ */
+#define DEFINE_STATIC_KEY_TRUE_ENTRY(name) \
+ DEFINE_STATIC_KEY_TRUE(name)
+
+#define DEFINE_STATIC_KEY_FALSE_ENTRY(name) \
+ DEFINE_STATIC_KEY_FALSE(name)
+
#define DECLARE_STATIC_KEY_FALSE(name) \
extern struct static_key_false name
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* [PATCH v10 06/10] objtool: Add .entry.text validation for static branches
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (4 preceding siblings ...)
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 ` Valentin Schneider
2026-11-28 20:15 ` sashiko-bot
2026-11-27 20:12 ` [PATCH v10 07/10] x86/jump_label: Add ASM support for static_branch_likely() Valentin Schneider
` (6 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
From: Josh Poimboeuf <jpoimboe@kernel.org>
Warn about static branches in entry text, unless the corresponding key is
RO-after-init.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
[Reduced to only .entry.text rather than .noinstr]
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
include/linux/jump_label.h | 17 ++++---
include/linux/objtool.h | 16 ++++++
tools/objtool/Documentation/objtool.txt | 15 ++++++
tools/objtool/check.c | 68 ++++++++++++++++++++++++-
tools/objtool/include/objtool/check.h | 2 +
tools/objtool/include/objtool/elf.h | 3 +-
tools/objtool/include/objtool/special.h | 1 +
tools/objtool/special.c | 15 +++++-
8 files changed, 128 insertions(+), 9 deletions(-)
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 36634f08d30a7..e4a4bb9320a42 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -76,6 +76,7 @@
#include <linux/types.h>
#include <linux/compiler.h>
#include <linux/cleanup.h>
+#include <linux/objtool.h>
extern bool static_key_initialized;
@@ -362,8 +363,9 @@ struct static_key_false {
#define DEFINE_STATIC_KEY_TRUE(name) \
struct static_key_true name = STATIC_KEY_TRUE_INIT
-#define DEFINE_STATIC_KEY_TRUE_RO(name) \
- struct static_key_true name __ro_after_init = STATIC_KEY_TRUE_INIT
+#define DEFINE_STATIC_KEY_TRUE_RO(name) \
+ struct static_key_true name __ro_after_init = STATIC_KEY_TRUE_INIT; \
+ ANNOTATE_ENTRY_ALLOWED(name)
#define DECLARE_STATIC_KEY_TRUE(name) \
extern struct static_key_true name
@@ -371,8 +373,9 @@ struct static_key_false {
#define DEFINE_STATIC_KEY_FALSE(name) \
struct static_key_false name = STATIC_KEY_FALSE_INIT
-#define DEFINE_STATIC_KEY_FALSE_RO(name) \
- struct static_key_false name __ro_after_init = STATIC_KEY_FALSE_INIT
+#define DEFINE_STATIC_KEY_FALSE_RO(name) \
+ struct static_key_false name __ro_after_init = STATIC_KEY_FALSE_INIT; \
+ ANNOTATE_ENTRY_ALLOWED(name)
/*
* Objtool will warn about static keys used in early entry code, as they may
@@ -383,10 +386,12 @@ struct static_key_false {
* definition with the rationale.
*/
#define DEFINE_STATIC_KEY_TRUE_ENTRY(name) \
- DEFINE_STATIC_KEY_TRUE(name)
+ DEFINE_STATIC_KEY_TRUE(name); \
+ ANNOTATE_ENTRY_ALLOWED(name)
#define DEFINE_STATIC_KEY_FALSE_ENTRY(name) \
- DEFINE_STATIC_KEY_FALSE(name)
+ DEFINE_STATIC_KEY_FALSE(name); \
+ ANNOTATE_ENTRY_ALLOWED(name)
#define DECLARE_STATIC_KEY_FALSE(name) \
extern struct static_key_false name
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
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
+
+ This means that .entry.text function func() uses a static key named 'key'
+ which can be modified at runtime. This is discouraged because the jump
+ location may be accessed before a serializing operation has been
+ executed.
+
+ Check whether the static key in question is only modified during init. If so,
+ define it as read-only-after-init with DEFINE_STATIC_KEY_*_RO().
+
+ Alternatively, if observing a stale/wrong value of the key isn't critical
+ (i.e. the system is in a transient state as lots of things are being updated),
+ you can mark it as safe with DEFINE_STATIC_KEY_*_ENTRY().
If the error doesn't seem to make sense, it could be a bug in objtool.
Feel free to ask objtool maintainers for help.
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;
+ }
}
static struct cfi_state *cfi_alloc(void)
@@ -433,6 +435,9 @@ static int decode_instructions(struct objtool_file *file)
!strncmp(sec->name, ".text..__x86.", 13))
sec->noinstr = true;
+ if (!strcmp(sec->name, ".entry.text"))
+ sec->entry= true;
+
/*
* .init.text code is ran before userspace and thus doesn't
* strictly need retpolines, except for modules which are
@@ -1046,6 +1051,45 @@ static int create_direct_call_sections(struct objtool_file *file)
return 0;
}
+static int read_entry_allowed(struct objtool_file *file)
+{
+ struct section *rsec;
+ struct symbol *sym;
+ struct reloc *reloc;
+
+ rsec = find_section_by_name(file->elf, ".rela.discard.entry_allowed");
+ if (!rsec)
+ return 0;
+
+ for_each_reloc(rsec, reloc) {
+ switch (reloc->sym->type) {
+ case STT_OBJECT:
+ case STT_FUNC:
+ sym = reloc->sym;
+ break;
+
+ case STT_SECTION:
+ sym = find_symbol_by_offset(reloc->sym->sec,
+ reloc_addend(reloc));
+ if (!sym) {
+ WARN_FUNC(reloc->sym->sec, reloc_addend(reloc),
+ "can't find static key/call symbol");
+ return -1;
+ }
+ break;
+
+ default:
+ WARN("unexpected relocation symbol type in %s: %d",
+ rsec->name, reloc->sym->type);
+ return -1;
+ }
+
+ sym->entry_allowed = 1;
+ }
+
+ return 0;
+}
+
/*
* Warnings shouldn't be reported for ignored functions.
*/
@@ -1884,6 +1928,8 @@ static int handle_jump_alt(struct objtool_file *file,
return -1;
}
+ orig_insn->key = special_alt->key;
+
if (opts.hack_jump_label && special_alt->key_addend & 2) {
struct reloc *reloc = insn_reloc(file, orig_insn);
@@ -2681,6 +2727,9 @@ int decode_file(struct objtool_file *file)
if (read_annotate(file, __annotate_late))
return -1;
+ if (read_entry_allowed(file))
+ return -1;
+
return 0;
}
@@ -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;
+}
+
static struct instruction *next_insn_to_validate(struct objtool_file *file,
struct instruction *insn)
{
@@ -3760,6 +3820,12 @@ static int validate_insn(struct objtool_file *file, struct symbol *func,
if (handle_insn_ops(insn, next_insn, statep))
return 1;
+ if (insn->key) {
+ ret = validate_static_key(insn, statep);
+ if (ret)
+ return ret;
+ }
+
switch (insn->type) {
case INSN_RETURN:
diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/objtool/check.h
index 063f5985fecd0..2b5d2f47def6f 100644
--- a/tools/objtool/include/objtool/check.h
+++ b/tools/objtool/include/objtool/check.h
@@ -16,6 +16,7 @@ struct insn_state {
bool uaccess;
bool df;
bool noinstr;
+ bool entry;
s8 instr;
};
@@ -98,6 +99,7 @@ struct instruction {
struct symbol *_sym;
struct stack_op *stack_ops;
struct cfi_state *cfi;
+ struct symbol *key;
};
/*
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index a82517a76a0f6..4a51e8f7a7001 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -58,7 +58,7 @@ struct section {
Elf_Data *data;
const char *name;
int idx;
- bool _changed, text, rodata, noinstr, init, truncate;
+ bool _changed, text, rodata, noinstr, init, truncate, entry;
struct reloc *relocs;
unsigned long nr_alloc_relocs;
struct section *twin;
@@ -98,6 +98,7 @@ struct symbol {
u8 klp : 1;
u8 dont_correlate : 1;
u8 fake : 1;
+ u8 entry_allowed : 1;
struct list_head pv_target;
struct reloc *relocs;
struct section *group_sec;
diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/include/objtool/special.h
index 620dbf6cb0e58..2d6d76326889f 100644
--- a/tools/objtool/include/objtool/special.h
+++ b/tools/objtool/include/objtool/special.h
@@ -18,6 +18,7 @@ struct special_alt {
bool group;
bool jump_or_nop;
u8 key_addend;
+ struct symbol *key;
struct section *orig_sec;
unsigned long orig_off;
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;
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 06/10] objtool: Add .entry.text validation for static branches
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Josh Poimboeuf, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Paolo Bonzini, Arnd Bergmann,
Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
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
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH v10 07/10] x86/jump_label: Add ASM support for static_branch_likely()
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (5 preceding siblings ...)
2026-11-27 20:12 ` [PATCH v10 06/10] objtool: Add .entry.text validation for static branches Valentin Schneider
@ 2026-11-27 20:12 ` Valentin Schneider
2026-11-27 20:12 ` [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded Valentin Schneider
` (5 subsequent siblings)
12 siblings, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Frederic Weisbecker, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Andy Lutomirski,
Peter Zijlstra, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
A later commit will add some early entry code that only needs to be
executed if nohz_full is present on the cmdline, not just if
CONFIG_NO_HZ_FULL is compiled in. Add an ASM-callable static branch macro.
Note that I haven't found a way to express unlikely (i.e. out-of-line)
static branches in ASM macros without using extra jumps, which kind of
defeats the purpose. Consider:
.macro FOOBAR
// Key enabled: JMP .Ldostuff_\@
// Key disabled: NOP
STATIC_BRANCH_UNLIKELY key, .Ldostuff_\@ // Patched to JMP if enabled
jmp .Lend_\@
.Ldostuff_\@:
<dostuff>
.Lend_\@:
.endm
Instead, this should be expressed as a likely (i.e. in-line) static key:
.macro FOOBAR
// Key enabled: NOP
// Key disabled: JMP .Lend_\@
STATIC_BRANCH_LIKELY key, .Lend\@ // Patched to NOP if enabled
<dostuff>
.Lend_\@:
.endm
Suggested-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
arch/x86/include/asm/jump_label.h | 34 ++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index 05b16299588d5..524368fb9f308 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -7,7 +7,39 @@
#include <asm/asm.h>
#include <asm/nops.h>
-#ifndef __ASSEMBLER__
+#ifdef __ASSEMBLER__
+
+/*
+ * There isn't a neat way to craft unlikely static branches in ASM, so they
+ * all have to be expressed as likely (inline) static branches. This macro
+ * thus assumes a "likely" usage.
+ */
+.macro ARCH_STATIC_BRANCH_LIKELY_ASM key, label, jump, hack
+.Lentry_code_\@:
+.if \jump || \hack
+ jmp \label
+.else
+ .byte BYTES_NOP5
+.endif
+ .pushsection __jump_table, "aw"
+ _ASM_ALIGN
+ ANNOTATE_DATA_SPECIAL
+ .long .Lentry_code_\@ - .
+ .long \label - .
+ /* LIKELY so bit0=1, bit1=hack */
+ _ASM_PTR \key + 1 + (\hack << 1) - .
+ .popsection
+.endm
+
+.macro STATIC_BRANCH_TRUE_LIKELY key, label
+ ARCH_STATIC_BRANCH_LIKELY_ASM \key, \label, 0, IS_ENABLED(CONFIG_HAVE_JUMP_LABEL_HACK)
+.endm
+
+.macro STATIC_BRANCH_FALSE_LIKELY key, label
+ ARCH_STATIC_BRANCH_LIKELY_ASM \key, \label, 1, 0
+.endm
+
+#else /* !__ASSEMBLER__ */
#include <linux/stringify.h>
#include <linux/types.h>
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (6 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Later commits will rely on being able to check whether a remote CPU is
using the kernel or the user CR3.
Add a per-cpu variable that will be updated right before switching to the
kernel CR3.
Note that this only adds the backing data, a later commit will drive the
updates.
pcpu access in early entry
==========================
The variable is accessed through two different ways:
1) The general case where swapgs has already been executed, and the usual
gs-based per-cpu offset is usable. This requires mapping the variable in
the userspace visible pages, since CR3 hasn't been switched to the
kernel CR3 yet.
2) The paranoid case where swapgs has *not* be executed, in which case
a CEA alias is used.
security concerns
=================
That variable does not contain any exploitable data, and being in the
.data..percpu..aligned section it occupies a whole page - that is, as long
as it is not the last variable in that section. AFAICT the last one is
always @entry_stack_storage (which by itself is a whole page), although I'm
not sure if that's a happy accident or if it is actually enforced somehow?
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
arch/x86/include/asm/cpu_entry_area.h | 4 +++
arch/x86/include/asm/pti.h | 11 ++++++++
arch/x86/kernel/asm-offsets.c | 3 ++
arch/x86/mm/cpu_entry_area.c | 5 ++++
arch/x86/mm/pti.c | 40 +++++++++++++++++++--------
5 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/cpu_entry_area.h b/arch/x86/include/asm/cpu_entry_area.h
index 462fc34f13176..e321fd7f50d2b 100644
--- a/arch/x86/include/asm/cpu_entry_area.h
+++ b/arch/x86/include/asm/cpu_entry_area.h
@@ -127,6 +127,10 @@ struct cpu_entry_area {
* Reserve enough fixmap PTEs.
*/
struct debug_store_buffers cpu_debug_buffers;
+
+#ifdef CONFIG_TRACK_CR3
+ atomic_t kernel_cr3_loaded __aligned(PAGE_SIZE);
+#endif
};
#define CPU_ENTRY_AREA_SIZE (sizeof(struct cpu_entry_area))
diff --git a/arch/x86/include/asm/pti.h b/arch/x86/include/asm/pti.h
index 88d0a1ab1f77e..142b2d225c5eb 100644
--- a/arch/x86/include/asm/pti.h
+++ b/arch/x86/include/asm/pti.h
@@ -1,12 +1,23 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_X86_PTI_H
#define _ASM_X86_PTI_H
+
+#ifdef CONFIG_TRACK_CR3
+#define KERNEL_CR3_IN_USER 0
+#define KERNEL_CR3_IN_KERNEL 1
+#endif
+
#ifndef __ASSEMBLER__
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
extern void pti_init(void);
extern void pti_check_boottime_disable(void);
extern void pti_finalize(void);
+
+#ifdef CONFIG_TRACK_CR3
+DECLARE_PER_CPU_PAGE_ALIGNED(atomic_t, kernel_cr3_loaded);
+#endif
+
#else
static inline void pti_check_boottime_disable(void) { }
#endif
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index 081816888f7a0..5ba8d5b791e1f 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -117,6 +117,9 @@ static void __used common(void)
OFFSET(CPU_ENTRY_AREA_entry_stack, cpu_entry_area, entry_stack_page);
DEFINE(SIZEOF_entry_stack, sizeof(struct entry_stack));
DEFINE(MASK_entry_stack, (~(sizeof(struct entry_stack) - 1)));
+#ifdef CONFIG_TRACK_CR3
+ OFFSET(CPU_ENTRY_AREA_kernel_cr3, cpu_entry_area, kernel_cr3_loaded);
+#endif
/* Offset for fields in tss_struct */
OFFSET(TSS_sp0, tss_struct, x86_tss.sp0);
diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
index 575f863f3c75e..a8c3381432a57 100644
--- a/arch/x86/mm/cpu_entry_area.c
+++ b/arch/x86/mm/cpu_entry_area.c
@@ -202,6 +202,11 @@ static void __init setup_cpu_entry_area(unsigned int cpu)
per_cpu_ptr(&entry_stack_storage, cpu), 1,
PAGE_KERNEL);
+#ifdef CONFIG_TRACK_CR3
+ cea_map_percpu_pages(&cea->kernel_cr3_loaded,
+ per_cpu_ptr(&kernel_cr3_loaded, cpu), 1,
+ PAGE_KERNEL);
+#endif
/*
* The Intel SDM says (Volume 3, 7.2.1):
*
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 598f553cc8713..69c03acceb1de 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -446,6 +446,22 @@ static void __init pti_clone_p4d(unsigned long addr)
*user_p4d = *kernel_p4d;
}
+static void __init pti_clone_percpu(unsigned long va)
+{
+ phys_addr_t pa = per_cpu_ptr_to_phys((void *)va);
+ pte_t *target_pte;
+
+ target_pte = pti_user_pagetable_walk_pte(va, false);
+ if (WARN_ON(!target_pte))
+ return;
+
+ *target_pte = pfn_pte(pa >> PAGE_SHIFT, PAGE_KERNEL);
+}
+
+#ifdef CONFIG_TRACK_CR3
+DEFINE_PER_CPU_PAGE_ALIGNED(atomic_t, kernel_cr3_loaded) = ATOMIC_INIT(KERNEL_CR3_IN_KERNEL);
+#endif
+
/*
* Clone the CPU_ENTRY_AREA and associated data into the user space visible
* page table.
@@ -456,25 +472,25 @@ static void __init pti_clone_user_shared(void)
pti_clone_p4d(CPU_ENTRY_AREA_BASE);
+ /*
+ * This is done for all possible CPUs during boot to ensure that it's
+ * propagated to all mms.
+ */
for_each_possible_cpu(cpu) {
/*
* The SYSCALL64 entry code needs one word of scratch space
* in which to spill a register. It lives in the sp2 slot
* of the CPU's TSS.
- *
- * This is done for all possible CPUs during boot to ensure
- * that it's propagated to all mms.
*/
+ pti_clone_percpu((unsigned long)&per_cpu(cpu_tss_rw, cpu));
- unsigned long va = (unsigned long)&per_cpu(cpu_tss_rw, cpu);
- phys_addr_t pa = per_cpu_ptr_to_phys((void *)va);
- pte_t *target_pte;
-
- target_pte = pti_user_pagetable_walk_pte(va, false);
- if (WARN_ON(!target_pte))
- return;
-
- *target_pte = pfn_pte(pa >> PAGE_SHIFT, PAGE_KERNEL);
+#ifdef CONFIG_TRACK_CR3
+ /*
+ * The entry code needs access to the @kernel_cr3_loaded percpu
+ * variable before the kernel CR3 is loaded.
+ */
+ pti_clone_percpu((unsigned long)&per_cpu(kernel_cr3_loaded, cpu));
+#endif
}
}
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] x86/mm/pti: 4-byte kernel_cr3_loaded leaks adjacent per-CPU
data to PTI tables
--
commit b76db130a4c2a9e321887010d2e7a62358550f8a
Author: Valentin Schneider <vschneid@redhat.com>
x86/mm/pti: Introduce kernel_cr3_loaded
This commit adds a page-aligned per-CPU variable, kernel_cr3_loaded, and
maps it into the cpu_entry_area and the user-visible PTI page tables so
later patches can track whether a CPU is using the kernel or user CR3.
> diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
> index 598f553cc8713..69c03acceb1de 100644
> --- a/arch/x86/mm/pti.c
> +++ b/arch/x86/mm/pti.c
> @@ -446,6 +446,22 @@ static void __init pti_clone_p4d(unsigned long addr)
> *user_p4d = *kernel_p4d;
> }
>
> +static void __init pti_clone_percpu(unsigned long va)
> +{
> + phys_addr_t pa = per_cpu_ptr_to_phys((void *)va);
> + pte_t *target_pte;
> +
> + target_pte = pti_user_pagetable_walk_pte(va, false);
> + if (WARN_ON(!target_pte))
> + return;
> +
> + *target_pte = pfn_pte(pa >> PAGE_SHIFT, PAGE_KERNEL);
> +}
> +
> +#ifdef CONFIG_TRACK_CR3
> +DEFINE_PER_CPU_PAGE_ALIGNED(atomic_t, kernel_cr3_loaded) = ATOMIC_INIT(KERNEL_CR3_IN_KERNEL);
> +#endif
> +
> /*
> * Clone the CPU_ENTRY_AREA and associated data into the user space visible
> * page table.
> @@ -456,25 +472,25 @@ static void __init pti_clone_user_shared(void)
>
> pti_clone_p4d(CPU_ENTRY_AREA_BASE);
>
> + /*
> + * This is done for all possible CPUs during boot to ensure that it's
> + * propagated to all mms.
> + */
> for_each_possible_cpu(cpu) {
> /*
> * The SYSCALL64 entry code needs one word of scratch space
> * in which to spill a register. It lives in the sp2 slot
> * of the CPU's TSS.
> - *
> - * This is done for all possible CPUs during boot to ensure
> - * that it's propagated to all mms.
> */
> + pti_clone_percpu((unsigned long)&per_cpu(cpu_tss_rw, cpu));
>
> - unsigned long va = (unsigned long)&per_cpu(cpu_tss_rw, cpu);
> - phys_addr_t pa = per_cpu_ptr_to_phys((void *)va);
> - pte_t *target_pte;
> -
> - target_pte = pti_user_pagetable_walk_pte(va, false);
> - if (WARN_ON(!target_pte))
> - return;
> -
> - *target_pte = pfn_pte(pa >> PAGE_SHIFT, PAGE_KERNEL);
> +#ifdef CONFIG_TRACK_CR3
> + /*
> + * The entry code needs access to the @kernel_cr3_loaded percpu
> + * variable before the kernel CR3 is loaded.
> + */
> + pti_clone_percpu((unsigned long)&per_cpu(kernel_cr3_loaded, cpu));
> +#endif
[Severity: High]
Does mapping kernel_cr3_loaded expose the adjacent .data..percpu..hot.* and
.data..percpu..read_mostly variables in the user-visible PTI page tables and
the cpu_entry_area alias?
In arch/x86/mm/Makefile, pti.o is linked after cpu_entry_area.o, and no
object linked after pti.o defines anything in .data..percpu..page_aligned.
That makes kernel_cr3_loaded the last variable in
.data..percpu..page_aligned, after entry_stack_storage.
Unlike a struct type marked __aligned(PAGE_SIZE), applying
DEFINE_PER_CPU_PAGE_ALIGNED() to an atomic_t only aligns its starting offset
while leaving its size at 4 bytes, and PERCPU_INPUT() only aligns the next
section to a cacheline:
include/asm-generic/vmlinux.lds.h:PERCPU_INPUT() {
...
*(.data..percpu..page_aligned) \
. = ALIGN(cacheline); \
__per_cpu_hot_start = .; \
*(SORT_BY_ALIGNMENT(.data..percpu..hot.*)) \
...
}
As a result, __per_cpu_hot_start (including __stack_chk_guard, current_task,
and cpu_current_top_of_stack) starts at offset 64 of the same 4 KiB page as
kernel_cr3_loaded, and pti_clone_percpu() and cea_map_percpu_pages() map that
entire page into the user page tables.
Wrapping kernel_cr3_loaded in a page-aligned struct (or union with a
PAGE_SIZE char array) would pad its size to a full page.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=8
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH v10 09/10] x86/mm/pti: Drive kernel_cr3_loaded
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (7 preceding siblings ...)
2026-11-27 20:12 ` [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded Valentin Schneider
@ 2026-11-27 20:12 ` 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
` (3 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Later commits will rely on being able to check whether a remote CPU is
using the kernel or the user CR3.
This per-CPU variable needs to be updated before the actual CR3 write, IOW
it always immediately precedes it:
KERNEL_CR3_LOADED := 1
SWITCH_TO_KERNEL_CR3
[...]
KERNEL_CR3_LOADED := 0
SWITCH_TO_USER_CR3
NMI reentry considerations
==========================
NMIs are cheeky and can occur e.g. after @kernel_cr3_loaded has been updated
but before the actual CR3 has been switched. This requires some extra care when
exiting the NMI to *not* restore @kernel_cr3_loaded to its userland value.
That part is implemented by abusing bit #60 of the CR3 which is reserved;
it itself is never written to in the actual CR3, but is fiddled in its
register copy.
Per the Intel SDM:
```Volume 3, Chapter 5.1.4 Enumeration of Paging Features by CPUID
This width is referred to as MAXPHYADDR. MAXPHYADDR is at most 52.
```
```Volume 3, Chapter 5.5.2 Use of CR3 with Ordinary 4-Level Paging and 5-Level Paging
| Bit position | Contents |
|--------------+----------------------------------------------------------------------------------------|
| 11:0 | PCID |
| M-1:12 | Physical address of the 4-KByte aligned PML4 table used for linear-address translation |
| 60:M | Reserved (must be 0) |
| 61 | Enables LAM57 for user pointers; Section 4.4.3 |
| 62 | Enables LAM48 for user pointers; ignored if bit 61 is set |
| 63 | Reserved (must be 0) |
```
unconditional update
=====================
This will only be really useful for NOHZ_FULL CPUs, but it should be
cheaper to unconditionally update a never-used per-CPU variable living in
its own cacheline than to check a shared cpumask such as
housekeeping_cpumask(HK_TYPE_KERNEL_NOISE)
at every entry.
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
arch/x86/Kconfig | 14 ++++
arch/x86/entry/calling.h | 71 +++++++++++++++++++++
arch/x86/include/uapi/asm/processor-flags.h | 3 +
kernel/sched/isolation.c | 9 ++-
4 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 15fd9ec5ecacb..cc8bc8a47b0f4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2163,6 +2163,20 @@ config ADDRESS_MASKING
The capability can be used for efficient address sanitizers (ASAN)
implementation and for optimizations in JITs.
+config TRACK_CR3
+ def_bool n
+ prompt "Track which CR3 is in use"
+ depends on X86_64 && MITIGATION_PAGE_TABLE_ISOLATION && NO_HZ_FULL
+ help
+ This option adds a software signal that allows checking remotely
+ whether a CPU is using the user or the kernel page table.
+
+ This allows further optimizations for NOHZ_FULL CPUs.
+
+ This obviously makes the user<->kernel transition overhead even worse.
+
+ If unsure, say N.
+
config HOTPLUG_CPU
def_bool y
depends on SMP
diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
index 77e2d920a6407..e28e41a011394 100644
--- a/arch/x86/entry/calling.h
+++ b/arch/x86/entry/calling.h
@@ -9,6 +9,8 @@
#include <asm/ptrace-abi.h>
#include <asm/msr.h>
#include <asm/nospec-branch.h>
+#include <asm/jump_label.h>
+#include <asm/pti.h>
/*
@@ -170,9 +172,74 @@ For 32-bit we have the following conventions - kernel is built with
andq $(~PTI_USER_PGTABLE_AND_PCID_MASK), \reg
.endm
+.macro TRACK_CR3_KERNEL_ENTRY
+#ifdef CONFIG_TRACK_CR3
+ STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
+ orl $KERNEL_CR3_IN_KERNEL, PER_CPU_VAR(kernel_cr3_loaded)
+.Lend_\@:
+#endif // CONFIG_TRACK_CR3
+.endm
+
+.macro TRACK_CR3_KERNEL_EXIT
+#ifdef CONFIG_TRACK_CR3
+ STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
+ movl $KERNEL_CR3_IN_USER, PER_CPU_VAR(kernel_cr3_loaded)
+.Lend_\@:
+#endif // CONFIG_TRACK_CR3
+.endm
+
+.macro PARANOID_TRACK_CR3_KERNEL_ENTRY scratch_reg:req save_reg:req
+#ifdef CONFIG_TRACK_CR3
+ STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
+
+ /*
+ * Due to FSGSBASE hilarity, we don't have a viable GS to rely on to
+ * do a classic percpu access here.
+ * Instead, fetch the percpu address via the CEA.
+ */
+ subq $10, %rsp
+ sgdt (%rsp)
+ movq 2(%rsp), \scratch_reg /* GDT address */
+ addq $10, %rsp
+
+ /*
+ * We may have just interrupted another entry that has set
+ * $KERNEL_CR3_IN_KERNEL, but hasn't written to CR3 yet.
+ * Abuse \save_reg to remember that at exit and to leave
+ * @kernel_cr3_loaded as it was.
+ */
+ testl $KERNEL_CR3_IN_KERNEL, CPU_ENTRY_AREA_kernel_cr3(\scratch_reg)
+ jz .Ltrack_\@
+ bts $X86_CR3_REENTRY_BIT, \save_reg
+ jmp .Lend_restore_\@
+.Ltrack_\@:
+ movl $KERNEL_CR3_IN_KERNEL, CPU_ENTRY_AREA_kernel_cr3(\scratch_reg)
+.Lend_restore_\@:
+ /* CEA hackery done; restore @scratch_reg */
+ mov \save_reg, \scratch_reg
+ btr $X86_CR3_REENTRY_BIT, \scratch_reg
+.Lend_\@:
+#endif // CONFIG_TRACK_CR3
+.endm
+
+.macro PARANOID_TRACK_CR3_KERNEL_EXIT save_reg:req
+#ifdef CONFIG_TRACK_CR3
+ STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
+ /*
+ * If we entered with @kernel_cr3_loaded already written to, leave it
+ * as is.
+ */
+ btr $X86_CR3_REENTRY_BIT, \save_reg
+ jc .Lend_\@
+ movl $KERNEL_CR3_IN_USER, PER_CPU_VAR(kernel_cr3_loaded)
+.Lend_\@:
+#endif // CONFIG_TRACK_CR3
+.endm
+
.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
mov %cr3, \scratch_reg
+ TRACK_CR3_KERNEL_ENTRY
ADJUST_KERNEL_CR3 \scratch_reg
mov \scratch_reg, %cr3
.Lend_\@:
@@ -182,6 +249,7 @@ For 32-bit we have the following conventions - kernel is built with
PER_CPU_VAR(cpu_tlbstate + TLB_STATE_user_pcid_flush_mask)
.macro SWITCH_TO_USER_CR3 scratch_reg:req scratch_reg2:req
+ TRACK_CR3_KERNEL_EXIT
mov %cr3, \scratch_reg
ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID
@@ -239,6 +307,7 @@ For 32-bit we have the following conventions - kernel is built with
bt $PTI_USER_PGTABLE_BIT, \scratch_reg
jnc .Ldone_\@
+ PARANOID_TRACK_CR3_KERNEL_ENTRY \scratch_reg \save_reg
ADJUST_KERNEL_CR3 \scratch_reg
movq \scratch_reg, %cr3
@@ -257,6 +326,8 @@ For 32-bit we have the following conventions - kernel is built with
bt $PTI_USER_PGTABLE_BIT, \save_reg
jnc .Lend_\@
+ PARANOID_TRACK_CR3_KERNEL_EXIT \save_reg
+
ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID
/*
diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h
index 81d0c8bf11377..279c745db7cf1 100644
--- a/arch/x86/include/uapi/asm/processor-flags.h
+++ b/arch/x86/include/uapi/asm/processor-flags.h
@@ -82,6 +82,9 @@
#define X86_CR3_PCID_BITS 12
#define X86_CR3_PCID_MASK (_AC((1UL << X86_CR3_PCID_BITS) - 1, UL))
+#define X86_CR3_REENTRY_BIT 60 /* NOT a CPU flag, but a pure software abuse of the CR3 layout */
+#define X86_CR3_REENTRY _BITULL(X86_CR3_REENTRY_BIT)
+
#define X86_CR3_LAM_U57_BIT 61 /* Activate LAM for userspace, 62:57 bits masked */
#define X86_CR3_LAM_U57 _BITULL(X86_CR3_LAM_U57_BIT)
#define X86_CR3_LAM_U48_BIT 62 /* Activate LAM for userspace, 62:48 bits masked */
diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
index 156025ef81b75..90640c9e7f811 100644
--- a/kernel/sched/isolation.c
+++ b/kernel/sched/isolation.c
@@ -19,7 +19,14 @@ enum hk_flags {
HK_FLAG_KERNEL_NOISE = BIT(HK_TYPE_KERNEL_NOISE),
};
-DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
+/*
+ * This key is accessed in early entry code to drive the CPU isolation IPI
+ * quiescing mechanism. This happens before a serializing instruction has been
+ * executed in the entry path. This is acceptable as a stale value will only be
+ * observed during transient CPU isolation states, and the updated value will be
+ * acted upon at the next kernel exit.
+ */
+DEFINE_STATIC_KEY_FALSE_ENTRY(housekeeping_overridden);
EXPORT_SYMBOL_GPL(housekeeping_overridden);
struct housekeeping {
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 09/10] x86/mm/pti: Drive kernel_cr3_loaded
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] x86/entry: runtime text poking of housekeeping_overridden
crashes entry
- [Medium] x86/entry: NMI in CR3 exit window leaves kernel_cr3_loaded as
IN_USER
- [Medium] x86/hw_breakpoint: missing within_cpu_entry() check for
kernel_cr3_loaded
- [Medium] x86/entry: gating CR3 tracking on housekeeping_overridden
without nohz_full
--
commit 084ab06088ad604a25eb3511c62e665e540e068d
Author: Valentin Schneider <vschneid@redhat.com>
x86/mm/pti: Drive kernel_cr3_loaded
This commit updates the per-CPU kernel_cr3_loaded variable around PTI CR3
switches in the x86 entry and exit paths when CONFIG_TRACK_CR3 is enabled.
> diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h
> index 77e2d920a6407..e28e41a011394 100644
> --- a/arch/x86/entry/calling.h
> +++ b/arch/x86/entry/calling.h
[ ... ]
> @@ -170,9 +172,74 @@ For 32-bit we have the following conventions - kernel is built with
> andq $(~PTI_USER_PGTABLE_AND_PCID_MASK), \reg
> .endm
>
> +.macro TRACK_CR3_KERNEL_ENTRY
> +#ifdef CONFIG_TRACK_CR3
> + STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
> + orl $KERNEL_CR3_IN_KERNEL, PER_CPU_VAR(kernel_cr3_loaded)
> +.Lend_\@:
> +#endif // CONFIG_TRACK_CR3
> +.endm
[Severity: Medium]
Does gating these entry and exit macros on housekeeping_overridden enable
per-transition updates to kernel_cr3_loaded even when NO_HZ_FULL is not
active?
housekeeping_init() and housekeeping_update() enable housekeeping_overridden
whenever any housekeeping flag is set, including HK_FLAG_DOMAIN and
HK_FLAG_MANAGED_IRQ from isolcpus= or isolated cpuset partitions. Since
kernel_cr3_loaded only serves HK_TYPE_KERNEL_NOISE (nohz_full) CPUs, gating
it on a boot-time static key specific to HK_FLAG_KERNEL_NOISE (such as
tick_nohz_full_running) would avoid paying the entry/exit RMW and store cost
on every CPU when only domain or managed_irq isolation is used.
> +
> +.macro TRACK_CR3_KERNEL_EXIT
> +#ifdef CONFIG_TRACK_CR3
> + STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
> + movl $KERNEL_CR3_IN_USER, PER_CPU_VAR(kernel_cr3_loaded)
> +.Lend_\@:
> +#endif // CONFIG_TRACK_CR3
> +.endm
> +
> +.macro PARANOID_TRACK_CR3_KERNEL_ENTRY scratch_reg:req save_reg:req
> +#ifdef CONFIG_TRACK_CR3
> + STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
> +
> + /*
> + * Due to FSGSBASE hilarity, we don't have a viable GS to rely on to
> + * do a classic percpu access here.
> + * Instead, fetch the percpu address via the CEA.
> + */
> + subq $10, %rsp
> + sgdt (%rsp)
> + movq 2(%rsp), \scratch_reg /* GDT address */
> + addq $10, %rsp
> +
> + /*
> + * We may have just interrupted another entry that has set
> + * $KERNEL_CR3_IN_KERNEL, but hasn't written to CR3 yet.
> + * Abuse \save_reg to remember that at exit and to leave
> + * @kernel_cr3_loaded as it was.
> + */
> + testl $KERNEL_CR3_IN_KERNEL, CPU_ENTRY_AREA_kernel_cr3(\scratch_reg)
> + jz .Ltrack_\@
> + bts $X86_CR3_REENTRY_BIT, \save_reg
> + jmp .Lend_restore_\@
> +.Ltrack_\@:
> + movl $KERNEL_CR3_IN_KERNEL, CPU_ENTRY_AREA_kernel_cr3(\scratch_reg)
> +.Lend_restore_\@:
> + /* CEA hackery done; restore @scratch_reg */
> + mov \save_reg, \scratch_reg
> + btr $X86_CR3_REENTRY_BIT, \scratch_reg
> +.Lend_\@:
> +#endif // CONFIG_TRACK_CR3
> +.endm
> +
> +.macro PARANOID_TRACK_CR3_KERNEL_EXIT save_reg:req
> +#ifdef CONFIG_TRACK_CR3
> + STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden, .Lend_\@
> + /*
> + * If we entered with @kernel_cr3_loaded already written to, leave it
> + * as is.
> + */
> + btr $X86_CR3_REENTRY_BIT, \save_reg
> + jc .Lend_\@
> + movl $KERNEL_CR3_IN_USER, PER_CPU_VAR(kernel_cr3_loaded)
> +.Lend_\@:
> +#endif // CONFIG_TRACK_CR3
> +.endm
[Severity: Medium]
Can placing a hardware data watchpoint on per_cpu(kernel_cr3_loaded, cpu)
cause infinite #DB recursion on the #DB IST stack?
Unlike PARANOID_TRACK_CR3_KERNEL_ENTRY, which writes through the
CPU_ENTRY_AREA alias, TRACK_CR3_KERNEL_ENTRY, TRACK_CR3_KERNEL_EXIT, and
PARANOID_TRACK_CR3_KERNEL_EXIT write directly to
PER_CPU_VAR(kernel_cr3_loaded). Because within_cpu_entry() in
arch/x86/kernel/hw_breakpoint.c does not reject breakpoints on
per_cpu(kernel_cr3_loaded, cpu), exc_debug_kernel() restores DR7 before
returning to paranoid_exit -> PARANOID_RESTORE_CR3 ->
PARANOID_TRACK_CR3_KERNEL_EXIT while still on DB_stack, where writing
kernel_cr3_loaded immediately re-triggers #DB (and in entry_SYSCALL_64,
TRACK_CR3_KERNEL_ENTRY fires #DB while %rsp holds %cr3).
> +
> .macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
> ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
> mov %cr3, \scratch_reg
> + TRACK_CR3_KERNEL_ENTRY
> ADJUST_KERNEL_CR3 \scratch_reg
> mov \scratch_reg, %cr3
> .Lend_\@:
> @@ -182,6 +249,7 @@ For 32-bit we have the following conventions - kernel is built with
> PER_CPU_VAR(cpu_tlbstate + TLB_STATE_user_pcid_flush_mask)
>
> .macro SWITCH_TO_USER_CR3 scratch_reg:req scratch_reg2:req
> + TRACK_CR3_KERNEL_EXIT
> mov %cr3, \scratch_reg
>
> ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID
> @@ -239,6 +307,7 @@ For 32-bit we have the following conventions - kernel is built with
> bt $PTI_USER_PGTABLE_BIT, \scratch_reg
> jnc .Ldone_\@
>
> + PARANOID_TRACK_CR3_KERNEL_ENTRY \scratch_reg \save_reg
> ADJUST_KERNEL_CR3 \scratch_reg
> movq \scratch_reg, %cr3
>
> @@ -257,6 +326,8 @@ For 32-bit we have the following conventions - kernel is built with
> bt $PTI_USER_PGTABLE_BIT, \save_reg
> jnc .Lend_\@
>
> + PARANOID_TRACK_CR3_KERNEL_EXIT \save_reg
> +
> ALTERNATIVE "jmp .Lwrcr3_\@", "", X86_FEATURE_PCID
[Severity: Medium]
Can an NMI or paranoid exception arriving during the CR3 exit window run
its entire C handler with kernel_cr3_loaded set to KERNEL_CR3_IN_USER?
SWITCH_TO_USER_CR3 (or PARANOID_RESTORE_CR3)
TRACK_CR3_KERNEL_EXIT
kernel_cr3_loaded = KERNEL_CR3_IN_USER
<NMI before mov %cr3>
paranoid_entry
SAVE_AND_SWITCH_TO_KERNEL_CR3
movq %cr3, \scratch_reg
bt $PTI_USER_PGTABLE_BIT, \scratch_reg
jnc .Ldone <-- taken (%cr3 still has kernel CR3)
exc_nmi() <-- runs in kernel with kernel_cr3_loaded == IN_USER
In both SWITCH_TO_USER_CR3 and PARANOID_RESTORE_CR3, kernel_cr3_loaded is
cleared to KERNEL_CR3_IN_USER before the PCID flush check and before the
final write to %cr3. If an NMI or IST exception fires in that window,
%cr3 still has PTI_USER_PGTABLE_BIT clear, so SAVE_AND_SWITCH_TO_KERNEL_CR3
jumps to .Ldone without running PARANOID_TRACK_CR3_KERNEL_ENTRY. Throughout
the handler, remote CPUs checking kernel_cr3_loaded will see the CPU as in
userspace and skip text-poke serialization IPIs while it executes kernel
code without a subsequent serializing CR3 write on paranoid_exit.
> diff --git a/kernel/sched/isolation.c b/kernel/sched/isolation.c
> index 156025ef81b75..90640c9e7f811 100644
> --- a/kernel/sched/isolation.c
> +++ b/kernel/sched/isolation.c
> @@ -19,7 +19,14 @@ enum hk_flags {
> HK_FLAG_KERNEL_NOISE = BIT(HK_TYPE_KERNEL_NOISE),
> };
>
> -DEFINE_STATIC_KEY_FALSE(housekeeping_overridden);
> +/*
> + * This key is accessed in early entry code to drive the CPU isolation IPI
> + * quiescing mechanism. This happens before a serializing instruction has been
> + * executed in the entry path. This is acceptable as a stale value will only be
> + * observed during transient CPU isolation states, and the updated value will be
> + * acted upon at the next kernel exit.
> + */
> +DEFINE_STATIC_KEY_FALSE_ENTRY(housekeeping_overridden);
> EXPORT_SYMBOL_GPL(housekeeping_overridden);
[Severity: High]
Can enabling housekeeping_overridden at runtime via housekeeping_update()
crash a CPU executing early entry/exit assembly when text poking places an
INT3 on the static branch?
When a system boots without nohz_full= or isolcpus= and an isolated cpuset
partition is later created at runtime, housekeeping_update() calls
static_branch_enable(&housekeeping_overridden):
kernel/sched/isolation.c:housekeeping_update() {
...
if (!housekeeping.flags)
static_branch_enable(&housekeeping_overridden);
...
}
On x86 SMP, static_branch_enable() patches each
STATIC_BRANCH_FALSE_LIKELY housekeeping_overridden site using an INT3
breakpoint and broadcasts a sync IPI. Unlike #DB or #NMI, X86_TRAP_BP
(asm_exc_int3) uses DEFAULT_STACK and error_entry; if a CPU hits the INT3 at
CPL 0 inside SWITCH_TO_KERNEL_CR3 (where entry_SYSCALL_64 and
entry_SYSCALL_compat have just executed mov %cr3, %rsp and user page tables
are still loaded), SWITCH_TO_USER_CR3, or SAVE_AND_SWITCH_TO_KERNEL_CR3, the
CPU takes #BP with user CR3, user GSBASE, or %rsp holding %cr3, immediately
double-faulting. In addition, if PARANOID_TRACK_CR3_KERNEL_ENTRY runs after
its jump is patched (setting X86_CR3_REENTRY_BIT in save_reg because
kernel_cr3_loaded was initialized to 1 at boot) while
PARANOID_TRACK_CR3_KERNEL_EXIT still takes its unpatched jump to .Lend,
btr $X86_CR3_REENTRY_BIT, \save_reg is skipped and PARANOID_RESTORE_CR3
writes reserved bit 60 into %cr3, raising #GP(0).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=9
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH v10 10/10] context_tracking,x86: Quiesce kernel text patching IPIs when tracking CR3 switches
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (8 preceding siblings ...)
2026-11-27 20:12 ` [PATCH v10 09/10] x86/mm/pti: Drive kernel_cr3_loaded Valentin Schneider
@ 2026-11-27 20:12 ` Valentin Schneider
2026-11-28 20:15 ` sashiko-bot
2026-11-30 17:31 ` [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Dave Hansen
` (2 subsequent siblings)
12 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-11-27 20:12 UTC (permalink / raw)
To: linux-kernel, linux-mm, x86
Cc: Peter Zijlstra (Intel), Nicolas Saenz Julienne, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
text_poke_bp_batch() sends IPIs to all online CPUs to synchronize
them vs the newly patched instruction. CPUs that are executing in userspace
do not need this synchronization to happen immediately, and this is
actually harmful interference for NOHZ_FULL CPUs.
As the synchronization IPIs are sent using a blocking call, returning from
text_poke_bp_batch() implies all CPUs will observe the patched
instruction(s), and this should be preserved even if the IPI is quiesced.
In other words, to safely postpone this synchronization, any kernel
instruction leading to the execution of the postponed instruction
sync must *not* be mutable (patchable) at runtime.
This means we must pay attention to mutable instructions in the early entry
code:
- alternatives
- static keys
- static calls
- all sorts of probes (kprobes/ftrace/bpf/???)
The early entry code is noinstr, which gets rid of the probes.
Alternatives are safe, because it's boot-time patching (before SMP is
even brought up) which is before any IPI quiescing can happen.
This leaves us with static keys and static calls. Any static key used in
early entry code should be only forever-enabled at boot time, IOW
__ro_after_init (pretty much like alternatives). Exceptions to that will
now be caught by objtool.
The postponed instruction sync is the CR3 RMW done as part of
kPTI when switching to the kernel page table:
SDM vol2 chapter 4.3 - Move to/from control registers:
```
MOV CR* instructions, except for MOV CR8, are serializing instructions.
```
Leverage the new kernel_cr3_loaded signal and the kPTI CR3 RMW to quiesce
sync_core() IPIs targeting NOHZ_FULL CPUs.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Nicolas Saenz Julienne <nsaenzju@redhat.com>
Signed-off-by: Valentin Schneider <vschneid@redhat.com>
---
arch/x86/include/asm/text-patching.h | 5 +++
arch/x86/kernel/alternative.c | 59 +++++++++++++++++++++++++---
arch/x86/kernel/kprobes/core.c | 4 +-
arch/x86/kernel/kprobes/opt.c | 4 +-
arch/x86/kernel/module.c | 2 +-
include/asm-generic/sections.h | 14 +++++++
6 files changed, 77 insertions(+), 11 deletions(-)
diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/text-patching.h
index ea09381070e82..25dc52f423cc0 100644
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -33,6 +33,11 @@ extern void text_poke_apply_relocation(u8 *buf, const u8 * const instr, size_t i
*/
extern void *text_poke(void *addr, const void *opcode, size_t len);
extern void smp_text_poke_sync_each_cpu(void);
+#ifdef CONFIG_TRACK_CR3
+extern void smp_text_poke_sync_each_cpu_quiescable(void);
+#else
+#define smp_text_poke_sync_each_cpu_quiescable smp_text_poke_sync_each_cpu
+#endif
extern void *text_poke_kgdb(void *addr, const void *opcode, size_t len);
extern void *text_poke_copy(void *addr, const void *opcode, size_t len);
#define text_poke_copy text_poke_copy
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index 582c6d8307d15..283c94394c0b9 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -9,6 +9,7 @@
#include <linux/cleanup.h>
#include <linux/kgdb.h>
#include <linux/mmap_lock.h>
+#include <linux/sched/isolation.h>
#include <asm/text-patching.h>
#include <asm/insn.h>
@@ -16,6 +17,7 @@
#include <asm/ibt.h>
#include <asm/set_memory.h>
#include <asm/nmi.h>
+#include <asm/tlbflush.h>
int __read_mostly alternatives_patched;
@@ -2636,11 +2638,46 @@ static void do_sync_core(void *info)
sync_core();
}
+static void __smp_text_poke_sync_each_cpu(smp_cond_func_t cond_func)
+{
+ on_each_cpu_cond(cond_func, do_sync_core, NULL, 1);
+}
+
void smp_text_poke_sync_each_cpu(void)
{
- on_each_cpu(do_sync_core, NULL, 1);
+ __smp_text_poke_sync_each_cpu(NULL);
}
+#ifdef CONFIG_TRACK_CR3
+/*
+ * This returns true if the IPI must be sent to @cpu;
+ *
+ * do that if @cpu is a housekeeping CPU, or if it is already executing
+ * in kernelspace.
+ */
+static bool kernel_cr3_poke_quiesce_cond(int cpu, void *info)
+{
+ if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE))
+ return true;
+
+ return atomic_read(&per_cpu(kernel_cr3_loaded, cpu)) & KERNEL_CR3_IN_KERNEL;
+}
+
+void smp_text_poke_sync_each_cpu_quiescable(void)
+{
+ /*
+ * Pairs with the MOV CR3 serializing instruction in SWITCH_TO_KERNEL_CR3
+ *
+ * Ensures any previous operations are visible on a remote CPU
+ * entering the kernel and updating CR3, if this one decides to quiesce
+ * the IPI.
+ */
+ smp_mb();
+
+ __smp_text_poke_sync_each_cpu(kernel_cr3_poke_quiesce_cond);
+}
+#endif
+
/*
* NOTE: crazy scheme to allow patching Jcc.d32 but not increase the size of
* this thing. When len == 6 everything is prefixed with 0x0f and we map
@@ -2808,6 +2845,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs *regs)
*/
void smp_text_poke_batch_finish(void)
{
+ void (*sync_fn)(void) = smp_text_poke_sync_each_cpu_quiescable;
unsigned char int3 = INT3_INSN_OPCODE;
unsigned int i;
int do_sync;
@@ -2844,11 +2882,20 @@ void smp_text_poke_batch_finish(void)
* First step: add a INT3 trap to the address that will be patched.
*/
for (i = 0; i < text_poke_array.nr_entries; i++) {
- text_poke_array.vec[i].old = *(u8 *)text_poke_addr(&text_poke_array.vec[i]);
- text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE);
+ void *addr = text_poke_addr(&text_poke_array.vec[i]);
+
+ /*
+ * There's no safe way to defer IPIs for patching text in
+ * entry, record whether there is at least one such poke.
+ */
+ if (is_kernel_entrytext((unsigned long)addr))
+ sync_fn = smp_text_poke_sync_each_cpu;
+
+ text_poke_array.vec[i].old = *((u8 *)addr);
+ text_poke(addr, &int3, INT3_INSN_SIZE);
}
- smp_text_poke_sync_each_cpu();
+ sync_fn();
/*
* Second step: update all but the first byte of the patched range.
@@ -2910,7 +2957,7 @@ void smp_text_poke_batch_finish(void)
* not necessary and we'd be safe even without it. But
* better safe than sorry (plus there's not only Intel).
*/
- smp_text_poke_sync_each_cpu();
+ sync_fn();
}
/*
@@ -2931,7 +2978,7 @@ void smp_text_poke_batch_finish(void)
}
if (do_sync)
- smp_text_poke_sync_each_cpu();
+ sync_fn();
/*
* Remove and wait for refs to be zero.
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 133ff20caccd4..84cbc92853259 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -785,7 +785,7 @@ void arch_arm_kprobe(struct kprobe *p)
u8 int3 = INT3_INSN_OPCODE;
text_poke(p->addr, &int3, 1);
- smp_text_poke_sync_each_cpu();
+ smp_text_poke_sync_each_cpu_quiescable();
perf_event_text_poke(p->addr, &p->opcode, 1, &int3, 1);
}
@@ -795,7 +795,7 @@ void arch_disarm_kprobe(struct kprobe *p)
perf_event_text_poke(p->addr, &int3, 1, &p->opcode, 1);
text_poke(p->addr, &p->opcode, 1);
- smp_text_poke_sync_each_cpu();
+ smp_text_poke_sync_each_cpu_quiescable();
}
void arch_remove_kprobe(struct kprobe *p)
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 3f8fea52619f9..87979b93e1dd0 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -508,11 +508,11 @@ void arch_unoptimize_kprobe(struct optimized_kprobe *op)
JMP32_INSN_SIZE - INT3_INSN_SIZE);
text_poke(addr, new, INT3_INSN_SIZE);
- smp_text_poke_sync_each_cpu();
+ smp_text_poke_sync_each_cpu_quiescable();
text_poke(addr + INT3_INSN_SIZE,
new + INT3_INSN_SIZE,
JMP32_INSN_SIZE - INT3_INSN_SIZE);
- smp_text_poke_sync_each_cpu();
+ smp_text_poke_sync_each_cpu_quiescable();
perf_event_text_poke(op->kp.addr, old, JMP32_INSN_SIZE, new, JMP32_INSN_SIZE);
}
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 33080ad889b71..ce8acafc932ed 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -194,7 +194,7 @@ static int write_relocate_add(Elf64_Shdr *sechdrs,
write, apply);
if (!early) {
- smp_text_poke_sync_each_cpu();
+ smp_text_poke_sync_each_cpu_quiescable();
mutex_unlock(&text_mutex);
}
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 0755bc39b0d80..7496d26a85a4c 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -199,6 +199,20 @@ static inline bool is_kernel_inittext(unsigned long addr)
addr < (unsigned long)_einittext;
}
+/**
+ * is_kernel_entrytext - checks if the pointer address is located in the
+ * .entry.text section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .entry.text, false otherwise.
+ */
+static inline bool is_kernel_entrytext(unsigned long addr)
+{
+ return addr >= (unsigned long)__entry_text_start &&
+ addr < (unsigned long)__entry_text_end;
+}
+
/**
* __is_kernel_text - checks if the pointer address is located in the
* .text section
--
2.56.1
^ permalink raw reply related [flat|nested] 44+ messages in thread* Re: [PATCH v10 10/10] context_tracking,x86: Quiesce kernel text patching IPIs when tracking CR3 switches
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
0 siblings, 0 replies; 44+ messages in thread
From: sashiko-bot @ 2026-11-28 20:15 UTC (permalink / raw)
To: Valentin Schneider, linux-mm, x86
Cc: Peter Zijlstra (Intel), Nicolas Saenz Julienne, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] x86/alternative: missed sync_core() IPI during NMI/IST in CR3
exit window
- [High] x86/alternative: double fault when smp_text_poke_batch_finish()
patches entry
- [High] x86/pti: user PTI page tables map pcpu_hot sharing
kernel_cr3_loaded page
--
commit ec3303ea2095c7cee59dcdba3812d5ac034b296c
Author: Valentin Schneider <vschneid@redhat.com>
context_tracking,x86: Quiesce kernel text patching IPIs when tracking CR3 switches
This commit introduces smp_text_poke_sync_each_cpu_quiescable() to skip
sending sync_core() IPIs to isolated CPUs that have kernel_cr3_loaded set
to user mode, while falling back to broadcasting the IPI when patching
.entry.text.
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index 582c6d8307d15..283c94394c0b9 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
[ ... ]
> @@ -2636,11 +2638,46 @@ static void do_sync_core(void *info)
> sync_core();
> }
>
> +static void __smp_text_poke_sync_each_cpu(smp_cond_func_t cond_func)
> +{
> + on_each_cpu_cond(cond_func, do_sync_core, NULL, 1);
> +}
> +
> void smp_text_poke_sync_each_cpu(void)
> {
> - on_each_cpu(do_sync_core, NULL, 1);
> + __smp_text_poke_sync_each_cpu(NULL);
> }
>
> +#ifdef CONFIG_TRACK_CR3
> +/*
> + * This returns true if the IPI must be sent to @cpu;
> + *
> + * do that if @cpu is a housekeeping CPU, or if it is already executing
> + * in kernelspace.
> + */
> +static bool kernel_cr3_poke_quiesce_cond(int cpu, void *info)
> +{
> + if (housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE))
> + return true;
> +
> + return atomic_read(&per_cpu(kernel_cr3_loaded, cpu)) & KERNEL_CR3_IN_KERNEL;
> +}
> +
> +void smp_text_poke_sync_each_cpu_quiescable(void)
> +{
> + /*
> + * Pairs with the MOV CR3 serializing instruction in SWITCH_TO_KERNEL_CR3
> + *
> + * Ensures any previous operations are visible on a remote CPU
> + * entering the kernel and updating CR3, if this one decides to quiesce
> + * the IPI.
> + */
> + smp_mb();
> +
> + __smp_text_poke_sync_each_cpu(kernel_cr3_poke_quiesce_cond);
> +}
> +#endif
[Severity: High]
Can kernel_cr3_poke_quiesce_cond() skip an isolated CPU while it is
executing an NMI or IST handler in kernel mode?
In commit "x86/mm/pti: Drive kernel_cr3_loaded", SWITCH_TO_USER_CR3 and
PARANOID_RESTORE_CR3 clear kernel_cr3_loaded to KERNEL_CR3_IN_USER before
writing the user page table value to %cr3:
arch/x86/entry/calling.h:SWITCH_TO_USER_CR3
TRACK_CR3_KERNEL_EXIT
mov %cr3, \scratch_reg
...
mov \scratch_reg, %cr3
arch/x86/entry/calling.h:SAVE_AND_SWITCH_TO_KERNEL_CR3
bt $PTI_USER_PGTABLE_BIT, \scratch_reg
jnc .Ldone_\@
PARANOID_TRACK_CR3_KERNEL_ENTRY \scratch_reg \save_reg
ADJUST_KERNEL_CR3 \scratch_reg
movq \scratch_reg, %cr3
.Ldone_\@:
If an NMI or IST exception arrives during that window, %cr3 still holds
the kernel page table (PTI_USER_PGTABLE_BIT is 0):
CPU0 CPU1 (isolated)
SWITCH_TO_USER_CR3
TRACK_CR3_KERNEL_EXIT
kernel_cr3_loaded = 0
<NMI / IST>
paranoid_entry
SAVE_AND_SWITCH_TO_KERNEL_CR3
bt $PTI_USER_PGTABLE_BIT
jnc .Ldone
exc_nmi()
smp_text_poke_batch_finish()
text_poke(...)
kernel_cr3_poke_quiesce_cond(1)
reads kernel_cr3_loaded == 0
skips sync_core() IPI
executes patched kernel text
<-- unsynchronized icache
Because SAVE_AND_SWITCH_TO_KERNEL_CR3 branches to .Ldone without setting
KERNEL_CR3_IN_KERNEL or writing %cr3, CPU1 runs the entire NMI or IST C
handler with kernel_cr3_loaded == 0 and no serializing MOV CR3 on entry or
exit, so it can fetch partially patched instructions.
[Severity: High]
Does defining and mapping kernel_cr3_loaded in commit "x86/mm/pti:
Introduce kernel_cr3_loaded" also expose pcpu_hot in user PTI page tables?
arch/x86/mm/pti.c defines kernel_cr3_loaded with
DEFINE_PER_CPU_PAGE_ALIGNED(atomic_t, kernel_cr3_loaded), which aligns the
start of the 4-byte atomic_t to PAGE_SIZE in .data..percpu..page_aligned
without padding its size to a full page. Because arch/x86/mm/pti.o is the
last object contributing to .data..percpu..page_aligned and PERCPU_INPUT()
in include/asm-generic/vmlinux.lds.h only aligns the next section to a
cacheline:
include/asm-generic/vmlinux.lds.h:PERCPU_INPUT
*(.data..percpu..page_aligned) \
. = ALIGN(cacheline); \
__per_cpu_hot_start = .; \
*(SORT_BY_ALIGNMENT(.data..percpu..hot.*)) \
__per_cpu_hot_start (including pcpu_hot with __stack_chk_guard,
current_task, and cpu_current_top_of_stack) is placed at offset 64 of the
same 4KB page as kernel_cr3_loaded, and pti_clone_user_shared() maps that
entire 4KB page into the user page tables.
> @@ -2808,6 +2845,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs *regs)
> */
> void smp_text_poke_batch_finish(void)
> {
> + void (*sync_fn)(void) = smp_text_poke_sync_each_cpu_quiescable;
> unsigned char int3 = INT3_INSN_OPCODE;
> unsigned int i;
> int do_sync;
> @@ -2844,11 +2882,20 @@ void smp_text_poke_batch_finish(void)
> * First step: add a INT3 trap to the address that will be patched.
> */
> for (i = 0; i < text_poke_array.nr_entries; i++) {
> - text_poke_array.vec[i].old = *(u8 *)text_poke_addr(&text_poke_array.vec[i]);
> - text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE);
> + void *addr = text_poke_addr(&text_poke_array.vec[i]);
> +
> + /*
> + * There's no safe way to defer IPIs for patching text in
> + * entry, record whether there is at least one such poke.
> + */
> + if (is_kernel_entrytext((unsigned long)addr))
> + sync_fn = smp_text_poke_sync_each_cpu;
> +
> + text_poke_array.vec[i].old = *((u8 *)addr);
> + text_poke(addr, &int3, INT3_INSN_SIZE);
> }
>
> - smp_text_poke_sync_each_cpu();
> + sync_fn();
[Severity: High]
Can patching a static branch in .entry.text at runtime via
smp_text_poke_batch_finish() cause a double fault on CPUs entering or
exiting the kernel?
When housekeeping_update() enables housekeeping_overridden at runtime (for
example, when creating an isolated cpuset partition),
smp_text_poke_batch_finish() writes INT3 (0xCC) to the static branch sites
inside TRACK_CR3_KERNEL_ENTRY, TRACK_CR3_KERNEL_EXIT,
PARANOID_TRACK_CR3_KERNEL_ENTRY, and PARANOID_TRACK_CR3_KERNEL_EXIT, and
then broadcasts sync_fn():
arch/x86/entry/entry_64.S:entry_SYSCALL_64
swapgs
movq %rsp, PER_CPU_VAR(cpu_tss_rw + TSS_sp2)
SWITCH_TO_KERNEL_CR3 scratch_reg=%rsp
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
arch/x86/entry/calling.h:SWITCH_TO_KERNEL_CR3
ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
mov %cr3, \scratch_reg
TRACK_CR3_KERNEL_ENTRY
ADJUST_KERNEL_CR3 \scratch_reg
mov \scratch_reg, %cr3
A CPU that hits this transient INT3 traps into asm_exc_int3 at CPL 0 while
%cr3 still points to the user page tables (and in entry_SYSCALL_64 and
entry_SYSCALL_compat, while %rsp holds the raw %cr3 value because X86_TRAP_BP
does not use an IST stack). error_entry sees CS at CPL 0 and skips
switching to the kernel CR3 or kernel GSBASE, so pushing the exception
frame or calling exc_int3() faults immediately and escalates to a double
fault.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127201221.434876-1-vschneid@redhat.com?part=10
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (9 preceding siblings ...)
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-30 17:31 ` Dave Hansen
2026-11-30 17:44 ` Steven Rostedt
2026-11-30 19:55 ` Andy Lutomirski
2026-12-04 7:58 ` [syzbot ci] Re: x86: Quiesce text_poke() IPIs syzbot ci
12 siblings, 1 reply; 44+ messages in thread
From: Dave Hansen @ 2026-11-30 17:31 UTC (permalink / raw)
To: Valentin Schneider, linux-kernel, linux-mm, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Steven Rostedt, Ard Biesheuvel, Sami Tolvanen, David S. Miller,
Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng,
Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 11/27/26 12:12, Valentin Schneider wrote:
> So yeah, thoughts welcome here!
My first thought is that it's not worth it. Want to skip text patching
IPIs? Get a Meltdown-free CPU.
The entry assembly is also way too complicated. There must be some
routes to simplification here.
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 17:31 ` [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Dave Hansen
@ 2026-11-30 17:44 ` Steven Rostedt
2026-11-30 17:55 ` Dave Hansen
0 siblings, 1 reply; 44+ messages in thread
From: Steven Rostedt @ 2026-11-30 17:44 UTC (permalink / raw)
To: Dave Hansen
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Mon, 30 Nov 2026 09:31:55 -0800
Dave Hansen <dave.hansen@intel.com> wrote:
> On 11/27/26 12:12, Valentin Schneider wrote:
> > So yeah, thoughts welcome here!
>
> My first thought is that it's not worth it. Want to skip text patching
> IPIs? Get a Meltdown-free CPU.
Hmm, how does that help?
-- Steve
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 17:44 ` Steven Rostedt
@ 2026-11-30 17:55 ` Dave Hansen
2026-11-30 18:50 ` Steven Rostedt
0 siblings, 1 reply; 44+ messages in thread
From: Dave Hansen @ 2026-11-30 17:55 UTC (permalink / raw)
To: Steven Rostedt
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On 11/30/26 09:44, Steven Rostedt wrote:
> On Mon, 30 Nov 2026 09:31:55 -0800 Dave Hansen <dave.hansen@intel.com> wrote:
>> On 11/27/26 12:12, Valentin Schneider wrote:
>>> So yeah, thoughts welcome here!
>> My first thought is that it's not worth it. Want to skip text patching
>> IPIs? Get a Meltdown-free CPU.
> Hmm, how does that help?
I honestly don't mean to be dismissive about it. There are natural
limits to how far we're willing to push the kernel to achieve a given
goal. Think of the 4G/4G kernel patches [1] for example.
There were two ways to get 64GB of RAM on x86 in those days: Run the
4G/4G patches or get an x86_64 CPU. The upstream kernel path was "get an
x86_64 CPU".
So, how do we avoid text_poke() IPIs? There are two paths I see:
A. Get a Meltdown-free CPU.
Pro: Simpler kernel maintenance forever
Con: Lots of otherwise-fine CPUs can't avoid the IPIs
B. Merge something like this series
Pro: Old CPUs are free of text_poke() IPIs
Con: A harder to maintain kernel forever
So, how does it help to just throw out all the old CPUs? It makes
maintaining this chunk of the kernel easier forever.
1. https://lwn.net/Articles/39283/
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 17:55 ` Dave Hansen
@ 2026-11-30 18:50 ` Steven Rostedt
2026-11-30 19:04 ` Dave Hansen
0 siblings, 1 reply; 44+ messages in thread
From: Steven Rostedt @ 2026-11-30 18:50 UTC (permalink / raw)
To: Dave Hansen
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Mon, 30 Nov 2026 09:55:32 -0800
Dave Hansen <dave.hansen@intel.com> wrote:
> On 11/30/26 09:44, Steven Rostedt wrote:
> > On Mon, 30 Nov 2026 09:31:55 -0800 Dave Hansen <dave.hansen@intel.com> wrote:
> >> On 11/27/26 12:12, Valentin Schneider wrote:
> >>> So yeah, thoughts welcome here!
> >> My first thought is that it's not worth it. Want to skip text patching
> >> IPIs? Get a Meltdown-free CPU.
> > Hmm, how does that help?
>
> I honestly don't mean to be dismissive about it. There are natural
> limits to how far we're willing to push the kernel to achieve a given
> goal. Think of the 4G/4G kernel patches [1] for example.
>
> There were two ways to get 64GB of RAM on x86 in those days: Run the
> 4G/4G patches or get an x86_64 CPU. The upstream kernel path was "get an
> x86_64 CPU".
>
> So, how do we avoid text_poke() IPIs? There are two paths I see:
>
> A. Get a Meltdown-free CPU.
> Pro: Simpler kernel maintenance forever
> Con: Lots of otherwise-fine CPUs can't avoid the IPIs
I guess my question is why does a Meltdown-free CPU not need the IPIs?
Text poke changes the running kernel text. To do so, it must synchronize
*all* CPUs. It's needed because of required memory barrier that all CPUs
must perform.
In order to convert a nop into a jump, the patching CPU will create a new
page table over the text page that needs to be udpated. It then inserts a
breakpoint at the beginning instruction. In order to make sure all CPUs see
that breakpoint, it issues an IPI to all CPUS to force memory barriers. It
then updates the rest of the instruction and issues another set of IPIs to
force all CPUs to see the new update. It then replaces the breakpoint with
the jump op code and now all CPUs see a jump and not a nop.
Of course a CPU running in user space under NO_HZ doesn't need the IPI as
it's not executing kernel code. Which is the point of this patch series.
> B. Merge something like this series
> Pro: Old CPUs are free of text_poke() IPIs
> Con: A harder to maintain kernel forever
>
> So, how does it help to just throw out all the old CPUs? It makes
> maintaining this chunk of the kernel easier forever.
>
> 1. https://lwn.net/Articles/39283/
I haven't looked at the entire patch set yet, and I'm guessing there's ugly
logic to handle old Meltdown CPUs. I'm fine if we only make this feature
available for kernels without the meltdown mitigation. My point was that
even with a Meltdown-free CPU we still need IPIs.
-- Steve
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 18:50 ` Steven Rostedt
@ 2026-11-30 19:04 ` Dave Hansen
2026-11-30 19:15 ` Steven Rostedt
0 siblings, 1 reply; 44+ messages in thread
From: Dave Hansen @ 2026-11-30 19:04 UTC (permalink / raw)
To: Steven Rostedt
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On 11/30/26 10:50, Steven Rostedt wrote:
>> A. Get a Meltdown-free CPU.
>> Pro: Simpler kernel maintenance forever
>> Con: Lots of otherwise-fine CPUs can't avoid the IPIs
> I guess my question is why does a Meltdown-free CPU not need the IPIs?
Oh, that is a good question. I was forgetting how this thing actually works.
I was wrong: meltdown-free CPUs don't get to skip the IPIs. They just
don't have to worry about the per-cpu data structures being unmapped
when they come back in to the kernel.
But there did end up being some substantial complexity with the per-cpu
variables to make PTI work correctly. That's the part I was reacting to.
My overall reaction is still the same, though: too much pain for too
little gain. There has to be a simpler way to do this.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:04 ` Dave Hansen
@ 2026-11-30 19:15 ` Steven Rostedt
2026-11-30 19:31 ` Mathieu Desnoyers
0 siblings, 1 reply; 44+ messages in thread
From: Steven Rostedt @ 2026-11-30 19:15 UTC (permalink / raw)
To: Dave Hansen
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Mon, 30 Nov 2026 11:04:24 -0800
Dave Hansen <dave.hansen@intel.com> wrote:
> On 11/30/26 10:50, Steven Rostedt wrote:
> >> A. Get a Meltdown-free CPU.
> >> Pro: Simpler kernel maintenance forever
> >> Con: Lots of otherwise-fine CPUs can't avoid the IPIs
> > I guess my question is why does a Meltdown-free CPU not need the IPIs?
>
> Oh, that is a good question. I was forgetting how this thing actually works.
>
> I was wrong: meltdown-free CPUs don't get to skip the IPIs. They just
> don't have to worry about the per-cpu data structures being unmapped
> when they come back in to the kernel.
>
> But there did end up being some substantial complexity with the per-cpu
> variables to make PTI work correctly. That's the part I was reacting to.
>
> My overall reaction is still the same, though: too much pain for too
> little gain. There has to be a simpler way to do this.
I will say that there's a big demand for this in my new industry where we
run most our work in user space under NO_HZ mode where people get really
upset when their applications get interrupted by the kernel.
Without this, just enabling tracing (including perf) on any CPU causes a
big disruption to the system.
Maybe there's a simpler way to do this, but this isn't a niche market. It's
pretty much all of the financial industry and likely other use cases as well.
-- Steve
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:15 ` Steven Rostedt
@ 2026-11-30 19:31 ` Mathieu Desnoyers
2026-11-30 19:40 ` Dave Hansen
2026-11-30 20:10 ` Mathieu Desnoyers
0 siblings, 2 replies; 44+ messages in thread
From: Mathieu Desnoyers @ 2026-11-30 19:31 UTC (permalink / raw)
To: Steven Rostedt, Dave Hansen
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 2026-11-30 14:15, Steven Rostedt wrote:
> On Mon, 30 Nov 2026 11:04:24 -0800
> Dave Hansen <dave.hansen@intel.com> wrote:
>
>> On 11/30/26 10:50, Steven Rostedt wrote:
>>>> A. Get a Meltdown-free CPU.
>>>> Pro: Simpler kernel maintenance forever
>>>> Con: Lots of otherwise-fine CPUs can't avoid the IPIs
>>> I guess my question is why does a Meltdown-free CPU not need the IPIs?
>>
>> Oh, that is a good question. I was forgetting how this thing actually works.
>>
>> I was wrong: meltdown-free CPUs don't get to skip the IPIs. They just
>> don't have to worry about the per-cpu data structures being unmapped
>> when they come back in to the kernel.
>>
>> But there did end up being some substantial complexity with the per-cpu
>> variables to make PTI work correctly. That's the part I was reacting to.
>>
>> My overall reaction is still the same, though: too much pain for too
>> little gain. There has to be a simpler way to do this.
>
> I will say that there's a big demand for this in my new industry where we
> run most our work in user space under NO_HZ mode where people get really
> upset when their applications get interrupted by the kernel.
>
> Without this, just enabling tracing (including perf) on any CPU causes a
> big disruption to the system.
>
> Maybe there's a simpler way to do this, but this isn't a niche market. It's
> pretty much all of the financial industry and likely other use cases as well.
My understanding of the high level dilemma here is as follows:
1- the kernel needs to learn about quiescence of all CPUs (e.g. context
synchronizing instructions) when it does code patching.
2- currently IPIs are sent to each non-idle CPU to achieve this.
3- NO_HZ userspace is allergic to IPI delays.
How about the following idea:
Introduce a new vDSO which can be called periodically from NO_HZ userspace
to note kernel quiescence for that CPU. It would do so by incrementing a
counter in the rseq per-thread area from userspace. Observing this counter
increment would allow the kernel to detect that this CPU was running in
userspace at some point between the two loads of that field from the kernel.
Those loads from the kernel would happen from remote CPUs. The running thread
on the NO_HZ CPU would be guaranteed stable by the rq lock.
Let me know if this may work, or if I'm missing the point entirely.
Thanks!
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:31 ` Mathieu Desnoyers
@ 2026-11-30 19:40 ` Dave Hansen
2026-11-30 19:52 ` Mathieu Desnoyers
2026-11-30 20:22 ` Steven Rostedt
2026-11-30 20:10 ` Mathieu Desnoyers
1 sibling, 2 replies; 44+ messages in thread
From: Dave Hansen @ 2026-11-30 19:40 UTC (permalink / raw)
To: Mathieu Desnoyers, Steven Rostedt
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 11/30/26 11:31, Mathieu Desnoyers wrote:
> 1- the kernel needs to learn about quiescence of all CPUs (e.g. context
> synchronizing instructions) when it does code patching.
There was also an attempt to "quiesce" the TLB invalidation IPIs. That
one means that the TLB needs to be flushed on the way back in to the
kernel as well.
There are a whole lot of moving parts on this one. :)
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:40 ` Dave Hansen
@ 2026-11-30 19:52 ` Mathieu Desnoyers
2026-11-30 20:22 ` Steven Rostedt
1 sibling, 0 replies; 44+ messages in thread
From: Mathieu Desnoyers @ 2026-11-30 19:52 UTC (permalink / raw)
To: Dave Hansen, Steven Rostedt
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 2026-11-30 14:40, Dave Hansen wrote:
> On 11/30/26 11:31, Mathieu Desnoyers wrote:
>> 1- the kernel needs to learn about quiescence of all CPUs (e.g. context
>> synchronizing instructions) when it does code patching.
>
> There was also an attempt to "quiesce" the TLB invalidation IPIs. That
> one means that the TLB needs to be flushed on the way back in to the
> kernel as well.
AFAIU that would be required for TLB entires pointing to kernel pages.
>
> There are a whole lot of moving parts on this one. :)
In addition to flush TLB on kernel entry, TLB entries pointing
to userspace memory are also a separate concern, right ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:40 ` Dave Hansen
2026-11-30 19:52 ` Mathieu Desnoyers
@ 2026-11-30 20:22 ` Steven Rostedt
2026-12-01 11:10 ` Valentin Schneider
1 sibling, 1 reply; 44+ messages in thread
From: Steven Rostedt @ 2026-11-30 20:22 UTC (permalink / raw)
To: Dave Hansen
Cc: Mathieu Desnoyers, Valentin Schneider, linux-kernel, linux-mm,
x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Andy Lutomirski, Peter Zijlstra,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Ard Biesheuvel, Sami Tolvanen, David S. Miller, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Mon, 30 Nov 2026 11:40:40 -0800
Dave Hansen <dave.hansen@intel.com> wrote:
> On 11/30/26 11:31, Mathieu Desnoyers wrote:
> > 1- the kernel needs to learn about quiescence of all CPUs (e.g. context
> > synchronizing instructions) when it does code patching.
>
> There was also an attempt to "quiesce" the TLB invalidation IPIs. That
> one means that the TLB needs to be flushed on the way back in to the
> kernel as well.
>
> There are a whole lot of moving parts on this one. :)
Yes, and we have an awful hack to get around that one. As vkfree will
eventually trigger a TLB for all the virtual addresses it needs to clean
up, and reading the proc file system causes a lot of vmalloc and vkfree's
to be called, monitoring the proc file system from the house keeping CPUs
will eventually trigger a TLB shootdown on all CPUS! The nasty hack is to
delay that until *after* trading hours have finished! :-p
Yes, we really rather have what Valentin is proposing!
-- Steve
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 20:22 ` Steven Rostedt
@ 2026-12-01 11:10 ` Valentin Schneider
2026-12-01 12:55 ` Peter Zijlstra
2026-12-02 17:01 ` Andy Lutomirski
0 siblings, 2 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-12-01 11:10 UTC (permalink / raw)
To: Steven Rostedt, Dave Hansen
Cc: Mathieu Desnoyers, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 30/11/26 15:22, Steven Rostedt wrote:
> On Mon, 30 Nov 2026 11:40:40 -0800
> Dave Hansen <dave.hansen@intel.com> wrote:
>
>> On 11/30/26 11:31, Mathieu Desnoyers wrote:
>> > 1- the kernel needs to learn about quiescence of all CPUs (e.g. context
>> > synchronizing instructions) when it does code patching.
>>
>> There was also an attempt to "quiesce" the TLB invalidation IPIs. That
>> one means that the TLB needs to be flushed on the way back in to the
>> kernel as well.
>>
>> There are a whole lot of moving parts on this one. :)
>
> Yes, and we have an awful hack to get around that one. As vkfree will
> eventually trigger a TLB for all the virtual addresses it needs to clean
> up, and reading the proc file system causes a lot of vmalloc and vkfree's
> to be called, monitoring the proc file system from the house keeping CPUs
> will eventually trigger a TLB shootdown on all CPUS! The nasty hack is to
> delay that until *after* trading hours have finished! :-p
>
> Yes, we really rather have what Valentin is proposing!
>
I'm replying to the tail end of that thread to clear things up somewhat;
The whole x86-specific grubby kernel entry tracking is *not* required for
text_poke() IPI quiescing. Thanks to Josh's objtool patches we can actually
validate which keys get used where, and that means we can shove the
catch-up sequence (serialize()) in C code. For reference this is what I had
for v7, leveraging context_tracking:
https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@redhat.com/
And on the plus side this mostly architecture-agnostic; AFAICT arm64 would
need that too as of at least:
cfb00a357864 ("arm64: jump_label: Ensure patched jump_labels are visible to all CPUs")
The real problem is those (kernel) TLB flushes. I found no way to
check/validate when/where exactly vmalloc accesses can happen in the kernel
entry, so the only sane approach was to have the catch-up sequence (TLB
flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
switch.
All of that ugly ASM code is to pretty much reproduce context_tracking but
at CR3-switch level. If we can somehow validate/confirm that we can live
with stale vmalloc entries down to where ct_kernel_enter_state() happens,
then I could have this all be tied back to context_tracking() which was so
much cleaner. Unfortunately from what I understood from Dave regarding what
the CPU is allowed to cache behind our backs, it's really not that
straightforward, nor maybe even possible.
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 11:10 ` Valentin Schneider
@ 2026-12-01 12:55 ` Peter Zijlstra
2026-12-01 18:41 ` Valentin Schneider
2026-12-01 21:28 ` Andy Lutomirski
2026-12-02 17:01 ` Andy Lutomirski
1 sibling, 2 replies; 44+ messages in thread
From: Peter Zijlstra @ 2026-12-01 12:55 UTC (permalink / raw)
To: Valentin Schneider
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers, linux-kernel,
linux-mm, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Ard Biesheuvel, Sami Tolvanen, David S. Miller, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Tue, Dec 01, 2026 at 12:10:26PM +0100, Valentin Schneider wrote:
> The real problem is those (kernel) TLB flushes. I found no way to
> check/validate when/where exactly vmalloc accesses can happen in the kernel
> entry, so the only sane approach was to have the catch-up sequence (TLB
> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
> switch.
Right, so the task stacks are vmalloc. So since you didn't qualify what
vmalloc accesses are problematic, it is pretty much the very first thing
you touch.
On 'legacy' IDT systems we do that trampoline stack thing due to PTI;
however:
> All of that ugly ASM code is to pretty much reproduce context_tracking but
> at CR3-switch level. If we can somehow validate/confirm that we can live
> with stale vmalloc entries down to where ct_kernel_enter_state() happens,
> then I could have this all be tied back to context_tracking() which was so
> much cleaner. Unfortunately from what I understood from Dave regarding what
> the CPU is allowed to cache behind our backs, it's really not that
> straightforward, nor maybe even possible.
all of that ugly CR3 ASM code is totally unused on FRED and as such none
of this will work with FRED on.
Realistically we will likely live if you do it from the normal context
tracking code (you done that, it worked), but yes, tricky.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 12:55 ` Peter Zijlstra
@ 2026-12-01 18:41 ` Valentin Schneider
2026-12-01 21:28 ` Andy Lutomirski
1 sibling, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-12-01 18:41 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers, linux-kernel,
linux-mm, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Andy Lutomirski,
Arnaldo Carvalho de Melo, Josh Poimboeuf, Paolo Bonzini,
Arnd Bergmann, Frederic Weisbecker, Paul E. McKenney, Jason Baron,
Ard Biesheuvel, Sami Tolvanen, David S. Miller, Neeraj Upadhyay,
Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On 01/12/26 13:55, Peter Zijlstra wrote:
> On Tue, Dec 01, 2026 at 12:10:26PM +0100, Valentin Schneider wrote:
>
>> The real problem is those (kernel) TLB flushes. I found no way to
>> check/validate when/where exactly vmalloc accesses can happen in the kernel
>> entry, so the only sane approach was to have the catch-up sequence (TLB
>> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
>> switch.
>
> Right, so the task stacks are vmalloc. So since you didn't qualify what
> vmalloc accesses are problematic, it is pretty much the very first thing
> you touch.
>
Well AFAICT it's quite often the task stacks... At least anything somewhat
fork-heavy on the HK CPUs will get there.
> On 'legacy' IDT systems we do that trampoline stack thing due to PTI;
> however:
>
>> All of that ugly ASM code is to pretty much reproduce context_tracking but
>> at CR3-switch level. If we can somehow validate/confirm that we can live
>> with stale vmalloc entries down to where ct_kernel_enter_state() happens,
>> then I could have this all be tied back to context_tracking() which was so
>> much cleaner. Unfortunately from what I understood from Dave regarding what
>> the CPU is allowed to cache behind our backs, it's really not that
>> straightforward, nor maybe even possible.
>
> all of that ugly CR3 ASM code is totally unused on FRED and as such none
> of this will work with FRED on.
>
Bah, I had dismissed that when looking at the NMI paths but now that I take
a proper look at it yeah, FRED gives this the finger.
> Realistically we will likely live if you do it from the normal context
> tracking code (you done that, it worked), but yes, tricky.
I don't really know how to go about this; yes technically this survived for
a few days of soak test, but the moment it explodes it's going to be nearly
undebuggable.
And that's all going to be hardware dependent, so even if I find a customer
willing to soak test this for a while, that's no guarantee it'll also work
on other setups.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 12:55 ` Peter Zijlstra
2026-12-01 18:41 ` Valentin Schneider
@ 2026-12-01 21:28 ` Andy Lutomirski
2026-12-01 21:41 ` Andy Lutomirski
1 sibling, 1 reply; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-01 21:28 UTC (permalink / raw)
To: Peter Zijlstra (Intel), Valentin Schneider
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers,
Linux Kernel Mailing List, linux-mm, the arch/x86 maintainers,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On Tue, Dec 1, 2026, at 4:55 AM, Peter Zijlstra wrote:
> On Tue, Dec 01, 2026 at 12:10:26PM +0100, Valentin Schneider wrote:
>
>> The real problem is those (kernel) TLB flushes. I found no way to
>> check/validate when/where exactly vmalloc accesses can happen in the kernel
>> entry, so the only sane approach was to have the catch-up sequence (TLB
>> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
>> switch.
>
> Right, so the task stacks are vmalloc. So since you didn't qualify what
> vmalloc accesses are problematic, it is pretty much the very first thing
> you touch.
I spent like thirty seconds contemplating exactly how nasty it would be to try to implement all this cleanly without touching the vmapped stack.
And then I decided this was a nonissue. Consider how we actually reach the enter-the-kernel code: we start in the kernel *on the task stack*, then we run the exit-the-kernel code, then we maybe go to userspace and come back, then we run the enter-the-kernel code.
There had better not be anything in the kernel that changes the task stack mapping and relies on an IPI that runs in the interim! If there was, it would surely crash us just as crashily if we were just executing normal kernel code, expecially with IRQs off :)
IOW, the task stack is just about the only vmapped thing that we *can* rely on to be coherent wrt the TLB.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 21:28 ` Andy Lutomirski
@ 2026-12-01 21:41 ` Andy Lutomirski
2026-12-02 10:41 ` Valentin Schneider
0 siblings, 1 reply; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-01 21:41 UTC (permalink / raw)
To: Peter Zijlstra (Intel), Valentin Schneider
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers,
Linux Kernel Mailing List, linux-mm, the arch/x86 maintainers,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On Tue, Dec 1, 2026, at 1:28 PM, Andy Lutomirski wrote:
> On Tue, Dec 1, 2026, at 4:55 AM, Peter Zijlstra wrote:
>> On Tue, Dec 01, 2026 at 12:10:26PM +0100, Valentin Schneider wrote:
>>
>>> The real problem is those (kernel) TLB flushes. I found no way to
>>> check/validate when/where exactly vmalloc accesses can happen in the kernel
>>> entry, so the only sane approach was to have the catch-up sequence (TLB
>>> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
>>> switch.
>>
>> Right, so the task stacks are vmalloc. So since you didn't qualify what
>> vmalloc accesses are problematic, it is pretty much the very first thing
>> you touch.
>
> I spent like thirty seconds contemplating exactly how nasty it would be
> to try to implement all this cleanly without touching the vmapped stack.
>
> And then I decided this was a nonissue. Consider how we actually reach
> the enter-the-kernel code: we start in the kernel *on the task stack*,
> then we run the exit-the-kernel code, then we maybe go to userspace and
> come back, then we run the enter-the-kernel code.
>
> There had better not be anything in the kernel that changes the task
> stack mapping and relies on an IPI that runs in the interim! If there
> was, it would surely crash us just as crashily if we were just
> executing normal kernel code, expecially with IRQs off :)
Let me say this more clearly: no one unmaps the task stack while the task is still running.
>
> IOW, the task stack is just about the only vmapped thing that we *can*
> rely on to be coherent wrt the TLB.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 21:41 ` Andy Lutomirski
@ 2026-12-02 10:41 ` Valentin Schneider
2026-12-03 17:21 ` Valentin Schneider
0 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-12-02 10:41 UTC (permalink / raw)
To: Andy Lutomirski, Peter Zijlstra (Intel)
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers,
Linux Kernel Mailing List, linux-mm, the arch/x86 maintainers,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 01/12/26 13:41, Andy Lutomirski wrote:
> On Tue, Dec 1, 2026, at 1:28 PM, Andy Lutomirski wrote:
>> On Tue, Dec 1, 2026, at 4:55 AM, Peter Zijlstra wrote:
>>> On Tue, Dec 01, 2026 at 12:10:26PM +0100, Valentin Schneider wrote:
>>>
>>>> The real problem is those (kernel) TLB flushes. I found no way to
>>>> check/validate when/where exactly vmalloc accesses can happen in the kernel
>>>> entry, so the only sane approach was to have the catch-up sequence (TLB
>>>> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
>>>> switch.
>>>
>>> Right, so the task stacks are vmalloc. So since you didn't qualify what
>>> vmalloc accesses are problematic, it is pretty much the very first thing
>>> you touch.
>>
>> I spent like thirty seconds contemplating exactly how nasty it would be
>> to try to implement all this cleanly without touching the vmapped stack.
>>
>> And then I decided this was a nonissue. Consider how we actually reach
>> the enter-the-kernel code: we start in the kernel *on the task stack*,
>> then we run the exit-the-kernel code, then we maybe go to userspace and
>> come back, then we run the enter-the-kernel code.
>>
>> There had better not be anything in the kernel that changes the task
>> stack mapping and relies on an IPI that runs in the interim! If there
>> was, it would surely crash us just as crashily if we were just
>> executing normal kernel code, expecially with IRQs off :)
>
> Let me say this more clearly: no one unmaps the task stack while the task is still running.
>
Right, the task has to reach do_exit() in kernelspace proper before that
happens; I think I had established quite early on that this one of the
few safe cases.
The annoying thing is that I can't quiesce kernel TLB range flushes /just/
for the task stacks, there's too much indirection and from what I've seen
these flushes are mainly driven by __purge_vmap_area_lazy() which is
completely out of line.
Ideally I would like to have some static/build time analysis (like objtool
for the text_poke() stuff) that can catch vmap'd accesses in .entry text to
1) validate this stuff
2) prevent future breakage
but again I fear there's too much indirection.
I had given up trying to set up some poisoning scheme to at least get some
debug info under QEMU, maybe I can try again by shoving that to an AI.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-02 10:41 ` Valentin Schneider
@ 2026-12-03 17:21 ` Valentin Schneider
0 siblings, 0 replies; 44+ messages in thread
From: Valentin Schneider @ 2026-12-03 17:21 UTC (permalink / raw)
To: Andy Lutomirski, Peter Zijlstra (Intel)
Cc: Steven Rostedt, Dave Hansen, Mathieu Desnoyers,
Linux Kernel Mailing List, linux-mm, the arch/x86 maintainers,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 02/12/26 11:41, Valentin Schneider wrote:
> I had given up trying to set up some poisoning scheme to at least get some
> debug info under QEMU, maybe I can try again by shoving that to an AI.
Well colour me impressed, my good friend Claude wrote me a QEMU plugin and
a custom init to stress all of the entry paths & figure out what memory is
being accessed.
Supposedly, all vmalloc accesses there are:
- the task stack
- the idle stack
- the hardirq stack
with percpu_alloc=page this adds percpu accesses (e.g. PER_CPU_VAR(cpu_tss_rw + TSS_sp2))
I now need to sift through the claudeslop, but that sounds promising.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 11:10 ` Valentin Schneider
2026-12-01 12:55 ` Peter Zijlstra
@ 2026-12-02 17:01 ` Andy Lutomirski
1 sibling, 0 replies; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-02 17:01 UTC (permalink / raw)
To: Valentin Schneider, Steven Rostedt, Dave Hansen
Cc: Mathieu Desnoyers, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin,
Peter Zijlstra (Intel), Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On Tue, Dec 1, 2026, at 3:10 AM, Valentin Schneider wrote:
> On 30/11/26 15:22, Steven Rostedt wrote:
>> On Mon, 30 Nov 2026 11:40:40 -0800
>> Dave Hansen <dave.hansen@intel.com> wrote:
>>
>>> On 11/30/26 11:31, Mathieu Desnoyers wrote:
>>> > 1- the kernel needs to learn about quiescence of all CPUs (e.g. context
>>> > synchronizing instructions) when it does code patching.
>>>
>>> There was also an attempt to "quiesce" the TLB invalidation IPIs. That
>>> one means that the TLB needs to be flushed on the way back in to the
>>> kernel as well.
>>>
>>> There are a whole lot of moving parts on this one. :)
>>
>> Yes, and we have an awful hack to get around that one. As vkfree will
>> eventually trigger a TLB for all the virtual addresses it needs to clean
>> up, and reading the proc file system causes a lot of vmalloc and vkfree's
>> to be called, monitoring the proc file system from the house keeping CPUs
>> will eventually trigger a TLB shootdown on all CPUS! The nasty hack is to
>> delay that until *after* trading hours have finished! :-p
>>
>> Yes, we really rather have what Valentin is proposing!
>>
>
> I'm replying to the tail end of that thread to clear things up somewhat;
>
> The whole x86-specific grubby kernel entry tracking is *not* required for
> text_poke() IPI quiescing. Thanks to Josh's objtool patches we can actually
> validate which keys get used where, and that means we can shove the
> catch-up sequence (serialize()) in C code. For reference this is what I had
> for v7, leveraging context_tracking:
>
> https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@redhat.com/
I don't think entry tracking is required in a correctness sense. But I do think it might be required in a don't-make-a-giant-mess sense.
The issue is that we have at least three different things that all uses IPIs and that, with appropriate care, can skip the IPIs to "quiescent" CPUs: text_poke, kernel TLB flushes, and RCU. We have "context tracking" for RCU and we're talking about introducing a new thing for text_poke and maybe IPIs. Each one of these has, as its primary overhead in the no-actual-IPI-skipped case, a full barrier upon leaving quiescent mode.
I think it would be REALLY REALLY nice if we could unify all of them into *one* full barrier on kernel entry. Then we could consider being quite aggressive about going quiescent in all three senses in userspace without taking an absurd performance hit.
P.S. I have thought, and I still think, that any sensible CPU architecture MUST have the property, even if undocumented, that a TLB fill from a no-entry-in-TLB state on a page of text is sufficient to make prior writes to that page correctly executable. I have not convinced any CPU architect to confirm this, but I also don't see how one could build a CPU that runs userspace code correctly if it didn't have this property. If I'm right, text_poke IPIs could be changed to RAR or INVLPBG invocations.
>
> And on the plus side this mostly architecture-agnostic; AFAICT arm64 would
> need that too as of at least:
>
> cfb00a357864 ("arm64: jump_label: Ensure patched jump_labels are
> visible to all CPUs")
>
>
> The real problem is those (kernel) TLB flushes. I found no way to
> check/validate when/where exactly vmalloc accesses can happen in the kernel
> entry, so the only sane approach was to have the catch-up sequence (TLB
> flush) happen exactly when any vmalloc becomes possible: at the kPTI CR3
> switch.
>
> All of that ugly ASM code is to pretty much reproduce context_tracking but
> at CR3-switch level. If we can somehow validate/confirm that we can live
> with stale vmalloc entries down to where ct_kernel_enter_state() happens,
> then I could have this all be tied back to context_tracking() which was so
> much cleaner. Unfortunately from what I understood from Dave regarding what
> the CPU is allowed to cache behind our backs, it's really not that
> straightforward, nor maybe even possible.
If we can tidy up context tracking to run it early in the noinstr entry code, I bet we can pull this off.
--Andy
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:31 ` Mathieu Desnoyers
2026-11-30 19:40 ` Dave Hansen
@ 2026-11-30 20:10 ` Mathieu Desnoyers
1 sibling, 0 replies; 44+ messages in thread
From: Mathieu Desnoyers @ 2026-11-30 20:10 UTC (permalink / raw)
To: Steven Rostedt, Dave Hansen
Cc: Valentin Schneider, linux-kernel, linux-mm, x86, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, H. Peter Anvin,
Andy Lutomirski, Peter Zijlstra, Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mel Gorman, Andrew Morton,
Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn, Dan Carpenter,
Oleg Nesterov, Juri Lelli, Clark Williams, Tomas Glozar,
Yair Podemsky, Marcelo Tosatti, Daniel Wagner, Petr Tesarik,
Shrikanth Hegde, Dan Beimborn, Pak Hung Vincent Chiu
On 2026-11-30 14:31, Mathieu Desnoyers wrote:
[...]
>
>
> How about the following idea:
>
> Introduce a new vDSO which can be called periodically from NO_HZ userspace
> to note kernel quiescence for that CPU. It would do so by incrementing a
> counter in the rseq per-thread area from userspace. Observing this counter
> increment would allow the kernel to detect that this CPU was running in
> userspace at some point between the two loads of that field from the kernel.
> Those loads from the kernel would happen from remote CPUs. The running thread
> on the NO_HZ CPU would be guaranteed stable by the rq lock.
>
> Let me know if this may work, or if I'm missing the point entirely.
Except my idea is kind of dumb, and Valentin's approach is much better:
let the kernel keep track of this on return to userspace/kernel entry.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (10 preceding siblings ...)
2026-11-30 17:31 ` [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Dave Hansen
@ 2026-11-30 19:55 ` Andy Lutomirski
2026-11-30 20:34 ` Steven Rostedt
2026-12-01 11:13 ` Valentin Schneider
2026-12-04 7:58 ` [syzbot ci] Re: x86: Quiesce text_poke() IPIs syzbot ci
12 siblings, 2 replies; 44+ messages in thread
From: Andy Lutomirski @ 2026-11-30 19:55 UTC (permalink / raw)
To: Valentin Schneider, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Fri, Nov 27, 2026, at 12:12 PM, Valentin Schneider wrote:
> Christmas comes early this year, here's v10!
>
> Approach
> ========
>
> The heart of this series is the thought that while we cannot remove NOHZ_FULL
> CPUs from the list of CPUs targeted by these IPIs, they may not have to execute
> the callbacks immediately. Anything that only affects kernelspace can wait
> until the next user->kernel transition, providing it can be executed "early
> enough" in the entry code as a postponed operation.
So I had a thought a while ago that I called "exact CT" (exact connection tracing). Basically the idea was to promote CT from a sort-of-specialized realtime/nohz feature to a core part of the entry and exit path. I probably sent some emails about it. The complexity (aside from rearranging a bunch of code) sort of boils down to needing a kind of unfortunate full barrier, and it goes like this:
transition to user mode / quiescent:
we set a percpu [0] quiescent flag saying "I promise that I'm on my way to userspace [1], and I will not access problematic mappings or rely on RCU (or, with your idea) run deferred-pokable code until I transition back". We need accesses that logically predate this to be logically synchronized with anything remote that reads this flag, so we make it a release. No big deal, I think.
transition back from user mode / quiescent:
This one is far trickier. We're going to clear the flag. But a remote CPU needs to be able to observe that the flag is clear and therefore not IPI us, which (on every architecture I'm familiar) requires smp_mb() or the equivalent.
So I think we clear the quiescent flag and then read the "did anything happen that we need to handle bit". This could literally be a write, smp_mb(), read, or it could be a CAS (and I haven't really contemplated whether it needs to be a sequentially consistent CAS on architectures (not x86) where this is a real distinction).
And here's why I'm bringing this up. The unquiesce sequence is kind of expensive (tens of cycles! we used to care about this on syscall return!), but maybe it solves your problem too. After all, a deferred TLB flush looks a lot like a deferred serializing operation, and those two look at least a little bit like a remote CPU relying on us being RCU-quiescent. (Okay, RCU really is different, since we probably want to increment a *count* of quiescence too, but I think this can be made to fit in.)
And one thing I hate about the current context tracking is that it's sort of glued on and RCU-specific instead of being a real part of the entry/exit sequence. But maybe it's actually time to change this.
I call my idea "exact" context tracking specifically because I think this stuff should change:
void noinstr __ct_user_enter(enum ctx_state state)
{
struct context_tracking *ct = this_cpu_ptr(&context_tracking);
lockdep_assert_irqs_disabled();
/* Kernel threads aren't supposed to go to userspace */
WARN_ON_ONCE(!current->mm);
^^^^^ excuse me, what is this doing here?
if (!context_tracking_recursion_enter())
return;
^^^^^^ the x86 and generic code do not have recursion confusion any more
if (__ct_state() != state) {
^^^^^ the state transition really should be a foregone conclusion
if (ct->active) {
In the bad old days of the entry/exit code, we had lots of code paths that didn't really know the state that they were transitioning *from*. These days we keep extremely careful track of exactly what's going on, but CT never got updated.
I would be absolutely delighted to help review this if you write it :)
[0] We have a weird tradition of actually using per-task flags on the current task for this kind of thing. This particular use case might require either annoying remote acquisitions of the rq lock or actually using a percpu flag.
[1] There's nothing wrong with aborting the transition as long as we still do the reverse transition.
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:55 ` Andy Lutomirski
@ 2026-11-30 20:34 ` Steven Rostedt
2026-12-01 11:13 ` Valentin Schneider
1 sibling, 0 replies; 44+ messages in thread
From: Steven Rostedt @ 2026-11-30 20:34 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Valentin Schneider, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin,
Peter Zijlstra (Intel), Arnaldo Carvalho de Melo, Josh Poimboeuf,
Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Ard Biesheuvel, Sami Tolvanen,
David S. Miller, Neeraj Upadhyay, Joel Fernandes, Josh Triplett,
Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers, Mel Gorman,
Andrew Morton, Masahiro Yamada, Han Shen, Rik van Riel, Jann Horn,
Dan Carpenter, Oleg Nesterov, Juri Lelli, Clark Williams,
Tomas Glozar, Yair Podemsky, Marcelo Tosatti, Daniel Wagner,
Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Mon, 30 Nov 2026 11:55:11 -0800
"Andy Lutomirski" <luto@kernel.org> wrote:
> On Fri, Nov 27, 2026, at 12:12 PM, Valentin Schneider wrote:
> > Christmas comes early this year, here's v10!
> >
>
> > Approach
> > ========
> >
> > The heart of this series is the thought that while we cannot remove NOHZ_FULL
> > CPUs from the list of CPUs targeted by these IPIs, they may not have to execute
> > the callbacks immediately. Anything that only affects kernelspace can wait
> > until the next user->kernel transition, providing it can be executed "early
> > enough" in the entry code as a postponed operation.
>
> So I had a thought a while ago that I called "exact CT" (exact connection
> tracing). Basically the idea was to promote CT from a
> sort-of-specialized realtime/nohz feature to a core part of the entry and
> exit path. I probably sent some emails about it. The complexity (aside
> from rearranging a bunch of code) sort of boils down to needing a kind of
> unfortunate full barrier, and it goes like this:
>
> transition to user mode / quiescent:
>
> we set a percpu [0] quiescent flag saying "I promise that I'm on my way
> to userspace [1], and I will not access problematic mappings or rely on
> RCU (or, with your idea) run deferred-pokable code until I transition
> back". We need accesses that logically predate this to be logically
> synchronized with anything remote that reads this flag, so we make it a
> release. No big deal, I think.
>
> transition back from user mode / quiescent:
>
> This one is far trickier. We're going to clear the flag. But a remote
> CPU needs to be able to observe that the flag is clear and therefore not
> IPI us, which (on every architecture I'm familiar) requires smp_mb() or
> the equivalent.
Note, at least in our use case (and perhaps others), we do not need an
"exact" moment for not bothering NO_HZ full after it enters user space.
Heck, RCU needs a few ticks before it will stop bothering a NO_HZ CPU.
Could we take advantage of that? That is, we do not use smp_mb() until a
NO_HZ full CPU is fully registered after some time running in user space
(perhaps way for a RCU synchronization period?). Once a CPU has fully
registered that a task is running in NO_HZ full, then we can start doing
more invasive memory synchronizations from other CPUs when it needs to send
an IPI to this one.
As NO_HZ tasks tend to not want to ever go into the kernel, we do not care
if it is expensive when that task returns back from user space.
>
> So I think we clear the quiescent flag and then read the "did anything
> happen that we need to handle bit". This could literally be a write,
> smp_mb(), read, or it could be a CAS (and I haven't really contemplated
> whether it needs to be a sequentially consistent CAS on architectures
> (not x86) where this is a real distinction).
>
> And here's why I'm bringing this up. The unquiesce sequence is kind of
> expensive (tens of cycles! we used to care about this on syscall
> return!), but maybe it solves your problem too. After all, a deferred
> TLB flush looks a lot like a deferred serializing operation, and those
> two look at least a little bit like a remote CPU relying on us being
> RCU-quiescent. (Okay, RCU really is different, since we probably want to
> increment a *count* of quiescence too, but I think this can be made to
> fit in.)
>
> And one thing I hate about the current context tracking is that it's sort
> of glued on and RCU-specific instead of being a real part of the
> entry/exit sequence. But maybe it's actually time to change this.
+1
>
> I call my idea "exact" context tracking specifically because I think this
> stuff should change:
>
> void noinstr __ct_user_enter(enum ctx_state state)
> {
> struct context_tracking *ct = this_cpu_ptr(&context_tracking);
> lockdep_assert_irqs_disabled();
>
> /* Kernel threads aren't supposed to go to userspace */
> WARN_ON_ONCE(!current->mm);
>
> ^^^^^ excuse me, what is this doing here?
>
> if (!context_tracking_recursion_enter())
> return;
>
> ^^^^^^ the x86 and generic code do not have recursion confusion
> any more
>
> if (__ct_state() != state) {
>
>
> ^^^^^ the state transition really should be a foregone conclusion
>
> if (ct->active) {
>
> In the bad old days of the entry/exit code, we had lots of code paths
> that didn't really know the state that they were transitioning *from*.
> These days we keep extremely careful track of exactly what's going on,
> but CT never got updated.
Looks like this code could use some TLC!
>
>
> I would be absolutely delighted to help review this if you write it :)
>
>
> [0] We have a weird tradition of actually using per-task flags on the
> current task for this kind of thing. This particular use case might
> require either annoying remote acquisitions of the rq lock or actually
> using a percpu flag.
This should most definitely be per-cpu flags and not rely on tasks
themselves.
-- Steve
>
> [1] There's nothing wrong with aborting the transition as long as we
> still do the reverse transition.
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-11-30 19:55 ` Andy Lutomirski
2026-11-30 20:34 ` Steven Rostedt
@ 2026-12-01 11:13 ` Valentin Schneider
2026-12-01 21:31 ` Andy Lutomirski
1 sibling, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-12-01 11:13 UTC (permalink / raw)
To: Andy Lutomirski, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On 30/11/26 11:55, Andy Lutomirski wrote:
> On Fri, Nov 27, 2026, at 12:12 PM, Valentin Schneider wrote:
>> Christmas comes early this year, here's v10!
>>
>
>> Approach
>> ========
>>
>> The heart of this series is the thought that while we cannot remove NOHZ_FULL
>> CPUs from the list of CPUs targeted by these IPIs, they may not have to execute
>> the callbacks immediately. Anything that only affects kernelspace can wait
>> until the next user->kernel transition, providing it can be executed "early
>> enough" in the entry code as a postponed operation.
>
> So I had a thought a while ago that I called "exact CT" (exact connection tracing). Basically the idea was to promote CT from a sort-of-specialized realtime/nohz feature to a core part of the entry and exit path. I probably sent some emails about it. The complexity (aside from rearranging a bunch of code) sort of boils down to needing a kind of unfortunate full barrier, and it goes like this:
>
> transition to user mode / quiescent:
>
> we set a percpu [0] quiescent flag saying "I promise that I'm on my way to userspace [1], and I will not access problematic mappings or rely on RCU (or, with your idea) run deferred-pokable code until I transition back". We need accesses that logically predate this to be logically synchronized with anything remote that reads this flag, so we make it a release. No big deal, I think.
>
> transition back from user mode / quiescent:
>
> This one is far trickier. We're going to clear the flag. But a remote CPU needs to be able to observe that the flag is clear and therefore not IPI us, which (on every architecture I'm familiar) requires smp_mb() or the equivalent.
>
> So I think we clear the quiescent flag and then read the "did anything happen that we need to handle bit". This could literally be a write, smp_mb(), read, or it could be a CAS (and I haven't really contemplated whether it needs to be a sequentially consistent CAS on architectures (not x86) where this is a real distinction).
>
> And here's why I'm bringing this up. The unquiesce sequence is kind of expensive (tens of cycles! we used to care about this on syscall return!), but maybe it solves your problem too. After all, a deferred TLB flush looks a lot like a deferred serializing operation, and those two look at least a little bit like a remote CPU relying on us being RCU-quiescent. (Okay, RCU really is different, since we probably want to increment a *count* of quiescence too, but I think this can be made to fit in.)
>
> And one thing I hate about the current context tracking is that it's sort of glued on and RCU-specific instead of being a real part of the entry/exit sequence. But maybe it's actually time to change this.
>
> I call my idea "exact" context tracking specifically because I think this stuff should change:
>
> void noinstr __ct_user_enter(enum ctx_state state)
> {
> struct context_tracking *ct = this_cpu_ptr(&context_tracking);
> lockdep_assert_irqs_disabled();
>
> /* Kernel threads aren't supposed to go to userspace */
> WARN_ON_ONCE(!current->mm);
>
> ^^^^^ excuse me, what is this doing here?
>
> if (!context_tracking_recursion_enter())
> return;
>
> ^^^^^^ the x86 and generic code do not have recursion confusion any more
>
> if (__ct_state() != state) {
>
>
> ^^^^^ the state transition really should be a foregone conclusion
>
> if (ct->active) {
>
> In the bad old days of the entry/exit code, we had lots of code paths that didn't really know the state that they were transitioning *from*. These days we keep extremely careful track of exactly what's going on, but CT never got updated.
>
>
> I would be absolutely delighted to help review this if you write it :)
>
At a high level that sort of sounds like what Frederic had suggested and I
had implemented here:
https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@redhat.com/
Although now I would just not store anything and have a single,
always-run-at-entry catchup sequence (like the CR3 RMW).
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 11:13 ` Valentin Schneider
@ 2026-12-01 21:31 ` Andy Lutomirski
2026-12-02 10:43 ` Valentin Schneider
0 siblings, 1 reply; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-01 21:31 UTC (permalink / raw)
To: Valentin Schneider, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Tue, Dec 1, 2026, at 3:13 AM, Valentin Schneider wrote:
> On 30/11/26 11:55, Andy Lutomirski wrote:
>> On Fri, Nov 27, 2026, at 12:12 PM, Valentin Schneider wrote:
>>> Christmas comes early this year, here's v10!
>>>
>>
>>> Approach
>>> ========
>>>
>>> The heart of this series is the thought that while we cannot remove NOHZ_FULL
>>> CPUs from the list of CPUs targeted by these IPIs, they may not have to execute
>>> the callbacks immediately. Anything that only affects kernelspace can wait
>>> until the next user->kernel transition, providing it can be executed "early
>>> enough" in the entry code as a postponed operation.
>>
>> So I had a thought a while ago that I called "exact CT" (exact connection tracing). Basically the idea was to promote CT from a sort-of-specialized realtime/nohz feature to a core part of the entry and exit path. I probably sent some emails about it. The complexity (aside from rearranging a bunch of code) sort of boils down to needing a kind of unfortunate full barrier, and it goes like this:
>>
>> transition to user mode / quiescent:
>>
>> we set a percpu [0] quiescent flag saying "I promise that I'm on my way to userspace [1], and I will not access problematic mappings or rely on RCU (or, with your idea) run deferred-pokable code until I transition back". We need accesses that logically predate this to be logically synchronized with anything remote that reads this flag, so we make it a release. No big deal, I think.
>>
>> transition back from user mode / quiescent:
>>
>> This one is far trickier. We're going to clear the flag. But a remote CPU needs to be able to observe that the flag is clear and therefore not IPI us, which (on every architecture I'm familiar) requires smp_mb() or the equivalent.
>>
>> So I think we clear the quiescent flag and then read the "did anything happen that we need to handle bit". This could literally be a write, smp_mb(), read, or it could be a CAS (and I haven't really contemplated whether it needs to be a sequentially consistent CAS on architectures (not x86) where this is a real distinction).
>>
>> And here's why I'm bringing this up. The unquiesce sequence is kind of expensive (tens of cycles! we used to care about this on syscall return!), but maybe it solves your problem too. After all, a deferred TLB flush looks a lot like a deferred serializing operation, and those two look at least a little bit like a remote CPU relying on us being RCU-quiescent. (Okay, RCU really is different, since we probably want to increment a *count* of quiescence too, but I think this can be made to fit in.)
>>
>> And one thing I hate about the current context tracking is that it's sort of glued on and RCU-specific instead of being a real part of the entry/exit sequence. But maybe it's actually time to change this.
>>
>> I call my idea "exact" context tracking specifically because I think this stuff should change:
>>
>> void noinstr __ct_user_enter(enum ctx_state state)
>> {
>> struct context_tracking *ct = this_cpu_ptr(&context_tracking);
>> lockdep_assert_irqs_disabled();
>>
>> /* Kernel threads aren't supposed to go to userspace */
>> WARN_ON_ONCE(!current->mm);
>>
>> ^^^^^ excuse me, what is this doing here?
>>
>> if (!context_tracking_recursion_enter())
>> return;
>>
>> ^^^^^^ the x86 and generic code do not have recursion confusion any more
>>
>> if (__ct_state() != state) {
>>
>>
>> ^^^^^ the state transition really should be a foregone conclusion
>>
>> if (ct->active) {
>>
>> In the bad old days of the entry/exit code, we had lots of code paths that didn't really know the state that they were transitioning *from*. These days we keep extremely careful track of exactly what's going on, but CT never got updated.
>>
>>
>> I would be absolutely delighted to help review this if you write it :)
>>
>
> At a high level that sort of sounds like what Frederic had suggested and I
> had implemented here:
>
> https://lore.kernel.org/lkml/20251114151428.1064524-4-vschneid@redhat.com/
I actually like that better. This is in line with what I was trying to suggest with my email. But I think the right way to do it would be to actually enumerate the allowed state transitions *from the perspective of the entry code* and then to reimplement it without all the weird ifs and incs and generally bizarre tolerance of being called for nonsensical state transitions.
Make it simple and clean.
>
> Although now I would just not store anything and have a single,
> always-run-at-entry catchup sequence (like the CR3 RMW).
CR3 is slow. Even SERIALIZE is probably pretty slow.
--Andy
^ permalink raw reply [flat|nested] 44+ messages in thread* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-01 21:31 ` Andy Lutomirski
@ 2026-12-02 10:43 ` Valentin Schneider
2026-12-02 17:08 ` Andy Lutomirski
0 siblings, 1 reply; 44+ messages in thread
From: Valentin Schneider @ 2026-12-02 10:43 UTC (permalink / raw)
To: Andy Lutomirski, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On 01/12/26 13:31, Andy Lutomirski wrote:
> On Tue, Dec 1, 2026, at 3:13 AM, Valentin Schneider wrote:
>
>>
>> Although now I would just not store anything and have a single,
>> always-run-at-entry catchup sequence (like the CR3 RMW).
>
> CR3 is slow. Even SERIALIZE is probably pretty slow.
>
If we can get this enabled iff NOHZ_FULL is enabled & in use, then making
kernel entry a few times more expensive is fair game IMO.
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs
2026-12-02 10:43 ` Valentin Schneider
@ 2026-12-02 17:08 ` Andy Lutomirski
2026-12-04 5:11 ` Exact context tracking (Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs) Andy Lutomirski
0 siblings, 1 reply; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-02 17:08 UTC (permalink / raw)
To: Valentin Schneider, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu
On Wed, Dec 2, 2026, at 2:43 AM, Valentin Schneider wrote:
> On 01/12/26 13:31, Andy Lutomirski wrote:
>> On Tue, Dec 1, 2026, at 3:13 AM, Valentin Schneider wrote:
>>
>>>
>>> Although now I would just not store anything and have a single,
>>> always-run-at-entry catchup sequence (like the CR3 RMW).
>>
>> CR3 is slow. Even SERIALIZE is probably pretty slow.
>>
>
> If we can get this enabled iff NOHZ_FULL is enabled & in use, then making
> kernel entry a few times more expensive is fair game IMO.
If implemented cleanly, my suggestion will boil down to:
u64 work = read_clear_quiescent_bits_unquiesce_rcu();
bool serialized = false;
if (work & TLBFLUSH) {
serialized = do_deferred_flushes();
}
if ((work & SERIALIZE) && !serialized) {
serialize();
}
read_clear_quiescent_bits_unquiesce_rcu() is mildly complex, but I claim that it can likely be implemented at the approximate cost of *one* MFENCE and/or CAS. The entry into quiescent mode should be a single store-release.
I think this entire sequence will be cheap enough that we should seriously consider enabling it unconditionally. Or *maybe* do it heuristically where we only quiesce in the first place if we think it makes sense, but I think it should at least be compiled into the kernel unconditionally.
If, on the other hand, we don't unify it with RCU, then we're starting to multiply the cost by a factor of at least two, and maybe we want it to stay conditional. Yuck.
FWIW, this code can (I think) be fully shared with the RCU idle EQS code, so long as we can make the same promises about vmap in the idle path as we would in the userspace path. That should be possible too unless we have truly stupid driver code, and that's where objtool would come in, I think.
--Andy
^ permalink raw reply [flat|nested] 44+ messages in thread* Exact context tracking (Re: [PATCH v10 00/10] x86: Quiesce text_poke() IPIs)
2026-12-02 17:08 ` Andy Lutomirski
@ 2026-12-04 5:11 ` Andy Lutomirski
0 siblings, 0 replies; 44+ messages in thread
From: Andy Lutomirski @ 2026-12-04 5:11 UTC (permalink / raw)
To: Valentin Schneider, Linux Kernel Mailing List, linux-mm,
the arch/x86 maintainers
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Peter Zijlstra (Intel), Arnaldo Carvalho de Melo,
Josh Poimboeuf, Paolo Bonzini, Arnd Bergmann, Frederic Weisbecker,
Paul E. McKenney, Jason Baron, Steven Rostedt, Ard Biesheuvel,
Sami Tolvanen, David S. Miller, Neeraj Upadhyay, Joel Fernandes,
Josh Triplett, Boqun Feng, Uladzislau Rezki, Mathieu Desnoyers,
Mel Gorman, Andrew Morton, Masahiro Yamada, Han Shen,
Rik van Riel, Jann Horn, Dan Carpenter, Oleg Nesterov, Juri Lelli,
Clark Williams, Tomas Glozar, Yair Podemsky, Marcelo Tosatti,
Daniel Wagner, Petr Tesarik, Shrikanth Hegde, Dan Beimborn,
Pak Hung Vincent Chiu, Linus Torvalds
[long email here...]
On Wed, Dec 2, 2026, at 9:08 AM, Andy Lutomirski wrote:
>
> I think this entire sequence [EQS enter + exit] will be cheap enough that we should
> seriously consider enabling it unconditionally. Or *maybe* do it
> heuristically where we only quiesce in the first place if we think it
> makes sense, but I think it should at least be compiled into the kernel
> unconditionally.
>
> If, on the other hand, we don't unify it with RCU, then we're starting
> to multiply the cost by a factor of at least two, and maybe we want it
> to stay conditional. Yuck.
>
> FWIW, this code can (I think) be fully shared with the RCU idle EQS
> code, so long as we can make the same promises about vmap in the idle
> path as we would in the userspace path. That should be possible too
> unless we have truly stupid driver code, and that's where objtool would
> come in, I think.
>
I dug in some more.
Let's start this with a big warning, which I should have remembered earlier since the last time we screwed this up, I was the one who did it!
WE CANNOT DEFER IPIS WHEN FREEING A PAGETABLE. It's not a code problem -- it's a fundamental architectural issue and it is incorrect for us to make this optimization:
https://lore.kernel.org/all/CA+55aFwfOavB9EEnhoXh95wRfCd3uC0SX_Th6s_38jZxQLKDLg@mail.gmail.com/
And let's keep in mind that we used to have a mechanism for queueing deferred work to be done on EQS exit:
https://lore.kernel.org/lkml/CALCETrWNPOOdTrFabTDd=H7+wc6xJ9rJceg6OL1S0rTV5pfSsA@mail.gmail.com/
But we also do keep track of whether we're freeing a pagetable, and we already flushes when not freeing pagetables for idle CPUs, except that we haven't actually wired it up for kernel flushes:
commit 145f573b89a62bf53cfc0144fa9b1c56b0f70b45
Author: Rik van Riel <riel@surriel.com>
Date: Tue Sep 25 23:58:44 2018 -0400
x86/mm/tlb: Make lazy TLB mode lazier
So all this discussion of whether it's safe to run, say, the idle code while we may have stale TLB entries is 8 years out of date. We already do!
As for EQS, everyone seems to think that EQS is expensive, and we use it in idle where latency doesn't matter so much, and we don't use it for usermode except in NOHZ_FULL. And little speedups to idle entry/exit won't show up in benchmarks (and no one really cares that much anyway), and NOHZ_FULL is only used by users who don't care about user->kernel->user latency. So there's a chicken and egg problem here.
And there has been discussion of making EQS faster by weakening the ordering requirements:
https://lore.kernel.org/all/20210728173715.GA9416@paulmck-ThinkPad-P17-Gen-1/
Sadly that never went anywhere.
I think we can go farther than that weakening proposal I linked above, but only if we go all in. So here's what I think we should do.
We introduce a new mode, selected at compile time (probably as an arch opt-in thing) called EXACT_CONTEXT_TRACKING. In this mode:
1. The API becomes ct_enter_eqs() and ct_exit_eqs(). Callers are responsible for never entering EQS when already in EQS and never exiting EQS when not in EQS. Running noinstr code in EQS is illegal.
2. We make a rule: when a CPU is not in EQS, neither remote CPUs nor NMI may modify context_tracking.state. When a CPU is in EQS, neither remote CPUs nor NMI may cause that cpu to stop being in an EQS (except that NMI may exit and reenter EQS). (MCE counts as NMI for this purpose.) As a partial exception, remote CPUs may modify context_tracking.state if the target CPU is somehow locked (e.g. hotplug).
3. The rules above imply that NMI must do, effectively:
bool was_eqs = ct_in_eqs();
if (was_eqs)
ct_exit_eqs();
do actual work;
if (was_eqs)
ct_enter_eqs();
4. The nesting and nmi_nesting fields go away. Nothing needs then in EXACT_CONTEXT_TRACKING mode. (This interferes with rcu_is_cpu_rrupt_from_idle(). Maybe we can just remove that, but maybe we can keep track of whether we interrupted an EQS and tell RCU about it.)
5. We do the weakening thing. ct_enter_eqs() becomes a plain read followed by a store-release. Note that, because of the rule 2, nothing else will modify context_tracking.state and thus cause a malfunction.
6. We change ordinary exit to usermode to enter EQS, unconditionally. We consider making it conditional only if it ends up being a performance problem. (It would be a performance problem if entering EQS always turns off the scheduler tick, so that probably needs to remain conditional. I have not dug in to how coupled the dynticks code is to the EQS code.)
And then we DO NOT ADD DEFERRED WORK. Instead we pause, review the code, let it soak in -next, maybe even hit a real stable release, and catch our breaths.
----------
And now we add deferred work for text_poke because it's simpler than TLB flushes. text_pokes to anything other than noinstr code can be deferred, I think (on the theory that, in the new regime, we will never execute non-noinstr code while in EQS). To comply with rule 2, remote CPUs setting the bit need to use CAS and not do it if the target is not in EQS. But we need to be very careful: for NMI safety, we might need to leave the deferred work bit set until *after* the serialize so that an NMI that hits between the CAS and the serialize can notice the deferred work bit and do an extra serialize. So ct_exit_eqs() does *not* clear the deferred bit. Instead the various non-NMI-like kernel entry paths do something like:
bool was_eqs = ct_in_eqs();
if (was_eqs) {
ct_exit_eqs();
ct_do_and_clear_deferred_work();
}
(keeping in mind that enter-from-usermode, which is very hot, can just assume that usermode was always EQS and can skip the ct_in_eqs() part.)
and the NMI-like ones do:
bool was_eqs = ct_in_eqs();
if (was_eqs) {
ct_exit_eqs();
}
if (context_tracking.state & CT_DEFERRED_WORK) {
do the deferred work;
// DO NOT CLEAR THE DEFERRED BIT -- see rule 2.
// (this means we might serialize twice, which is fine.)
}
(This is totally irrelevant on non-FRED where NMI delivery is a serializing operation (very very clearly so on AMD). But FRED does not obviously document it as serializing.)
HOWEVER!
There is more to the text_poke machinery's IPI than just the serialization. It also synchronizes against smp_text_poke_int3_handler(). But now we come full circle: we don't defer IPIs if we're poking noinstr text, and if we're poking non-noinstr text, we do:
if (do_sync) {
smp_text_poke_sync_each_cpu();
if (we deferred anything)
synchronize_rcu(); // <--- this!
}
/*
* Remove and wait for refs to be zero.
Because we've already defined non-noinstr code as being an RCU-watching state, we know that synchronize_rcu() will wait for it. Or, if this is too slow, we come up with some other clever scheme -- maybe we leave the text_poke descriptor in place until an RCU cycle and we only forcibly synchronize if we try to poke that address a second time. Or we make the int3 handler recover by reading the text to see if it changed. There are lots of solutions but I haven't found a trivial one.
----------
And then, if anyone is still feeling ambitious, we find and update every single code path that frees a kernel page table and all the kernel TLB flush APIs to track freed_tables just like we do for user mode. And we audit the idle driver code and possibly update objtool to help out. And we carefully set up a race-free way to do a non-freed-table TLB flush to a remote CPU that can be deferred (and not forgotten in the NMI path) and we wire it up through the EQS deferral mechanism.
----------
Or we decide that Intel needs to catch up to AMD and that INVLPGB is the future and we don't care about TLB flush deferral or about text_poke serialize deferral. I still think that INVLPGB + TLBSYNC (on the executable mapping, not the temporary text_poke mapping) is adequate for text_poke *if we handle the synchronization with int3 some other way, e.g. using RCU*. Even if we decide this, I still think the EXACT_CONTEXT_TRACKING thing is worthwhile.
(I seem to have convinced ChatGPT 6 Pro that I'm right about INVLPGB + TLBSYNC.)
Anyone want to try this? Valentin? This is a big project. Also, Valentin, there is a lot in here that needs to be dealt with one way or another in any scheme that defers kernel TLB flushes or text_poke serialization.
--Andy
^ permalink raw reply [flat|nested] 44+ messages in thread
* [syzbot ci] Re: x86: Quiesce text_poke() IPIs
2026-11-27 20:12 [PATCH v10 00/10] x86: Quiesce text_poke() IPIs Valentin Schneider
` (11 preceding siblings ...)
2026-11-30 19:55 ` Andy Lutomirski
@ 2026-12-04 7:58 ` syzbot ci
12 siblings, 0 replies; 44+ messages in thread
From: syzbot ci @ 2026-12-04 7:58 UTC (permalink / raw)
To: acme, akpm, ardb, arnd, boqun.feng, bp, dan.beimborn,
dan.carpenter, dave.hansen, davem, dwagner, frederic, hpa, jannh,
jbaron, joelagnelf, josh, jpoimboe, juri.lelli, linux-kernel,
linux-mm, luto, masahiroy, mathieu.desnoyers, mgorman, mingo,
mtosatti, neeraj.upadhyay, nsaenzju, oleg, pak-hung.chiu, paulmck,
pbonzini, peterz, ptesarik, riel, rostedt, samitolvanen, shenhan,
sshegde, tglozar, tglx, urezki, vschneid, williams, x86, ypodemsk
Cc: syzbot, syzkaller-bugs
syzbot ci has tested the following series
[v10] x86: Quiesce text_poke() IPIs
https://lore.kernel.org/all/20261127201221.434876-1-vschneid@redhat.com
* [PATCH v10 01/10] objtool: Make validate_call() recognize indirect calls to pv_ops[]
* [PATCH v10 02/10] objtool: Flesh out warning related to pv_ops[] calls
* [PATCH v10 03/10] objtool: Always pass a section to validate_unwind_hints()
* [PATCH v10 04/10] x86/retpoline: Make warn_thunk_thunk .noinstr
* [PATCH v10 05/10] jump_label: Add annotations for validating .entry.text key usage
* [PATCH v10 06/10] objtool: Add .entry.text validation for static branches
* [PATCH v10 07/10] x86/jump_label: Add ASM support for static_branch_likely()
* [PATCH v10 08/10] x86/mm/pti: Introduce kernel_cr3_loaded
* [PATCH v10 09/10] x86/mm/pti: Drive kernel_cr3_loaded
* [PATCH v10 10/10] context_tracking,x86: Quiesce kernel text patching IPIs when tracking CR3 switches
and found the following issue:
kernel BUG in __jump_label_patch
Full report is available here:
https://ci.syzbot.org/series/651c9101-68db-46a5-b059-311fa83b60a7
***
kernel BUG in __jump_label_patch
tree: linux-next
URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/next/linux-next
base: 8f6626bd6594a78f454d02b27b74a580c890cab9
arch: amd64
compiler: Debian clang version 22.1.8 (1~deb13u5), Debian LLD 22.1.8
config: https://ci.syzbot.org/builds/01c55802-5740-48e7-808d-688d28aa40a0/config
syz repro: https://ci.syzbot.org/findings/a1c67c82-9f1a-4b7e-9892-508e04625c0b/syz_repro
jump_label: Fatal kernel bug, unexpected op at ceph_parse_fsid+0x90/0x490 [ffffffff8ba66480] (e9 41 03 00 00 != 0f 1f 44 00 00)) size:5 type:1
------------[ cut here ]------------
kernel BUG at arch/x86/kernel/jump_label.c:73!
Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
CPU: 1 UID: 0 PID: 5891 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
RIP: 0010:__jump_label_patch+0x485/0x4a0 arch/x86/kernel/jump_label.c:73
Code: e8 c0 f8 5d 00 48 c7 c7 c0 52 06 8c 48 8b 4c 24 10 48 89 ce 48 89 ca 4d 89 e0 4c 8b 0c 24 41 56 e8 60 b4 bc ff 48 83 c4 08 90 <0f> 0b e8 94 f8 5d 00 90 0f 0b e8 8c f8 5d 00 90 0f 0b e8 84 f8 5d
RSP: 0018:ffffc9000408f7e0 EFLAGS: 00010292
RAX: 000000000000008e RBX: ffffffff949baa60 RCX: dcbdd5ab1a163000
RDX: 0000000000000000 RSI: 8000000000000000 RDI: 0000000000000000
RBP: ffffc9000408f920 R08: ffffc9000408f547 R09: 1ffff92000811ea8
R10: dffffc0000000000 R11: fffff52000811ea9 R12: ffffffff8c066f8a
R13: 00000000000000da R14: 0000000000000001 R15: ffffffff8c066f8a
FS: 00007f3722e146c0(0000) GS:ffff8882a7c95000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2d463fff CR3: 000000010ba2e000 CR4: 00000000000006f0
Call Trace:
<TASK>
arch_jump_label_transform_queue+0x69/0x110 arch/x86/kernel/jump_label.c:137
__jump_label_update+0x189/0x370 kernel/jump_label.c:513
static_key_enable_cpuslocked+0x128/0x240 kernel/jump_label.c:210
static_key_enable+0x1a/0x20 kernel/jump_label.c:223
ddebug_change lib/dynamic_debug.c:255 [inline]
ddebug_exec_query lib/dynamic_debug.c:561 [inline]
ddebug_exec_queries+0xfdf/0x1eb0 lib/dynamic_debug.c:587
ddebug_proc_write+0x50/0xd0 lib/dynamic_debug.c:1022
full_proxy_write+0x127/0x1f0 fs/debugfs/file.c:389
vfs_write+0x296/0xba0 fs/read_write.c:685
ksys_write+0x150/0x270 fs/read_write.c:739
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f3721fa9b59
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f3722e14028 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f3722235fa0 RCX: 00007f3721fa9b59
RDX: 0000000000000012 RSI: 00002000000001c0 RDI: 0000000000000003
RBP: 00007f372203a18b R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f3722236038 R14: 00007f3722235fa0 R15: 00007fff9559e388
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:__jump_label_patch+0x485/0x4a0 arch/x86/kernel/jump_label.c:73
Code: e8 c0 f8 5d 00 48 c7 c7 c0 52 06 8c 48 8b 4c 24 10 48 89 ce 48 89 ca 4d 89 e0 4c 8b 0c 24 41 56 e8 60 b4 bc ff 48 83 c4 08 90 <0f> 0b e8 94 f8 5d 00 90 0f 0b e8 8c f8 5d 00 90 0f 0b e8 84 f8 5d
RSP: 0018:ffffc9000408f7e0 EFLAGS: 00010292
RAX: 000000000000008e RBX: ffffffff949baa60 RCX: dcbdd5ab1a163000
RDX: 0000000000000000 RSI: 8000000000000000 RDI: 0000000000000000
RBP: ffffc9000408f920 R08: ffffc9000408f547 R09: 1ffff92000811ea8
R10: dffffc0000000000 R11: fffff52000811ea9 R12: ffffffff8c066f8a
R13: 00000000000000da R14: 0000000000000001 R15: ffffffff8c066f8a
FS: 00007f3722e146c0(0000) GS:ffff8882a7c95000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2d463fff CR3: 000000010ba2e000 CR4: 00000000000006f0
***
If these findings have caused you to resend the series or submit a
separate fix, please add the following tag to your commit message:
Tested-by: syzbot@syzkaller.appspotmail.com
---
This report is generated by a bot. It may contain errors.
syzbot ci engineers can be reached at syzkaller@googlegroups.com.
^ permalink raw reply [flat|nested] 44+ messages in thread