File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments