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=1796408903; b=MLwW2plTaejqihHsI6tg4Py8eU+QH59nfHVaxBkeXXDgxJoUHiAhvB27blvY/walQ7S9 wLzfSit7/A5Z4NnBD4RqQ8AwoAavYmHcyh6pLtjenDTc+kiDej4X+DCDpXdyxQFTUF8wD NxPTn1ljaaJl6O5Tel3stxfTK3+rqa6DkzdkArS/P15x73bVmd9RgtvsUDny2UCIfr5v5 409t9CnwNMepn6iy9P5FQmzeDOMH+b5hi+/QHwfnMOltyE4AmhNlB5fMHRPGE8vL+wg8A KUGrEdU2/gKaDA94EPBwERbL0lsFVapNm4JPHYk8RIa91cKotL6tmUyUlQdCFVtZiag== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796408903; 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=T4W9OLIjKWtr7cGT3K0fevn9ByO3F9o64ykcouTFbEM=; b=Kl4I09mz8GKLYzxYgTTmVxQbeYCkOBz//MhY92/kKlMA+nSPfmhG6y55PXAyGCkCDDlK Yi5pHHK2gR23ZPc3SJpU0qCCyqdEgKxaI2xaL//RHf3CuY9ZQ9Cx9l6vKw/58j1bjMDlt Os9OI7uAz8c/WUgVAOsUPABrf9crbfv/uimbydFMpegHV2xiKHsqvCB7TgFaeb6cWWMUH ztc8Dax2B3MMQQVY67vh3JBkrWHTggjltnglR+7/FDGSUtaJhlnPsnutcOYtCQSqoQ+7E Mtf98uLQDG/UKpAGc1+tEEpNEyhojly6SEERRszI5kY89pC4Mpd3DMLkBrkV1urm3ZA== 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=JWVgi50E; 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 D4062606A334 for ; Fri, 4 Dec 2026 18:28:23 +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=JWVgi50E 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=1796408903; b=3RiziRzWt59FjNT0VRGYvCCnXCiCot+c73Wne7iqBhzmaVucXadP/5tA0NdkFcsmtOjX 1+RUlhXaAT6Fx275POLDOe5145s96kIcLI/is6/LGPQv40f+49T9bv+zmSjzUy8b0AwkR +7yeVjMgZh1SHYjRdnX2/L36MtaMX/v6dCSclSzA7NRP7Z/e35q8TokRV0OshVXaNPaea mcfLtGo+VwNcIC0iMdY5HBJiw06YQIO5/IlT3viuDMS+AIerFhH9eLlm+EmJ89r/FL9Jg RXi3oPEV57P4/TyVxp8GOFqEa1YZRnxeO9NfbCpqk3Of1JWwn8euN7YfRt0fHZLewiQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796408903; 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=T4W9OLIjKWtr7cGT3K0fevn9ByO3F9o64ykcouTFbEM=; b=1FSAS7AmhT2ozDYxg/KUbfzP8pM4CymOhrJsrwF02k1exJtIXGcdR3KDUZghILXx9poN 8lY2USR7tnfyDZC8DAt2FUWzgHJSQ9CxfHiil8/b3Ush075jTrfySXl73B2BtumqG+n/l EFyzw0OhVLHODPQ726BxpRkjnDP58byHnf5Qxqy0I+GR4iPpxGI398iSZ5sdfbX8qrFed 5n+Y+DagDyDE/PcYUBqeij/n9unC2CAgz/IFVjDA3aUkkT/26Beur3R9U1pL0k/3GYfKn A4gAeH9EaP7aOf6NEBO6y6xdkLMlwJhU8kFaVflpN5n6Z5NwqEWRu9s19m/wSVRMqtA== 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 0C5581F00A06; Fri, 4 Dec 2026 18:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796408903; bh=T4W9OLIjKWtr7cGT3K0fevn9ByO3F9o64ykcouTFbEM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=JWVgi50ES97uheY3OjFcBkp4zfbUQTUITmFe4EzpvCTQCDVmIi/97R920eNORC7n6 9EyrpI8tk6dajp5ZkT7jwQYtGW+mkGqLzCoA9RaY6/2jx9iPYI1PAtYjLEWsv3OCsd 9F6XKuCTVkTx5dJn23VAYqIZyI/5IZjbzXbN+rcHBEJ4pxE5bJrG85uweObYyJnHAo jFzZK/z9j6LKkonU/dbWRE9GL9jiyGatQZSjaXXgcJWIibvB3ogpfwEfXFkvoPemtk 7RP60Oa7L9e//eZsCe/rqCJ4sRoDs1Jjo4fIgSC8pi6miyru7L2WDtGVqYUiM9RW0U Ih+1jLQIpJv1Q== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 8ACD24DC17; Fri, 4 Dec 2026 18:28:22 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Fri, 04 Dec 2026 11:27:53 -0700 Subject: [PATCH v3 2/5] 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: <20261204-jump-batch-261128-v3-2-2adda55a5d71@gmail.com> References: <20261204-jump-batch-261128-v3-0-2adda55a5d71@gmail.com> In-Reply-To: <20261204-jump-batch-261128-v3-0-2adda55a5d71@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=1796408901; l=5175; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=n/Dd3OJkqLoj4U8rpcE5pJYOFyymBypHiVA2d1bDm/Y=; b=ZS7OSNMTTfE6YjINU9emICYI7FYarvGQYHSmqnt7QfN+Jy9rrZjRMDhbGpcUHyrjcpiARSqbt isicCjoIa8FBIlCoyzHemce7qrT3H52PWXoWWfsHA7Nxkzd9G4EEC+A 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 current architecture batch cannot accept another poke, so the caller can apply the pending batch and queue that entry at the start of a fresh batch. On x86, however, arch_jump_label_transform_queue() calls smp_text_poke_batch_add(), which silently flushes text_poke_array when it fills (TEXT_POKE_ARRAY_MAX = 256) or hits an already-queued address, and unconditionally returns true. Hiding those flush boundaries is harmless when updating one static key at a time, where key->enabled stays fixed across internal flushes. Multi-key static_key_batch updates, however, defer publishing key->enabled = 1 until the batch flushes: because multi-site (e.g. inlined) keys fill the 256-entry text_poke_array ahead of the 256-key queue, jump_label.c needs the false return so it can flush the pending batch, publish completed key states, and start the next batch in lockstep without extra runt flushes. 1. Extract smp_text_poke_batch_try_add() in alternative.c, returning false without flushing when text_poke_array is full or addr is already queued, and keep smp_text_poke_batch_add() as an auto-flushing wrapper for callers such as ftrace_replace_code(). 2. Call smp_text_poke_batch_try_add() in x86's arch_jump_label_transform_queue() and return its result so __jump_label_update() flushes and starts a fresh batch on boundary hits. 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 c837678f379f..034a9f1d8568 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -3075,6 +3075,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 @@ -3090,14 +3116,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