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: <ede5fcf72e26fc0a6f443d7393c804e39d51c029.1741988314.git.jpoimboe@kernel.org>
Date: Fri, 14 Mar 2025 14:41:22 -0700
From: Josh Poimboeuf <jpoimboe@...nel.org>
To: x86@...nel.org
Cc: linux-kernel@...r.kernel.org,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Borislav Petkov <bp@...en8.de>,
	"H. Peter Anvin" <hpa@...or.com>,
	Uros Bizjak <ubizjak@...il.com>,
	Andrew Cooper <andrew.cooper3@...rix.com>,
	Ingo Molnar <mingo@...nel.org>
Subject: [PATCH 09/20] x86/alternative: Simplify alternative_io() interface

Similar to alternative_call(), change alternative_io() to allow outputs,
inputs, and clobbers to be specified individually.

Also add in the "memory" clobber for consistent behavior with the other
alternative macros.

Signed-off-by: Josh Poimboeuf <jpoimboe@...nel.org>
---
 arch/x86/include/asm/alternative.h   | 15 +++++++++++----
 arch/x86/include/asm/apic.h          |  3 ++-
 arch/x86/include/asm/special_insns.h |  3 ++-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
index 3804b82cb03c..870b1633e1e0 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -219,10 +219,17 @@ static inline int alternatives_text_reserved(void *start, void *end)
 	asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \
 		: : input)
 
-/* Like alternative_input, but with a single output argument */
-#define alternative_io(oldinstr, newinstr, ft_flags, output, input...)	\
-	asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags)	\
-		: output : input)
+/*
+ * Alternative inline assembly with input, output and clobbers.
+ *
+ * All @output, @input, and @clobbers should be wrapped with ARG() for both
+ * functionality and readability reasons.
+ */
+#define alternative_io(oldinstr, newinstr, ft_flags, output, input, clobbers...)	\
+	asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags)			\
+			    : output							\
+			    : input							\
+			    : "memory", ## clobbers)
 
 /*
  * Like alternative_io, but for replacing a direct call with another one.
diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 6526bad6ec81..8b0c2a392f8b 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -100,7 +100,8 @@ static inline void native_apic_mem_write(u32 reg, u32 v)
 
 	alternative_io("movl %[val], %[mem]",
 		       "xchgl %[val], %[mem]", X86_BUG_11AP,
-		       ARG([val] "+r" (v), [mem] "+m" (*addr)));
+		       ARG([val] "+r" (v), [mem] "+m" (*addr)),
+		       ARG());
 }
 
 static inline u32 native_apic_mem_read(u32 reg)
diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index a6a3f4c95f03..16fb2bc09059 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -178,7 +178,8 @@ static inline void clflushopt(volatile void *__p)
 {
 	alternative_io(".byte 0x3e; clflush %[val]",
 		       ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT,
-		       ARG([val] "+m" (*(volatile char __force *)__p)));
+		       ARG([val] "+m" (*(volatile char __force *)__p)),
+		       ARG());
 }
 
 static inline void clwb(volatile void *__p)
-- 
2.48.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ