Skip to content

Commit c6c973d

Browse files
ubizjakbp3tk0v
authored andcommitted
x86/asm: Remove code depending on __GCC_ASM_FLAG_OUTPUTS__
The minimum supported GCC version is 8.1, which supports flag output operands and always defines __GCC_ASM_FLAG_OUTPUTS__ macro. Remove code depending on __GCC_ASM_FLAG_OUTPUTS__ and use the "=@ccCOND" flag output operand directly. Use the equivalent "=@ccz" instead of "=@cce" flag output operand for CMPXCHG8B and CMPXCHG16B instructions. These instructions set a single flag bit - the Zero flag - and "=@ccz" is used to distinguish the CC user from comparison instructions, where set ZERO flag indeed means that the values are equal. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20250905121723.GCaLrU04lP2A50PT-B@fat_crate.local
1 parent 13bdfb5 commit c6c973d

File tree

17 files changed

+35
-104
lines changed

17 files changed

+35
-104
lines changed

arch/x86/boot/bitops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline bool variable_test_bit(int nr, const void *addr)
2727
bool v;
2828
const u32 *p = addr;
2929

30-
asm("btl %2,%1" CC_SET(c) : CC_OUT(c) (v) : "m" (*p), "Ir" (nr));
30+
asm("btl %2,%1" : "=@ccc" (v) : "m" (*p), "Ir" (nr));
3131
return v;
3232
}
3333

arch/x86/boot/boot.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ static inline void wrgs32(u32 v, addr_t addr)
155155
static inline bool memcmp_fs(const void *s1, addr_t s2, size_t len)
156156
{
157157
bool diff;
158-
asm volatile("fs repe cmpsb" CC_SET(nz)
159-
: CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
158+
asm volatile("fs repe cmpsb"
159+
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
160160
return diff;
161161
}
162162
static inline bool memcmp_gs(const void *s1, addr_t s2, size_t len)
163163
{
164164
bool diff;
165-
asm volatile("gs repe cmpsb" CC_SET(nz)
166-
: CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
165+
asm volatile("gs repe cmpsb"
166+
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
167167
return diff;
168168
}
169169

arch/x86/boot/string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
int memcmp(const void *s1, const void *s2, size_t len)
3333
{
3434
bool diff;
35-
asm("repe cmpsb" CC_SET(nz)
36-
: CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));
35+
asm("repe cmpsb"
36+
: "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len));
3737
return diff;
3838
}
3939

arch/x86/include/asm/archrandom.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ static inline bool __must_check rdrand_long(unsigned long *v)
2323
unsigned int retry = RDRAND_RETRY_LOOPS;
2424
do {
2525
asm volatile("rdrand %[out]"
26-
CC_SET(c)
27-
: CC_OUT(c) (ok), [out] "=r" (*v));
26+
: "=@ccc" (ok), [out] "=r" (*v));
2827
if (ok)
2928
return true;
3029
} while (--retry);
@@ -35,8 +34,7 @@ static inline bool __must_check rdseed_long(unsigned long *v)
3534
{
3635
bool ok;
3736
asm volatile("rdseed %[out]"
38-
CC_SET(c)
39-
: CC_OUT(c) (ok), [out] "=r" (*v));
37+
: "=@ccc" (ok), [out] "=r" (*v));
4038
return ok;
4139
}
4240

arch/x86/include/asm/asm.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,6 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
122122
}
123123
#endif
124124

125-
/*
126-
* Macros to generate condition code outputs from inline assembly,
127-
* The output operand must be type "bool".
128-
*/
129-
#ifdef __GCC_ASM_FLAG_OUTPUTS__
130-
# define CC_SET(c) "\n\t/* output condition code " #c "*/\n"
131-
# define CC_OUT(c) "=@cc" #c
132-
#else
133-
# define CC_SET(c) "\n\tset" #c " %[_cc_" #c "]\n"
134-
# define CC_OUT(c) [_cc_ ## c] "=qm"
135-
#endif
136-
137125
#ifdef __KERNEL__
138126

139127
# include <asm/extable_fixup_types.h>

arch/x86/include/asm/bitops.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ static __always_inline bool arch_xor_unlock_is_negative_byte(unsigned long mask,
9999
{
100100
bool negative;
101101
asm_inline volatile(LOCK_PREFIX "xorb %2,%1"
102-
CC_SET(s)
103-
: CC_OUT(s) (negative), WBYTE_ADDR(addr)
102+
: "=@ccs" (negative), WBYTE_ADDR(addr)
104103
: "iq" ((char)mask) : "memory");
105104
return negative;
106105
}
@@ -149,8 +148,7 @@ arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
149148
bool oldbit;
150149

151150
asm(__ASM_SIZE(bts) " %2,%1"
152-
CC_SET(c)
153-
: CC_OUT(c) (oldbit)
151+
: "=@ccc" (oldbit)
154152
: ADDR, "Ir" (nr) : "memory");
155153
return oldbit;
156154
}
@@ -175,8 +173,7 @@ arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
175173
bool oldbit;
176174

177175
asm volatile(__ASM_SIZE(btr) " %2,%1"
178-
CC_SET(c)
179-
: CC_OUT(c) (oldbit)
176+
: "=@ccc" (oldbit)
180177
: ADDR, "Ir" (nr) : "memory");
181178
return oldbit;
182179
}
@@ -187,8 +184,7 @@ arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
187184
bool oldbit;
188185

189186
asm volatile(__ASM_SIZE(btc) " %2,%1"
190-
CC_SET(c)
191-
: CC_OUT(c) (oldbit)
187+
: "=@ccc" (oldbit)
192188
: ADDR, "Ir" (nr) : "memory");
193189

194190
return oldbit;
@@ -211,8 +207,7 @@ static __always_inline bool constant_test_bit_acquire(long nr, const volatile un
211207
bool oldbit;
212208

213209
asm volatile("testb %2,%1"
214-
CC_SET(nz)
215-
: CC_OUT(nz) (oldbit)
210+
: "=@ccnz" (oldbit)
216211
: "m" (((unsigned char *)addr)[nr >> 3]),
217212
"i" (1 << (nr & 7))
218213
:"memory");
@@ -225,8 +220,7 @@ static __always_inline bool variable_test_bit(long nr, volatile const unsigned l
225220
bool oldbit;
226221

227222
asm volatile(__ASM_SIZE(bt) " %2,%1"
228-
CC_SET(c)
229-
: CC_OUT(c) (oldbit)
223+
: "=@ccc" (oldbit)
230224
: "m" (*(unsigned long *)addr), "Ir" (nr) : "memory");
231225

232226
return oldbit;

arch/x86/include/asm/cmpxchg.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ extern void __add_wrong_size(void)
166166
{ \
167167
volatile u8 *__ptr = (volatile u8 *)(_ptr); \
168168
asm_inline volatile(lock "cmpxchgb %[new], %[ptr]" \
169-
CC_SET(z) \
170-
: CC_OUT(z) (success), \
169+
: "=@ccz" (success), \
171170
[ptr] "+m" (*__ptr), \
172171
[old] "+a" (__old) \
173172
: [new] "q" (__new) \
@@ -178,8 +177,7 @@ extern void __add_wrong_size(void)
178177
{ \
179178
volatile u16 *__ptr = (volatile u16 *)(_ptr); \
180179
asm_inline volatile(lock "cmpxchgw %[new], %[ptr]" \
181-
CC_SET(z) \
182-
: CC_OUT(z) (success), \
180+
: "=@ccz" (success), \
183181
[ptr] "+m" (*__ptr), \
184182
[old] "+a" (__old) \
185183
: [new] "r" (__new) \
@@ -190,8 +188,7 @@ extern void __add_wrong_size(void)
190188
{ \
191189
volatile u32 *__ptr = (volatile u32 *)(_ptr); \
192190
asm_inline volatile(lock "cmpxchgl %[new], %[ptr]" \
193-
CC_SET(z) \
194-
: CC_OUT(z) (success), \
191+
: "=@ccz" (success), \
195192
[ptr] "+m" (*__ptr), \
196193
[old] "+a" (__old) \
197194
: [new] "r" (__new) \
@@ -202,8 +199,7 @@ extern void __add_wrong_size(void)
202199
{ \
203200
volatile u64 *__ptr = (volatile u64 *)(_ptr); \
204201
asm_inline volatile(lock "cmpxchgq %[new], %[ptr]" \
205-
CC_SET(z) \
206-
: CC_OUT(z) (success), \
202+
: "=@ccz" (success), \
207203
[ptr] "+m" (*__ptr), \
208204
[old] "+a" (__old) \
209205
: [new] "r" (__new) \

arch/x86/include/asm/cmpxchg_32.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static __always_inline u64 __cmpxchg64_local(volatile u64 *ptr, u64 old, u64 new
4646
bool ret; \
4747
\
4848
asm_inline volatile(_lock "cmpxchg8b %[ptr]" \
49-
CC_SET(e) \
50-
: CC_OUT(e) (ret), \
49+
: "=@ccz" (ret), \
5150
[ptr] "+m" (*(_ptr)), \
5251
"+a" (o.low), "+d" (o.high) \
5352
: "b" (n.low), "c" (n.high) \
@@ -125,8 +124,7 @@ static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64
125124
ALTERNATIVE(_lock_loc \
126125
"call cmpxchg8b_emu", \
127126
_lock "cmpxchg8b %a[ptr]", X86_FEATURE_CX8) \
128-
CC_SET(e) \
129-
: ALT_OUTPUT_SP(CC_OUT(e) (ret), \
127+
: ALT_OUTPUT_SP("=@ccz" (ret), \
130128
"+a" (o.low), "+d" (o.high)) \
131129
: "b" (n.low), "c" (n.high), \
132130
[ptr] "S" (_ptr) \

arch/x86/include/asm/cmpxchg_64.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ static __always_inline u128 arch_cmpxchg128_local(volatile u128 *ptr, u128 old,
6666
bool ret; \
6767
\
6868
asm_inline volatile(_lock "cmpxchg16b %[ptr]" \
69-
CC_SET(e) \
70-
: CC_OUT(e) (ret), \
69+
: "=@ccz" (ret), \
7170
[ptr] "+m" (*(_ptr)), \
7271
"+a" (o.low), "+d" (o.high) \
7372
: "b" (n.low), "c" (n.high) \

arch/x86/include/asm/percpu.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ do { \
309309
\
310310
asm qual (__pcpu_op_##size("cmpxchg") "%[nval], " \
311311
__percpu_arg([var]) \
312-
CC_SET(z) \
313-
: CC_OUT(z) (success), \
312+
: "=@ccz" (success), \
314313
[oval] "+a" (pco_old__), \
315314
[var] "+m" (__my_cpu_var(_var)) \
316315
: [nval] __pcpu_reg_##size(, pco_new__) \
@@ -367,8 +366,7 @@ do { \
367366
asm_inline qual ( \
368367
ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
369368
"cmpxchg8b " __percpu_arg([var]), X86_FEATURE_CX8) \
370-
CC_SET(z) \
371-
: ALT_OUTPUT_SP(CC_OUT(z) (success), \
369+
: ALT_OUTPUT_SP("=@ccz" (success), \
372370
[var] "+m" (__my_cpu_var(_var)), \
373371
"+a" (old__.low), "+d" (old__.high)) \
374372
: "b" (new__.low), "c" (new__.high), \
@@ -436,8 +434,7 @@ do { \
436434
asm_inline qual ( \
437435
ALTERNATIVE("call this_cpu_cmpxchg16b_emu", \
438436
"cmpxchg16b " __percpu_arg([var]), X86_FEATURE_CX16) \
439-
CC_SET(z) \
440-
: ALT_OUTPUT_SP(CC_OUT(z) (success), \
437+
: ALT_OUTPUT_SP("=@ccz" (success), \
441438
[var] "+m" (__my_cpu_var(_var)), \
442439
"+a" (old__.low), "+d" (old__.high)) \
443440
: "b" (new__.low), "c" (new__.high), \
@@ -585,8 +582,7 @@ do { \
585582
bool oldbit; \
586583
\
587584
asm volatile("btl %[nr], " __percpu_arg([var]) \
588-
CC_SET(c) \
589-
: CC_OUT(c) (oldbit) \
585+
: "=@ccc" (oldbit) \
590586
: [var] "m" (__my_cpu_var(_var)), \
591587
[nr] "rI" (_nr)); \
592588
oldbit; \

0 commit comments

Comments
 (0)