[PATCH 09/20] x86/alternative: Simplify alternative_io() interface
From: Josh Poimboeuf
Date: Fri Mar 14 2025 - 17:50:07 EST
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@xxxxxxxxxx>
---
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