.. | .. |
---|
1 | 1 | /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ |
---|
2 | 2 | |
---|
3 | | -#define RSEQ_SIG 0x53053053 |
---|
| 3 | +/* |
---|
| 4 | + * RSEQ_SIG uses the trap4 instruction. As Linux does not make use of the |
---|
| 5 | + * access-register mode nor the linkage stack this instruction will always |
---|
| 6 | + * cause a special-operation exception (the trap-enabled bit in the DUCT |
---|
| 7 | + * is and will stay 0). The instruction pattern is |
---|
| 8 | + * b2 ff 0f ff trap4 4095(%r0) |
---|
| 9 | + */ |
---|
| 10 | +#define RSEQ_SIG 0xB2FF0FFF |
---|
4 | 11 | |
---|
5 | 12 | #define rseq_smp_mb() __asm__ __volatile__ ("bcr 15,0" ::: "memory") |
---|
6 | 13 | #define rseq_smp_rmb() rseq_smp_mb() |
---|
.. | .. |
---|
37 | 44 | |
---|
38 | 45 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
39 | 46 | start_ip, post_commit_offset, abort_ip) \ |
---|
40 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 47 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
41 | 48 | ".balign 32\n\t" \ |
---|
42 | 49 | __rseq_str(label) ":\n\t" \ |
---|
43 | 50 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
44 | 51 | ".quad " __rseq_str(start_ip) ", " __rseq_str(post_commit_offset) ", " __rseq_str(abort_ip) "\n\t" \ |
---|
| 52 | + ".popsection\n\t" \ |
---|
| 53 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 54 | + ".quad " __rseq_str(label) "b\n\t" \ |
---|
| 55 | + ".popsection\n\t" |
---|
| 56 | + |
---|
| 57 | +/* |
---|
| 58 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 59 | + * of the critical section where a critical section can either branch to or |
---|
| 60 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 61 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 62 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 63 | + * useful to assist debuggers stepping over the critical section. |
---|
| 64 | + */ |
---|
| 65 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 66 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 67 | + ".quad " __rseq_str(start_ip) ", " __rseq_str(exit_ip) "\n\t" \ |
---|
45 | 68 | ".popsection\n\t" |
---|
46 | 69 | |
---|
47 | 70 | #elif __s390__ |
---|
48 | 71 | |
---|
49 | 72 | #define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \ |
---|
50 | 73 | start_ip, post_commit_offset, abort_ip) \ |
---|
51 | | - ".pushsection __rseq_table, \"aw\"\n\t" \ |
---|
| 74 | + ".pushsection __rseq_cs, \"aw\"\n\t" \ |
---|
52 | 75 | ".balign 32\n\t" \ |
---|
53 | 76 | __rseq_str(label) ":\n\t" \ |
---|
54 | 77 | ".long " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \ |
---|
55 | 78 | ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) "\n\t" \ |
---|
| 79 | + ".popsection\n\t" \ |
---|
| 80 | + ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \ |
---|
| 81 | + ".long 0x0, " __rseq_str(label) "b\n\t" \ |
---|
| 82 | + ".popsection\n\t" |
---|
| 83 | + |
---|
| 84 | +/* |
---|
| 85 | + * Exit points of a rseq critical section consist of all instructions outside |
---|
| 86 | + * of the critical section where a critical section can either branch to or |
---|
| 87 | + * reach through the normal course of its execution. The abort IP and the |
---|
| 88 | + * post-commit IP are already part of the __rseq_cs section and should not be |
---|
| 89 | + * explicitly defined as additional exit points. Knowing all exit points is |
---|
| 90 | + * useful to assist debuggers stepping over the critical section. |
---|
| 91 | + */ |
---|
| 92 | +#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \ |
---|
| 93 | + ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \ |
---|
| 94 | + ".long 0x0, " __rseq_str(start_ip) ", 0x0, " __rseq_str(exit_ip) "\n\t" \ |
---|
56 | 95 | ".popsection\n\t" |
---|
57 | 96 | |
---|
58 | 97 | #define LONG_L "l" |
---|
.. | .. |
---|
85 | 124 | ".long " __rseq_str(RSEQ_SIG) "\n\t" \ |
---|
86 | 125 | __rseq_str(label) ":\n\t" \ |
---|
87 | 126 | teardown \ |
---|
88 | | - "j %l[" __rseq_str(abort_label) "]\n\t" \ |
---|
| 127 | + "jg %l[" __rseq_str(abort_label) "]\n\t" \ |
---|
89 | 128 | ".popsection\n\t" |
---|
90 | 129 | |
---|
91 | 130 | #define RSEQ_ASM_DEFINE_CMPFAIL(label, teardown, cmpfail_label) \ |
---|
92 | 131 | ".pushsection __rseq_failure, \"ax\"\n\t" \ |
---|
93 | 132 | __rseq_str(label) ":\n\t" \ |
---|
94 | 133 | teardown \ |
---|
95 | | - "j %l[" __rseq_str(cmpfail_label) "]\n\t" \ |
---|
| 134 | + "jg %l[" __rseq_str(cmpfail_label) "]\n\t" \ |
---|
96 | 135 | ".popsection\n\t" |
---|
97 | 136 | |
---|
98 | 137 | static inline __attribute__((always_inline)) |
---|
.. | .. |
---|
102 | 141 | |
---|
103 | 142 | __asm__ __volatile__ goto ( |
---|
104 | 143 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 144 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 145 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 146 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 147 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 148 | +#endif |
---|
105 | 149 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
106 | 150 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
107 | 151 | RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
.. | .. |
---|
121 | 165 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
122 | 166 | : /* gcc asm goto does not allow outputs */ |
---|
123 | 167 | : [cpu_id] "r" (cpu), |
---|
124 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
125 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 168 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 169 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
126 | 170 | [v] "m" (*v), |
---|
127 | 171 | [expect] "r" (expect), |
---|
128 | 172 | [newv] "r" (newv) |
---|
.. | .. |
---|
134 | 178 | , error1, error2 |
---|
135 | 179 | #endif |
---|
136 | 180 | ); |
---|
| 181 | + rseq_after_asm_goto(); |
---|
137 | 182 | return 0; |
---|
138 | 183 | abort: |
---|
| 184 | + rseq_after_asm_goto(); |
---|
139 | 185 | RSEQ_INJECT_FAILED |
---|
140 | 186 | return -1; |
---|
141 | 187 | cmpfail: |
---|
| 188 | + rseq_after_asm_goto(); |
---|
142 | 189 | return 1; |
---|
143 | 190 | #ifdef RSEQ_COMPARE_TWICE |
---|
144 | 191 | error1: |
---|
| 192 | + rseq_after_asm_goto(); |
---|
145 | 193 | rseq_bug("cpu_id comparison failed"); |
---|
146 | 194 | error2: |
---|
| 195 | + rseq_after_asm_goto(); |
---|
147 | 196 | rseq_bug("expected value comparison failed"); |
---|
148 | 197 | #endif |
---|
149 | 198 | } |
---|
.. | .. |
---|
154 | 203 | */ |
---|
155 | 204 | static inline __attribute__((always_inline)) |
---|
156 | 205 | int rseq_cmpnev_storeoffp_load(intptr_t *v, intptr_t expectnot, |
---|
157 | | - off_t voffp, intptr_t *load, int cpu) |
---|
| 206 | + long voffp, intptr_t *load, int cpu) |
---|
158 | 207 | { |
---|
159 | 208 | RSEQ_INJECT_C(9) |
---|
160 | 209 | |
---|
161 | 210 | __asm__ __volatile__ goto ( |
---|
162 | 211 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 212 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 213 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 214 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 215 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 216 | +#endif |
---|
163 | 217 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
164 | 218 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
165 | 219 | RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
.. | .. |
---|
184 | 238 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
185 | 239 | : /* gcc asm goto does not allow outputs */ |
---|
186 | 240 | : [cpu_id] "r" (cpu), |
---|
187 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
188 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 241 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 242 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
189 | 243 | /* final store input */ |
---|
190 | 244 | [v] "m" (*v), |
---|
191 | 245 | [expectnot] "r" (expectnot), |
---|
.. | .. |
---|
199 | 253 | , error1, error2 |
---|
200 | 254 | #endif |
---|
201 | 255 | ); |
---|
| 256 | + rseq_after_asm_goto(); |
---|
202 | 257 | return 0; |
---|
203 | 258 | abort: |
---|
| 259 | + rseq_after_asm_goto(); |
---|
204 | 260 | RSEQ_INJECT_FAILED |
---|
205 | 261 | return -1; |
---|
206 | 262 | cmpfail: |
---|
| 263 | + rseq_after_asm_goto(); |
---|
207 | 264 | return 1; |
---|
208 | 265 | #ifdef RSEQ_COMPARE_TWICE |
---|
209 | 266 | error1: |
---|
| 267 | + rseq_after_asm_goto(); |
---|
210 | 268 | rseq_bug("cpu_id comparison failed"); |
---|
211 | 269 | error2: |
---|
| 270 | + rseq_after_asm_goto(); |
---|
212 | 271 | rseq_bug("expected value comparison failed"); |
---|
213 | 272 | #endif |
---|
214 | 273 | } |
---|
.. | .. |
---|
220 | 279 | |
---|
221 | 280 | __asm__ __volatile__ goto ( |
---|
222 | 281 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 282 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 283 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 284 | +#endif |
---|
223 | 285 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
224 | 286 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
225 | 287 | RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
.. | .. |
---|
236 | 298 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
237 | 299 | : /* gcc asm goto does not allow outputs */ |
---|
238 | 300 | : [cpu_id] "r" (cpu), |
---|
239 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
240 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 301 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 302 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
241 | 303 | /* final store input */ |
---|
242 | 304 | [v] "m" (*v), |
---|
243 | 305 | [count] "r" (count) |
---|
.. | .. |
---|
249 | 311 | , error1 |
---|
250 | 312 | #endif |
---|
251 | 313 | ); |
---|
| 314 | + rseq_after_asm_goto(); |
---|
252 | 315 | return 0; |
---|
253 | 316 | abort: |
---|
| 317 | + rseq_after_asm_goto(); |
---|
254 | 318 | RSEQ_INJECT_FAILED |
---|
255 | 319 | return -1; |
---|
256 | 320 | #ifdef RSEQ_COMPARE_TWICE |
---|
257 | 321 | error1: |
---|
| 322 | + rseq_after_asm_goto(); |
---|
258 | 323 | rseq_bug("cpu_id comparison failed"); |
---|
259 | 324 | #endif |
---|
260 | 325 | } |
---|
.. | .. |
---|
268 | 333 | |
---|
269 | 334 | __asm__ __volatile__ goto ( |
---|
270 | 335 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 336 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 337 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 338 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 339 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 340 | +#endif |
---|
271 | 341 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
272 | 342 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
273 | 343 | RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
.. | .. |
---|
290 | 360 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
291 | 361 | : /* gcc asm goto does not allow outputs */ |
---|
292 | 362 | : [cpu_id] "r" (cpu), |
---|
293 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
294 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 363 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 364 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
295 | 365 | /* try store input */ |
---|
296 | 366 | [v2] "m" (*v2), |
---|
297 | 367 | [newv2] "r" (newv2), |
---|
.. | .. |
---|
307 | 377 | , error1, error2 |
---|
308 | 378 | #endif |
---|
309 | 379 | ); |
---|
| 380 | + rseq_after_asm_goto(); |
---|
310 | 381 | return 0; |
---|
311 | 382 | abort: |
---|
| 383 | + rseq_after_asm_goto(); |
---|
312 | 384 | RSEQ_INJECT_FAILED |
---|
313 | 385 | return -1; |
---|
314 | 386 | cmpfail: |
---|
| 387 | + rseq_after_asm_goto(); |
---|
315 | 388 | return 1; |
---|
316 | 389 | #ifdef RSEQ_COMPARE_TWICE |
---|
317 | 390 | error1: |
---|
| 391 | + rseq_after_asm_goto(); |
---|
318 | 392 | rseq_bug("cpu_id comparison failed"); |
---|
319 | 393 | error2: |
---|
| 394 | + rseq_after_asm_goto(); |
---|
320 | 395 | rseq_bug("expected value comparison failed"); |
---|
321 | 396 | #endif |
---|
322 | 397 | } |
---|
.. | .. |
---|
339 | 414 | |
---|
340 | 415 | __asm__ __volatile__ goto ( |
---|
341 | 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]) |
---|
| 421 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error3]) |
---|
| 422 | +#endif |
---|
342 | 423 | /* Start rseq by storing table entry pointer into rseq_cs. */ |
---|
343 | 424 | RSEQ_ASM_STORE_RSEQ_CS(1, 3b, rseq_cs) |
---|
344 | 425 | RSEQ_ASM_CMP_CPU_ID(cpu_id, current_cpu_id, 4f) |
---|
.. | .. |
---|
363 | 444 | RSEQ_ASM_DEFINE_ABORT(4, "", abort) |
---|
364 | 445 | : /* gcc asm goto does not allow outputs */ |
---|
365 | 446 | : [cpu_id] "r" (cpu), |
---|
366 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
367 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 447 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 448 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
368 | 449 | /* cmp2 input */ |
---|
369 | 450 | [v2] "m" (*v2), |
---|
370 | 451 | [expect2] "r" (expect2), |
---|
.. | .. |
---|
380 | 461 | , error1, error2, error3 |
---|
381 | 462 | #endif |
---|
382 | 463 | ); |
---|
| 464 | + rseq_after_asm_goto(); |
---|
383 | 465 | return 0; |
---|
384 | 466 | abort: |
---|
| 467 | + rseq_after_asm_goto(); |
---|
385 | 468 | RSEQ_INJECT_FAILED |
---|
386 | 469 | return -1; |
---|
387 | 470 | cmpfail: |
---|
| 471 | + rseq_after_asm_goto(); |
---|
388 | 472 | return 1; |
---|
389 | 473 | #ifdef RSEQ_COMPARE_TWICE |
---|
390 | 474 | error1: |
---|
| 475 | + rseq_after_asm_goto(); |
---|
391 | 476 | rseq_bug("cpu_id comparison failed"); |
---|
392 | 477 | error2: |
---|
| 478 | + rseq_after_asm_goto(); |
---|
393 | 479 | rseq_bug("1st expected value comparison failed"); |
---|
394 | 480 | error3: |
---|
| 481 | + rseq_after_asm_goto(); |
---|
395 | 482 | rseq_bug("2nd expected value comparison failed"); |
---|
396 | 483 | #endif |
---|
397 | 484 | } |
---|
.. | .. |
---|
407 | 494 | |
---|
408 | 495 | __asm__ __volatile__ goto ( |
---|
409 | 496 | RSEQ_ASM_DEFINE_TABLE(3, 1f, 2f, 4f) /* start, commit, abort */ |
---|
| 497 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[cmpfail]) |
---|
| 498 | +#ifdef RSEQ_COMPARE_TWICE |
---|
| 499 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error1]) |
---|
| 500 | + RSEQ_ASM_DEFINE_EXIT_POINT(1f, %l[error2]) |
---|
| 501 | +#endif |
---|
410 | 502 | LONG_S " %[src], %[rseq_scratch0]\n\t" |
---|
411 | 503 | LONG_S " %[dst], %[rseq_scratch1]\n\t" |
---|
412 | 504 | LONG_S " %[len], %[rseq_scratch2]\n\t" |
---|
.. | .. |
---|
466 | 558 | #endif |
---|
467 | 559 | : /* gcc asm goto does not allow outputs */ |
---|
468 | 560 | : [cpu_id] "r" (cpu), |
---|
469 | | - [current_cpu_id] "m" (__rseq_abi.cpu_id), |
---|
470 | | - [rseq_cs] "m" (__rseq_abi.rseq_cs), |
---|
| 561 | + [current_cpu_id] "m" (rseq_get_abi()->cpu_id), |
---|
| 562 | + [rseq_cs] "m" (rseq_get_abi()->rseq_cs.arch.ptr), |
---|
471 | 563 | /* final store input */ |
---|
472 | 564 | [v] "m" (*v), |
---|
473 | 565 | [expect] "r" (expect), |
---|
.. | .. |
---|
487 | 579 | , error1, error2 |
---|
488 | 580 | #endif |
---|
489 | 581 | ); |
---|
| 582 | + rseq_after_asm_goto(); |
---|
490 | 583 | return 0; |
---|
491 | 584 | abort: |
---|
| 585 | + rseq_after_asm_goto(); |
---|
492 | 586 | RSEQ_INJECT_FAILED |
---|
493 | 587 | return -1; |
---|
494 | 588 | cmpfail: |
---|
| 589 | + rseq_after_asm_goto(); |
---|
495 | 590 | return 1; |
---|
496 | 591 | #ifdef RSEQ_COMPARE_TWICE |
---|
497 | 592 | error1: |
---|
| 593 | + rseq_after_asm_goto(); |
---|
498 | 594 | rseq_bug("cpu_id comparison failed"); |
---|
499 | 595 | error2: |
---|
| 596 | + rseq_after_asm_goto(); |
---|
500 | 597 | rseq_bug("expected value comparison failed"); |
---|
501 | 598 | #endif |
---|
502 | 599 | } |
---|