hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-vmx.c
....@@ -1,19 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * 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
- *
94 *
105 * Test the kernel's signal frame code.
116 *
127 * 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).
1410 * 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).
1713 *
1814 * The rationale for this is that if TM unaware code (which linked
1915 * against TM libs) installs a signal handler it will not know of the
....@@ -34,18 +30,24 @@
3430
3531 #define MAX_ATTEMPT 500000
3632
37
-#define NV_VMX_REGS 12
33
+#define NV_VMX_REGS 12 /* Number of non-volatile VMX registers */
34
+#define VMX20 20 /* First non-volatile register to check in vr20-31 subset */
3835
3936 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
4037
41
-static sig_atomic_t fail;
38
+static sig_atomic_t fail, broken;
4239
40
+/* Test only non-volatile registers, i.e. 12 vmx registers from vr20 to vr31 */
4341 vector int vms[] = {
44
- {1, 2, 3, 4 },{5, 6, 7, 8 },{9, 10,11,12},
42
+ /* First context will be set with these values, i.e. non-speculative */
43
+ /* VMX20 , VMX21 , ... */
44
+ { 1, 2, 3, 4},{ 5, 6, 7, 8},{ 9,10,11,12},
4545 {13,14,15,16},{17,18,19,20},{21,22,23,24},
4646 {25,26,27,28},{29,30,31,32},{33,34,35,36},
4747 {37,38,39,40},{41,42,43,44},{45,46,47,48},
48
- {-1, -2, -3, -4}, {-5, -6, -7, -8}, {-9, -10,-11,-12},
48
+ /* Second context will be set with these values, i.e. speculative */
49
+ /* VMX20 , VMX21 , ... */
50
+ { -1, -2, -3, -4},{ -5, -6, -7, -8},{ -9,-10,-11,-12},
4951 {-13,-14,-15,-16},{-17,-18,-19,-20},{-21,-22,-23,-24},
5052 {-25,-26,-27,-28},{-29,-30,-31,-32},{-33,-34,-35,-36},
5153 {-37,-38,-39,-40},{-41,-42,-43,-44},{-45,-46,-47,-48}
....@@ -53,26 +55,43 @@
5355
5456 static void signal_usr1(int signum, siginfo_t *info, void *uc)
5557 {
56
- int i;
58
+ int i, j;
5759 ucontext_t *ucp = uc;
5860 ucontext_t *tm_ucp = ucp->uc_link;
5961
60
- for (i = 0; i < NV_VMX_REGS && !fail; i++) {
61
- fail = memcmp(ucp->uc_mcontext.v_regs->vrregs[i + 20],
62
+ for (i = 0; i < NV_VMX_REGS; i++) {
63
+ /* Check first context. Print all mismatches. */
64
+ fail = memcmp(ucp->uc_mcontext.v_regs->vrregs[VMX20 + i],
6265 &vms[i], sizeof(vector int));
63
- fail |= memcmp(tm_ucp->uc_mcontext.v_regs->vrregs[i + 20],
64
- &vms[i + NV_VMX_REGS], sizeof (vector int));
65
-
6666 if (fail) {
67
- int j;
68
-
69
- fprintf(stderr, "Failed on %d vmx 0x", i);
67
+ broken = 1;
68
+ printf("VMX%d (1st context) == 0x", VMX20 + i);
69
+ /* Print actual value in first context. */
7070 for (j = 0; j < 4; j++)
71
- fprintf(stderr, "%04x", ucp->uc_mcontext.v_regs->vrregs[i + 20][j]);
72
- fprintf(stderr, " vs 0x");
73
- for (j = 0 ; j < 4; j++)
74
- fprintf(stderr, "%04x", tm_ucp->uc_mcontext.v_regs->vrregs[i + 20][j]);
75
- fprintf(stderr, "\n");
71
+ printf("%08x", ucp->uc_mcontext.v_regs->vrregs[VMX20 + i][j]);
72
+ printf(" instead of 0x");
73
+ /* Print expected value. */
74
+ for (j = 0; j < 4; j++)
75
+ printf("%08x", vms[i][j]);
76
+ printf(" (expected)\n");
77
+ }
78
+ }
79
+
80
+ for (i = 0; i < NV_VMX_REGS; i++) {
81
+ /* Check second context. Print all mismatches. */
82
+ fail = memcmp(tm_ucp->uc_mcontext.v_regs->vrregs[VMX20 + i],
83
+ &vms[NV_VMX_REGS + i], sizeof (vector int));
84
+ if (fail) {
85
+ broken = 1;
86
+ printf("VMX%d (2nd context) == 0x", NV_VMX_REGS + i);
87
+ /* Print actual value in second context. */
88
+ for (j = 0; j < 4; j++)
89
+ printf("%08x", tm_ucp->uc_mcontext.v_regs->vrregs[VMX20 + i][j]);
90
+ printf(" instead of 0x");
91
+ /* Print expected value. */
92
+ for (j = 0; j < 4; j++)
93
+ printf("%08x", vms[NV_VMX_REGS + i][j]);
94
+ printf(" (expected)\n");
7695 }
7796 }
7897 }
....@@ -95,13 +114,19 @@
95114 }
96115
97116 i = 0;
98
- while (i < MAX_ATTEMPT && !fail) {
117
+ while (i < MAX_ATTEMPT && !broken) {
118
+ /*
119
+ * tm_signal_self_context_load will set both first and second
120
+ * contexts accordingly to the values passed through non-NULL
121
+ * array pointers to it, in that case 'vms', and invoke the
122
+ * signal handler installed for SIGUSR1.
123
+ */
99124 rc = tm_signal_self_context_load(pid, NULL, NULL, vms, NULL);
100125 FAIL_IF(rc != pid);
101126 i++;
102127 }
103128
104
- return fail;
129
+ return (broken);
105130 }
106131
107132 int main(void)