-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tbegin_pr.c
154 lines (130 loc) · 3.36 KB
/
test_tbegin_pr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* test tbegin at privileged state:
* It is for PR KVM test and need to run at PR KVM guest.
* Here we verfiy the behavior that tbegin is always failed at PR KVM guest, and
* return with expected SPR TM reg vals.
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kthread.h>
#include <asm/reg.h>
#include <asm/tm.h>
#include <asm/asm-prototypes.h>
#define SPRN_TEXASR 0x82 /* Transaction Exception and Status Register */
#define SPRN_TFIAR 0x81 /* Transaction Failure Inst Addr */
#define SPRN_TFHAR 0x80 /* Transaction Failure Handler Addr */
#define PPC_INST_TBEGIN 0x7c00051d
#define __PPC_TB_ROT(rot) (((rot) & 0x1) << 21)
#define PPC_TBEGIN(rot) stringify_in_c(.long PPC_INST_TBEGIN | \
__PPC_TB_ROT(rot))
#define LOOP_CNT 100
MODULE_LICENSE("GPL");
struct task_struct *kthread_task;
static void print_tm_sprs(unsigned long texasr, unsigned long tfiar,
unsigned long tfhar, unsigned long tbegin_pc,
unsigned long msr) {
printk(KERN_EMERG "texasr[%lx],tfiar[%lx],tfhar[%lx],tbg_pc[%lx],msr[%lx]",
texasr, tfiar, tfhar, tbegin_pc, msr);
}
int test_tbegin(void) {
unsigned long texasr = 0xdeadbeaf, tfiar = 0xdeadbeaf, tfhar = 0xdeadbeaf, msr= 0xdeadbeaf, tbegin_pc = 0xdeadbeaf;
int result = 0;
tm_enable();
asm __volatile__(
"mfmsr %[msr];"
"mflr 6;"
"bl 1f;"
"1: ;"
"mflr %[tbegin_pc];"
"mtlr 6;"
"2: ;"
PPC_TBEGIN(1) ";"
"beq 3f;"
"tend.;"
"li 0, 0;"
"ori %[res], 0, 0;"
"b 4f;"
/* Transaction abort handler */
"3: ;"
"li 0, 1;"
"ori %[res], 0, 0;"
"mfspr %[texasr], %[sprn_texasr];"
"mfspr %[tfiar], %[sprn_tfiar];"
"mfspr %[tfhar], %[sprn_tfhar];"
"4: ;"
"addi %[tbegin_pc], %[tbegin_pc], 8;"
: [res] "=r" (result), [texasr] "=&r" (texasr), [tfiar] "=r" (tfiar),
[tfhar] "=r" (tfhar), [msr] "=r" (msr), [tbegin_pc] "=r" (tbegin_pc)
: [sprn_texasr] "i" (SPRN_TEXASR), [sprn_tfiar] "i" (SPRN_TFIAR), [sprn_tfhar] "i" (SPRN_TFHAR)
: "memory", "r6");
tm_disable();
if (!result)
return -1;
/* check texasr value */
if (!(texasr & TEXASR_EX)) {
result = -2;
goto out;
}
if (!(texasr & TEXASR_FS)) {
result = -3;
goto out;
}
if (!!(texasr & TEXASR_PR) != !!(msr & MSR_PR)) {
result = -4;
goto out;
}
if (!!(texasr & TEXASR_HV) != !!(msr & MSR_HV)) {
result = -5;
goto out;
}
if (((texasr & TEXASR_FC) >> TEXASR_FC_LG) != (TM_CAUSE_EMULATE | TM_CAUSE_PERSISTENT)) {
result = -6;
goto out;
}
/* check tfiar value */
if (tfiar != tbegin_pc) {
result = -7;
goto out;
}
if (tfhar != tbegin_pc + 4) {
result = -8;
goto out;
}
if (!(texasr & TEXASR_ROT)) {
result = -9;
goto out;
}
out:
if (result < 0) {
print_tm_sprs(texasr, tfiar, tfhar, tbegin_pc, msr);
return result;
}
return 0;
}
int test_tbegin_thread_func(void *data)
{
int i, res;
for (i = 0; i < LOOP_CNT; i++) {
if ((i % 50) == 0)
schedule();
if ((res = test_tbegin()) != 0)
break;
}
if (i == LOOP_CNT)
printk(KERN_EMERG "test_tbegin success!\n");
else
printk(KERN_EMERG "test_tbegin failed at %d attempt, res=%d!\n", i, res);
return 0;
}
static int __init test_tbegin_init(void)
{
int ret = 0;
kthread_task = kthread_run(test_tbegin_thread_func, NULL, "test_tbegin");
return ret;
}
module_init(test_tbegin_init);
static void __exit test_tbegin_exit(void)
{
return;
}
module_exit(test_tbegin_exit);