Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 9bc2ff8

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
jump_label: Simplify and clarify static_key_fast_inc_cpus_locked()
Make the code more obvious and add proper comments to avoid future head scratching. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20240610124406.548322963@linutronix.de
1 parent 695ef79 commit 9bc2ff8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

kernel/jump_label.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,24 @@ bool static_key_slow_inc_cpuslocked(struct static_key *key)
162162
if (static_key_fast_inc_not_disabled(key))
163163
return true;
164164

165-
jump_label_lock();
166-
if (atomic_read(&key->enabled) == 0) {
167-
atomic_set(&key->enabled, -1);
165+
guard(mutex)(&jump_label_mutex);
166+
/* Try to mark it as 'enabling in progress. */
167+
if (!atomic_cmpxchg(&key->enabled, 0, -1)) {
168168
jump_label_update(key);
169169
/*
170-
* Ensure that if the above cmpxchg loop observes our positive
171-
* value, it must also observe all the text changes.
170+
* Ensure that when static_key_fast_inc_not_disabled() or
171+
* static_key_slow_try_dec() observe the positive value,
172+
* they must also observe all the text changes.
172173
*/
173174
atomic_set_release(&key->enabled, 1);
174175
} else {
175-
if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key))) {
176-
jump_label_unlock();
176+
/*
177+
* While holding the mutex this should never observe
178+
* anything else than a value >= 1 and succeed
179+
*/
180+
if (WARN_ON_ONCE(!static_key_fast_inc_not_disabled(key)))
177181
return false;
178-
}
179182
}
180-
jump_label_unlock();
181183
return true;
182184
}
183185

0 commit comments

Comments
 (0)