mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Cromie via B4 Relay <devnull+jim.cromie.gmail.com@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	 Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	 Jason Baron <jbaron@akamai.com>,
	Alice Ryhl <aliceryhl@google.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH v2 2/7] x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit
Date: Sun, 29 Nov 2026 00:44:15 -0700	[thread overview]
Message-ID: <20261129-jump-batch-261128-v2-2-b1829d2429f0@gmail.com> (raw)
In-Reply-To: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com>

From: Jim Cromie <jim.cromie@gmail.com>

__jump_label_update() expects arch_jump_label_transform_queue() to
return false when the architecture patch queue is full so the caller can
apply the current batch and retry. On x86, however,
arch_jump_label_transform_queue() calls smp_text_poke_batch_add(), which
silently finish()es text_poke_array at TEXT_POKE_ARRAY_MAX (256), and
unconditionally returns true.

That hides batch boundaries from kernel/jump_label.c -- harmless for a
single static_key, where key->enabled stays fixed across internal
flushes, but upcoming multi-key static_key_batch queueing needs the
queue-full signal whenever multi-site (e.g. inlined) keys fill the
256-site text_poke_array ahead of the 256-key queue, avoiding extra
runt flushes every cycle.

Wire the bool queue-full return back up to __jump_label_update():

0. Extract smp_text_poke_batch_try_add() in alternative.c, returning
   false without finish()ing when text_poke_array is full or @addr is
   already queued in vec[], and keep smp_text_poke_batch_add() as an
   auto-finishing wrapper for callers such as ftrace_replace_code().
1. Call smp_text_poke_batch_try_add() in x86's
   arch_jump_label_transform_queue() and return its bool result so
   __jump_label_update() flushes and retries at TEXT_POKE_ARRAY_MAX.

What's Unchanged:

0. smp_text_poke_batch_add() callers -- ftrace_replace_code() and
   smp_text_poke_single() -- keep identical auto-finishing behavior.
1. Single-key jump_label_update() behavior is unchanged: entry 256 now
   triggers arch_jump_label_transform_apply() from __jump_label_update()
   rather than inside smp_text_poke_batch_add().

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 arch/x86/include/asm/text-patching.h |  1 +
 arch/x86/kernel/alternative.c        | 34 ++++++++++++++++++++++++++++------
 arch/x86/kernel/jump_label.c         |  6 ++++--
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/text-patching.h
index ea09381070e8..de43b5266867 100644
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -41,6 +41,7 @@ extern void *text_poke_set(void *addr, int c, size_t len);
 extern int smp_text_poke_int3_handler(struct pt_regs *regs);
 extern void smp_text_poke_single(void *addr, const void *opcode, size_t len, const void *emulate);
 
+bool smp_text_poke_batch_try_add(void *addr, const void *opcode, size_t len, const void *emulate);
 extern void smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, const void *emulate);
 extern void smp_text_poke_batch_finish(void);
 
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index d924c3e891b6..046b7da6a3f9 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -3076,6 +3076,32 @@ static bool text_poke_find_slot(void *addr, int *pos)
 	return true;
 }
 
+/**
+ * smp_text_poke_batch_try_add() -- queue a batched live-kernel text poke
+ * @addr:	address to patch
+ * @opcode:	opcode of new instruction
+ * @len:	length to copy
+ * @emulate:	instruction to be emulated
+ *
+ * Queue a patching request in sorted position for execution on the next
+ * smp_text_poke_batch_finish() call without finish()ing an existing batch.
+ *
+ * Return: true if queued, or false if the batch is full or @addr is already
+ * queued.
+ */
+bool __ref smp_text_poke_batch_try_add(void *addr, const void *opcode,
+				       size_t len, const void *emulate)
+{
+	int pos;
+
+	if (text_poke_array.nr_entries == TEXT_POKE_ARRAY_MAX ||
+	    !text_poke_find_slot(addr, &pos))
+		return false;
+
+	__smp_text_poke_batch_add(addr, opcode, len, emulate, pos);
+	return true;
+}
+
 /**
  * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, batched
  * @addr:	address to patch
@@ -3092,14 +3118,10 @@ static bool text_poke_find_slot(void *addr, int *pos)
 void __ref smp_text_poke_batch_add(void *addr, const void *opcode,
 				   size_t len, const void *emulate)
 {
-	int pos = 0;
-
-	if (text_poke_array.nr_entries == TEXT_POKE_ARRAY_MAX ||
-	    !text_poke_find_slot(addr, &pos)) {
+	if (!smp_text_poke_batch_try_add(addr, opcode, len, emulate)) {
 		smp_text_poke_batch_finish();
-		pos = 0;
+		__smp_text_poke_batch_add(addr, opcode, len, emulate, 0);
 	}
-	__smp_text_poke_batch_add(addr, opcode, len, emulate, pos);
 }
 
 /**
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index a7949a54a0ff..4a7daea5ce6e 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -124,6 +124,7 @@ bool arch_jump_label_transform_queue(struct jump_entry *entry,
 				     enum jump_label_type type)
 {
 	struct jump_label_patch jlp;
+	bool queued;
 
 	if (system_state == SYSTEM_BOOTING) {
 		/*
@@ -135,9 +136,10 @@ bool arch_jump_label_transform_queue(struct jump_entry *entry,
 
 	mutex_lock(&text_mutex);
 	jlp = __jump_label_patch(entry, type);
-	smp_text_poke_batch_add((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL);
+	queued = smp_text_poke_batch_try_add((void *)jump_entry_code(entry),
+					     jlp.code, jlp.size, NULL);
 	mutex_unlock(&text_mutex);
-	return true;
+	return queued;
 }
 
 void arch_jump_label_transform_apply(void)

-- 
2.56.1



  parent reply	other threads:[~2026-11-29  7:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  7:44 [PATCH v2 0/7] jump_label, x86, dyndbg: Batch multi-key static branch updates Jim Cromie via B4 Relay
2026-11-29  7:44 ` [PATCH v2 1/7] x86/alternatives: Keep text-poke batch sorted on insert Jim Cromie via B4 Relay
2026-11-29  7:44 ` Jim Cromie via B4 Relay [this message]
2026-11-29  7:44 ` [PATCH v2 3/7] jump_label: Plumb bool apply through jump_label_update_key() Jim Cromie via B4 Relay
2026-11-29  7:44 ` [PATCH v2 4/7] jump_label: Add batching API for queued static key updates Jim Cromie via B4 Relay
2026-11-29  7:44 ` [PATCH v2 5/7] dyndbg: Use queued static-key batching in ddebug_change() Jim Cromie via B4 Relay
2026-11-29  7:44 ` [PATCH v2 6/7] dyndbg: Batch classmap param bit-changes into multi-query Jim Cromie via B4 Relay
2026-11-29  7:44 ` [PATCH v2 7/7] dyndbg: Hoist lock and static_key_batch across queries Jim Cromie via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129-jump-batch-261128-v2-2-b1829d2429f0@gmail.com \
    --to=devnull+jim.cromie.gmail.com@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@akamai.com \
    --cc=jim.cromie@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®