| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright 2016, Cyril Bur, IBM Corp. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or |
|---|
| 5 | | - * modify it under the terms of the GNU General Public License |
|---|
| 6 | | - * as published by the Free Software Foundation; either version |
|---|
| 7 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | 4 | * |
|---|
| 10 | 5 | * Test the kernel's signal frame code. |
|---|
| 11 | 6 | * |
|---|
| 12 | 7 | * The kernel sets up two sets of ucontexts if the signal was to be |
|---|
| 13 | | - * delivered while the thread was in a transaction. |
|---|
| 8 | + * delivered while the thread was in a transaction (referred too as |
|---|
| 9 | + * first and second contexts). |
|---|
| 14 | 10 | * Expected behaviour is that the checkpointed state is in the user |
|---|
| 15 | | - * context passed to the signal handler. The speculated state can be |
|---|
| 16 | | - * accessed with the uc_link pointer. |
|---|
| 11 | + * context passed to the signal handler (first context). The speculated |
|---|
| 12 | + * state can be accessed with the uc_link pointer (second context). |
|---|
| 17 | 13 | * |
|---|
| 18 | 14 | * The rationale for this is that if TM unaware code (which linked |
|---|
| 19 | 15 | * against TM libs) installs a signal handler it will not know of the |
|---|
| .. | .. |
|---|
| 33 | 29 | |
|---|
| 34 | 30 | #define MAX_ATTEMPT 500000 |
|---|
| 35 | 31 | |
|---|
| 36 | | -#define NV_GPR_REGS 18 |
|---|
| 32 | +#define NV_GPR_REGS 18 /* Number of non-volatile GPR registers */ |
|---|
| 33 | +#define R14 14 /* First non-volatile register to check in r14-r31 subset */ |
|---|
| 37 | 34 | |
|---|
| 38 | 35 | long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss); |
|---|
| 39 | 36 | |
|---|
| 40 | | -static sig_atomic_t fail; |
|---|
| 37 | +static sig_atomic_t fail, broken; |
|---|
| 41 | 38 | |
|---|
| 42 | | -static long gps[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
|---|
| 43 | | - -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18}; |
|---|
| 39 | +/* Test only non-volatile general purpose registers, i.e. r14-r31 */ |
|---|
| 40 | +static long gprs[] = { |
|---|
| 41 | + /* First context will be set with these values, i.e. non-speculative */ |
|---|
| 42 | + /* R14, R15, ... */ |
|---|
| 43 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
|---|
| 44 | + /* Second context will be set with these values, i.e. speculative */ |
|---|
| 45 | + /* R14, R15, ... */ |
|---|
| 46 | + -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18 |
|---|
| 47 | +}; |
|---|
| 44 | 48 | |
|---|
| 45 | 49 | static void signal_usr1(int signum, siginfo_t *info, void *uc) |
|---|
| 46 | 50 | { |
|---|
| .. | .. |
|---|
| 48 | 52 | ucontext_t *ucp = uc; |
|---|
| 49 | 53 | ucontext_t *tm_ucp = ucp->uc_link; |
|---|
| 50 | 54 | |
|---|
| 51 | | - for (i = 0; i < NV_GPR_REGS && !fail; i++) { |
|---|
| 52 | | - fail = (ucp->uc_mcontext.gp_regs[i + 14] != gps[i]); |
|---|
| 53 | | - fail |= (tm_ucp->uc_mcontext.gp_regs[i + 14] != gps[i + NV_GPR_REGS]); |
|---|
| 54 | | - if (fail) |
|---|
| 55 | | - printf("Failed on %d GPR %lu or %lu\n", i, |
|---|
| 56 | | - ucp->uc_mcontext.gp_regs[i + 14], tm_ucp->uc_mcontext.gp_regs[i + 14]); |
|---|
| 55 | + /* Check first context. Print all mismatches. */ |
|---|
| 56 | + for (i = 0; i < NV_GPR_REGS; i++) { |
|---|
| 57 | + fail = (ucp->uc_mcontext.gp_regs[R14 + i] != gprs[i]); |
|---|
| 58 | + if (fail) { |
|---|
| 59 | + broken = 1; |
|---|
| 60 | + printf("GPR%d (1st context) == %lu instead of %lu (expected)\n", |
|---|
| 61 | + R14 + i, ucp->uc_mcontext.gp_regs[R14 + i], gprs[i]); |
|---|
| 62 | + } |
|---|
| 63 | + } |
|---|
| 64 | + |
|---|
| 65 | + /* Check second context. Print all mismatches. */ |
|---|
| 66 | + for (i = 0; i < NV_GPR_REGS; i++) { |
|---|
| 67 | + fail = (tm_ucp->uc_mcontext.gp_regs[R14 + i] != gprs[NV_GPR_REGS + i]); |
|---|
| 68 | + if (fail) { |
|---|
| 69 | + broken = 1; |
|---|
| 70 | + printf("GPR%d (2nd context) == %lu instead of %lu (expected)\n", |
|---|
| 71 | + R14 + i, tm_ucp->uc_mcontext.gp_regs[R14 + i], gprs[NV_GPR_REGS + i]); |
|---|
| 72 | + } |
|---|
| 57 | 73 | } |
|---|
| 58 | 74 | } |
|---|
| 59 | 75 | |
|---|
| .. | .. |
|---|
| 75 | 91 | } |
|---|
| 76 | 92 | |
|---|
| 77 | 93 | i = 0; |
|---|
| 78 | | - while (i < MAX_ATTEMPT && !fail) { |
|---|
| 79 | | - rc = tm_signal_self_context_load(pid, gps, NULL, NULL, NULL); |
|---|
| 94 | + while (i < MAX_ATTEMPT && !broken) { |
|---|
| 95 | + /* |
|---|
| 96 | + * tm_signal_self_context_load will set both first and second |
|---|
| 97 | + * contexts accordingly to the values passed through non-NULL |
|---|
| 98 | + * array pointers to it, in that case 'gprs', and invoke the |
|---|
| 99 | + * signal handler installed for SIGUSR1. |
|---|
| 100 | + */ |
|---|
| 101 | + rc = tm_signal_self_context_load(pid, gprs, NULL, NULL, NULL); |
|---|
| 80 | 102 | FAIL_IF(rc != pid); |
|---|
| 81 | 103 | i++; |
|---|
| 82 | 104 | } |
|---|
| 83 | 105 | |
|---|
| 84 | | - return fail; |
|---|
| 106 | + return broken; |
|---|
| 85 | 107 | } |
|---|
| 86 | 108 | |
|---|
| 87 | 109 | int main(void) |
|---|