Skip to content

Commit 224fa35

Browse files
author
Peter Zijlstra
committed
jump_label: Fix the fix, brown paper bags galore
Per the example of: !atomic_cmpxchg(&key->enabled, 0, 1) the inverse was written as: atomic_cmpxchg(&key->enabled, 1, 0) except of course, that while !old is only true for old == 0, old is true for everything except old == 0. Fix it to read: atomic_cmpxchg(&key->enabled, 1, 0) == 1 such that only the 1->0 transition returns true and goes on to disable the keys. Fixes: 83ab38e ("jump_label: Fix concurrency issues in static_key_slow_dec()") Reported-by: Darrick J. Wong <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Darrick J. Wong <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6623b02 commit 224fa35

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/jump_label.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void static_key_disable_cpuslocked(struct static_key *key)
236236
}
237237

238238
jump_label_lock();
239-
if (atomic_cmpxchg(&key->enabled, 1, 0))
239+
if (atomic_cmpxchg(&key->enabled, 1, 0) == 1)
240240
jump_label_update(key);
241241
jump_label_unlock();
242242
}
@@ -289,7 +289,7 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key)
289289
return;
290290

291291
guard(mutex)(&jump_label_mutex);
292-
if (atomic_cmpxchg(&key->enabled, 1, 0))
292+
if (atomic_cmpxchg(&key->enabled, 1, 0) == 1)
293293
jump_label_update(key);
294294
else
295295
WARN_ON_ONCE(!static_key_slow_try_dec(key));

0 commit comments

Comments
 (0)