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=1795938265; b=mHRBQNio32vqlEeAvrGTSwqVXe6SyAK6WXseGVCs58Xo4c+DMy9sX1MmaiRCkfVZUmt6 sm74AR26gwN0eViQNQtWE2xT0SNk2v0d6s6dvXNWgzRpC15vXALn1tksyzUnM0fPWhegI 7PEu/3uzubkm2OUS8Z+8wKvYhUxBlNeypGygt//TO1CsyQqfDE5lodjsm89wSjO3cm9FC +ndOu3UBHI7xlmuJqhCa9IrmL9OONKcV7I+f2qTIvXegLb6SJnZTp8qEsGJayFqA8CGon fd3eE7St8E6P1vi3uBRYwBgGkKaicbE422Mr2skfJafusE+SHbLwnkEIuiA3gNV7v3w== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795938265; 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=kfmdi3OmkDhrj2v29QL5h3y6P7R7eu5RcH3t5+vzymw=; b=agf91w3yFDu8Aba8wlZ1vyPu6tdfDw5uSq3QUJckvqFlg30q0sF/AmwzVV2TiYLw4POE 5I8HGUWncYGPMfPnsy7/FF5zR56vdE+T4mzTr3RoY8ULo7AMmuRz36PG12logqUWNaHKK 16I39UUY//12XG11AqWQIh/vh0k4l4YzuL/ASw28RE5j+caKfJahXzEGvIW9oWjLP6TPG z0gbz5wn+YRdAN7PWeO7p63Y4CepHp4lowVSf/1p2uGU5A+HCeeLv0CL3MVQPhUkp4n7W wPPBBDU3/21IeuyIZatcFssRaawO7ZVQOrdl0uHx3WKzjmHKzHsnd0/choD5zRDY1ww== 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="MpqFFv/L"; 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 6A3A0606A33A for ; Sun, 29 Nov 2026 07:44:25 +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=MpqFFv/L 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=1795938265; b=AEv3yiiM5MZCTeUmm1gPttt6R0zQwTaEGKPFU5Vyi38H3eTjwT0yvr4Va6btmyNaYFj2 3d+7TAT9vprE6snvWxhJ7kFvHVnZA5fOgBFw5Dp8XN9OhRCyQ/At5UOH9hkaEn4qfI6hm 5D032sgkYK7yCSkTRR45KGASvyNNmklaqFjjPTNEr9E6e2CQk6Q+5+1kND1p6I6cisxaI fS20QOPP0up/dO0aM9+QxfBZ4AevAqUet0Dr64XKFLPbrWGhNLGOCTHCRqYjPGykF2Qjo 7ZFhXmb+YoIbPxXkNhjzWFWES3qAI7vphzQkIzSgLELyjxAEikVkrSPRhdRoEd3Wd6A== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795938265; 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=kfmdi3OmkDhrj2v29QL5h3y6P7R7eu5RcH3t5+vzymw=; b=ktLqvJu8lDepoNesE6DNwD97maVYtG4DwGlBC93XvsokMed3MQpFuPvNmqcPlhq7hi6N U8pcFIHib4+cVyBIgMOYHWbsleVCjJczxb5Vo37EeGkoINGvFd3G0mMh8Y+m9VbxXIpZb 11gNKaWI6J2VNdQHSXLOBFLRPam2m3EyFiBCxytmorYlx1IZ2+1SwAfzRoHwiuwu7qK1G ZjnR3HeoOHz1vuuKH/DixmOEA5JpVlUAwchqseKCZfzSjuh/N/8tzL6KOR2UNzzJTTiYL lQlx81E1Na+h2g2gL/V/t2wqxUc4zqIkZW2izKNvyjTggPHY7F+MQxnRar0J++yZ6gw== 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 9EA891F0089B; 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=1795938264; bh=kfmdi3OmkDhrj2v29QL5h3y6P7R7eu5RcH3t5+vzymw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=MpqFFv/Luh4eaFL+mZDtwCHZMduZp1SbspAjGxbR0QMkHgWN3GqhvhkbK78NOvk+B HLeuiHkRzZFcdQpSTG1Paw9prvDsNca5RZt/lZImR9OIRBQH4MWHzpbO0KeF6RjrRJ 5lI3JECbqo1Lp9yKV1Q27FMluYAnHIUSGhprPapan3XjGcbJ8Ijq7yoamdbIgamXKY 4VpRHO/IG4EP2xmP3jnQMQvTklWB4PAV7iDsYr9vhAvDlJGzqRkwvFVdDGhNYIgoWJ yOOrzYyhFkBLJIfT0SWw9OrtPHaem4MuIGuCFJTFShY4TbK7wrRWcnKLEF4lu2Riqr Qc6WMAedXnkLA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 24C724E3F1; Sun, 29 Nov 2026 07:44:19 +0000 (UTC) From: Jim Cromie via B4 Relay Date: Sun, 29 Nov 2026 00:44:17 -0700 Subject: [PATCH v2 4/7] jump_label: Add batching API for queued static key updates 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-4-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=15789; i=jim.cromie@gmail.com; s=20260203; h=from:subject:message-id; bh=Au7jHC7KP8TdrnuialOqE+X6uqO13EovqYLPq6oxfgg=; b=dFX3hVyauV8IWZto40ML3yKYsCpSFN/aNC0Hlkb5C6miUTCAE1tFKcfPMjni2lHBZzgytaYYP 9AMSuPGzAZLBxDp2YVB63cBI4G+XZj0s8rGXG4TwWLXrOYvSatQUDk9 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 Built-in subsystems such as dynamic-debug may toggle thousands of boolean static keys in one operation, incurring O(N) cross-CPU text-poke IPIs when calling static_branch_enable() or static_branch_disable() one key at a time. Add a core-only batching API that amortizes cross-CPU text-poke synchronization across a batch of static keys (up to TEXT_POKE_ARRAY_MAX = 256 pokes per flush on x86) while keeping key->enabled consistent with live kernel text: 0. Add static_key_batch_begin() and static_key_batch_end() (wrapped by DEFINE_LOCK_GUARD_0(static_key_batch, ...) and static_branch_batch_* helpers) to hold cpus_read_lock() and jump_label_lock() across a batch and flush pending updates on exit. 1. Add static_key_enable_queued() and static_key_disable_queued() (plus static_branch_*_queued() wrappers and !CONFIG_JUMP_LABEL stubs), unified in __static_key_set_queued(key, enable) and unexported so only built-in core code may batch-flip keys. 2. Defer publishing final key->enabled values (1 or 0) until after IPI completion using negative transitional markers: STATIC_KEY_TRANS_ENABLE (-1: 0 -> -1 -> 1, counted as 1) and STATIC_KEY_TRANS_DISABLE (-2: 1 -> -2 -> 0, counted as 0). Record in-flight keys in jump_label_queued_keys[MAX_QUEUED_KEYS] and release-store their stable state in jump_label_finalize_queued_keys() after arch_jump_label_transform_apply(). 3. Flush the active batch via __static_key_flush_queued() before queueing when jump_label_queued_keys[] is full, when the arch transform queue fills mid-key, or when a batch reverses a key already in-flight in the opposite direction (val == opp_trans) so live text and key->enabled settle before the reverse patch is generated. 4. Fall back to immediate jump_label_update() on architectures without HAVE_JUMP_LABEL_BATCH, and extend jump_label_test() to exercise scoped_guard(static_key_batch) and same-batch reversals. What's Unchanged: 0. Unqueued static_key_enable(), static_key_disable(), and refcounted static_key_slow_inc() / static_key_slow_dec() keep identical behavior and locking, and arch SYSTEM_BOOTING handling is unchanged. 1. External jump_label_mutex acquisitions never observe transitional states (-1 or -2), because static_key_batch holds jump_label_mutex until all queued keys are finalized. Signed-off-by: Jim Cromie --- include/linux/jump_label.h | 22 +++++ kernel/jump_label.c | 240 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 246 insertions(+), 16 deletions(-) diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h index c95350a10987..7daff74670dc 100644 --- a/include/linux/jump_label.h +++ b/include/linux/jump_label.h @@ -227,6 +227,10 @@ extern void static_key_slow_dec_cpuslocked(struct static_key *key); extern int static_key_count(struct static_key *key); extern void static_key_enable(struct static_key *key); extern void static_key_disable(struct static_key *key); +void static_key_enable_queued(struct static_key *key); +void static_key_disable_queued(struct static_key *key); +void static_key_batch_begin(void); +void static_key_batch_end(void); extern void static_key_enable_cpuslocked(struct static_key *key); extern void static_key_disable_cpuslocked(struct static_key *key); extern enum jump_label_type jump_label_init_type(struct jump_entry *entry); @@ -326,6 +330,19 @@ static inline void static_key_disable(struct static_key *key) atomic_set(&key->enabled, 0); } +static inline void static_key_enable_queued(struct static_key *key) +{ + static_key_enable(key); +} + +static inline void static_key_disable_queued(struct static_key *key) +{ + static_key_disable(key); +} + +static inline void static_key_batch_begin(void) {} +static inline void static_key_batch_end(void) {} + #define static_key_enable_cpuslocked(k) static_key_enable((k)) #define static_key_disable_cpuslocked(k) static_key_disable((k)) @@ -335,6 +352,7 @@ static inline void static_key_disable(struct static_key *key) #endif /* CONFIG_JUMP_LABEL */ DEFINE_LOCK_GUARD_0(jump_label_lock, jump_label_lock(), jump_label_unlock()) +DEFINE_LOCK_GUARD_0(static_key_batch, static_key_batch_begin(), static_key_batch_end()) #define STATIC_KEY_INIT STATIC_KEY_INIT_FALSE #define jump_label_enabled static_key_enabled @@ -521,6 +539,10 @@ extern bool ____wrong_branch_error(void); #define static_branch_enable(x) static_key_enable(&(x)->key) #define static_branch_disable(x) static_key_disable(&(x)->key) +#define static_branch_enable_queued(x) static_key_enable_queued(&(x)->key) +#define static_branch_disable_queued(x) static_key_disable_queued(&(x)->key) +#define static_branch_batch_begin() static_key_batch_begin() +#define static_branch_batch_end() static_key_batch_end() #define static_branch_enable_cpuslocked(x) static_key_enable_cpuslocked(&(x)->key) #define static_branch_disable_cpuslocked(x) static_key_disable_cpuslocked(&(x)->key) diff --git a/kernel/jump_label.c b/kernel/jump_label.c index d20b5b3ffbd3..f068e6484a29 100644 --- a/kernel/jump_label.c +++ b/kernel/jump_label.c @@ -91,6 +91,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) } static void jump_label_update(struct static_key *key); +#ifdef HAVE_JUMP_LABEL_BATCH +static void jump_label_update_queued(struct static_key *key); +#endif /* * There are similar definitions for the !CONFIG_JUMP_LABEL case in jump_label.h. @@ -101,14 +104,22 @@ static void jump_label_update(struct static_key *key); * 'static_key_disable()', which require bug.h. This should allow jump_label.h * to be included from most/all places for CONFIG_JUMP_LABEL. */ +#define STATIC_KEY_TRANS_ENABLE (-1) +#define STATIC_KEY_TRANS_DISABLE (-2) + int static_key_count(struct static_key *key) { /* - * -1 means the first static_key_slow_inc() is in progress. - * static_key_enabled() must return true, so return 1 here. + * STATIC_KEY_TRANS_ENABLE (-1): first static_key_slow_inc() or + * static_key_enable_queued() in progress; static_key_enabled() must + * return true, so return 1. + * STATIC_KEY_TRANS_DISABLE (-2): static_key_disable_queued() in + * progress; static_key_enabled() must return false, so return 0. */ int n = atomic_read(&key->enabled); + if (n == STATIC_KEY_TRANS_DISABLE) + return 0; return n >= 0 ? n : 1; } EXPORT_SYMBOL_GPL(static_key_count); @@ -130,9 +141,10 @@ bool static_key_fast_inc_not_disabled(struct static_key *key) STATIC_KEY_CHECK_USE(key); /* - * Negative key->enabled has a special meaning: it sends - * static_key_slow_inc/dec() down the slow path, and it is non-zero - * so it counts as "enabled" in jump_label_update(). + * Negative key->enabled marks an in-flight transition and sends + * static_key_slow_inc/dec() down the slow path: + * STATIC_KEY_TRANS_ENABLE (-1) counts as enabled in static_key_count(), + * while STATIC_KEY_TRANS_DISABLE (-2) counts as disabled. * * The INT_MAX overflow condition is either used by the networking * code to reset or detected in the slow path of @@ -250,10 +262,173 @@ void static_key_disable(struct static_key *key) } EXPORT_SYMBOL_GPL(static_key_disable); +#ifdef HAVE_JUMP_LABEL_BATCH +/* + * On arches whose arch_jump_label_transform_queue() always returns true + * (e.g. arm64/riscv/s390 nosync pokes), cap how many keys stay in + * transitional states before __static_key_flush_queued() finalizes them. + */ +#define MAX_QUEUED_KEYS 256 +static struct static_key *jump_label_queued_keys[MAX_QUEUED_KEYS]; +static int jump_label_num_queued_keys; + +static void jump_label_finalize_queued_keys(void) +{ + int i, val; + + lockdep_assert_held(&jump_label_mutex); + + for (i = 0; i < jump_label_num_queued_keys; i++) { + struct static_key *k = jump_label_queued_keys[i]; + + if (WARN_ON_ONCE(!k)) + continue; + + val = atomic_read(&k->enabled); + switch (val) { + case STATIC_KEY_TRANS_ENABLE: + atomic_set_release(&k->enabled, 1); + break; + case STATIC_KEY_TRANS_DISABLE: + atomic_set_release(&k->enabled, 0); + break; + default: + WARN_ONCE(1, "jump_label: unexpected state %d for queued key %pS\n", + val, k); + break; + } + } + jump_label_num_queued_keys = 0; +} + +static void __static_key_flush_queued(void) +{ + arch_jump_label_transform_apply(); + jump_label_finalize_queued_keys(); +} + +static void jump_label_prepare_queued_slot(void) +{ + if (jump_label_num_queued_keys >= MAX_QUEUED_KEYS) + __static_key_flush_queued(); +} + +static void jump_label_record_queued_key(struct static_key *key) +{ + jump_label_queued_keys[jump_label_num_queued_keys++] = key; +} +#endif + +static void __static_key_set_queued(struct static_key *key, bool enable) +{ + int from = enable ? 0 : 1; + int to = enable ? 1 : 0; + int trans = enable ? STATIC_KEY_TRANS_ENABLE : STATIC_KEY_TRANS_DISABLE; +#ifdef HAVE_JUMP_LABEL_BATCH + int opp_trans = enable ? STATIC_KEY_TRANS_DISABLE + : STATIC_KEY_TRANS_ENABLE; +#endif + int val; + + STATIC_KEY_CHECK_USE(key); + lockdep_assert_cpus_held(); + lockdep_assert_held(&jump_label_mutex); + + val = atomic_read(&key->enabled); +#ifdef HAVE_JUMP_LABEL_BATCH + if (val == opp_trans) { + /* + * Reversing a key already queued in this batch: flush the + * pending batch first so live text matches __jump_label_patch() + * expectations and key->enabled settles to @from. + */ + __static_key_flush_queued(); + val = atomic_read(&key->enabled); + } +#endif + if (val != from) { + /* + * Already in target state or in-flight to it; warn if + * refcounted (> 1) or unexpected negative state. + */ + WARN_ON_ONCE(val != to && val != trans); + return; + } + +#ifdef HAVE_JUMP_LABEL_BATCH + jump_label_prepare_queued_slot(); + if (atomic_cmpxchg(&key->enabled, from, trans) == from) { + jump_label_update_queued(key); + jump_label_record_queued_key(key); + } +#else + if (atomic_cmpxchg(&key->enabled, from, trans) == from) { + jump_label_update(key); + atomic_set_release(&key->enabled, to); + } +#endif +} + +/** + * static_key_enable_queued - queue enabling a boolean static key + * @key: static key to enable + * + * Queues a 0 -> 1 branch transition inside an active static_key_batch + * critical section (see static_key_batch_begin() and guard(static_key_batch)). + * On SMP, text patching and final key->enabled publication are deferred until + * the batch flushes. + */ +void static_key_enable_queued(struct static_key *key) +{ + __static_key_set_queued(key, true); +} + +/** + * static_key_disable_queued - queue disabling a boolean static key + * @key: static key to disable + * + * Queues a 1 -> 0 branch transition inside an active static_key_batch + * critical section (see static_key_batch_begin() and guard(static_key_batch)). + * On SMP, text patching and final key->enabled publication are deferred until + * the batch flushes. + */ +void static_key_disable_queued(struct static_key *key) +{ + __static_key_set_queued(key, false); +} + +/** + * static_key_batch_begin - enter a batched static key update section + * + * Acquires cpus_read_lock() and jump_label_lock() across a batch of + * static_key_enable_queued() / static_key_disable_queued() calls. Prefer + * scoped_guard(static_key_batch) or guard(static_key_batch)(). + */ +void static_key_batch_begin(void) +{ + cpus_read_lock(); + jump_label_lock(); +} + +/** + * static_key_batch_end - flush queued static key updates and release locks + * + * Applies any pending batched jump-label text pokes, finalizes transitional + * key->enabled states, and releases jump_label_lock() and cpus_read_lock(). + */ +void static_key_batch_end(void) +{ +#ifdef HAVE_JUMP_LABEL_BATCH + if (jump_label_num_queued_keys) + __static_key_flush_queued(); +#endif + jump_label_unlock(); + cpus_read_unlock(); +} + static bool static_key_dec_not_one(struct static_key *key) { int v; - /* * Go into the slow path if key::enabled is less than or equal than * one. One is valid to shut down the key, anything less than one @@ -268,10 +443,9 @@ static bool static_key_dec_not_one(struct static_key *key) v = atomic_read(&key->enabled); do { /* - * Warn about the '-1' case though; since that means a - * decrement is concurrent with a first (0->1) increment. IOW - * people are trying to disable something that wasn't yet fully - * enabled. This suggests an ordering problem on the user side. + * Warn about negative transitional values (-1/-2); a decrement + * is racing an in-flight 0->1 increment or a queued boolean + * transition, which indicates a caller ordering bug. */ WARN_ON_ONCE(v < 0); @@ -291,19 +465,22 @@ static bool static_key_dec_not_one(struct static_key *key) static void __static_key_slow_dec_cpuslocked(struct static_key *key) { - lockdep_assert_cpus_held(); int val; + lockdep_assert_cpus_held(); + if (static_key_dec_not_one(key)) return; guard(mutex)(&jump_label_mutex); val = atomic_read(&key->enabled); /* - * It should be impossible to observe -1 with jump_label_mutex held, - * see static_key_slow_inc_cpuslocked(). + * It should be impossible to observe transitional states with + * jump_label_mutex held; see static_key_slow_inc_cpuslocked() and + * static_key_batch_begin(). */ - if (WARN_ON_ONCE(val == -1)) + if (WARN_ON_ONCE(val == STATIC_KEY_TRANS_ENABLE || + val == STATIC_KEY_TRANS_DISABLE)) return; /* * Cannot already be 0, something went sideways. @@ -500,9 +677,10 @@ static void __jump_label_update(struct static_key *key, #ifdef HAVE_JUMP_LABEL_BATCH if (!arch_jump_label_transform_queue(entry, jump_label_type(entry))) { /* - * Queue is full: Apply the current queue and try again. + * Queue is full: Apply the current queue, finalize + * previously completed keys, and retry this entry. */ - arch_jump_label_transform_apply(); + __static_key_flush_queued(); BUG_ON(!arch_jump_label_transform_queue(entry, jump_label_type(entry))); } #else @@ -907,6 +1085,13 @@ static void jump_label_update(struct static_key *key) jump_label_update_key(key, true); } +#ifdef HAVE_JUMP_LABEL_BATCH +static void jump_label_update_queued(struct static_key *key) +{ + jump_label_update_key(key, false); +} +#endif + #ifdef CONFIG_STATIC_KEYS_SELFTEST static DEFINE_STATIC_KEY_TRUE(sk_true); static DEFINE_STATIC_KEY_FALSE(sk_false); @@ -937,6 +1122,29 @@ static __init int jump_label_test(void) static_branch_enable(&sk_true); static_branch_disable(&sk_false); + + scoped_guard(static_key_batch) { + static_branch_disable_queued(&sk_true); + static_branch_enable_queued(&sk_false); + } + + WARN_ON(static_key_enabled(&sk_true.key) == true); + WARN_ON(static_key_enabled(&sk_false.key) == false); + WARN_ON(static_branch_likely(&sk_true)); + WARN_ON(static_branch_unlikely(&sk_true)); + WARN_ON(!static_branch_likely(&sk_false)); + WARN_ON(!static_branch_unlikely(&sk_false)); + + /* Same-batch reversal: flip back and forth in one batch */ + scoped_guard(static_key_batch) { + static_branch_enable_queued(&sk_true); + static_branch_disable_queued(&sk_true); + static_branch_enable_queued(&sk_true); + + static_branch_disable_queued(&sk_false); + static_branch_enable_queued(&sk_false); + static_branch_disable_queued(&sk_false); + } } return 0; -- 2.56.1