Skip to content

Commit df34052

Browse files
keesIngo Molnar
authored andcommitted
x86/asm: Add suffix macro for GEN_*_RMWcc()
The coming x86 refcount protection needs to be able to add trailing instructions to the GEN_*_RMWcc() operations. This extracts the difference between the goto/non-goto cases so the helper macros can be defined outside the #ifdef cases. Additionally adds argument naming to the resulting asm for referencing from suffixed instructions, and adds clobbers for "cc", and "cx" to let suffixes use _ASM_CX, and retain any set flags. Signed-off-by: Kees Cook <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: David S. Miller <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Elena Reshetova <[email protected]> Cc: Eric Biggers <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Greg KH <[email protected]> Cc: Hans Liljestrand <[email protected]> Cc: James Bottomley <[email protected]> Cc: Jann Horn <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Manfred Spraul <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Serge E. Hallyn <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: linux-arch <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 867ac9d commit df34052

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

arch/x86/include/asm/rmwcc.h

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,56 @@
11
#ifndef _ASM_X86_RMWcc
22
#define _ASM_X86_RMWcc
33

4+
#define __CLOBBERS_MEM "memory"
5+
#define __CLOBBERS_MEM_CC_CX "memory", "cc", "cx"
6+
47
#if !defined(__GCC_ASM_FLAG_OUTPUTS__) && defined(CC_HAVE_ASM_GOTO)
58

69
/* Use asm goto */
710

8-
#define __GEN_RMWcc(fullop, var, cc, ...) \
11+
#define __GEN_RMWcc(fullop, var, cc, clobbers, ...) \
912
do { \
1013
asm_volatile_goto (fullop "; j" #cc " %l[cc_label]" \
11-
: : "m" (var), ## __VA_ARGS__ \
12-
: "memory" : cc_label); \
14+
: : [counter] "m" (var), ## __VA_ARGS__ \
15+
: clobbers : cc_label); \
1316
return 0; \
1417
cc_label: \
1518
return 1; \
1619
} while (0)
1720

18-
#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19-
__GEN_RMWcc(op " " arg0, var, cc)
21+
#define __BINARY_RMWcc_ARG " %1, "
2022

21-
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
22-
__GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
2323

2424
#else /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
2525

2626
/* Use flags output or a set instruction */
2727

28-
#define __GEN_RMWcc(fullop, var, cc, ...) \
28+
#define __GEN_RMWcc(fullop, var, cc, clobbers, ...) \
2929
do { \
3030
bool c; \
3131
asm volatile (fullop ";" CC_SET(cc) \
32-
: "+m" (var), CC_OUT(cc) (c) \
33-
: __VA_ARGS__ : "memory"); \
32+
: [counter] "+m" (var), CC_OUT(cc) (c) \
33+
: __VA_ARGS__ : clobbers); \
3434
return c; \
3535
} while (0)
3636

37+
#define __BINARY_RMWcc_ARG " %2, "
38+
39+
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
40+
3741
#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
38-
__GEN_RMWcc(op " " arg0, var, cc)
42+
__GEN_RMWcc(op " " arg0, var, cc, __CLOBBERS_MEM)
43+
44+
#define GEN_UNARY_SUFFIXED_RMWcc(op, suffix, var, arg0, cc) \
45+
__GEN_RMWcc(op " " arg0 "\n\t" suffix, var, cc, \
46+
__CLOBBERS_MEM_CC_CX)
3947

4048
#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
41-
__GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
49+
__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0, var, cc, \
50+
__CLOBBERS_MEM, vcon (val))
4251

43-
#endif /* defined(__GCC_ASM_FLAG_OUTPUTS__) || !defined(CC_HAVE_ASM_GOTO) */
52+
#define GEN_BINARY_SUFFIXED_RMWcc(op, suffix, var, vcon, val, arg0, cc) \
53+
__GEN_RMWcc(op __BINARY_RMWcc_ARG arg0 "\n\t" suffix, var, cc, \
54+
__CLOBBERS_MEM_CC_CX, vcon (val))
4455

4556
#endif /* _ASM_X86_RMWcc */

0 commit comments

Comments
 (0)