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: <20250602144756.054408110@infradead.org>
Date: Mon, 02 Jun 2025 16:42:08 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: x86@...nel.org
Cc: linux-kernel@...r.kernel.org,
 peterz@...radead.org,
 kees@...nel.org,
 acarmina@...hat.com,
 jpoimboe@...nel.org,
 mark.rutland@....com,
 torvalds@...uxfoundation.org
Subject: [RFC 7/8] x86/bug: Implement WARN_ONCE()

Implement WARN_ONCE like WARN using BUGFLAG_ONCE.

Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
---
 arch/x86/include/asm/bug.h |   28 ++++++++++++++++++++++++++++
 include/asm-generic/bug.h  |    2 ++
 2 files changed, 30 insertions(+)

--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -221,6 +221,34 @@ do {									\
 #define __WARN_printf(taint, fmt, arg...) \
 	CONCATENATE(__WARN_printf_, WARN_ARGS(arg))(BUGFLAG_TAINT(taint), fmt, ## arg)
 
+#define __WONCE_printf_0(flags, format) \
+	__WARN_printf_0(flags|BUGFLAG_ONCE, format)
+
+#define __WONCE_printf_1(flags, format, arg1) \
+	__WARN_printf_1(flags|BUGFLAG_ONCE, format, arg1)
+
+#define __WONCE_printf_2(flags, format, arg1, arg2) \
+	__WARN_printf_2(flags|BUGFLAG_ONCE, format, arg1, arg2)
+
+#define __WONCE_printf_3(flags, format, arg1, arg2, arg3) \
+	__WARN_printf_3(flags|BUGFLAG_ONCE, format, arg1, arg2, arg3)
+
+#define __WONCE_printf_n(flags, format, arg...) \
+	if (__ONCE_LITE_IF(true)) __WARN_printf_n(flags, format, arg)
+
+#define _WARN_ONCE(cond, format, arg...) ({				\
+	int __ret_warn_on = !!(cond);					\
+	if (unlikely(__ret_warn_on)) {					\
+		CONCATENATE(__WONCE_printf_, WARN_ARGS(arg))(0, format, ## arg); \
+	}								\
+	__ret_warn_on;							\
+})
+
+/*
+ * Make sure WARN_ONCE() arguments get expanded before trying to count them.
+ */
+#define WARN_ONCE(cond, format...) _WARN_ONCE(cond, format)
+
 #endif /* HAVE_ARCH_BUG_FORMAT */
 
 #include <asm-generic/bug.h>
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -155,8 +155,10 @@ extern __printf(1, 2) void __warn_printk
 	DO_ONCE_LITE_IF(condition, WARN_ON, 1)
 #endif
 
+#ifndef WARN_ONCE
 #define WARN_ONCE(condition, format...)				\
 	DO_ONCE_LITE_IF(condition, WARN, 1, format)
+#endif
 
 #define WARN_TAINT_ONCE(condition, taint, format...)		\
 	DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format)



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ