Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/rseq: Fix ppc32 missing instruction selection "u" and "x" for load/store

Building the rseq basic test with
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)
Target: powerpc-linux-gnu

leads to these errors:

/tmp/ccieEWxU.s: Assembler messages:
/tmp/ccieEWxU.s:118: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:118: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:121: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:121: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:626: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:626: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:629: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:629: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:735: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:735: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:738: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:738: Error: junk at end of line: `,8'
/tmp/ccieEWxU.s:741: Error: syntax error; found `,', expected `('
/tmp/ccieEWxU.s:741: Error: junk at end of line: `,8'
Makefile:581: recipe for target 'basic_percpu_ops_test.o' failed

Based on discussion with Linux powerpc maintainers and review of
the use of the "m" operand in powerpc kernel code, add the missing
%Un%Xn (where n is operand number) to the lwz, stw, ld, and std
instructions when used with "m" operands.

Using "WORD" to mean either a 32-bit or 64-bit type depending on
the architecture is misleading. The term "WORD" really means a
32-bit type in both 32-bit and 64-bit powerpc assembler. The intent
here is to wrap load/store to intptr_t into common macros for both
32-bit and 64-bit.

Rename the macros with a RSEQ_ prefix, and use the terms "INT"
for always 32-bit type, and "LONG" for architecture bitness-sized
type.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220124171253.22072-10-mathieu.desnoyers@efficios.com

authored by

Mathieu Desnoyers and committed by
Peter Zijlstra
de6b52a2 24d1136a

+28 -27
+28 -27
tools/testing/selftests/rseq/rseq-ppc.h
··· 47 47 48 48 #ifdef __PPC64__ 49 49 50 - #define STORE_WORD "std " 51 - #define LOAD_WORD "ld " 52 - #define LOADX_WORD "ldx " 53 - #define CMP_WORD "cmpd " 50 + #define RSEQ_STORE_LONG(arg) "std%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ 51 + #define RSEQ_STORE_INT(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ 52 + #define RSEQ_LOAD_LONG(arg) "ld%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ 53 + #define RSEQ_LOAD_INT(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ 54 + #define RSEQ_LOADX_LONG "ldx " /* From base register ("b" constraint) */ 55 + #define RSEQ_CMP_LONG "cmpd " 56 + #define RSEQ_CMP_LONG_INT "cmpdi " 54 57 55 58 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ 56 59 start_ip, post_commit_offset, abort_ip) \ ··· 92 89 93 90 #else /* #ifdef __PPC64__ */ 94 91 95 - #define STORE_WORD "stw " 96 - #define LOAD_WORD "lwz " 97 - #define LOADX_WORD "lwzx " 98 - #define CMP_WORD "cmpw " 92 + #define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */ 93 + #define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */ 94 + #define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */ 95 + #define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */ 96 + #define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */ 97 + #define RSEQ_CMP_LONG "cmpw " 98 + #define RSEQ_CMP_LONG_INT "cmpwi " 99 99 100 100 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ 101 101 start_ip, post_commit_offset, abort_ip) \ ··· 131 125 RSEQ_INJECT_ASM(1) \ 132 126 "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \ 133 127 "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \ 134 - "stw %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \ 128 + RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \ 135 129 __rseq_str(label) ":\n\t" 136 130 137 131 #endif /* #ifdef __PPC64__ */ ··· 142 136 143 137 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \ 144 138 RSEQ_INJECT_ASM(2) \ 145 - "lwz %%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \ 139 + RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \ 146 140 "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \ 147 141 "bne- cr7, " __rseq_str(label) "\n\t" 148 142 ··· 159 153 * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7) 160 154 */ 161 155 #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \ 162 - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ 163 - CMP_WORD "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \ 156 + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ 157 + RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \ 164 158 "bne- cr7, " __rseq_str(label) "\n\t" 165 159 166 160 #define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \ 167 - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ 168 - CMP_WORD "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \ 161 + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ 162 + RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \ 169 163 "beq- cr7, " __rseq_str(label) "\n\t" 170 164 171 165 #define RSEQ_ASM_OP_STORE(value, var) \ 172 - STORE_WORD "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" 166 + RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" 173 167 174 168 /* Load @var to r17 */ 175 169 #define RSEQ_ASM_OP_R_LOAD(var) \ 176 - LOAD_WORD "%%r17, %[" __rseq_str(var) "]\n\t" 170 + RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" 177 171 178 172 /* Store r17 to @var */ 179 173 #define RSEQ_ASM_OP_R_STORE(var) \ 180 - STORE_WORD "%%r17, %[" __rseq_str(var) "]\n\t" 174 + RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" 181 175 182 176 /* Add @count to r17 */ 183 177 #define RSEQ_ASM_OP_R_ADD(count) \ ··· 185 179 186 180 /* Load (r17 + voffp) to r17 */ 187 181 #define RSEQ_ASM_OP_R_LOADX(voffp) \ 188 - LOADX_WORD "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t" 182 + RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t" 189 183 190 184 /* TODO: implement a faster memcpy. */ 191 185 #define RSEQ_ASM_OP_R_MEMCPY() \ 192 - "cmpdi %%r19, 0\n\t" \ 186 + RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \ 193 187 "beq 333f\n\t" \ 194 188 "addi %%r20, %%r20, -1\n\t" \ 195 189 "addi %%r21, %%r21, -1\n\t" \ ··· 197 191 "lbzu %%r18, 1(%%r20)\n\t" \ 198 192 "stbu %%r18, 1(%%r21)\n\t" \ 199 193 "addi %%r19, %%r19, -1\n\t" \ 200 - "cmpdi %%r19, 0\n\t" \ 194 + RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \ 201 195 "bne 222b\n\t" \ 202 196 "333:\n\t" \ 203 197 204 198 #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \ 205 - STORE_WORD "%%r17, %[" __rseq_str(var) "]\n\t" \ 199 + RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \ 206 200 __rseq_str(post_commit_label) ":\n\t" 207 201 208 202 #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \ 209 - STORE_WORD "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \ 203 + RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \ 210 204 __rseq_str(post_commit_label) ":\n\t" 211 205 212 206 static inline __attribute__((always_inline)) ··· 748 742 rseq_bug("expected value comparison failed"); 749 743 #endif 750 744 } 751 - 752 - #undef STORE_WORD 753 - #undef LOAD_WORD 754 - #undef LOADX_WORD 755 - #undef CMP_WORD 756 745 757 746 #endif /* !RSEQ_SKIP_FASTPATH */