forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-gpr.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
....@@ -33,14 +29,22 @@
3329
3430 #define MAX_ATTEMPT 500000
3531
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 */
3734
3835 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
3936
40
-static sig_atomic_t fail;
37
+static sig_atomic_t fail, broken;
4138
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
+};
4448
4549 static void signal_usr1(int signum, siginfo_t *info, void *uc)
4650 {
....@@ -48,12 +52,24 @@
4852 ucontext_t *ucp = uc;
4953 ucontext_t *tm_ucp = ucp->uc_link;
5054
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
+ }
5773 }
5874 }
5975
....@@ -75,13 +91,19 @@
7591 }
7692
7793 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);
80102 FAIL_IF(rc != pid);
81103 i++;
82104 }
83105
84
- return fail;
106
+ return broken;
85107 }
86108
87109 int main(void)