]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
locking/static_keys: Add static_key_{en,dis}able() helpers
authorPeter Zijlstra <peterz@infradead.org>
Fri, 24 Jul 2015 13:03:40 +0000 (15:03 +0200)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Sat, 11 Aug 2018 00:44:38 +0000 (20:44 -0400)
Add two helpers to make it easier to treat the refcount as boolean.

Suggested-by: Jason Baron <jasonbaron0@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Orabug: 28220674
CVE: CVE-2018-3620

(cherry picked from commit e33886b38cc82a9fc3b2d655dfc7f50467594138)
This commit was necessary for porting 13b7b7.

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
include/linux/jump_label.h
kernel/sched/core.c

index f4de473f226b8ab5332dabc7083b74c80de8a664..6d80f843eb5bc01745bc28c02c187ba095d8f01b 100644 (file)
@@ -213,6 +213,26 @@ static inline bool static_key_enabled(struct static_key *key)
        return static_key_count(key) > 0;
 }
 
+static inline void static_key_enable(struct static_key *key)
+{
+       int count = static_key_count(key);
+
+       WARN_ON_ONCE(count < 0 || count > 1);
+
+       if (!count)
+               static_key_slow_inc(key);
+}
+
+static inline void static_key_disable(struct static_key *key)
+{
+       int count = static_key_count(key);
+
+       WARN_ON_ONCE(count < 0 || count > 1);
+
+       if (count)
+               static_key_slow_dec(key);
+}
+
 #endif /* _LINUX_JUMP_LABEL_H */
 
 #endif /* __ASSEMBLY__ */
index 32e91382ee1e880ec3bb20d7898be25c6a096989..400adfcafd1ba43879657be0f32226563017ca78 100644 (file)
@@ -185,14 +185,12 @@ struct static_key sched_feat_keys[__SCHED_FEAT_NR] = {
 
 static void sched_feat_disable(int i)
 {
-       if (static_key_enabled(&sched_feat_keys[i]))
-               static_key_slow_dec(&sched_feat_keys[i]);
+       static_key_disable(&sched_feat_keys[i]);
 }
 
 static void sched_feat_enable(int i)
 {
-       if (!static_key_enabled(&sched_feat_keys[i]))
-               static_key_slow_inc(&sched_feat_keys[i]);
+       static_key_enable(&sched_feat_keys[i]);
 }
 #else
 static void sched_feat_disable(int i) { };