x86: Cleanup alternative_io() and friends, prep for asm_call()
Subsystems (5)
cover x86: Cleanup alternative_io() and friends, prep for asm_call()
Make the alternative_io() interface more straightforward and flexible, and get rid of alternative_input().
These patches are a prereq for another set[1] which will get rid of ASM_CALL_CONSTRAINT[2] in favor of a much more flexible asm_call() interface similar to the new alternative_io().
[1] Additional 20+ patches not posted yet to avoid flooding inboxes
[2] ASM_CALL_CONSTRAINT is semi-broken with Clang+KCOV+KMSAN.
https://lore.kernel.org/174108458465.14745.15292444415957816824.tip-bot2@tip-bot2/ https://lore.kernel.org/174099976188.10177.7153571701278544000.tip-bot2@tip-bot2
Josh Poimboeuf (20):
x86/cpu: Use named asm operands in prefetch[w]()
x86/apic: Use named asm operands in native_apic_mem_write() x86/mm: Use named asm operands in task_size_max()
x86/cpu: Use named asm operands in clflushopt()
x86/asm: Always use flag output operands
x86/asm: Remove CC_SET()
x86/alternative: Remove operand numbering restrictions x86/asm: Replace ASM_{OUTPUT,INPUT}() with ARG() x86/alternative: Simplify alternative_io() interface x86/alternative: Add alternative_2_io()
x86/alternative: Make alternative() a wrapper around alternative_io() x86/cpu: Use alternative_io() in prefetch[w]() x86/alternative: Remove alternative_input()
x86/barrier: Use alternative_io() in 32-bit barrier functions x86/cpu/amd: Use named asm operands in asm_clear_divider() x86/cpu: Use alternative_io() in amd_clear_divider() x86/smap: Use named asm operands in smap_{save,restore}() x86/smap: Use alternative_io() in smap_{save,restore}() x86/uaccess: Use alternative_io() in __untagged_addr() x86/msr: Use alternative_2_io() in rdtsc_ordered()
arch/x86/boot/bitops.h | 2 +- arch/x86/boot/boot.h | 4 +- arch/x86/boot/string.c | 2 +- arch/x86/include/asm/alternative.h | 31 +++++----- arch/x86/include/asm/apic.h | 7 ++- arch/x86/include/asm/archrandom.h | 2 - arch/x86/include/asm/asm.h | 21 +++---- arch/x86/include/asm/atomic64_32.h | 93 +++++++++++++++------------- arch/x86/include/asm/barrier.h | 23 +++++-- arch/x86/include/asm/bitops.h | 6 -- arch/x86/include/asm/cmpxchg.h | 4 -- arch/x86/include/asm/cmpxchg_32.h | 2 - arch/x86/include/asm/cmpxchg_64.h | 1 - arch/x86/include/asm/msr.h | 13 ++-- arch/x86/include/asm/page_64.h | 16 ++--- arch/x86/include/asm/percpu.h | 4 -- arch/x86/include/asm/processor.h | 22 ++++--- arch/x86/include/asm/rmwcc.h | 24 +------ arch/x86/include/asm/segment.h | 5 +- arch/x86/include/asm/sev.h | 1 - arch/x86/include/asm/signal.h | 2 +- arch/x86/include/asm/smap.h | 18 +++--- arch/x86/include/asm/special_insns.h | 9 ++- arch/x86/include/asm/uaccess.h | 1 - arch/x86/include/asm/uaccess_64.h | 8 +-- tools/arch/x86/include/asm/asm.h | 10 +-- tools/perf/bench/find-bit-bench.c | 4 -- 27 files changed, 153 insertions(+), 182 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/20 x86/cpu: Use named asm operands in prefetch[w]()
Use named operands in preparation for removing the operand numbering restrictions in alternative_input().
--- arch/x86/include/asm/processor.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/include/asm/processor.h +7 -7
@@ -613,7 +613,7 @@ extern char ignore_fpu_irq;# define BASE_PREFETCH ""# define ARCH_HAS_PREFETCH #else -# define BASE_PREFETCH "prefetcht0 %1" +# define BASE_PREFETCH "prefetcht0 %[val]"#endif /*
@@ -624,9 +624,9 @@ extern char ignore_fpu_irq;*/ static inline void prefetch (const void *x) { -alternative_input (BASE_PREFETCH ,"prefetchnta %1" , -X86_FEATURE_XMM , -"m" (*(const char *)x)); +alternative_input (BASE_PREFETCH , + "prefetchnta %[val]", X86_FEATURE_XMM, + [val] "m" (*(const char *)x)); }/*
@@ -636,9 +636,9 @@ static inline void prefetch(const void *x)*/ static __always_inline void prefetchw(const void *x) { -alternative_input (BASE_PREFETCH ,"prefetchw %1" , -X86_FEATURE_3DNOWPREFETCH , -"m" (*(const char *)x)); +alternative_input (BASE_PREFETCH , + "prefetchw %[val]", X86_FEATURE_3DNOWPREFETCH, + [val] "m" (*(const char *)x)); }#define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
Signature · 1 line
2.48.1
PATCH 2/20 x86/apic: Use named asm operands in native_apic_mem_write()
In reply to Josh PoimboeufUse named operands in preparation for removing the operand numbering restrictions in alternative_io().
Note this includes removing the "0" input constraint and converting its corresponding output constraint from "=r" to "+r". While at it, do the same for the memory constraint.
--- arch/x86/include/asm/apic.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/apic.h +3 -3
@@ -98,9 +98,9 @@ static inline void native_apic_mem_write(u32 reg, u32 v) {volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg); -alternative_io ("movl %0, %1" ,"xchgl %0, %1" ,X86_BUG_11AP , -ASM_OUTPUT ("=r" (v),"=m" (*addr)), -ASM_INPUT ("0" (v),"m" (*addr))); +alternative_io ("movl %[val], %[mem]" , +"xchgl %[val], %[mem]" ,X86_BUG_11AP , + ASM_OUTPUT([val] "+r" (v), [mem] "+m" (*addr))); } static inline u32 native_apic_mem_read(u32 reg)
Signature · 1 line
2.48.1
PATCH 3/20 x86/mm: Use named asm operands in task_size_max()
In reply to Josh PoimboeufUse named operands in preparation for removing the operand numbering restrictions in alternative_io().
--- arch/x86/include/asm/page_64.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/page_64.h +3 -3
@@ -85,9 +85,9 @@ static __always_inline unsigned long task_size_max(void) {unsigned long ret; -alternative_io ("movq %[small],%0" ,"movq %[large],%0" , -X86_FEATURE_LA57 , - "=r" (ret), +alternative_io ("movq %[small], %[ret]" , + "movq %[large], %[ret]", X86_FEATURE_LA57, + [ret] "=r" (ret), [small] "i" ((1ul << 47)-PAGE_SIZE), [large] "i" ((1ul << 56)-PAGE_SIZE));
Signature · 1 line
2.48.1
PATCH 4/20 x86/cpu: Use named asm operands in clflushopt()
In reply to Josh PoimboeufUse named operands in preparation for removing the operand numbering restrictions in alternative_io().
--- arch/x86/include/asm/special_insns.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/special_insns.h +3 -4
@@ -176,10 +176,9 @@ static __always_inline void clflush(volatile void *__p)static inline void clflushopt (volatile void *__p) { -alternative_io (".byte 0x3e; clflush %0" , -".byte 0x66; clflush %0" , -X86_FEATURE_CLFLUSHOPT , -"+m" (*(volatile char __force *)__p)); +alternative_io (".byte 0x3e; clflush %[val]" , + ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT, + [val] "+m" (*(volatile char __force *)__p)); }static inline void clwb (volatile void *__p)
Signature · 1 line
2.48.1
PATCH 5/20 x86/asm: Always use flag output operands
In reply to Josh PoimboeufOn x86, __GCC_ASM_FLAG_OUTPUTS__ is supported starting with GCC 6.0 and Clang 9.
Now that the GCC minimum version on x86 has been bumped to 8.1 with the following commit:
commit a3e8fe814ad1 ("x86/build: Raise the minimum GCC version to 8.1")
the flag output operand support can be assumed everywhere.
--- arch/x86/include/asm/asm.h | 9 ++------- arch/x86/include/asm/rmwcc.h | 22 ---------------------- tools/arch/x86/include/asm/asm.h | 5 ----- tools/perf/bench/find-bit-bench.c | 4 ---- 4 files changed, 2 insertions(+), 38 deletions(-)
arch/x86/include/asm/asm.h +2 -7
@@ -131,13 +131,8 @@ static __always_inline __pure void *rip_rel_ptr(void *p)* Macros to generate condition code outputs from inline assembly, * The output operand must be type "bool". */ -#ifdef __GCC_ASM_FLAG_OUTPUTS__ -# define CC_SET(c) "\n\t/* output condition code " #c "*/\n" -# define CC_OUT (c) "=@cc" #c -#else -# define CC_SET (c) "\n\tset" #c " %[_cc_" #c "]\n" -# define CC_OUT (c) [_cc_ ## c] "=qm" -#endif +#define CC_SET(c) "\n\t/* output condition code " #c "*/\n" +#define CC_OUT (c) "=@cc" #c#ifdef __KERNEL__
arch/x86/include/asm/rmwcc.h +0 -22
@@ -6,26 +6,6 @@ #define __CLOBBERS_MEM(clb...) "memory", ## clb -#ifndef __GCC_ASM_FLAG_OUTPUTS__ - -/* Use asm goto */ - -#define __GEN_RMWcc (fullop, _var, cc, clobbers, ...) \ -({ \ - bool c = false; \ - asm goto (fullop "; j" #cc " %l[cc_label]" \ - : : [var] "m" (_var), ## __VA_ARGS__ \ - : clobbers : cc_label); \ - if (0) { \ -cc_label: c = true; \ - } \ - c; \ -}) - -#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) */ - -/* Use flags output or a set instruction */ -#define __GEN_RMWcc (fullop, _var, cc, clobbers, ...) \ ({ \ bool c; \
@@ -35,8 +15,6 @@ cc_label: c = true; \ c; \ }) -#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) */ -#define GEN_UNARY_RMWcc_4 (op, var, cc, arg0) \ __GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM())
tools/arch/x86/include/asm/asm.h +0 -5
@@ -112,13 +112,8 @@* Macros to generate condition code outputs from inline assembly, * The output operand must be type "bool". */ -#ifdef __GCC_ASM_FLAG_OUTPUTS__ # define CC_SET(c) "\n\t/* output condition code " #c "*/\n"# define CC_OUT (c) "=@cc" #c -#else -# define CC_SET (c) "\n\tset" #c " %[_cc_" #c "]\n" -# define CC_OUT (c) [_cc_ ## c] "=qm" -#endif #ifdef __KERNEL__
tools/perf/bench/find-bit-bench.c +0 -4
@@ -37,7 +37,6 @@ static noinline void workload(int val) accumulator++; } -#if (defined(__i386__) || defined(__x86_64__)) && defined(__GCC_ASM_FLAG_OUTPUTS__)static bool asm_test_bit (long nr,const unsigned long *addr) {bool oldbit;
@@ -48,9 +47,6 @@ static bool asm_test_bit(long nr, const unsigned long *addr)return oldbit; } -#else -#define asm_test_bit test_bit -#endif static int do_for_each_set_bit (unsigned int num_bits) {
Signature · 1 line
2.48.1
PATCH 6/20 x86/asm: Remove CC_SET()
In reply to Josh PoimboeufNow that flag output operands are unconditionally supported, CC_SET() is just a comment. Remove it.
--- arch/x86/boot/bitops.h | 2 +- arch/x86/boot/boot.h | 4 ++-- arch/x86/boot/string.c | 2 +- arch/x86/include/asm/archrandom.h | 2 -- arch/x86/include/asm/asm.h | 3 +-- arch/x86/include/asm/bitops.h | 6 ------ arch/x86/include/asm/cmpxchg.h | 4 ---- arch/x86/include/asm/cmpxchg_32.h | 2 -- arch/x86/include/asm/cmpxchg_64.h | 1 - arch/x86/include/asm/percpu.h | 4 ---- arch/x86/include/asm/rmwcc.h | 2 +- arch/x86/include/asm/sev.h | 1 - arch/x86/include/asm/signal.h | 2 +- arch/x86/include/asm/special_insns.h | 1 - arch/x86/include/asm/uaccess.h | 1 - tools/arch/x86/include/asm/asm.h | 5 ++--- 16 files changed, 9 insertions(+), 33 deletions(-)
arch/x86/boot/bitops.h +1 -1
@@ -27,7 +27,7 @@ static inline bool variable_test_bit(int nr, const void *addr)bool v;const u32 *p = addr; - asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr)); + asm("btl %2,%1" : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));return v; }
arch/x86/boot/boot.h +2 -2
@@ -155,14 +155,14 @@ static inline void wrgs32(u32 v, addr_t addr)static inline bool memcmp_fs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("fs; repe; cmpsb" CC_SET(nz) + asmvolatile ("fs; repe; cmpsb" : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }static inline bool memcmp_gs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("gs; repe; cmpsb" CC_SET(nz) + asmvolatile ("gs; repe; cmpsb" : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/boot/string.c +1 -1
@@ -32,7 +32,7 @@int memcmp (const void *s1,const void *s2,size_t len) {bool diff; - asm("repe; cmpsb" CC_SET(nz) + asm("repe; cmpsb" : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/include/asm/archrandom.h +0 -2
@@ -23,7 +23,6 @@ static inline bool __must_check rdrand_long(unsigned long *v)unsigned int retry =RDRAND_RETRY_LOOPS ; do { asm volatile("rdrand %[out]" - CC_SET(c) : CC_OUT(c) (ok), [out] "=r" (*v)); if (ok) return true;
@@ -35,7 +34,6 @@ static inline bool __must_check rdseed_long(unsigned long *v) {bool ok; asmvolatile ("rdseed %[out]" - CC_SET(c) : CC_OUT(c) (ok), [out] "=r" (*v)); return ok; }
arch/x86/include/asm/asm.h +1 -2
@@ -128,10 +128,9 @@ static __always_inline __pure void *rip_rel_ptr(void *p)#endif /* -* Macros to generate condition code outputs from inline assembly, +* Generate condition code outputs from inline assembly. * The output operand must be type "bool". */ -#define CC_SET(c) "\n\t/* output condition code " #c "*/\n"#define CC_OUT (c) "=@cc" #c#ifdef __KERNEL__
arch/x86/include/asm/bitops.h +0 -6
@@ -99,7 +99,6 @@ static __always_inline bool arch_xor_unlock_is_negative_byte(unsigned long mask, {bool negative; asm volatile(LOCK_PREFIX "xorb %2,%1" - CC_SET(s) : CC_OUT(s) (negative), WBYTE_ADDR(addr) : "iq" ((char)mask) : "memory"); return negative;
@@ -149,7 +148,6 @@ arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)bool oldbit; asm(__ASM_SIZE(bts) " %2,%1" - CC_SET(c) : CC_OUT(c) (oldbit) : ADDR, "Ir" (nr) : "memory"); return oldbit;
@@ -175,7 +173,6 @@ arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)bool oldbit; asm volatile(__ASM_SIZE(btr) " %2,%1" - CC_SET(c) : CC_OUT(c) (oldbit) : ADDR, "Ir" (nr) : "memory"); return oldbit;
@@ -187,7 +184,6 @@ arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)bool oldbit; asm volatile(__ASM_SIZE(btc) " %2,%1" - CC_SET(c) : CC_OUT(c) (oldbit) : ADDR, "Ir" (nr) : "memory");
@@ -211,7 +207,6 @@ static __always_inline bool constant_test_bit_acquire(long nr, const volatile unbool oldbit; asm volatile("testb %2,%1" - CC_SET(nz) : CC_OUT(nz) (oldbit) : "m" (((unsigned char *)addr)[nr >> 3]),"i" (1 << (nr &7 ))
@@ -225,7 +220,6 @@ static __always_inline bool variable_test_bit(long nr, volatile const unsigned lbool oldbit; asm volatile(__ASM_SIZE(bt) " %2,%1" - CC_SET(c) : CC_OUT(c) (oldbit) : "m" (*(unsigned long *)addr), "Ir" (nr) : "memory");
arch/x86/include/asm/cmpxchg.h +0 -4
@@ -166,7 +166,6 @@ extern void __add_wrong_size(void) { \volatile u8 *__ptr = (volatile u8 *)(_ptr); \ asmvolatile (lock"cmpxchgb %[new], %[ptr]" \ - CC_SET(z) \ : CC_OUT(z) (success), \ [ptr] "+m" (*__ptr), \[old] " +a" (__old) \
@@ -178,7 +177,6 @@ extern void __add_wrong_size(void) { \volatile u16 *__ptr = (volatile u16 *)(_ptr); \ asmvolatile (lock"cmpxchgw %[new], %[ptr]" \ - CC_SET(z) \ : CC_OUT(z) (success), \ [ptr] "+m" (*__ptr), \[old] " +a" (__old) \
@@ -190,7 +188,6 @@ extern void __add_wrong_size(void) { \volatile u32 *__ptr = (volatile u32 *)(_ptr); \ asmvolatile (lock"cmpxchgl %[new], %[ptr]" \ - CC_SET(z) \ : CC_OUT(z) (success), \ [ptr] "+m" (*__ptr), \[old] " +a" (__old) \
@@ -202,7 +199,6 @@ extern void __add_wrong_size(void) { \volatile u64 *__ptr = (volatile u64 *)(_ptr); \ asmvolatile (lock"cmpxchgq %[new], %[ptr]" \ - CC_SET(z) \ : CC_OUT(z) (success), \ [ptr] "+m" (*__ptr), \[old] " +a" (__old) \
arch/x86/include/asm/cmpxchg_32.h +0 -2
@@ -46,7 +46,6 @@ static __always_inline u64 __cmpxchg64_local(volatile u64 *ptr, u64 old, u64 newbool ret; \ \ asmvolatile (_lock"cmpxchg8b %[ptr]" \ - CC_SET(e) \ : CC_OUT(e) (ret), \ [ptr] "+m" (*(_ptr)), \"+a" (o.low),"+d" (o.high) \
@@ -125,7 +124,6 @@ static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64 ALTERNATIVE(_lock_loc \ "call cmpxchg8b_emu", \ _lock "cmpxchg8b %a[ptr]", X86_FEATURE_CX8) \ - CC_SET(e) \ : ALT_OUTPUT_SP(CC_OUT(e) (ret), \ "+a" (o.low), "+d" (o.high)) \ : "b" (n.low), "c" (n.high), \
arch/x86/include/asm/cmpxchg_64.h +0 -1
@@ -66,7 +66,6 @@ static __always_inline u128 arch_cmpxchg128_local(volatile u128 *ptr, u128 old,bool ret; \ \ asmvolatile (_lock"cmpxchg16b %[ptr]" \ - CC_SET(e) \ : CC_OUT(e) (ret), \ [ptr] "+m" (*(_ptr)), \"+a" (o.low),"+d" (o.high) \
arch/x86/include/asm/percpu.h +0 -4
@@ -294,7 +294,6 @@ do { \ \ asm qual (__pcpu_op_##size("cmpxchg") "%[nval], " \ __percpu_arg([var]) \ - CC_SET(z) \ : CC_OUT(z) (success), \ [oval] "+a" (pco_old__), \ [var] "+m" (__my_cpu_var(_var)) \
@@ -352,7 +351,6 @@ do { \ asm_inline qual ( \ ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \ "cmpxchg8b " __percpu_arg([var]), X86_FEATURE_CX8) \ - CC_SET(z) \ : ALT_OUTPUT_SP(CC_OUT(z) (success), \ [var] "+m" (__my_cpu_var(_var)), \"+a" (old__.low),"+d" (old__.high)) \
@@ -421,7 +419,6 @@ do { \ asm_inline qual ( \ ALTERNATIVE("call this_cpu_cmpxchg16b_emu", \ "cmpxchg16b " __percpu_arg([var]), X86_FEATURE_CX16) \ - CC_SET(z) \ : ALT_OUTPUT_SP(CC_OUT(z) (success), \ [var] "+m" (__my_cpu_var(_var)), \"+a" (old__.low),"+d" (old__.high)) \
@@ -570,7 +567,6 @@ do { \bool oldbit; \ \ asm volatile("btl %[nr], " __percpu_arg([var]) \ - CC_SET(c) \ : CC_OUT(c) (oldbit) \ : [var] "m" (__my_cpu_var(_var)), \[nr] " rI" (_nr)); \
arch/x86/include/asm/rmwcc.h +1 -1
@@ -9,7 +9,7 @@#define __GEN_RMWcc (fullop, _var, cc, clobbers, ...) \ ({ \ bool c; \ - asm volatile (fullop CC_SET(cc) \ + asm volatile (fullop \ : [var] "+m" (_var), CC_OUT(cc) (c) \ : __VA_ARGS__ : clobbers); \ c; \
arch/x86/include/asm/sev.h +0 -1
@@ -440,7 +440,6 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate)/* "pvalidate" mnemonic support in binutils 2.36 and newer */ asmvolatile (".byte 0xF2, 0x0F, 0x01, 0xFF\n\t" - CC_SET(c) : CC_OUT(c) (no_rmpupdate), "=a"(rc) : "a"(vaddr), "c"(rmp_psize), "d"(validate) : "memory", "cc");
arch/x86/include/asm/signal.h +1 -1
@@ -83,7 +83,7 @@ static inline int __const_sigismember(sigset_t *set, int _sig)static inline int __gen_sigismember (sigset_t *set,int _sig) {bool ret; - asm("btl %2,%1" CC_SET(c) + asm("btl %2,%1" : CC_OUT(c) (ret) : "m"(*set), "Ir"(_sig-1));return ret; }
arch/x86/include/asm/special_insns.h +0 -1
@@ -274,7 +274,6 @@ static inline int enqcmds(void __iomem *dst, const void *src)* See movdir64b()'s comment on operand specification. */ asmvolatile (".byte 0xf3, 0x0f, 0x38, 0xf8, 0x02, 0x66, 0x90" - CC_SET(z) : CC_OUT(z) (zf), "+m" (*__dst) : "m" (*__src), "a" (__dst), "d" (__src));
arch/x86/include/asm/uaccess.h +0 -1
@@ -417,7 +417,6 @@ do { \ __typeof__(*(_ptr)) __new = (_new); \ asmvolatile ("\n" \"1: " LOCK_PREFIX "cmpxchg" itype" %[new], %[ptr]\n" \ - CC_SET(z) \"2:\n" \ _ASM_EXTABLE_TYPE_REG(1b, 2b, EX_TYPE_EFAULT_REG, \ %[errout]) \
tools/arch/x86/include/asm/asm.h +2 -3
@@ -109,11 +109,10 @@#endif /* -* Macros to generate condition code outputs from inline assembly, +* Generate condition code outputs from inline assembly. * The output operand must be type "bool". */ -# define CC_SET(c) "\n\t/* output condition code " #c "*/\n" -# define CC_OUT (c) "=@cc" #c +#define CC_OUT (c) "=@cc" #c#ifdef __KERNEL__
Signature · 1 line
2.48.1
PATCH 7/20 x86/alternative: Remove operand numbering restrictions
In reply to Josh Poimboeufalternative_input() and alternative_io() arbitrarily require input constraint operand numbering to start at index 1. No more callers rely on that. Simplify the interfaces by removing that restriction.
--- arch/x86/include/asm/alternative.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/include/asm/alternative.h +2 -4
@@ -214,17 +214,15 @@ static inline int alternatives_text_reserved(void *start, void *end)* * Peculiarities: * No memory clobber here. -* Argument numbers start with 1. -* Leaving an unused argument 0 to keep API compatibility. */ #define alternative_input(oldinstr, newinstr, ft_flags, input...) \ asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - : : "i" (0), ## input) + : : 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 : "i" (0), ## input) + : output : input)/* * Like alternative_io, but for replacing a direct call with another one.
Signature · 1 line
2.48.1
PATCH 8/20 x86/asm: Replace ASM_{OUTPUT,INPUT}() with ARG()
In reply to Josh PoimboeufReplace ASM_OUTPUT() and ASM_INPUT() with ARG(). It provides more visual separation and vertical alignment, making it easy to distinguish the outputs, inputs and clobbers. It will also come in handy for other inline asm wrappers.
--- arch/x86/include/asm/apic.h | 2 +- arch/x86/include/asm/asm.h | 11 ++-- arch/x86/include/asm/atomic64_32.h | 93 +++++++++++++++------------- arch/x86/include/asm/page_64.h | 12 ++-- arch/x86/include/asm/segment.h | 5 +- arch/x86/include/asm/special_insns.h | 2 +- 6 files changed, 67 insertions(+), 58 deletions(-)
arch/x86/include/asm/apic.h +1 -1
@@ -100,7 +100,7 @@ static inline void native_apic_mem_write(u32 reg, u32 v)alternative_io ("movl %[val], %[mem]" ,"xchgl %[val], %[mem]" ,X86_BUG_11AP , - ASM_OUTPUT([val] "+r" (v), [mem] "+m" (*addr))); + ARG([val] "+r" (v), [mem] "+m" (*addr))); } static inline u32 native_apic_mem_read(u32 reg)
arch/x86/include/asm/asm.h +7 -4
@@ -212,11 +212,14 @@ static __always_inline __pure void *rip_rel_ptr(void *p)#define __COMMA (...) , ##__VA_ARGS__/* -* Combine multiple asm inline constraint args into a single arg for passing to -* another macro. +* ARG() can be used to bundle multiple arguments into a single argument for +* passing to a macro. +* +* For inline asm constraint operands, this is recommended even for single +* operands as it provides visual separation and vertical alignment similar to +* the ':' characters in an inline asm statement. */ -#define ASM_OUTPUT(x...) x -#define ASM_INPUT(x...) x +#define ARG(x...) x/* * This output constraint should be used for any inline asm which has a "call"
arch/x86/include/asm/atomic64_32.h +49 -44
186 lines not on this page · raw message
arch/x86/include/asm/page_64.h +6 -6
@@ -54,9 +54,9 @@ static inline void clear_page(void *page)alternative_call_2 (clear_page_orig, clear_page_rep,X86_FEATURE_REP_GOOD , clear_page_erms,X86_FEATURE_ERMS , -"=D" (page), -"D" (page), -"cc" ,"memory" ,"rax" ,"rcx" ); +ARG ("=D" (page)), +ARG ("D" (page)), +ARG ("cc" ,"memory" ,"rax" ,"rcx" )); }void copy_page (void *to,void *from);
@@ -87,9 +87,9 @@ static __always_inline unsigned long task_size_max(void)alternative_io ("movq %[small], %[ret]" ,"movq %[large], %[ret]" ,X86_FEATURE_LA57 , - [ret] "=r" (ret), - [small] "i" ((1ul << 47)-PAGE_SIZE), - [large] "i" ((1ul << 56)-PAGE_SIZE)); + ARG([ret] "=r" (ret)), + ARG([small] "i" ((1ul << 47)-PAGE_SIZE), + [large] "i" ((1ul << 56)-PAGE_SIZE)));return ret; }
arch/x86/include/asm/segment.h +3 -2
@@ -254,10 +254,11 @@ static inline void vdso_read_cpunode(unsigned *cpu, unsigned *node)* * If RDPID is available, use it. */ -alternative_io ("lsl %[seg],%[p]" , +alternative_io ("lsl %[seg],%[p]" ,".byte 0xf3,0x0f,0xc7,0xf8" ,/* RDPID %eax/rax */ X86_FEATURE_RDPID , - [p] "=a" (p), [seg] "r" (__CPUNODE_SEG)); + ARG([p] "=a" (p)), + ARG([seg] "r" (__CPUNODE_SEG)));if (cpu) *cpu = (p &VDSO_CPUNODE_MASK );
arch/x86/include/asm/special_insns.h +1 -1
@@ -178,7 +178,7 @@ static inline void clflushopt(volatile void *__p) {alternative_io (".byte 0x3e; clflush %[val]" ,".byte 0x66; clflush %[val]" ,X86_FEATURE_CLFLUSHOPT , - [val] "+m" (*(volatile char __force *)__p)); + ARG([val] "+m" (*(volatile char __force *)__p))); } static inline void clwb(volatile void *__p)
Signature · 1 line
2.48.1
PATCH 9/20 x86/alternative: Simplify alternative_io() interface
In reply to Josh PoimboeufSimilar 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.
--- 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(-)
arch/x86/include/asm/alternative.h +11 -4
@@ -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.
arch/x86/include/asm/apic.h +2 -1
@@ -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)
arch/x86/include/asm/special_insns.h +2 -1
@@ -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)
Signature · 1 line
2.48.1
PATCH 10/20 x86/alternative: Add alternative_2_io()
In reply to Josh PoimboeufMake an ALTERNATIVE_2() version of alternative_io().
--- arch/x86/include/asm/alternative.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/include/asm/alternative.h +8 -0
@@ -231,6 +231,14 @@ static inline int alternatives_text_reserved(void *start, void *end) : input \ : "memory", ## clobbers) +#define alternative_2_io (oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2, \ + output, input, clobbers...) \ + asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, \ + newinstr2, ft_flags2) \ + : output \ + : input \ + : "memory", ## clobbers) +/* * Like alternative_io, but for replacing a direct call with another one. *
Signature · 1 line
2.48.1
PATCH 11/20 x86/alternative: Make alternative() a wrapper around alternative_io()
In reply to Josh PoimboeufTo reduce the number of independent implementations, make alternative() and alternative_2() wrappers around alternative_io() and alternative_2_io() respectively.
--- arch/x86/include/asm/alternative.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/alternative.h +2 -2
@@ -204,10 +204,10 @@ static inline int alternatives_text_reserved(void *start, void *end)* without volatile and memory clobber. */ #define alternative (oldinstr, newinstr, ft_flags) \ - asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "memory") + alternative_io(oldinstr, newinstr, ft_flags,,)#define alternative_2 (oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) \ - asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) ::: "memory") + alternatve_2_io(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2,,)/* * Alternative inline assembly with input.
Signature · 1 line
2.48.1
PATCH 12/20 x86/cpu: Use alternative_io() in prefetch[w]()
In reply to Josh PoimboeufUse the new alternative_io() interface in preparation for removing alternative_input().
--- arch/x86/include/asm/processor.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
arch/x86/include/asm/processor.h +8 -6
@@ -624,9 +624,10 @@ extern char ignore_fpu_irq;*/ static inline void prefetch (const void *x) { -alternative_input (BASE_PREFETCH , - "prefetchnta %[val]", X86_FEATURE_XMM, - [val] "m" (*(const char *)x)); +alternative_io (BASE_PREFETCH , +"prefetchnta %[val]" ,X86_FEATURE_XMM , +ARG (), + ARG([val] "m" (*(const char *)x))); }/*
@@ -636,9 +637,10 @@ static inline void prefetch(const void *x)*/ static __always_inline void prefetchw(const void *x) { -alternative_input (BASE_PREFETCH , - "prefetchw %[val]", X86_FEATURE_3DNOWPREFETCH, - [val] "m" (*(const char *)x)); +alternative_io (BASE_PREFETCH , +"prefetchw %[val]" ,X86_FEATURE_3DNOWPREFETCH , +ARG (), + ARG([val] "m" (*(const char *)x))); }#define TOP_OF_INIT_STACK ((unsigned long)&init_stack + sizeof(init_stack) - \
Signature · 1 line
2.48.1
PATCH 13/20 x86/alternative: Remove alternative_input()
In reply to Josh Poimboeufalternative_input() is redundant with alternative_io(), and has no more users. Remove it.
--- arch/x86/include/asm/alternative.h | 10 ---------- 1 file changed, 10 deletions(-)
arch/x86/include/asm/alternative.h +0 -10
@@ -209,16 +209,6 @@ static inline int alternatives_text_reserved(void *start, void *end)#define alternative_2 (oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2) \ alternatve_2_io(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2,,) -/* -* Alternative inline assembly with input. -* -* Peculiarities: -* No memory clobber here. -*/ -#define alternative_input(oldinstr, newinstr, ft_flags, input...) \ - asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - : : input) -/* * Alternative inline assembly with input, output and clobbers. *
Signature · 1 line
2.48.1
PATCH 14/20 x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Josh PoimboeufUse the standard alternative_io() interface.
--- arch/x86/include/asm/barrier.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
arch/x86/include/asm/barrier.h +17 -6
@@ -12,12 +12,23 @@*/ #ifdef CONFIG_X86_32 -#define mb () asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "mfence", \ - X86_FEATURE_XMM2) ::: "memory", "cc") -#define rmb () asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "lfence", \ - X86_FEATURE_XMM2) ::: "memory", "cc") -#define wmb () asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "sfence", \ - X86_FEATURE_XMM2) ::: "memory", "cc") +#define mb () alternative_io("lock addl $0,-4(%%esp)", \ + "mfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc")) + +#define rmb () alternative_io("lock addl $0, -4(%%esp)", \ + "lfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc")) + +#define wmb () alternative_io("lock addl $0, -4(%%esp)", \ + "sfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc"))#else #define __mb () asm volatile("mfence":::"memory")#define __rmb () asm volatile("lfence":::"memory")
Signature · 1 line
2.48.1
PATCH 15/20 x86/cpu/amd: Use named asm operands in asm_clear_divider()
In reply to Josh PoimboeufUse named inline asm operands in preparation for using alternative_io().
--- arch/x86/include/asm/processor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/include/asm/processor.h +2 -2
@@ -709,8 +709,8 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)*/ static __always_inline void amd_clear_divider(void) { - asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0) - :: "a" (0), "d" (0), "r" (1)); + asm volatile(ALTERNATIVE("", "div %[one]\n\t", X86_BUG_DIV0) + :: "a" (0), "d" (0), [one] "r" (1)); }extern void amd_check_microcode (void );
Signature · 1 line
2.48.1
PATCH 16/20 x86/cpu: Use alternative_io() in amd_clear_divider()
In reply to Josh PoimboeufUse the standard alternative_io() interface.
--- arch/x86/include/asm/processor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/include/asm/processor.h +4 -2
@@ -709,8 +709,10 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)*/ static __always_inline void amd_clear_divider(void) { - asm volatile(ALTERNATIVE("", "div %[one]\n\t", X86_BUG_DIV0) - :: "a" (0), "d" (0), [one] "r" (1)); +alternative_io ("" , +"div %[one]\n\t" ,X86_BUG_DIV0 , +ARG (), + ARG("a" (0), "d" (0), [one] "r" (1))); }extern void amd_check_microcode (void );
Signature · 1 line
2.48.1
PATCH 17/20 x86/smap: Use named asm operands in smap_{save,restore}()
In reply to Josh PoimboeufUse named operands in preparation for using alternative_io().
--- arch/x86/include/asm/smap.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/smap.h +6 -6
@@ -40,9 +40,9 @@ static __always_inline unsigned long smap_save(void)unsigned long flags; asmvolatile ("# smap_save\n\t" - ALTERNATIVE("", "pushf; pop %0; " "clac" "\n\t", -X86_FEATURE_SMAP ) - : "=rm" (flags) : : "memory", "cc"); + ALTERNATIVE("", +"pushf; pop %[flags]; clac\n\t" ,X86_FEATURE_SMAP ) + : [flags] "=rm" (flags) : : "memory", "cc"); return flags; }
@@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void) static __always_inline void smap_restore(unsigned long flags) { asmvolatile ("# smap_restore\n\t" - ALTERNATIVE("", "push %0; popf\n\t", - X86_FEATURE_SMAP) - : : "g" (flags) : "memory", "cc"); + ALTERNATIVE("", +"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP ) + : : [flags] "g" (flags) : "memory", "cc"); }/* These macros can be used in asm() statements */
Signature · 1 line
2.48.1
PATCH 18/20 x86/smap: Use alternative_io() in smap_{save,restore}()
In reply to Josh PoimboeufUse the standard alternative_io() interface.
--- arch/x86/include/asm/smap.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
arch/x86/include/asm/smap.h +10 -8
@@ -39,20 +39,22 @@ static __always_inline unsigned long smap_save(void) {unsigned long flags; - asmvolatile ("# smap_save\n\t" - ALTERNATIVE("", -"pushf; pop %[flags]; clac\n\t" ,X86_FEATURE_SMAP ) - : [flags] "=rm" (flags) : : "memory", "cc"); +alternative_io ("" , +"pushf; pop %[flags]; clac\n\t" ,X86_FEATURE_SMAP , + ARG([flags] "=rm" (flags)), +ARG (), + ARG("memory", "cc"));return flags; } static __always_inline void smap_restore(unsigned long flags) { - asmvolatile ("# smap_restore\n\t" - ALTERNATIVE("", -"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP ) - : : [flags] "g" (flags) : "memory", "cc"); +alternative_io ("" , +"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP , +ARG (), + ARG([flags] "g" (flags)), + ARG("memory", "cc")); }/* These macros can be used in asm() statements */
Signature · 1 line
2.48.1
PATCH 19/20 x86/uaccess: Use alternative_io() in __untagged_addr()
In reply to Josh PoimboeufUse the standard alternative_io() interface.
--- arch/x86/include/asm/uaccess_64.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/uaccess_64.h +4 -4
@@ -26,10 +26,10 @@ extern unsigned long USER_PTR_MAX;*/ static inline unsigned long __untagged_addr (unsigned long addr) { - asm (ALTERNATIVE("", - "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM) - : [addr] "+r" (addr) - : [mask] "m" (__my_cpu_var(tlbstate_untag_mask))); +alternative_io ("" , + "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM, + ARG([addr] "+r" (addr)), + ARG([mask] "m" (__my_cpu_var(tlbstate_untag_mask))));return addr; }
Signature · 1 line
2.48.1
PATCH 20/20 x86/msr: Use alternative_2_io() in rdtsc_ordered()
In reply to Josh PoimboeufUse the standard alternative_2_io() interface.
--- arch/x86/include/asm/msr.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
arch/x86/include/asm/msr.h +7 -6
@@ -214,12 +214,13 @@ static __always_inline unsigned long long rdtsc_ordered(void)* Thus, use the preferred barrier on the respective CPU, aiming for * RDTSCP as the default. */ - asm volatile(ALTERNATIVE_2("rdtsc", - "lfence; rdtsc", X86_FEATURE_LFENCE_RDTSC, - "rdtscp", X86_FEATURE_RDTSCP) - : EAX_EDX_RET(val, low, high) - /* RDTSCP clobbers ECX with MSR_TSC_AUX. */ - :: "ecx"); +alternative_2_io ("rdtsc" , +"lfence; rdtsc" ,X86_FEATURE_LFENCE_RDTSC , +"rdtscp" ,X86_FEATURE_RDTSCP , +ARG (EAX_EDX_RET (val, low, high)), +ARG (), +/* RDTSCP clobbers ECX with MSR_TSC_AUX. */ +ARG ("ecx" ));return EAX_EDX_VAL (val, low, high); }
Signature · 1 line
2.48.1
Quoted 8 lines · Josh Poimboeuf
Make the
alternative_io()interface more straightforward and flexible, and get rid ofalternative_input().These patches are a prereq for another set[1] which will get rid of ASM_CALL_CONSTRAINT[2] in favor of a much more flexible
asm_call()interface similar to the newalternative_io().[1] Additional 20+ patches not posted yet to avoid flooding inboxes
The rest of the patches are here if anybody wants to see where this is going:
git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git asm-call
Signature · 1 line
Josh
Re: [PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()
In reply to Josh Poimboeufarch/x86/include/asm/smap.h static __always_inline unsigned long smap_save(void) · line 58
Quoted 13 lines · Josh Poimboeuf
arch/x86/include/asm/smap.h +3
-3@@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void) static __always_inline void smap_restore(unsigned long flags) { asmvolatile ("# smap_restore\n\t" - ALTERNATIVE("", "push %0; popf\n\t", - X86_FEATURE_SMAP) - : : "g" (flags) : "memory", "cc"); + ALTERNATIVE("", +"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP ) + : : [flags] "g" (flags) : "memory", "cc"); }/* These macros can be used in asm() statements */
The problem with ASM_CALL_CONSTRAINT and asm_call() is that it's not just call instructions. It's any transient stack adjustment.
Peeking forwards the other half of the series, you convert IRET to asm_call(), but leave these alone.
These need converting, and hopefully someone can think of a better name than "call" to be used for the wrapper.
~Andrew
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
In reply to Josh Poimboeufarch/x86/include/asm/special_insns.h static __always_inline void clflush(volatile void *__p) · line 181
Quoted 4 lines · Josh Poimboeuf
arch/x86/include/asm/special_insns.h +3
-0+alternative_io (".byte 0x3e; clflush %[val]" , + ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT, + [val] "+m" (*(volatile char __force *)__p));
Hmm. I think we could just use 'clflushopt', it looks like it exists in binutils-2.25, which is our minimal version requirement.
But maybe that's a separate cleanup.
Linus
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Josh Poimboeufarch/x86/include/asm/barrier.h line 19
Quoted 6 lines · Josh Poimboeuf
arch/x86/include/asm/barrier.h +5
-0+#define mb () alternative_io("lock addl $0,-4(%%esp)", \ + "mfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc"))
So all of these patches look like good cleanups to me, but I do wonder if we should
(a) not use some naming *quite* as generic as 'ARG()'
(b) make the asms use ARG_OUT/ARG_IN/ARG_CLOBBER() to clarify
because that ARG(), ARG(), ARGC() pattern looks odd to me.
Maybe it's just me.
Regardless, I do think the series looks like a nice improvement even in the current form, even if that particular repeated pattern feels strange.
Linus
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
Quoted 4 lines · Linus Torvalds
because that
ARG(),ARG(),ARGC()pattern looks odd to me.Maybe it's just me.
Oh, and the other thing I reacted to is that I think the "alternative_io()" thing should be renamed.
The "io" makes me think "actual I/O". As in PCI or disks or whatever. It always read oddly, but now it's *comletely* pointless, because the new macro model actually takes pretty much arbitrary asm arguments, to the "both input and output arguments" no longer makes any real sense.
So I think it would be better to just call this "alternative_asm()", and make naming simpler. Hmm?
Linus
Re: [PATCH 17/20] x86/smap: Use named asm operands in smap_{save,restore}()
In reply to Andrew CooperQuoted 17 lines · Andrew Cooper
arch/x86/include/asm/smap.h static __always_inline unsigned long smap_save(void) · line 58
Quoted 13 lines · Josh Poimboeuf
arch/x86/include/asm/smap.h +3
-3@@ -50,9 +50,9 @@ static __always_inline unsigned long smap_save(void) static __always_inline void smap_restore(unsigned long flags) { asmvolatile ("# smap_restore\n\t" - ALTERNATIVE("", "push %0; popf\n\t", - X86_FEATURE_SMAP) - : : "g" (flags) : "memory", "cc"); + ALTERNATIVE("", +"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP ) + : : [flags] "g" (flags) : "memory", "cc"); }/* These macros can be used in asm() statements */ The problem with
ASM_CALL_CONSTRAINTandasm_call()is that it's not just call instructions. It's any transient stack adjustment.
Quoted 5 lines
Peeking forwards the other half of the series, you convert IRET to
asm_call(), but leave these alone.These need converting, and hopefully someone can think of a better name than "call" to be used for the wrapper.
After chatting with Josh, the CALL aspect really is for unwinding reasons. This will be fine, until the need for "redzone" arrives.
That said, through both series, there are definitely places which have ASM_CALL_CONSTRAINT and oughtn't to.
~Andrew
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds
So all of these patches look like good cleanups to me, but I do wonder if we should
(a) not use some naming *quite* as generic as '
ARG()'(b) make the asms use ARG_OUT/ARG_IN/ARG_CLOBBER() to clarify
Quoted 7 lines
because that
ARG(),ARG(),ARGC()pattern looks odd to me.Maybe it's just me.
Regardless, I do think the series looks like a nice improvement even in the current form, even if that particular repeated pattern feels strange.
So originally I had ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER, but I ended up going with ARG() due to its nice vertical alignment and conciseness:
__asm_call(qual, \
ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
"cmpxchg8b " __percpu_arg([var]), \
X86_FEATURE_CX8), \
ARG([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \
"+d" (old__.high)), \
ARG("b" (new__.low), "c" (new__.high), "S" (&(_var))), \
ARG("memory")); \Though ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER isn't so bad either:
__asm_call(qual, \
ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
"cmpxchg8b " __percpu_arg([var]), \
X86_FEATURE_CX8), \
ASM_OUTPUT([var] "+m" (__my_cpu_var(_var)), \
"+a" (old__.low), "+d" (old__.high)), \
ASM_INPUT("b" (new__.low), "c" (new__.high), \
"S" (&(_var))), \
ASM_CLOBBER("memory")); \That has the nice benefit of being more self-documenting, albeit more verbose and less vertically aligned.
So I could go either way, really.
Signature · 1 line
Josh
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
In reply to Linus TorvaldsQuoted 10 lines · Linus Torvalds
arch/x86/include/asm/special_insns.h static __always_inline void clflush(volatile void *__p) · line 181
Quoted 4 lines · Josh Poimboeuf
arch/x86/include/asm/special_insns.h +3
-0+alternative_io (".byte 0x3e; clflush %[val]" , + ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT, + [val] "+m" (*(volatile char __force *)__p));Hmm. I think we could just use 'clflushopt', it looks like it exists in binutils-2.25, which is our minimal version requirement.
But maybe that's a separate cleanup.
You appear to be correct, I'll add a patch for that.
Signature · 1 line
Josh
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Linus TorvaldsQuoted 10 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds
because that
ARG(),ARG(),ARGC()pattern looks odd to me.Maybe it's just me.
Oh, and the other thing I reacted to is that I think the "
alternative_io()" thing should be renamed.
Quoted 7 lines
The "io" makes me think "actual I/O". As in PCI or disks or whatever. It always read oddly, but now it's *comletely* pointless, because the new macro model actually takes pretty much arbitrary asm arguments, to the "both input and output arguments" no longer makes any real sense.
So I think it would be better to just call this "
alternative_asm()", and make naming simpler. Hmm?
Thing is, we still have alternative(), which is also an asm wrapper, but it's for when the caller doesn't care about adding any constraints.
So the "_io()" distinguishes from that.
Signature · 1 line
Josh
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
Quoted 5 lines · Josh Poimboeuf
Thing is, we still have
alternative(), which is also an asm wrapper, but it's for when the caller doesn't care about adding any constraints.So the "
_io()" distinguishes from that.
.. but I think it does so very badly because "io" really means something else entirely in absolutely all other contexts.
And it really makes no sense as "io", since it doesn't take inputs and outputs, it takes inputs, outputs AND CLOBBERS.
So it would make more sense to call it "ioc", but that's just obvious nonsense, and "ioc" is already taken as a globally recognized shorthand for "corruption in sports".
So "ioc" is bad too, but that should make you go "Oh, 'io' is _doubly_ nonsensical".
Ergo: I think "asm" would be a better distinguishing marker, withg the plain "alternative()" being used for particularly simple asms.
Linus
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
In reply to Josh PoimboeufQuoted 7 lines · Josh Poimboeuf
Quoted 6 lines · Linus Torvalds
Quoted 4 lines · Josh Poimboeuf
arch/x86/include/asm/special_insns.h +3
-0+alternative_io (".byte 0x3e; clflush %[val]" , + ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT, + [val] "+m" (*(volatile char __force *)__p));
Quoted 6 lines
Quoted 4 lines
Hmm. I think we could just use 'clflushopt', it looks like it exists in binutils-2.25, which is our minimal version requirement.
But maybe that's a separate cleanup.
You appear to be correct, I'll add a patch for that.
Please base your series on tip:master or tip:x86/asm, we already cleaned this up recently:
cc2e9e09d1a3 ("x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>")
Thanks,
Ingo
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Linus TorvaldsQuoted 9 lines · Linus Torvalds
Quoted 5 lines · Josh Poimboeuf
Thing is, we still have
alternative(), which is also an asm wrapper, but it's for when the caller doesn't care about adding any constraints.So the "
_io()" distinguishes from that... but I think it does so very badly because "io" really means something else entirely in absolutely all other contexts.
Yeah, alternative_io() is really a misnomer we should fix.
As a minor side note, it's *doubly* a misnomer, because 'io' mixes up the defined 'o/i' order of the output/input constraints:
arch/x86/include/asm/alternative.h:#define alternative_io(oldinstr, newinstr, ft_flags, output, input...) \
So it should have been alternative_oi().
Quoted 6 lines
And it really makes no sense as "io", since it doesn't take inputs and outputs, it takes inputs, outputs AND CLOBBERS.
So it would make more sense to call it "ioc", but that's just obvious nonsense, and "ioc" is already taken as a globally recognized shorthand for "corruption in sports".
lol ...
Quoted 5 lines
So "ioc" is bad too, but that should make you go "Oh, 'io' is _doubly_ nonsensical".
Ergo: I think "asm" would be a better distinguishing marker, withg the plain "
alternative()" being used for particularly simple asms.
Yeah, alternative_asm() or alternative_opts(). Anything but '_io()' :-)
Thanks,
Ingo
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Linus TorvaldsQuoted 11 lines · Linus Torvalds
arch/x86/include/asm/barrier.h line 19
Quoted 6 lines · Josh Poimboeuf
arch/x86/include/asm/barrier.h +5
-0+#define mb () alternative_io("lock addl $0,-4(%%esp)", \ + "mfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc"))So all of these patches look like good cleanups to me, but I do wonder if we should
Quoted 7 lines
(a) not use some naming *quite* as generic as '
ARG()'(b) make the asms use ARG_OUT/ARG_IN/ARG_CLOBBER() to clarify
because that
ARG(),ARG(),ARGC()pattern looks odd to me.Maybe it's just me.
Not just you, and I think the ARG_ prefix still looks a bit too generic-C to me, it should be something more specific and unambiguously asm() related, like:
ASM_ARGS_IN(), ASM_ARGS_OUT(), ASM_ARGS_CLOBBER(),
or maybe even:
ASM_CONSTRAINT_IN(),
ASM_CONSTRAINT_OUT(),
ASM_CONSTRAINT_CLOBBER(),
Because these asm()-ish syntactic constructs look better in separate lines anyway, and it's not like we are at risk of running out of letters in the kernel anytime soon.
Thanks,
Ingo
Re: [PATCH 15/20] x86/cpu/amd: Use named asm operands in asm_clear_divider()
In reply to Josh PoimboeufQuoted 13 lines · Josh Poimboeuf
Use named inline asm operands in preparation for using
alternative_io().Signed-off-by Josh Poimboeuf <[email protected]>--- arch/x86/include/asm/processor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/x86/include/asm/processor.h +0
-0
arch/x86/include/asm/processor.h static inline u32 per_cpu_l2c_id(unsigned int cpu) · line 713
Quoted 7 lines
arch/x86/include/asm/processor.h +2
-2@@ -709,8 +709,8 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)*/ static __always_inline void amd_clear_divider(void) { - asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0) - :: "a" (0), "d" (0), "r" (1)); + asm volatile(ALTERNATIVE("", "div %[one]\n\t", X86_BUG_DIV0) + :: "a" (0), "d" (0), [one] "r" (1));
Please remove trailing "\n\t" here and elsewhere.
Thanks,
Uros.
Re: [PATCH 16/20] x86/cpu: Use alternative_io() in amd_clear_divider()
In reply to Josh PoimboeufQuoted 13 lines · Josh Poimboeuf
Use the standard
alternative_io()interface.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/x86/include/asm/processor.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)arch/x86/include/asm/processor.h +0
-0
arch/x86/include/asm/processor.h static inline u32 per_cpu_l2c_id(unsigned int cpu) · line 713
Quoted 7 lines
arch/x86/include/asm/processor.h +2
-2@@ -709,8 +709,10 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)*/ static __always_inline void amd_clear_divider(void) { - asm volatile(ALTERNATIVE("", "div %[one]\n\t", X86_BUG_DIV0) - :: "a" (0), "d" (0), [one] "r" (1)); + alternative_io("", + "div %[one]\n\t", X86_BUG_DIV0,
A nit - can the above be in one line? Also no need for a trailing \n\t.
Thanks,
Uros.
Re: [PATCH 18/20] x86/smap: Use alternative_io() in smap_{save,restore}()
In reply to Josh PoimboeufQuoted 13 lines · Josh Poimboeuf
Use the standard
alternative_io()interface.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/x86/include/asm/smap.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)arch/x86/include/asm/smap.h +0
-0
arch/x86/include/asm/smap.h static __always_inline unsigned long smap_save(void) · line 43
Quoted 9 lines
arch/x86/include/asm/smap.h +2
-4@@ -39,20 +39,22 @@ static __always_inline unsigned long smap_save(void) {unsigned long flags; - asmvolatile ("# smap_save\n\t" - ALTERNATIVE("", -"pushf; pop %[flags]; clac\n\t" ,X86_FEATURE_SMAP ) - : [flags] "=rm" (flags) : : "memory", "cc"); + alternative_io("", + "pushf; pop %[flags]; clac\n\t", X86_FEATURE_SMAP,
Please merge two lines above (if possible, otherwise put feature condition in the next line. Please also remove trailing \n\t.
Quoted 5 lines
arch/x86/include/asm/smap.h +3
-0+ ARG([flags] "=rm" (flags)), +ARG (), + ARG("memory", "cc"));return flags;
arch/x86/include/asm/smap.h static __always_inline unsigned long smap_save(void) · line 54
Quoted 10 lines
arch/x86/include/asm/smap.h +2
-4} static __always_inline void smap_restore(unsigned long flags) { - asmvolatile ("# smap_restore\n\t" - ALTERNATIVE("", -"push %[flags]; popf\n\t" ,X86_FEATURE_SMAP ) - : : [flags] "g" (flags) : "memory", "cc"); + alternative_io("", + "push %[flags]; popf\n\t", X86_FEATURE_SMAP,
As above.
arch/x86/include/asm/smap.h static __always_inline unsigned long smap_save(void) · line 56
Quoted 2 lines
arch/x86/include/asm/smap.h +2
-0+ARG (), + ARG([flags] "g" (flags)),
Uh, a build failure waiting to happen here. Please use "rme" instead of "g". PUSH doesn't support 64bit immediates ("i") on x86_64 ("g" expands to "rmi").
Thanks,
Uros.
Re: [PATCH 19/20] x86/uaccess: Use alternative_io() in __untagged_addr()
In reply to Josh PoimboeufQuoted 13 lines · Josh Poimboeuf
Use the standard
alternative_io()interface.Signed-off-by Josh Poimboeuf <[email protected]>--- arch/x86/include/asm/uaccess_64.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)arch/x86/include/asm/uaccess_64.h +0
-0
arch/x86/include/asm/uaccess_64.h extern unsigned long USER_PTR_MAX; · line 29
Quoted 8 lines
arch/x86/include/asm/uaccess_64.h +1
-4@@ -26,10 +26,10 @@ extern unsigned long USER_PTR_MAX;*/ static inline unsigned long __untagged_addr (unsigned long addr) { - asm (ALTERNATIVE("", - "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM) - : [addr] "+r" (addr) - : [mask] "m" (__my_cpu_var(tlbstate_untag_mask))); + alternative_io("",
No, alternative_io() declares asm as volatile. Please define alternative_io_nv (or something like that) that will not use volatile. You will penalize the above asm unnecessarily with volatile.
Thanks,
Uros.
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Josh PoimboeufQuoted 20 lines · Josh Poimboeuf
Quoted 7 lines · Linus Torvalds
So all of these patches look like good cleanups to me, but I do wonder if we should
(a) not use some naming *quite* as generic as '
ARG()'(b) make the asms use ARG_OUT/ARG_IN/ARG_CLOBBER() to clarify
Quoted 7 lines
because that
ARG(),ARG(),ARGC()pattern looks odd to me.Maybe it's just me.
Regardless, I do think the series looks like a nice improvement even in the current form, even if that particular repeated pattern feels strange.
So originally I had ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER, but I ended up going with
ARG()due to its nice vertical alignment and conciseness:
Quoted 8 lines
__asm_call(qual, \
ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
"cmpxchg8b " __percpu_arg([var]), \
X86_FEATURE_CX8), \
ARG([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \
"+d" (old__.high)), \
ARG("b" (new__.low), "c" (new__.high), "S" (&(_var))), \
ARG("memory")); \Two nits:
1)
In justified cases we can align vertically just fine by using spaces:
ASM_INPUT ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low)... ASM_OUTPUT ("b" (new__.low), "c" (new__.high), "S" (&(_var))), ASM_CLOBBER("memory")
But I don't think the vertical alignment of visually disjoint, comma-separated arguments is an improvement in this specific case.
A *truly* advanced typographically aware syntactic construct would be something like:
ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
"cmpxchg8b " __percpu_arg([var]), \
X86_FEATURE_CX8), \
\
ASM_INPUT( [var] "+m" (__my_cpu_var(_var)), \
"+a" (old__.low), \
"+d" (old__.high)), \
\
ASM_OUTPUT( "b" (new__.low), \
"c" (new__.high), \
"S" (&(_var))), \
\
ASM_CLOBBER( "memory"));Note how horizontal and vertical grouping improves readability by an order of magnitude and properly highlights the only named operand and makes it very easy to review this code, should it be a new submission (which it isn't).
And as Knuth said, the intersection of the sets of good coders and good typographers is necessarily a tiny percentage of humanity (paraphrased), but I digress ...
2)
If 'ARGS' is included in the naming then I'd like to insist on the plural 'ARGS', not 'ARG', because the common case for more complicated asm() statements is multiple asm template constraint arguments separated by commas.
But I don't think we need the 'ARGS':
Quoted 13 lines
Though ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER isn't so bad either:
__asm_call(qual, \ ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \ "cmpxchg8b " __percpu_arg([var]), \ X86_FEATURE_CX8), \ ASM_OUTPUT([var] "+m" (__my_cpu_var(_var)), \ "+a" (old__.low), "+d" (old__.high)), \ ASM_INPUT("b" (new__.low), "c" (new__.high), \ "S" (&(_var))), \ ASM_CLOBBER("memory")); \
Quoted 4 lines
That has the nice benefit of being more self-documenting, albeit more verbose and less vertically aligned.
So I could go either way, really.
I'd vote on:
ASM_INPUT(), ASM_OUTPUT(), ASM_CLOBBER()
... because the ASM_ prefix is already unique enough visually to reset any cross-pollination from other well-known namespaces, and because in coding shorter is better, all other things equal.
Thanks,
Ingo
Re: [PATCH 04/20] x86/cpu: Use named asm operands in clflushopt()
In reply to Ingo MolnarQuoted 13 lines · Ingo Molnar
Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines · Linus Torvalds
arch/x86/include/asm/special_insns.h static __always_inline void clflush(volatile void *__p) · line 181
Quoted 4 lines · Josh Poimboeuf
arch/x86/include/asm/special_insns.h +3
-0+alternative_io (".byte 0x3e; clflush %[val]" , + ".byte 0x66; clflush %[val]", X86_FEATURE_CLFLUSHOPT, + [val] "+m" (*(volatile char __force *)__p));Hmm. I think we could just use 'clflushopt', it looks like it exists in binutils-2.25, which is our minimal version requirement.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
But maybe that's a separate cleanup.
You appear to be correct, I'll add a patch for that.
Please base your series on tip:master or tip:x86/asm, we already cleaned this up recently:
cc2e9e09d1a3("x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>")
Also, as a general principle I'd prefer to have .byte conversion to mnemonics and named-operands conversions to be separate patches - not all named-operands conversions are an improvement, especially very short and simple asm() templates are just fine using numeric operands.
Thanks,
Ingo
Re: [PATCH 06/20] x86/asm: Remove CC_SET()
In reply to Josh PoimboeufQuoted 3 lines · Josh Poimboeuf
Now that flag output operands are unconditionally supported,
CC_SET()is just a comment. Remove it.
Can you also replace CC_OUT with "=@cc"? CC_SET and CC_OUT were used together to handle compilers without flag outputs support, and they should die together. This change should be a simple string replacement.
Thanks,
Uros.
Quoted 9 lines · Josh Poimboeuf
Quoted 7 lines · Josh Poimboeuf
Make the
alternative_io()interface more straightforward and flexible, and get rid ofalternative_input().These patches are a prereq for another set[1] which will get rid of ASM_CALL_CONSTRAINT[2] in favor of a much more flexible
asm_call()interface similar to the newalternative_io().
Quoted 6 lines
Quoted 1 line
[1] Additional 20+ patches not posted yet to avoid flooding inboxes
The rest of the patches are here if anybody wants to see where this is going:
git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.gitasm-call
FYI, you missed one conversion of asm involving ALTERNATIVE in arch/x86/include/asm/nospec-branch.h:
void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature) {
asm volatile(ALTERNATIVE("", "wrmsr", %c[feature])
: : "c" (msr),
"a" ((u32)val),
"d" ((u32)(val >> 32)),
[feature] "i" (feature)
: "memory");
Uros.
Re: [PATCH 15/20] x86/cpu/amd: Use named asm operands in asm_clear_divider()
In reply to Uros BizjakQuoted 10 lines · Uros Bizjak
Quoted 8 lines · Josh Poimboeuf
Use named inline asm operands in preparation for using
alternative_io().Signed-off-by Josh Poimboeuf <[email protected]>--- arch/x86/include/asm/processor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines
arch/x86/include/asm/processor.h static inline u32 per_cpu_l2c_id(unsigned int cpu) · line 713
Quoted 12 lines
arch/x86/include/asm/processor.h +2
-2@@ -709,8 +709,8 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)*/ static __always_inline void amd_clear_divider(void) { - asm volatile(ALTERNATIVE("", "div %2\n\t", X86_BUG_DIV0) - :: "a" (0), "d" (0), "r" (1)); + asm volatile(ALTERNATIVE("", "div %[one]\n\t", X86_BUG_DIV0) + :: "a" (0), "d" (0), [one] "r" (1));Please remove trailing "\n\t" here and elsewhere.
Also, please change $subject to mention "amd_clear_divider", not "asm_clear_divider".
Thanks,
Uros.
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
In reply to Josh PoimboeufQuoted 10 lines · On Fri, 14 Mar 2025 17:05:34 -0700 Josh Poimboeuf <[email protected]> wrote:
Quoted 9 lines · Linus Torvalds
So all of these patches look like good cleanups to me, but I do wonder if we should
(a) not use some naming *quite* as generic as '
ARG()'(b) make the asms use ARG_OUT/ARG_IN/ARG_CLOBBER() to clarify
because that
ARG(),ARG(),ARGC()pattern looks odd to me.
Quoted 8 lines
Quoted 5 lines
Maybe it's just me.
Regardless, I do think the series looks like a nice improvement even in the current form, even if that particular repeated pattern feels strange.
So originally I had ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER, but I ended up going with
ARG()due to its nice vertical alignment and conciseness:
But ARG() does look horrid.
Is the ARG() necessary just to handle the comma separated lists? If so is it only actually needed if there is more than one item?
Another option is to just require () and add the ARG in the expansion. So with:
#define __asm_call(qual, alt, out, in, clobber) \
asm("zzz", ARG out, ARG in, ARG clobber)
__asm_call(qual, ALT(), \
([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \
"+d" (old__.high)), \
("b" (new__.low), "c" (new__.high), "S" (&(_var))), \
("memory"));would get expanded the same as the line below.
David
Quoted 30 lines
__asm_call(qual, \ ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \ "cmpxchg8b " __percpu_arg([var]), \ X86_FEATURE_CX8), \ ARG([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \ "+d" (old__.high)), \ ARG("b" (new__.low), "c" (new__.high), "S" (&(_var))), \ ARG("memory")); \Though ASM_OUTPUT/ASM_INPUT/ASM_CLOBBER isn't so bad either:
__asm_call(qual, \ ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \ "cmpxchg8b " __percpu_arg([var]), \ X86_FEATURE_CX8), \ ASM_OUTPUT([var] "+m" (__my_cpu_var(_var)), \ "+a" (old__.low), "+d" (old__.high)), \ ASM_INPUT("b" (new__.low), "c" (new__.high), \ "S" (&(_var))), \ ASM_CLOBBER("memory")); \That has the nice benefit of being more self-documenting, albeit more verbose and less vertically aligned.
So I could go either way, really.
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
Quoted 2 lines · David Laight
Is the
ARG()necessary just to handle the comma separated lists? If so is it only actually needed if there is more than one item?
No, but my preference is to require the use of the macro even for single constraints as it helps visually separate the lists.
Quoted 5 lines
Another option is to just require () and add the ARG in the expansion. So with:
#define__asm_call(qual, alt, out, in, clobber)\
asm("zzz", ARG out, ARG in, ARG clobber)
Quoted 7 lines
__asm_call(qual, ALT(), \ ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \ "+d" (old__.high)), \ ("b" (new__.low), "c" (new__.high), "S" (&(_var))), \ ("memory"));would get expanded the same as the line below.
Interesting idea, though I still prefer the self-documenting ASM_OUTPUT / ASM_INPUT / ASM_CLOBBER macros which are self-documenting and make it easier to read and visually distinguish the constraint lists.
Signature · 1 line
Josh
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
Quoted 18 lines · On Mon, 17 Mar 2025 17:11:58 -0700 Josh Poimboeuf <[email protected]> wrote:
Quoted 2 lines · David Laight
Is the
ARG()necessary just to handle the comma separated lists? If so is it only actually needed if there is more than one item?No, but my preference is to require the use of the macro even for single constraints as it helps visually separate the lists.
Quoted 11 lines
Another option is to just require () and add the ARG in the expansion. So with:
#define__asm_call(qual, alt, out, in, clobber)\
asm("zzz", ARG out, ARG in, ARG clobber)__asm_call(qual, ALT(), \ ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \ "+d" (old__.high)), \ ("b" (new__.low), "c" (new__.high), "S" (&(_var))), \ ("memory"));
Quoted 5 lines
Quoted 1 line
would get expanded the same as the line below.
Interesting idea, though I still prefer the self-documenting
ASM_OUTPUT/ASM_INPUT/ASM_CLOBBERmacros which are self-documenting and make it easier to read and visually distinguish the constraint lists.
Except that non of this really makes it easier to get out/in in the correct order or to use the right constraints.
So are you just adding 'syntactic sugar' for no real gain?
Looking back at one of the changes:
-#define mb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "mfence", \
- X86_FEATURE_XMM2) ::: "memory", "cc")
+#define mb() alternative_io("lock addl $0,-4(%%esp)", \
+ "mfence", X86_FEATURE_XMM2, \
+ ARG(), \
+ ARG(), \
+ ARG("memory", "cc")) is it really an improvement?
David
Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
Quoted 10 lines · David Laight
Quoted 10 lines
Quoted 10 lines
So with:
#define__asm_call(qual, alt, out, in, clobber)\
asm("zzz", ARG out, ARG in, ARG clobber)__asm_call(qual, ALT(), \ ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \ "+d" (old__.high)), \ ("b" (new__.low), "c" (new__.high), "S" (&(_var))), \ ("memory"));
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
would get expanded the same as the line below.
Interesting idea, though I still prefer the self-documenting
ASM_OUTPUT/ASM_INPUT/ASM_CLOBBERmacros which are self-documenting and make it easier to read and visually distinguish the constraint lists.Except that non of this really makes it easier to get out/in in the correct order or to use the right constraints.
At least it's still no worse than asm() itself in that respect.
Quoted 1 line
So are you just adding 'syntactic sugar' for no real gain?
Some wrappers need to modify their constraint lists, so the sugar does have a functional purpose. The new alternative_io() (or whatever it will be called) interface will especially be needed for the followup to this patch set which introduces asm_call() to try to fix an ASM_CALL_CONSTRAINT mess.
Quoted 10 lines
Looking back at one of the changes:
arch/x86/include/asm/barrier.h +5
-2-#define mb () asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "mfence", \ - X86_FEATURE_XMM2) ::: "memory", "cc") +#define mb () alternative_io("lock addl $0,-4(%%esp)", \ + "mfence", X86_FEATURE_XMM2, \ + ARG(), \ + ARG(), \ + ARG("memory", "cc"))is it really an improvement?
The motivation here is to use the alternative*() wrappers whenever possible. It helps achieve consistent behaviors and also removes the ugly nested ALTERNATIVE() macro.
In fact, the change in your example actually improves code generation:
it changes the asm() to asm_inline() which prevents GCC from doing crazy things due to the exploded size of the asm string.
Signature · 1 line
Josh