From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795938261; b=f8UHInNdUejOpeOShP1C+nDunDaNpAb8q7KquTr57pM0HkMXZ22V4IiO0s8RsCxN0T6Q 32D9lfNKkiiYLeS0oPpAZh7e1+apqJ0Slgj4+ZV34Z6fF6ffwaPdSxb7G2hEkGDxdW2LS g7bfX6hS7pDPBTKEdvqNgM1+19uRqOe2zVauuUeSOLhP8kAgNhFGhcAw0GzsZviThHWj/ ztTA/IAeQHuq+vemQf9fJPpcv1GDOYlv9UyBH/VVv0JXioemUQ4GPKZq8wdPtIoS4oQVH tuysT5OGfJrDgxu+6RGeA8visWJFzP3Ff33xhWD0Ja2g8AiH5xMTQPc7I9v3cbPhfwQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795938261; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=bM5WSk/EIqJwTxs8eJax93TZdYGd0zvvHghkGSPX5jc=; b=4j0NjU8S5Pc8ZKK0U+mGftvbnJ0oDaRCjmgeF6b/2wCzpJCBoG+5y8kisFp3s5A/M0Ok 1fMl2dUFlcuG+5QLbBTLCq32kiW1uvg9LvvMEJPOFr33Gb0XPhidSqzs+8Yi6a5qKqeLa VStZDS0Ot/iB6sfl/+GKi9xsSjexEbl3KY9ay3ahVPvOPOiTaih37EZMgzDwqJfRN+e24 R+vJ0er1FBKhROHmIJJJ25OcAsbZSudfkCeElrU95LoCt4bCEXrBZWZ7N8/pnma1gD55H FK4nO5BL8DrVL+hI4R7FgsYNzu3Cx2mBYqi3jE68Z/cUBvrx1HulO8sDdPV5kbthbJg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UGFSYHXk; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 400EB606A330 for ; Sun, 29 Nov 2026 07:44:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=UGFSYHXk Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795938261; b=plcclKUlu/53Gvu1NRvhkdE7Kw+7CIaELdOd4Scwl3aYfIoiNJ+k6MBfWRKurb1TCZdK Y6UyhXaH5IDatiDEi4NvQUSPJmyAAuCACwvVbRh8ZVhCgz2QrNqtTxp/ce3xzLYwREwg5 aeZp1R8+76BOaEXF4kM1OE4TBdWpPYfjYLjU551GHAr7TsFwuNm8zX8j0VKXjDVPaWSp6 rYrbBj/F0DgTa89inqKLhoCpipmL2mB3RHp42HSJaAsDwzF8sU3khG/zBCtiDwkoPJOp4 3L7VbwsLFVD2ex5vjPn7dWkRX4zKBQah9mIHhDhZy4+hD5j22b2x6rhwf3eOpHiDBKw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795938261; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=bM5WSk/EIqJwTxs8eJax93TZdYGd0zvvHghkGSPX5jc=; b=bswWP+7Jibk/AZdJ/HIuKQT6KIdOIOY58ST7mZSCP+s61TlE7HgwVnOcMxhouOMl+DM2 Ze+eEz9H5zHLAEcxtvUtf2ZmyRpbULGuDmQ3w2o80DATjl4De7FpqdMk9hGpfymbR3Mwo 4k33jey7g0jKmhFPsyEgSzeCGNl2JFx16bqpcU3L9fzuuzcvNryf9OsjNHztNqKzRTIE3 iYg5NsNXSeZvLIWgGoGYqR5brn1DDUb/UFYIgR2jjTxD7aajLf7OoPuFxN2mdz/f69oiy wnmQZtqy/L72NKjRPH3tle08IEN7MdZix/XBZS1zPbc2qpja/6l0ejSjhZmkSjB1CFg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 517661F00897; Sun, 29 Nov 2026 07:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795938260; bh=bM5WSk/EIqJwTxs8eJax93TZdYGd0zvvHghkGSPX5jc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=UGFSYHXkMCXsHsAgU5gTEMYx9wfaYrIk7ERiGdAiboeRWGw+3tgb7WIxKCarNGYxS 5lLQ1Jkeh2UxNqiLnCC0CtQynBUQdy1UQJsrEj6QYXdu1UyN1HELA7yMP2M+h4f0DT lsqI21LRx9Ry9sp7nTZebIRwY+eyVNiuPQHDlyxnjrq3zP6Y3gm90Frn+gK99T9nBE 6LCmtEt9CrNUDOJaZFRFyqql0Er2AW/DVVsn23MzjpIQPPRrBbf/l0TgiR2kEflGKd Hy1Xqh/YKfASY8lmfVbDvaWeJyXRuFXrHyZO54ypxq5qe3BY61yYuLVBm6JWt9zvmt Rgx7lfepuN3YA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id CEF044E3E9; Sun, 29 Nov 2026 07:44:18 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Sun, 29 Nov 2026 00:44:15 -0700 Subject: [PATCH v2 2/7] x86/jump_label: Sync arch_jump_label_transform_queue() with batch limit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261129-jump-batch-261128-v2-2-b1829d2429f0@gmail.com> References: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com> In-Reply-To: <20261129-jump-batch-261128-v2-0-b1829d2429f0@gmail.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Alice Ryhl , Steven Rostedt , Ard Biesheuvel , Andrew Morton Cc: linux-kernel@vger.kernel.org, Jim Cromie X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795938258; l=5354; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=4QCUCvL2QYZb/Z25ur1ddc/dZp66WsPKkxTfYhNKlM4=; b=PpjxTvNFHqAkOHi5Ksr3wJKpbOpJfsYbgFCImah/rDHhS9R2lMfziKVBIqdIZRn/SYDB0PAxA 2CWIEK/XNOHAbcYIuVKBBfaXx3W+wEg8eKwjBl5orQrNlKN1aT2E0oJ X-Developer-Key: i=jim.cromie@gmail.com; a=ed25519; pk=C6E5ODlPQo7ZBynATXH9wg7K6HxP0pIXyf4s38Qw0XE= X-Endpoint-Received: by B4 Relay for jim.cromie@gmail.com/20260203 with auth_id=958 X-Original-From: Jim Cromie Reply-To: jim.cromie@gmail.com Content-Transfer-Encoding: 7bit From: Jim Cromie __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 --- 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