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 "
57 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
58 start_ip, post_commit_offset, abort_ip) \
59 ".pushsection __rseq_cs, \"aw\"\n\t" \
61 __rseq_str(label) ":\n\t" \
62 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
63 ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \
65 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
66 ".quad " __rseq_str(label) "b\n\t" \
69 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
71 "lis %%r17, (" __rseq_str(cs_label) ")@highest\n\t" \
72 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@higher\n\t" \
73 "rldicr %%r17, %%r17, 32, 31\n\t" \
74 "oris %%r17, %%r17, (" __rseq_str(cs_label) ")@high\n\t" \
75 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
76 "std %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
77 __rseq_str(label) ":\n\t"
80 * Exit points of a rseq critical section consist of all instructions outside
81 * of the critical section where a critical section can either branch to or
82 * reach through the normal course of its execution. The abort IP and the
83 * post-commit IP are already part of the __rseq_cs section and should not be
84 * explicitly defined as additional exit points. Knowing all exit points is
85 * useful to assist debuggers stepping over the critical section.
87 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
88 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
89 ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \
92 #else /* #ifdef __PPC64__ */
94 #define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
95 #define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */
96 #define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
97 #define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */
98 #define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */
99 #define RSEQ_CMP_LONG "cmpw "
101 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
102 start_ip, post_commit_offset, abort_ip) \
103 ".pushsection __rseq_cs, \"aw\"\n\t" \
105 __rseq_str(label) ":\n\t" \
106 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
107 /* 32-bit only supported on BE */ \
108 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \
110 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
111 ".long 0x0, " __rseq_str(label) "b\n\t" \
115 * Exit points of a rseq critical section consist of all instructions outside
116 * of the critical section where a critical section can either branch to or
117 * reach through the normal course of its execution. The abort IP and the
118 * post-commit IP are already part of the __rseq_cs section and should not be
119 * explicitly defined as additional exit points. Knowing all exit points is
120 * useful to assist debuggers stepping over the critical section.
122 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
123 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
124 /* 32-bit only supported on BE */ \
125 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \
128 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
130 "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \
131 "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
132 RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
133 __rseq_str(label) ":\n\t"
135 #endif /* #ifdef __PPC64__ */
137 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
138 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
139 (post_commit_ip - start_ip), abort_ip)
141 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
143 RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \
144 "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \
145 "bne- cr7, " __rseq_str(label) "\n\t"
147 #define RSEQ_ASM_DEFINE_ABORT(label, abort_label) \
148 ".pushsection __rseq_failure, \"ax\"\n\t" \
149 ".long " __rseq_str(RSEQ_SIG) "\n\t" \
150 __rseq_str(label) ":\n\t" \
151 "b %l[" __rseq_str(abort_label) "]\n\t" \
155 * RSEQ_ASM_OPs: asm operations for rseq
156 * RSEQ_ASM_OP_R_*: has hard-code registers in it
157 * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7)
159 #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \
160 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
161 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \
162 "bne- cr7, " __rseq_str(label) "\n\t"
164 #define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \
165 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
166 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \
167 "beq- cr7, " __rseq_str(label) "\n\t"
169 #define RSEQ_ASM_OP_STORE(value, var) \
170 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t"
172 /* Load @var to r17 */
173 #define RSEQ_ASM_OP_R_LOAD(var) \
174 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
176 /* Store r17 to @var */
177 #define RSEQ_ASM_OP_R_STORE(var) \
178 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
180 /* Add @count to r17 */
181 #define RSEQ_ASM_OP_R_ADD(count) \
182 "add %%r17, %[" __rseq_str(count) "], %%r17\n\t"
184 /* Load (r17 + voffp) to r17 */
185 #define RSEQ_ASM_OP_R_LOADX(voffp) \
186 RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t"
188 /* TODO: implement a faster memcpy. */
189 #define RSEQ_ASM_OP_R_MEMCPY() \
190 "cmpdi %%r19, 0\n\t" \
192 "addi %%r20, %%r20, -1\n\t" \
193 "addi %%r21, %%r21, -1\n\t" \
195 "lbzu %%r18, 1(%%r20)\n\t" \
196 "stbu %%r18, 1(%%r21)\n\t" \
197 "addi %%r19, %%r19, -1\n\t" \
198 "cmpdi %%r19, 0\n\t" \
202 #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \
203 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
204 __rseq_str(post_commit_label) ":\n\t"
206 #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \
207 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \
208 __rseq_str(post_commit_label) ":\n\t"
210 static inline __attribute__((always_inline
))
211 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
215 __asm__ __volatile__
goto (
216 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
217 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
218 #ifdef RSEQ_COMPARE_TWICE
219 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
220 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
222 /* Start rseq by storing table entry pointer into rseq_cs. */
223 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
225 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
227 /* cmp @v equal to @expect */
228 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
230 #ifdef RSEQ_COMPARE_TWICE
232 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
233 /* cmp @v equal to @expect */
234 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
237 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
239 RSEQ_ASM_DEFINE_ABORT(4, abort
)
240 : /* gcc asm goto does not allow outputs */
241 : [cpu_id
] "r" (cpu
),
242 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
243 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
245 [expect
] "r" (expect
),
248 : "memory", "cc", "r17"
251 #ifdef RSEQ_COMPARE_TWICE
255 rseq_after_asm_goto();
258 rseq_after_asm_goto();
262 rseq_after_asm_goto();
264 #ifdef RSEQ_COMPARE_TWICE
266 rseq_after_asm_goto();
267 rseq_bug("cpu_id comparison failed");
269 rseq_after_asm_goto();
270 rseq_bug("expected value comparison failed");
274 static inline __attribute__((always_inline
))
275 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
276 off_t voffp
, intptr_t *load
, int cpu
)
280 __asm__ __volatile__
goto (
281 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
282 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
283 #ifdef RSEQ_COMPARE_TWICE
284 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
285 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
287 /* Start rseq by storing table entry pointer into rseq_cs. */
288 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
290 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
292 /* cmp @v not equal to @expectnot */
293 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[cmpfail
])
295 #ifdef RSEQ_COMPARE_TWICE
297 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
298 /* cmp @v not equal to @expectnot */
299 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[error2
])
301 /* load the value of @v */
302 RSEQ_ASM_OP_R_LOAD(v
)
303 /* store it in @load */
304 RSEQ_ASM_OP_R_STORE(load
)
305 /* dereference voffp(v) */
306 RSEQ_ASM_OP_R_LOADX(voffp
)
307 /* final store the value at voffp(v) */
308 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
310 RSEQ_ASM_DEFINE_ABORT(4, abort
)
311 : /* gcc asm goto does not allow outputs */
312 : [cpu_id
] "r" (cpu
),
313 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
314 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
315 /* final store input */
317 [expectnot
] "r" (expectnot
),
321 : "memory", "cc", "r17"
324 #ifdef RSEQ_COMPARE_TWICE
328 rseq_after_asm_goto();
331 rseq_after_asm_goto();
335 rseq_after_asm_goto();
337 #ifdef RSEQ_COMPARE_TWICE
339 rseq_after_asm_goto();
340 rseq_bug("cpu_id comparison failed");
342 rseq_after_asm_goto();
343 rseq_bug("expected value comparison failed");
347 static inline __attribute__((always_inline
))
348 int rseq_addv(intptr_t *v
, intptr_t count
, int cpu
)
352 __asm__ __volatile__
goto (
353 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
354 #ifdef RSEQ_COMPARE_TWICE
355 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
357 /* Start rseq by storing table entry pointer into rseq_cs. */
358 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
360 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
362 #ifdef RSEQ_COMPARE_TWICE
364 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
366 /* load the value of @v */
367 RSEQ_ASM_OP_R_LOAD(v
)
368 /* add @count to it */
369 RSEQ_ASM_OP_R_ADD(count
)
371 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
373 RSEQ_ASM_DEFINE_ABORT(4, abort
)
374 : /* gcc asm goto does not allow outputs */
375 : [cpu_id
] "r" (cpu
),
376 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
377 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
378 /* final store input */
382 : "memory", "cc", "r17"
385 #ifdef RSEQ_COMPARE_TWICE
389 rseq_after_asm_goto();
392 rseq_after_asm_goto();
395 #ifdef RSEQ_COMPARE_TWICE
397 rseq_after_asm_goto();
398 rseq_bug("cpu_id comparison failed");
402 static inline __attribute__((always_inline
))
403 int rseq_cmpeqv_trystorev_storev(intptr_t *v
, intptr_t expect
,
404 intptr_t *v2
, intptr_t newv2
,
405 intptr_t newv
, int cpu
)
409 __asm__ __volatile__
goto (
410 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
411 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
412 #ifdef RSEQ_COMPARE_TWICE
413 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
414 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
416 /* Start rseq by storing table entry pointer into rseq_cs. */
417 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
419 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
421 /* cmp @v equal to @expect */
422 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
424 #ifdef RSEQ_COMPARE_TWICE
426 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
427 /* cmp @v equal to @expect */
428 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
431 RSEQ_ASM_OP_STORE(newv2
, v2
)
434 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
436 RSEQ_ASM_DEFINE_ABORT(4, abort
)
437 : /* gcc asm goto does not allow outputs */
438 : [cpu_id
] "r" (cpu
),
439 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
440 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
441 /* try store input */
444 /* final store input */
446 [expect
] "r" (expect
),
449 : "memory", "cc", "r17"
452 #ifdef RSEQ_COMPARE_TWICE
456 rseq_after_asm_goto();
459 rseq_after_asm_goto();
463 rseq_after_asm_goto();
465 #ifdef RSEQ_COMPARE_TWICE
467 rseq_after_asm_goto();
468 rseq_bug("cpu_id comparison failed");
470 rseq_after_asm_goto();
471 rseq_bug("expected value comparison failed");
475 static inline __attribute__((always_inline
))
476 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v
, intptr_t expect
,
477 intptr_t *v2
, intptr_t newv2
,
478 intptr_t newv
, int cpu
)
482 __asm__ __volatile__
goto (
483 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
484 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
485 #ifdef RSEQ_COMPARE_TWICE
486 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
487 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
489 /* Start rseq by storing table entry pointer into rseq_cs. */
490 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
492 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
494 /* cmp @v equal to @expect */
495 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
497 #ifdef RSEQ_COMPARE_TWICE
499 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
500 /* cmp @v equal to @expect */
501 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
504 RSEQ_ASM_OP_STORE(newv2
, v2
)
509 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
511 RSEQ_ASM_DEFINE_ABORT(4, abort
)
512 : /* gcc asm goto does not allow outputs */
513 : [cpu_id
] "r" (cpu
),
514 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
515 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
516 /* try store input */
519 /* final store input */
521 [expect
] "r" (expect
),
524 : "memory", "cc", "r17"
527 #ifdef RSEQ_COMPARE_TWICE
531 rseq_after_asm_goto();
534 rseq_after_asm_goto();
538 rseq_after_asm_goto();
540 #ifdef RSEQ_COMPARE_TWICE
542 rseq_after_asm_goto();
543 rseq_bug("cpu_id comparison failed");
545 rseq_after_asm_goto();
546 rseq_bug("expected value comparison failed");
550 static inline __attribute__((always_inline
))
551 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
552 intptr_t *v2
, intptr_t expect2
,
553 intptr_t newv
, int cpu
)
557 __asm__ __volatile__
goto (
558 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
559 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
560 #ifdef RSEQ_COMPARE_TWICE
561 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
562 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
563 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
565 /* Start rseq by storing table entry pointer into rseq_cs. */
566 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
568 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
570 /* cmp @v equal to @expect */
571 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
573 /* cmp @v2 equal to @expct2 */
574 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[cmpfail
])
576 #ifdef RSEQ_COMPARE_TWICE
578 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
579 /* cmp @v equal to @expect */
580 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
581 /* cmp @v2 equal to @expct2 */
582 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[error3
])
585 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
587 RSEQ_ASM_DEFINE_ABORT(4, abort
)
588 : /* gcc asm goto does not allow outputs */
589 : [cpu_id
] "r" (cpu
),
590 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
591 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
594 [expect2
] "r" (expect2
),
595 /* final store input */
597 [expect
] "r" (expect
),
600 : "memory", "cc", "r17"
603 #ifdef RSEQ_COMPARE_TWICE
604 , error1
, error2
, error3
607 rseq_after_asm_goto();
610 rseq_after_asm_goto();
614 rseq_after_asm_goto();
616 #ifdef RSEQ_COMPARE_TWICE
618 rseq_after_asm_goto();
619 rseq_bug("cpu_id comparison failed");
621 rseq_after_asm_goto();
622 rseq_bug("1st expected value comparison failed");
624 rseq_after_asm_goto();
625 rseq_bug("2nd expected value comparison failed");
629 static inline __attribute__((always_inline
))
630 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
631 void *dst
, void *src
, size_t len
,
632 intptr_t newv
, int cpu
)
636 __asm__ __volatile__
goto (
637 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
638 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
639 #ifdef RSEQ_COMPARE_TWICE
640 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
641 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
643 /* setup for mempcy */
644 "mr %%r19, %[len]\n\t"
645 "mr %%r20, %[src]\n\t"
646 "mr %%r21, %[dst]\n\t"
647 /* Start rseq by storing table entry pointer into rseq_cs. */
648 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
650 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
652 /* cmp @v equal to @expect */
653 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
655 #ifdef RSEQ_COMPARE_TWICE
657 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
658 /* cmp @v equal to @expect */
659 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
662 RSEQ_ASM_OP_R_MEMCPY()
665 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
668 RSEQ_ASM_DEFINE_ABORT(4, abort
)
669 : /* gcc asm goto does not allow outputs */
670 : [cpu_id
] "r" (cpu
),
671 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
672 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
673 /* final store input */
675 [expect
] "r" (expect
),
677 /* try memcpy input */
682 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
685 #ifdef RSEQ_COMPARE_TWICE
689 rseq_after_asm_goto();
692 rseq_after_asm_goto();
696 rseq_after_asm_goto();
698 #ifdef RSEQ_COMPARE_TWICE
700 rseq_after_asm_goto();
701 rseq_bug("cpu_id comparison failed");
703 rseq_after_asm_goto();
704 rseq_bug("expected value comparison failed");
708 static inline __attribute__((always_inline
))
709 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
710 void *dst
, void *src
, size_t len
,
711 intptr_t newv
, int cpu
)
715 __asm__ __volatile__
goto (
716 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
717 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
718 #ifdef RSEQ_COMPARE_TWICE
719 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
720 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
722 /* setup for mempcy */
723 "mr %%r19, %[len]\n\t"
724 "mr %%r20, %[src]\n\t"
725 "mr %%r21, %[dst]\n\t"
726 /* Start rseq by storing table entry pointer into rseq_cs. */
727 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
729 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
731 /* cmp @v equal to @expect */
732 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
734 #ifdef RSEQ_COMPARE_TWICE
736 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
737 /* cmp @v equal to @expect */
738 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
741 RSEQ_ASM_OP_R_MEMCPY()
746 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
749 RSEQ_ASM_DEFINE_ABORT(4, abort
)
750 : /* gcc asm goto does not allow outputs */
751 : [cpu_id
] "r" (cpu
),
752 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
753 [rseq_cs
] "m" (rseq_get_abi()->rseq_cs
),
754 /* final store input */
756 [expect
] "r" (expect
),
758 /* try memcpy input */
763 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
766 #ifdef RSEQ_COMPARE_TWICE
770 rseq_after_asm_goto();
773 rseq_after_asm_goto();
777 rseq_after_asm_goto();
779 #ifdef RSEQ_COMPARE_TWICE
781 rseq_after_asm_goto();
782 rseq_bug("cpu_id comparison failed");
784 rseq_after_asm_goto();
785 rseq_bug("expected value comparison failed");
789 #undef RSEQ_STORE_LONG
790 #undef RSEQ_LOAD_LONG
791 #undef RSEQ_LOADX_LONG
794 #endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.046058 seconds and 5 git commands to generate.