locking/static_key: Fix false positive warnings on concurrent dec/inc
[sfrench/cifs-2.6.git] / kernel / jump_label.c
index bad96b476eb6eb13c1d7f1774a1348506d0e5f10..a799b1ac6b2fec9d2096f874c14550dcd026e382 100644 (file)
@@ -206,6 +206,8 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key,
                                           unsigned long rate_limit,
                                           struct delayed_work *work)
 {
+       int val;
+
        lockdep_assert_cpus_held();
 
        /*
@@ -215,17 +217,20 @@ static void __static_key_slow_dec_cpuslocked(struct static_key *key,
         * returns is unbalanced, because all other static_key_slow_inc()
         * instances block while the update is in progress.
         */
-       if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
-               WARN(atomic_read(&key->enabled) < 0,
-                    "jump label: negative count!\n");
+       val = atomic_fetch_add_unless(&key->enabled, -1, 1);
+       if (val != 1) {
+               WARN(val < 0, "jump label: negative count!\n");
                return;
        }
 
-       if (rate_limit) {
-               atomic_inc(&key->enabled);
-               schedule_delayed_work(work, rate_limit);
-       } else {
-               jump_label_update(key);
+       jump_label_lock();
+       if (atomic_dec_and_test(&key->enabled)) {
+               if (rate_limit) {
+                       atomic_inc(&key->enabled);
+                       schedule_delayed_work(work, rate_limit);
+               } else {
+                       jump_label_update(key);
+               }
        }
        jump_label_unlock();
 }