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_CS_PTR rseq_cs.ptr
60 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
61 start_ip, post_commit_offset, abort_ip) \
62 ".pushsection __rseq_cs, \"aw\"\n\t" \
64 __rseq_str(label) ":\n\t" \
65 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
66 ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \
68 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
69 ".quad " __rseq_str(label) "b\n\t" \
72 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
74 "lis %%r17, (" __rseq_str(cs_label) ")@highest\n\t" \
75 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@higher\n\t" \
76 "rldicr %%r17, %%r17, 32, 31\n\t" \
77 "oris %%r17, %%r17, (" __rseq_str(cs_label) ")@high\n\t" \
78 "ori %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
79 "std %%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
80 __rseq_str(label) ":\n\t"
83 * Exit points of a rseq critical section consist of all instructions outside
84 * of the critical section where a critical section can either branch to or
85 * reach through the normal course of its execution. The abort IP and the
86 * post-commit IP are already part of the __rseq_cs section and should not be
87 * explicitly defined as additional exit points. Knowing all exit points is
88 * useful to assist debuggers stepping over the critical section.
90 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
91 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
92 ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \
95 #else /* #ifdef __PPC64__ */
97 #define RSEQ_STORE_LONG(arg) "stw%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* To memory ("m" constraint) */
98 #define RSEQ_STORE_INT(arg) RSEQ_STORE_LONG(arg) /* To memory ("m" constraint) */
99 #define RSEQ_LOAD_LONG(arg) "lwz%U[" __rseq_str(arg) "]%X[" __rseq_str(arg) "] " /* From memory ("m" constraint) */
100 #define RSEQ_LOAD_INT(arg) RSEQ_LOAD_LONG(arg) /* From memory ("m" constraint) */
101 #define RSEQ_LOADX_LONG "lwzx " /* From base register ("b" constraint) */
102 #define RSEQ_CMP_LONG "cmpw "
103 #define RSEQ_CMP_LONG_INT "cmpwi "
105 #define RSEQ_CS_PTR rseq_cs.ptr.ptr32
107 #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
108 start_ip, post_commit_offset, abort_ip) \
109 ".pushsection __rseq_cs, \"aw\"\n\t" \
111 __rseq_str(label) ":\n\t" \
112 ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
113 /* 32-bit only supported on BE */ \
114 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \
116 ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
117 ".long 0x0, " __rseq_str(label) "b\n\t" \
121 * Exit points of a rseq critical section consist of all instructions outside
122 * of the critical section where a critical section can either branch to or
123 * reach through the normal course of its execution. The abort IP and the
124 * post-commit IP are already part of the __rseq_cs section and should not be
125 * explicitly defined as additional exit points. Knowing all exit points is
126 * useful to assist debuggers stepping over the critical section.
128 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
129 ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
130 /* 32-bit only supported on BE */ \
131 ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \
134 #define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
136 "lis %%r17, (" __rseq_str(cs_label) ")@ha\n\t" \
137 "addi %%r17, %%r17, (" __rseq_str(cs_label) ")@l\n\t" \
138 RSEQ_STORE_INT(rseq_cs) "%%r17, %[" __rseq_str(rseq_cs) "]\n\t" \
139 __rseq_str(label) ":\n\t"
141 #endif /* #ifdef __PPC64__ */
143 #define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
144 __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
145 (post_commit_ip - start_ip), abort_ip)
147 #define RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, label) \
149 RSEQ_LOAD_INT(current_cpu_id) "%%r17, %[" __rseq_str(current_cpu_id) "]\n\t" \
150 "cmpw cr7, %[" __rseq_str(cpu_id) "], %%r17\n\t" \
151 "bne- cr7, " __rseq_str(label) "\n\t"
153 #define RSEQ_ASM_DEFINE_ABORT(label, abort_label) \
154 ".pushsection __rseq_failure, \"ax\"\n\t" \
155 ".long " __rseq_str(RSEQ_SIG) "\n\t" \
156 __rseq_str(label) ":\n\t" \
157 "b %l[" __rseq_str(abort_label) "]\n\t" \
161 * RSEQ_ASM_OPs: asm operations for rseq
162 * RSEQ_ASM_OP_R_*: has hard-code registers in it
163 * RSEQ_ASM_OP_* (else): doesn't have hard-code registers(unless cr7)
165 #define RSEQ_ASM_OP_CMPEQ(var, expect, label) \
166 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
167 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expect) "]\n\t" \
168 "bne- cr7, " __rseq_str(label) "\n\t"
170 #define RSEQ_ASM_OP_CMPNE(var, expectnot, label) \
171 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
172 RSEQ_CMP_LONG "cr7, %%r17, %[" __rseq_str(expectnot) "]\n\t" \
173 "beq- cr7, " __rseq_str(label) "\n\t"
175 #define RSEQ_ASM_OP_STORE(value, var) \
176 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t"
178 /* Load @var to r17 */
179 #define RSEQ_ASM_OP_R_LOAD(var) \
180 RSEQ_LOAD_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
182 /* Store r17 to @var */
183 #define RSEQ_ASM_OP_R_STORE(var) \
184 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t"
186 /* Add @count to r17 */
187 #define RSEQ_ASM_OP_R_ADD(count) \
188 "add %%r17, %[" __rseq_str(count) "], %%r17\n\t"
190 /* Load (r17 + voffp) to r17 */
191 #define RSEQ_ASM_OP_R_LOADX(voffp) \
192 RSEQ_LOADX_LONG "%%r17, %[" __rseq_str(voffp) "], %%r17\n\t"
194 /* TODO: implement a faster memcpy. */
195 #define RSEQ_ASM_OP_R_MEMCPY() \
196 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
198 "addi %%r20, %%r20, -1\n\t" \
199 "addi %%r21, %%r21, -1\n\t" \
201 "lbzu %%r18, 1(%%r20)\n\t" \
202 "stbu %%r18, 1(%%r21)\n\t" \
203 "addi %%r19, %%r19, -1\n\t" \
204 RSEQ_CMP_LONG_INT "%%r19, 0\n\t" \
208 #define RSEQ_ASM_OP_R_FINAL_STORE(var, post_commit_label) \
209 RSEQ_STORE_LONG(var) "%%r17, %[" __rseq_str(var) "]\n\t" \
210 __rseq_str(post_commit_label) ":\n\t"
212 #define RSEQ_ASM_OP_FINAL_STORE(value, var, post_commit_label) \
213 RSEQ_STORE_LONG(var) "%[" __rseq_str(value) "], %[" __rseq_str(var) "]\n\t" \
214 __rseq_str(post_commit_label) ":\n\t"
216 static inline __attribute__((always_inline
))
217 int rseq_cmpeqv_storev(intptr_t *v
, intptr_t expect
, intptr_t newv
, int cpu
)
221 __asm__ __volatile__
goto (
222 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
223 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
224 #ifdef RSEQ_COMPARE_TWICE
225 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
226 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
228 /* Start rseq by storing table entry pointer into rseq_cs. */
229 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
231 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
233 /* cmp @v equal to @expect */
234 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
236 #ifdef RSEQ_COMPARE_TWICE
238 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
239 /* cmp @v equal to @expect */
240 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
243 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
245 RSEQ_ASM_DEFINE_ABORT(4, abort
)
246 : /* gcc asm goto does not allow outputs */
247 : [cpu_id
] "r" (cpu
),
248 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
249 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
251 [expect
] "r" (expect
),
254 : "memory", "cc", "r17"
257 #ifdef RSEQ_COMPARE_TWICE
261 rseq_after_asm_goto();
264 rseq_after_asm_goto();
268 rseq_after_asm_goto();
270 #ifdef RSEQ_COMPARE_TWICE
272 rseq_after_asm_goto();
273 rseq_bug("cpu_id comparison failed");
275 rseq_after_asm_goto();
276 rseq_bug("expected value comparison failed");
280 static inline __attribute__((always_inline
))
281 int rseq_cmpnev_storeoffp_load(intptr_t *v
, intptr_t expectnot
,
282 off_t voffp
, intptr_t *load
, int cpu
)
286 __asm__ __volatile__
goto (
287 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
288 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
289 #ifdef RSEQ_COMPARE_TWICE
290 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
291 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
293 /* Start rseq by storing table entry pointer into rseq_cs. */
294 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
296 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
298 /* cmp @v not equal to @expectnot */
299 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[cmpfail
])
301 #ifdef RSEQ_COMPARE_TWICE
303 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
304 /* cmp @v not equal to @expectnot */
305 RSEQ_ASM_OP_CMPNE(v
, expectnot
, %l
[error2
])
307 /* load the value of @v */
308 RSEQ_ASM_OP_R_LOAD(v
)
309 /* store it in @load */
310 RSEQ_ASM_OP_R_STORE(load
)
311 /* dereference voffp(v) */
312 RSEQ_ASM_OP_R_LOADX(voffp
)
313 /* final store the value at voffp(v) */
314 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
316 RSEQ_ASM_DEFINE_ABORT(4, abort
)
317 : /* gcc asm goto does not allow outputs */
318 : [cpu_id
] "r" (cpu
),
319 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
320 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
321 /* final store input */
323 [expectnot
] "r" (expectnot
),
327 : "memory", "cc", "r17"
330 #ifdef RSEQ_COMPARE_TWICE
334 rseq_after_asm_goto();
337 rseq_after_asm_goto();
341 rseq_after_asm_goto();
343 #ifdef RSEQ_COMPARE_TWICE
345 rseq_after_asm_goto();
346 rseq_bug("cpu_id comparison failed");
348 rseq_after_asm_goto();
349 rseq_bug("expected value comparison failed");
353 static inline __attribute__((always_inline
))
354 int rseq_addv(intptr_t *v
, intptr_t count
, int cpu
)
358 __asm__ __volatile__
goto (
359 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
360 #ifdef RSEQ_COMPARE_TWICE
361 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
363 /* Start rseq by storing table entry pointer into rseq_cs. */
364 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
366 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
368 #ifdef RSEQ_COMPARE_TWICE
370 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
372 /* load the value of @v */
373 RSEQ_ASM_OP_R_LOAD(v
)
374 /* add @count to it */
375 RSEQ_ASM_OP_R_ADD(count
)
377 RSEQ_ASM_OP_R_FINAL_STORE(v
, 2)
379 RSEQ_ASM_DEFINE_ABORT(4, abort
)
380 : /* gcc asm goto does not allow outputs */
381 : [cpu_id
] "r" (cpu
),
382 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
383 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
384 /* final store input */
388 : "memory", "cc", "r17"
391 #ifdef RSEQ_COMPARE_TWICE
395 rseq_after_asm_goto();
398 rseq_after_asm_goto();
401 #ifdef RSEQ_COMPARE_TWICE
403 rseq_after_asm_goto();
404 rseq_bug("cpu_id comparison failed");
408 static inline __attribute__((always_inline
))
409 int rseq_cmpeqv_trystorev_storev(intptr_t *v
, intptr_t expect
,
410 intptr_t *v2
, intptr_t newv2
,
411 intptr_t newv
, int cpu
)
415 __asm__ __volatile__
goto (
416 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
417 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
418 #ifdef RSEQ_COMPARE_TWICE
419 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
420 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
422 /* Start rseq by storing table entry pointer into rseq_cs. */
423 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
425 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
427 /* cmp @v equal to @expect */
428 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
430 #ifdef RSEQ_COMPARE_TWICE
432 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
433 /* cmp @v equal to @expect */
434 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
437 RSEQ_ASM_OP_STORE(newv2
, v2
)
440 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
442 RSEQ_ASM_DEFINE_ABORT(4, abort
)
443 : /* gcc asm goto does not allow outputs */
444 : [cpu_id
] "r" (cpu
),
445 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
446 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
447 /* try store input */
450 /* final store input */
452 [expect
] "r" (expect
),
455 : "memory", "cc", "r17"
458 #ifdef RSEQ_COMPARE_TWICE
462 rseq_after_asm_goto();
465 rseq_after_asm_goto();
469 rseq_after_asm_goto();
471 #ifdef RSEQ_COMPARE_TWICE
473 rseq_after_asm_goto();
474 rseq_bug("cpu_id comparison failed");
476 rseq_after_asm_goto();
477 rseq_bug("expected value comparison failed");
481 static inline __attribute__((always_inline
))
482 int rseq_cmpeqv_trystorev_storev_release(intptr_t *v
, intptr_t expect
,
483 intptr_t *v2
, intptr_t newv2
,
484 intptr_t newv
, int cpu
)
488 __asm__ __volatile__
goto (
489 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
490 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
491 #ifdef RSEQ_COMPARE_TWICE
492 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
493 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
495 /* Start rseq by storing table entry pointer into rseq_cs. */
496 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
498 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
500 /* cmp @v equal to @expect */
501 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
503 #ifdef RSEQ_COMPARE_TWICE
505 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
506 /* cmp @v equal to @expect */
507 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
510 RSEQ_ASM_OP_STORE(newv2
, v2
)
515 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
517 RSEQ_ASM_DEFINE_ABORT(4, abort
)
518 : /* gcc asm goto does not allow outputs */
519 : [cpu_id
] "r" (cpu
),
520 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
521 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
522 /* try store input */
525 /* final store input */
527 [expect
] "r" (expect
),
530 : "memory", "cc", "r17"
533 #ifdef RSEQ_COMPARE_TWICE
537 rseq_after_asm_goto();
540 rseq_after_asm_goto();
544 rseq_after_asm_goto();
546 #ifdef RSEQ_COMPARE_TWICE
548 rseq_after_asm_goto();
549 rseq_bug("cpu_id comparison failed");
551 rseq_after_asm_goto();
552 rseq_bug("expected value comparison failed");
556 static inline __attribute__((always_inline
))
557 int rseq_cmpeqv_cmpeqv_storev(intptr_t *v
, intptr_t expect
,
558 intptr_t *v2
, intptr_t expect2
,
559 intptr_t newv
, int cpu
)
563 __asm__ __volatile__
goto (
564 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
565 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
566 #ifdef RSEQ_COMPARE_TWICE
567 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
568 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
569 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error3
])
571 /* Start rseq by storing table entry pointer into rseq_cs. */
572 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
574 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
576 /* cmp @v equal to @expect */
577 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
579 /* cmp @v2 equal to @expct2 */
580 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[cmpfail
])
582 #ifdef RSEQ_COMPARE_TWICE
584 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
585 /* cmp @v equal to @expect */
586 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
587 /* cmp @v2 equal to @expct2 */
588 RSEQ_ASM_OP_CMPEQ(v2
, expect2
, %l
[error3
])
591 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
593 RSEQ_ASM_DEFINE_ABORT(4, abort
)
594 : /* gcc asm goto does not allow outputs */
595 : [cpu_id
] "r" (cpu
),
596 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
597 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
600 [expect2
] "r" (expect2
),
601 /* final store input */
603 [expect
] "r" (expect
),
606 : "memory", "cc", "r17"
609 #ifdef RSEQ_COMPARE_TWICE
610 , error1
, error2
, error3
613 rseq_after_asm_goto();
616 rseq_after_asm_goto();
620 rseq_after_asm_goto();
622 #ifdef RSEQ_COMPARE_TWICE
624 rseq_after_asm_goto();
625 rseq_bug("cpu_id comparison failed");
627 rseq_after_asm_goto();
628 rseq_bug("1st expected value comparison failed");
630 rseq_after_asm_goto();
631 rseq_bug("2nd expected value comparison failed");
635 static inline __attribute__((always_inline
))
636 int rseq_cmpeqv_trymemcpy_storev(intptr_t *v
, intptr_t expect
,
637 void *dst
, void *src
, size_t len
,
638 intptr_t newv
, int cpu
)
642 __asm__ __volatile__
goto (
643 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
644 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
645 #ifdef RSEQ_COMPARE_TWICE
646 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
647 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
649 /* setup for mempcy */
650 "mr %%r19, %[len]\n\t"
651 "mr %%r20, %[src]\n\t"
652 "mr %%r21, %[dst]\n\t"
653 /* Start rseq by storing table entry pointer into rseq_cs. */
654 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
656 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
658 /* cmp @v equal to @expect */
659 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
661 #ifdef RSEQ_COMPARE_TWICE
663 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
664 /* cmp @v equal to @expect */
665 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
668 RSEQ_ASM_OP_R_MEMCPY()
671 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
674 RSEQ_ASM_DEFINE_ABORT(4, abort
)
675 : /* gcc asm goto does not allow outputs */
676 : [cpu_id
] "r" (cpu
),
677 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
678 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
679 /* final store input */
681 [expect
] "r" (expect
),
683 /* try memcpy input */
688 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
691 #ifdef RSEQ_COMPARE_TWICE
695 rseq_after_asm_goto();
698 rseq_after_asm_goto();
702 rseq_after_asm_goto();
704 #ifdef RSEQ_COMPARE_TWICE
706 rseq_after_asm_goto();
707 rseq_bug("cpu_id comparison failed");
709 rseq_after_asm_goto();
710 rseq_bug("expected value comparison failed");
714 static inline __attribute__((always_inline
))
715 int rseq_cmpeqv_trymemcpy_storev_release(intptr_t *v
, intptr_t expect
,
716 void *dst
, void *src
, size_t len
,
717 intptr_t newv
, int cpu
)
721 __asm__ __volatile__
goto (
722 RSEQ_ASM_DEFINE_TABLE(3, 1f
, 2f
, 4f
) /* start, commit, abort */
723 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[cmpfail
])
724 #ifdef RSEQ_COMPARE_TWICE
725 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error1
])
726 RSEQ_ASM_DEFINE_EXIT_POINT(1f
, %l
[error2
])
728 /* setup for mempcy */
729 "mr %%r19, %[len]\n\t"
730 "mr %%r20, %[src]\n\t"
731 "mr %%r21, %[dst]\n\t"
732 /* Start rseq by storing table entry pointer into rseq_cs. */
733 RSEQ_ASM_STORE_RSEQ_CS(1, 3b
, rseq_cs
)
735 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, 4f
)
737 /* cmp @v equal to @expect */
738 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[cmpfail
])
740 #ifdef RSEQ_COMPARE_TWICE
742 RSEQ_ASM_CMP_CPU_ID(cpu_id
, current_cpu_id
, %l
[error1
])
743 /* cmp @v equal to @expect */
744 RSEQ_ASM_OP_CMPEQ(v
, expect
, %l
[error2
])
747 RSEQ_ASM_OP_R_MEMCPY()
752 RSEQ_ASM_OP_FINAL_STORE(newv
, v
, 2)
755 RSEQ_ASM_DEFINE_ABORT(4, abort
)
756 : /* gcc asm goto does not allow outputs */
757 : [cpu_id
] "r" (cpu
),
758 [current_cpu_id
] "m" (rseq_get_abi()->cpu_id
),
759 [rseq_cs
] "m" (rseq_get_abi()->RSEQ_CS_PTR
),
760 /* final store input */
762 [expect
] "r" (expect
),
764 /* try memcpy input */
769 : "memory", "cc", "r17", "r18", "r19", "r20", "r21"
772 #ifdef RSEQ_COMPARE_TWICE
776 rseq_after_asm_goto();
779 rseq_after_asm_goto();
783 rseq_after_asm_goto();
785 #ifdef RSEQ_COMPARE_TWICE
787 rseq_after_asm_goto();
788 rseq_bug("cpu_id comparison failed");
790 rseq_after_asm_goto();
791 rseq_bug("expected value comparison failed");
795 #undef RSEQ_STORE_LONG
796 #undef RSEQ_LOAD_LONG
797 #undef RSEQ_LOADX_LONG
800 #endif /* !RSEQ_SKIP_FASTPATH */
This page took 0.053208 seconds and 5 git commands to generate.