lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  3 Nov 2022 21:25:22 +0000
From:   Dmitry Safonov <dima@...sta.com>
To:     linux-kernel@...r.kernel.org, David Ahern <dsahern@...nel.org>,
        Eric Dumazet <edumazet@...gle.com>
Cc:     Dmitry Safonov <dima@...sta.com>,
        Bob Gilligan <gilligan@...sta.com>,
        "David S. Miller" <davem@...emloft.net>,
        Dmitry Safonov <0x7f454c46@...il.com>,
        Francesco Ruggeri <fruggeri@...sta.com>,
        Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Salam Noureddine <noureddine@...sta.com>,
        netdev@...r.kernel.org, Ard Biesheuvel <ardb@...nel.org>,
        Jason Baron <jbaron@...mai.com>,
        Josh Poimboeuf <jpoimboe@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Steven Rostedt <rostedt@...dmis.org>
Subject: [PATCH v2 1/3] jump_label: Add static_key_fast_inc()

A helper to add another user for an existing enabled static key.

Cc: Ard Biesheuvel <ardb@...nel.org>
Cc: Jason Baron <jbaron@...mai.com>
Cc: Josh Poimboeuf <jpoimboe@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Steven Rostedt <rostedt@...dmis.org>
Suggested-by: Eric Dumazet <edumazet@...gle.com>
Signed-off-by: Dmitry Safonov <dima@...sta.com>
---
 include/linux/jump_label.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 570831ca9951..cb6c722c4816 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -75,6 +75,8 @@
 
 #include <linux/types.h>
 #include <linux/compiler.h>
+#include <linux/atomic.h>
+#include <linux/bug.h>
 
 extern bool static_key_initialized;
 
@@ -235,6 +237,21 @@ extern void static_key_enable_cpuslocked(struct static_key *key);
 extern void static_key_disable_cpuslocked(struct static_key *key);
 extern enum jump_label_type jump_label_init_type(struct jump_entry *entry);
 
+/***
+ * static_key_fast_inc - adds a user for a static key
+ * @key: static key that must be already enabled
+ *
+ * The caller must make sure that the static key can't get disabled while
+ * in this function. It doesn't patch jump labels, only adds a user to
+ * an already enabled static key.
+ */
+static inline void static_key_fast_inc(struct static_key *key)
+{
+	STATIC_KEY_CHECK_USE(key);
+	WARN_ON_ONCE(atomic_read(&key->enabled) < 1);
+	atomic_inc(&key->enabled);
+}
+
 /*
  * We should be using ATOMIC_INIT() for initializing .enabled, but
  * the inclusion of atomic.h is problematic for inclusion of jump_label.h
@@ -251,9 +268,6 @@ extern enum jump_label_type jump_label_init_type(struct jump_entry *entry);
 
 #else  /* !CONFIG_JUMP_LABEL */
 
-#include <linux/atomic.h>
-#include <linux/bug.h>
-
 static __always_inline int static_key_count(struct static_key *key)
 {
 	return arch_atomic_read(&key->enabled);
@@ -290,6 +304,7 @@ static inline void static_key_slow_dec(struct static_key *key)
 	atomic_dec(&key->enabled);
 }
 
+#define static_key_fast_inc(key) static_key_slow_inc(key)
 #define static_key_slow_inc_cpuslocked(key) static_key_slow_inc(key)
 #define static_key_slow_dec_cpuslocked(key) static_key_slow_dec(key)
 
-- 
2.38.1

Powered by blists - more mailing lists