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]
Message-Id: <20210422194738.2175542-2-tannerlove.kernel@gmail.com>
Date:   Thu, 22 Apr 2021 15:47:36 -0400
From:   Tanner Love <tannerlove.kernel@...il.com>
To:     netdev@...r.kernel.org
Cc:     davem@...emloft.net, Tanner Love <tannerlove@...gle.com>,
        Eric Dumazet <edumazet@...gle.com>,
        Mahesh Bandewar <maheshb@...gle.com>
Subject: [PATCH net-next 1/3] once: implement DO_ONCE_LITE for non-fast-path "do once" functionality

From: Tanner Love <tannerlove@...gle.com>

Certain uses of "do once" functionality (such as many occurrences of
static bool __section(".data.once")) reside outside of fast path, and
thus do not require jump label patching via static keys.

Implement DO_ONCE_LITE, which offers this "do once" functionality
without using static keys.

Implement DO_ONCE_LITE_IF, which offers the same functionality but
gated by a condition test. This is common in current uses of static
bool __section(".data.once").

Signed-off-by: Tanner Love <tannerlove@...gle.com>
Acked-by: Eric Dumazet <edumazet@...gle.com>
Acked-by: Mahesh Bandewar <maheshb@...gle.com>
---
 include/linux/once.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/once.h b/include/linux/once.h
index 9225ee6d96c7..a92bb213f817 100644
--- a/include/linux/once.h
+++ b/include/linux/once.h
@@ -52,6 +52,22 @@ void __do_once_done(bool *done, struct static_key_true *once_key,
 		___ret;							     \
 	})
 
+/* Call a function once. Similar to DO_ONCE(), but does not use jump label
+ * patching via static keys.
+ */
+#define DO_ONCE_LITE(func, ...)						     \
+	DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__)
+#define DO_ONCE_LITE_IF(condition, func, ...)				     \
+	({								     \
+		static bool __section(".data.once") __already_done;	     \
+		bool __ret_do_once = !!(condition);			     \
+									     \
+		if (unlikely(__ret_do_once && !__already_done)) {	     \
+			__already_done = true;				     \
+			func(__VA_ARGS__);				     \
+		}							     \
+		unlikely(__ret_do_once);				     \
+	})
 #define get_random_once(buf, nbytes)					     \
 	DO_ONCE(get_random_bytes, (buf), (nbytes))
 #define get_random_once_wait(buf, nbytes)                                    \
-- 
2.31.1.498.g6c1eba8ee3d-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ