This source file includes following definitions.
- tm_poison_test
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #define _GNU_SOURCE
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <inttypes.h>
20 #include <sched.h>
21 #include <sys/types.h>
22 #include <signal.h>
23 #include <inttypes.h>
24
25 #include "tm.h"
26
27 int tm_poison_test(void)
28 {
29 int pid;
30 cpu_set_t cpuset;
31 uint64_t poison = 0xdeadbeefc0dec0fe;
32 uint64_t unknown = 0;
33 bool fail_fp = false;
34 bool fail_vr = false;
35
36 SKIP_IF(!have_htm());
37
38
39 CPU_ZERO(&cpuset);
40 CPU_SET(0, &cpuset);
41 sched_setaffinity(0, sizeof(cpuset), &cpuset);
42
43 pid = fork();
44 if (!pid) {
45
46
47
48 while (1) {
49 sched_yield();
50 asm (
51 "mtvsrd 31, %[poison];"
52 "mtvsrd 63, %[poison];"
53
54 : : [poison] "r" (poison) : );
55 }
56 }
57
58
59
60
61 asm (
62
63
64
65
66 " li 3, 0x1 ;"
67 " li 4, 0x1 ;"
68 " mtvsrd 31, 4 ;"
69
70
71
72
73
74
75
76
77
78
79
80
81
82 " lis 5, 14 ;"
83 " ori 5, 5, 19996 ;"
84 " sldi 5, 5, 16 ;"
85
86 " mfspr 6, 268 ;"
87 "1: mfspr 7, 268 ;"
88 " subf 7, 6, 7 ;"
89 " cmpd 7, 5 ;"
90 " bgt 3f ;"
91
92
93
94
95 " tbegin. ;"
96 " beq 1b ;"
97 " mfvsrd 3, 31 ;"
98 " cmpd 3, 4 ;"
99 " bne 2f ;"
100 " tabort. 3 ;"
101 "2: tend. ;"
102 "3: mr %[unknown], 3 ;"
103
104 : [unknown] "=r" (unknown)
105 :
106 : "cr0", "r3", "r4", "r5", "r6", "r7", "vs31"
107
108 );
109
110
111
112
113
114
115 fail_fp = unknown != 0x1;
116 if (fail_fp)
117 printf("Unknown value %#"PRIx64" leaked into f31!\n", unknown);
118 else
119 printf("Good, no poison or leaked value into FP registers\n");
120
121 asm (
122
123
124
125
126 " li 3, 0x1 ;"
127 " li 4, 0x1 ;"
128 " mtvsrd 63, 4 ;"
129
130 " lis 5, 14 ;"
131 " ori 5, 5, 19996 ;"
132 " sldi 5, 5, 16 ;"
133
134 " mfspr 6, 268 ;"
135 "1: mfspr 7, 268 ;"
136 " subf 7, 6, 7 ;"
137 " cmpd 7, 5 ;"
138 " bgt 3f ;"
139
140
141
142
143 " tbegin. ;"
144 " beq 1b ;"
145 " mfvsrd 3, 63 ;"
146 " cmpd 3, 4 ;"
147 " bne 2f ;"
148 " tabort. 3 ;"
149 "2: tend. ;"
150 "3: mr %[unknown], 3 ;"
151
152 : [unknown] "=r" (unknown)
153 :
154 : "cr0", "r3", "r4", "r5", "r6", "r7", "vs63"
155
156 );
157
158
159
160
161
162
163 fail_vr = unknown != 0x1;
164 if (fail_vr)
165 printf("Unknown value %#"PRIx64" leaked into vr31!\n", unknown);
166 else
167 printf("Good, no poison or leaked value into VEC registers\n");
168
169 kill(pid, SIGKILL);
170
171 return (fail_fp | fail_vr);
172 }
173
174 int main(int argc, char *argv[])
175 {
176
177 test_harness_set_timeout(250);
178 return test_harness(tm_poison_test, "tm_poison_test");
179 }