]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
jump_label: Fix the fix, brown paper bags galore
authorPeter Zijlstra <peterz@infradead.org>
Wed, 31 Jul 2024 10:43:21 +0000 (12:43 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 31 Jul 2024 10:57:39 +0000 (12:57 +0200)
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: 83ab38ef0a0b ("jump_label: Fix concurrency issues in static_key_slow_dec()")
Reported-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lkml.kernel.org/r/20240731105557.GY33588@noisy.programming.kicks-ass.net
kernel/jump_label.c

index 4ad5ed8adf96910395d2e62e8e23c78af815b1f6..6dc76b590703edd263f8e88c9f15da09f4b66aa7 100644 (file)
@@ -236,7 +236,7 @@ void static_key_disable_cpuslocked(struct static_key *key)
        }
 
        jump_label_lock();
-       if (atomic_cmpxchg(&key->enabled, 1, 0))
+       if (atomic_cmpxchg(&key->enabled, 1, 0) == 1)
                jump_label_update(key);
        jump_label_unlock();
 }
@@ -289,7 +289,7 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key)
                return;
 
        guard(mutex)(&jump_label_mutex);
-       if (atomic_cmpxchg(&key->enabled, 1, 0))
+       if (atomic_cmpxchg(&key->enabled, 1, 0) == 1)
                jump_label_update(key);
        else
                WARN_ON_ONCE(!static_key_slow_try_dec(key));