jump_label: Add RELEASE barrier after text changes
authorPeter Zijlstra <[email protected]>
Tue, 1 Aug 2017 21:58:50 +0000 (23:58 +0200)
committerIngo Molnar <[email protected]>
Thu, 10 Aug 2017 10:28:57 +0000 (12:28 +0200)
In the unlikely case text modification does not fully order things,
add some extra ordering of our own to ensure we only enabled the fast
path after all text is visible.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
kernel/jump_label.c

index 833eecae825ecff6bd9f988af7bac29a3a8ba981..f2ea678c269f5aeb445be04908746757716ba6bd 100644 (file)
@@ -108,7 +108,11 @@ void static_key_slow_inc(struct static_key *key)
        if (atomic_read(&key->enabled) == 0) {
                atomic_set(&key->enabled, -1);
                jump_label_update(key);
-               atomic_set(&key->enabled, 1);
+               /*
+                * Ensure that if the above cmpxchg loop observes our positive
+                * value, it must also observe all the text changes.
+                */
+               atomic_set_release(&key->enabled, 1);
        } else {
                atomic_inc(&key->enabled);
        }
@@ -130,7 +134,10 @@ void static_key_enable(struct static_key *key)
        if (atomic_read(&key->enabled) == 0) {
                atomic_set(&key->enabled, -1);
                jump_label_update(key);
-               atomic_set(&key->enabled, 1);
+               /*
+                * See static_key_slow_inc().
+                */
+               atomic_set_release(&key->enabled, 1);
        }
        jump_label_unlock();
        cpus_read_unlock();