1 /* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
5 * (C) Copyright 2016-2018 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * (C) Copyright 2016-2018 - Boqun Feng <boqun.feng@gmail.com>
10 * RSEQ_SIG is used with the following trap instruction:
12 * powerpc-be: 0f e5 00 0b twui r5,11
13 * powerpc64-le: 0b 00 e5 0f twui r5,11
14 * powerpc64-be: 0f e5 00 0b twui r5,11
17 #define RSEQ_SIG 0x0fe5000b
19 #define rseq_smp_mb() __asm__ __volatile__ ("sync" ::: "memory", "cc")
20 #define rseq_smp_lwsync() __asm__ __volatile__ ("lwsync" ::: "memory", "cc")
21 #define rseq_smp_rmb() rseq_smp_lwsync()
22 #define rseq_smp_wmb() rseq_smp_lwsync()
24 #define rseq_smp_load_acquire(p) \
26 __typeof(*p) ____p1 = RSEQ_READ_ONCE(*p); \
31 #define rseq_smp_acquire__after_ctrl_dep() rseq_smp_lwsync()
33 #define rseq_smp_store_release(p, v) \
36 RSEQ_WRITE_ONCE(*p, v); \
39 #ifdef RSEQ_SKIP_FASTPATH
40 #include "rseq-skip.h"
41 #else /* !RSEQ_SKIP_FASTPATH */
44 * The __rseq_cs_ptr_array and __rseq_cs sections can be used by debuggers to
45 * better handle single-stepping through the restartable critical sections.
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 "
58 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
59 start_ip, post_commit_offset, abort_ip) \
60 ".pushsection __rseq_cs, \"aw\"\n\t" \
62 __rseq_str(label) ":\n\t" \
63 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
64 ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \
66 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
67 ".quad " __rseq_str(label) "b\n\t" \
70 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
72 "lis %%r17, (" __rseq_str(cs_label) ")@highest\n\t" \
73 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@higher\n\t" \
74 "rldicr %%r17, %%r17, 32, 31\n\t" \
75 "oris %%r17, %%r17, (" __rseq_str(cs_label) ")@high\n\t" \
76 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
77 "std %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
78 __rseq_str(label) ":\n\t"
81 * Exit points of a rseq critical section consist of all instructions outside
82 * of the critical section where a critical section can either branch to or
83 * reach through the normal course of its execution. The abort IP and the
84 * post-commit IP are already part of the __rseq_cs section and should not be
85 * explicitly defined as additional exit points. Knowing all exit points is
86 * useful to assist debuggers stepping over the critical section.
88 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
89 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
90 ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \
93 #else /* #ifdef __PPC64__ */
95 #define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
96 #define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */
97 #define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
98 #define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */
99 #define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */
100 #define RSEQ_CMP_LONG "cmpw "
101 #define RSEQ_CMP_LONG_INT "cmpwi "
103 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
104 start_ip, post_commit_offset, abort_ip) \
105 ".pushsection __rseq_cs, \"aw\"\n\t" \
107 __rseq_str(label) ":\n\t" \
108 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
109 /* 32-bit only supported on BE */ \
110 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \
112 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
113 ".long 0x0, " __rseq_str(label) "b\n\t" \
117 * Exit points of a rseq critical section consist of all instructions outside
118 * of the critical section where a critical section can either branch to or
119 * reach through the normal course of its execution. The abort IP and the
120 * post-commit IP are already part of the __rseq_cs section and should not be
121 * explicitly defined as additional exit points. Knowing all exit points is
122 * useful to assist debuggers stepping over the critical section.
124 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
125 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
126 /* 32-bit only supported on BE */ \
127 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \
130 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
132 "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \
133 "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
134 RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
135 __rseq_str(label) ":\n\t"
137 #endif /* #ifdef __PPC64__ */
139 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
140 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
141 (post_commit_ip - start_ip), abort_ip)
143 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
145 RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \
146 "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \
147 "bne- cr7, " __rseq_str(label) "\n\t"
149 #define RSEQ_ASM_DEFINE_ABORT(label, abort_label) \
150 ".pushsection __rseq_failure, \"ax\"\n\t" \
151 ".long " __rseq_str(RSEQ_SIG) "\n\t" \
152 __rseq_str(label) ":\n\t" \
153 "b %l[" __rseq_str(abort_label) "]\n\t" \
157 * RSEQ_ASM_OPs: asm operations for rseq
158 * RSEQ_ASM_OP_R_*: has hard-code registers in it
159 * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7)
161 #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \
162 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
163 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \
164 "bne- cr7, " __rseq_str(label) "\n\t"
166 #define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \
167 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
168 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \
169 "beq- cr7, " __rseq_str(label) "\n\t"
171 #define RSEQ_ASM_OP_STORE(value, var) \
172 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t"
174 /* Load @var to r17 */
175 #define RSEQ_ASM_OP_R_LOAD(var) \
176 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
178 /* Store r17 to @var */
179 #define RSEQ_ASM_OP_R_STORE(var) \
180 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
182 /* Add @count to r17 */
183 #define RSEQ_ASM_OP_R_ADD(count) \
184 "add %%r17, %[" __rseq_str(count) "], %%r17\n\t"
186 /* Load (r17 + voffp) to r17 */
187 #define RSEQ_ASM_OP_R_LOADX(voffp) \
188 RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t"
190 /* TODO: implement a faster memcpy. */
191 #define RSEQ_ASM_OP_R_MEMCPY() \
192 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
194 "addi %%r20, %%r20, -1\n\t" \
195 "addi %%r21, %%r21, -1\n\t" \
197 "lbzu %%r18, 1(%%r20)\n\t" \
198 "stbu %%r18, 1(%%r21)\n\t" \
199 "addi %%r19, %%r19, -1\n\t" \
200 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
204 #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \
205 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
206 __rseq_str(post_commit_label) ":\n\t"
208 #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \
209 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \
210 __rseq_str(post_commit_label) ":\n\t"
212 static inline __attribute__((always_inline
))
213 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
217 __asm__ __volatile__
goto (
218 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
219 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
220 #ifdef RSEQ_COMPARE_TWICE
221 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
222 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
224 /* Start rseq by storing table entry pointer into rseq_cs. */
225 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
227 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
229 /* cmp @v equal to @expect */
230 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
232 #ifdef RSEQ_COMPARE_TWICE
234 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
235 /* cmp @v equal to @expect */
236 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
239 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
241 RSEQ_ASM_DEFINE_ABORT(4, abort
)
242 : /* gcc asm goto does not allow outputs */
243 : [cpu_id
] "r" (cpu
),
244 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
245 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
247 [expect
] "r" (expect
),
250 : "memory", "cc", "r17"
253 #ifdef RSEQ_COMPARE_TWICE
257 rseq_after_asm_goto();
260 rseq_after_asm_goto();
264 rseq_after_asm_goto();
266 #ifdef RSEQ_COMPARE_TWICE
268 rseq_after_asm_goto();
269 rseq_bug("cpu_id comparison failed");
271 rseq_after_asm_goto();
272 rseq_bug("expected value comparison failed");
276 static inline __attribute__((always_inline
))
277 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
278 long voffp
, intptr_t *load
, int cpu
)
282 __asm__ __volatile__
goto (
283 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
284 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
285 #ifdef RSEQ_COMPARE_TWICE
286 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
287 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
289 /* Start rseq by storing table entry pointer into rseq_cs. */
290 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
292 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
294 /* cmp @v not equal to @expectnot */
295 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[cmpfail
])
297 #ifdef RSEQ_COMPARE_TWICE
299 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
300 /* cmp @v not equal to @expectnot */
301 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[error2
])
303 /* load the value of @v */
304 RSEQ_ASM_OP_R_LOAD(v
)
305 /* store it in @load */
306 RSEQ_ASM_OP_R_STORE(load
)
307 /* dereference voffp(v) */
308 RSEQ_ASM_OP_R_LOADX(voffp
)
309 /* final store the value at voffp(v) */
310 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
312 RSEQ_ASM_DEFINE_ABORT(4, abort
)
313 : /* gcc asm goto does not allow outputs */
314 : [cpu_id
] "r" (cpu
),
315 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
316 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
317 /* final store input */
319 [expectnot
] "r" (expectnot
),
323 : "memory", "cc", "r17"
326 #ifdef RSEQ_COMPARE_TWICE
330 rseq_after_asm_goto();
333 rseq_after_asm_goto();
337 rseq_after_asm_goto();
339 #ifdef RSEQ_COMPARE_TWICE
341 rseq_after_asm_goto();
342 rseq_bug("cpu_id comparison failed");
344 rseq_after_asm_goto();
345 rseq_bug("expected value comparison failed");
349 static inline __attribute__((always_inline
))
350 int rseq_addv(intptr_t *v
, intptr_t count
, int cpu
)
354 __asm__ __volatile__
goto (
355 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
356 #ifdef RSEQ_COMPARE_TWICE
357 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
359 /* Start rseq by storing table entry pointer into rseq_cs. */
360 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
362 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
364 #ifdef RSEQ_COMPARE_TWICE
366 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
368 /* load the value of @v */
369 RSEQ_ASM_OP_R_LOAD(v
)
370 /* add @count to it */
371 RSEQ_ASM_OP_R_ADD(count
)
373 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
375 RSEQ_ASM_DEFINE_ABORT(4, abort
)
376 : /* gcc asm goto does not allow outputs */
377 : [cpu_id
] "r" (cpu
),
378 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
379 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
380 /* final store input */
384 : "memory", "cc", "r17"
387 #ifdef RSEQ_COMPARE_TWICE
391 rseq_after_asm_goto();
394 rseq_after_asm_goto();
397 #ifdef RSEQ_COMPARE_TWICE
399 rseq_after_asm_goto();
400 rseq_bug("cpu_id comparison failed");
404 static inline __attribute__((always_inline
))
405 int rseq_cmpeqv_trystorev_storev(intptr_t *v
, intptr_t expect
,
406 intptr_t *v2
, intptr_t newv2
,
407 intptr_t newv
, int cpu
)
411 __asm__ __volatile__
goto (
412 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
413 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
414 #ifdef RSEQ_COMPARE_TWICE
415 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
416 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
418 /* Start rseq by storing table entry pointer into rseq_cs. */
419 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
421 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
423 /* cmp @v equal to @expect */
424 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
426 #ifdef RSEQ_COMPARE_TWICE
428 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
429 /* cmp @v equal to @expect */
430 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
433 RSEQ_ASM_OP_STORE(newv2
, v2
)
436 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
438 RSEQ_ASM_DEFINE_ABORT(4, abort
)
439 : /* gcc asm goto does not allow outputs */
440 : [cpu_id
] "r" (cpu
),
441 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
442 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
443 /* try store input */
446 /* final store input */
448 [expect
] "r" (expect
),
451 : "memory", "cc", "r17"
454 #ifdef RSEQ_COMPARE_TWICE
458 rseq_after_asm_goto();
461 rseq_after_asm_goto();
465 rseq_after_asm_goto();
467 #ifdef RSEQ_COMPARE_TWICE
469 rseq_after_asm_goto();
470 rseq_bug("cpu_id comparison failed");
472 rseq_after_asm_goto();
473 rseq_bug("expected value comparison failed");
477 static inline __attribute__((always_inline
))
478 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v
, intptr_t expect
,
479 intptr_t *v2
, intptr_t newv2
,
480 intptr_t newv
, int cpu
)
484 __asm__ __volatile__
goto (
485 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
486 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
487 #ifdef RSEQ_COMPARE_TWICE
488 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
489 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
491 /* Start rseq by storing table entry pointer into rseq_cs. */
492 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
494 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
496 /* cmp @v equal to @expect */
497 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
499 #ifdef RSEQ_COMPARE_TWICE
501 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
502 /* cmp @v equal to @expect */
503 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
506 RSEQ_ASM_OP_STORE(newv2
, v2
)
511 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
513 RSEQ_ASM_DEFINE_ABORT(4, abort
)
514 : /* gcc asm goto does not allow outputs */
515 : [cpu_id
] "r" (cpu
),
516 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
517 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
518 /* try store input */
521 /* final store input */
523 [expect
] "r" (expect
),
526 : "memory", "cc", "r17"
529 #ifdef RSEQ_COMPARE_TWICE
533 rseq_after_asm_goto();
536 rseq_after_asm_goto();
540 rseq_after_asm_goto();
542 #ifdef RSEQ_COMPARE_TWICE
544 rseq_after_asm_goto();
545 rseq_bug("cpu_id comparison failed");
547 rseq_after_asm_goto();
548 rseq_bug("expected value comparison failed");
552 static inline __attribute__((always_inline
))
553 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
554 intptr_t *v2
, intptr_t expect2
,
555 intptr_t newv
, int cpu
)
559 __asm__ __volatile__
goto (
560 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
561 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
562 #ifdef RSEQ_COMPARE_TWICE
563 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
564 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
565 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
567 /* Start rseq by storing table entry pointer into rseq_cs. */
568 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
570 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
572 /* cmp @v equal to @expect */
573 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
575 /* cmp @v2 equal to @expct2 */
576 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[cmpfail
])
578 #ifdef RSEQ_COMPARE_TWICE
580 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
581 /* cmp @v equal to @expect */
582 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
583 /* cmp @v2 equal to @expct2 */
584 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[error3
])
587 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
589 RSEQ_ASM_DEFINE_ABORT(4, abort
)
590 : /* gcc asm goto does not allow outputs */
591 : [cpu_id
] "r" (cpu
),
592 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
593 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
596 [expect2
] "r" (expect2
),
597 /* final store input */
599 [expect
] "r" (expect
),
602 : "memory", "cc", "r17"
605 #ifdef RSEQ_COMPARE_TWICE
606 , error1
, error2
, error3
609 rseq_after_asm_goto();
612 rseq_after_asm_goto();
616 rseq_after_asm_goto();
618 #ifdef RSEQ_COMPARE_TWICE
620 rseq_after_asm_goto();
621 rseq_bug("cpu_id comparison failed");
623 rseq_after_asm_goto();
624 rseq_bug("1st expected value comparison failed");
626 rseq_after_asm_goto();
627 rseq_bug("2nd expected value comparison failed");
631 static inline __attribute__((always_inline
))
632 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
633 void *dst
, void *src
, size_t len
,
634 intptr_t newv
, int cpu
)
638 __asm__ __volatile__
goto (
639 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
640 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
641 #ifdef RSEQ_COMPARE_TWICE
642 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
643 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
645 /* setup for mempcy */
646 "mr %%r19, %[len]\n\t"
647 "mr %%r20, %[src]\n\t"
648 "mr %%r21, %[dst]\n\t"
649 /* Start rseq by storing table entry pointer into rseq_cs. */
650 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
652 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
654 /* cmp @v equal to @expect */
655 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
657 #ifdef RSEQ_COMPARE_TWICE
659 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
660 /* cmp @v equal to @expect */
661 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
664 RSEQ_ASM_OP_R_MEMCPY()
667 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
670 RSEQ_ASM_DEFINE_ABORT(4, abort
)
671 : /* gcc asm goto does not allow outputs */
672 : [cpu_id
] "r" (cpu
),
673 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
674 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
675 /* final store input */
677 [expect
] "r" (expect
),
679 /* try memcpy input */
684 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
687 #ifdef RSEQ_COMPARE_TWICE
691 rseq_after_asm_goto();
694 rseq_after_asm_goto();
698 rseq_after_asm_goto();
700 #ifdef RSEQ_COMPARE_TWICE
702 rseq_after_asm_goto();
703 rseq_bug("cpu_id comparison failed");
705 rseq_after_asm_goto();
706 rseq_bug("expected value comparison failed");
710 static inline __attribute__((always_inline
))
711 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
712 void *dst
, void *src
, size_t len
,
713 intptr_t newv
, int cpu
)
717 __asm__ __volatile__
goto (
718 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
719 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
720 #ifdef RSEQ_COMPARE_TWICE
721 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
722 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
724 /* setup for mempcy */
725 "mr %%r19, %[len]\n\t"
726 "mr %%r20, %[src]\n\t"
727 "mr %%r21, %[dst]\n\t"
728 /* Start rseq by storing table entry pointer into rseq_cs. */
729 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
731 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
733 /* cmp @v equal to @expect */
734 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
736 #ifdef RSEQ_COMPARE_TWICE
738 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
739 /* cmp @v equal to @expect */
740 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
743 RSEQ_ASM_OP_R_MEMCPY()
748 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
751 RSEQ_ASM_DEFINE_ABORT(4, abort
)
752 : /* gcc asm goto does not allow outputs */
753 : [cpu_id
] "r" (cpu
),
754 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
755 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
.arch
.ptr
),
756 /* final store input */
758 [expect
] "r" (expect
),
760 /* try memcpy input */
765 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
768 #ifdef RSEQ_COMPARE_TWICE
772 rseq_after_asm_goto();
775 rseq_after_asm_goto();
779 rseq_after_asm_goto();
781 #ifdef RSEQ_COMPARE_TWICE
783 rseq_after_asm_goto();
784 rseq_bug("cpu_id comparison failed");
786 rseq_after_asm_goto();
787 rseq_bug("expected value comparison failed");
791 #endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.059244 seconds and 4 git commands to generate.