4
4
#include <linux/preempt.h>
5
5
#include <asm/break.h>
6
6
7
- static const union loongarch_instruction breakpoint_insn = {
8
- .reg0i15_format = {
9
- .opcode = break_op ,
10
- .immediate = BRK_KPROBE_BP ,
11
- }
12
- };
13
-
14
- static const union loongarch_instruction singlestep_insn = {
15
- .reg0i15_format = {
16
- .opcode = break_op ,
17
- .immediate = BRK_KPROBE_SSTEPBP ,
18
- }
19
- };
7
+ #define KPROBE_BP_INSN larch_insn_gen_break(BRK_KPROBE_BP)
8
+ #define KPROBE_SSTEPBP_INSN larch_insn_gen_break(BRK_KPROBE_SSTEPBP)
20
9
21
10
DEFINE_PER_CPU (struct kprobe * , current_kprobe );
22
11
DEFINE_PER_CPU (struct kprobe_ctlblk , kprobe_ctlblk );
23
12
24
13
static void arch_prepare_ss_slot (struct kprobe * p )
25
14
{
26
15
p -> ainsn .insn [0 ] = * p -> addr ;
27
- p -> ainsn .insn [1 ] = singlestep_insn ;
16
+ p -> ainsn .insn [1 ] = KPROBE_SSTEPBP_INSN ;
28
17
p -> ainsn .restore = (unsigned long )p -> addr + LOONGARCH_INSN_SIZE ;
29
18
}
30
19
NOKPROBE_SYMBOL (arch_prepare_ss_slot );
@@ -37,17 +26,20 @@ NOKPROBE_SYMBOL(arch_prepare_simulate);
37
26
38
27
int arch_prepare_kprobe (struct kprobe * p )
39
28
{
29
+ union loongarch_instruction insn ;
30
+
40
31
if ((unsigned long )p -> addr & 0x3 )
41
32
return - EILSEQ ;
42
33
43
34
/* copy instruction */
44
35
p -> opcode = * p -> addr ;
36
+ insn .word = p -> opcode ;
45
37
46
38
/* decode instruction */
47
- if (insns_not_supported (p -> opcode ))
39
+ if (insns_not_supported (insn ))
48
40
return - EINVAL ;
49
41
50
- if (insns_need_simulation (p -> opcode )) {
42
+ if (insns_need_simulation (insn )) {
51
43
p -> ainsn .insn = NULL ;
52
44
} else {
53
45
p -> ainsn .insn = get_insn_slot ();
@@ -68,7 +60,7 @@ NOKPROBE_SYMBOL(arch_prepare_kprobe);
68
60
/* Install breakpoint in text */
69
61
void arch_arm_kprobe (struct kprobe * p )
70
62
{
71
- * p -> addr = breakpoint_insn ;
63
+ * p -> addr = KPROBE_BP_INSN ;
72
64
flush_insn_slot (p );
73
65
}
74
66
NOKPROBE_SYMBOL (arch_arm_kprobe );
@@ -163,6 +155,8 @@ NOKPROBE_SYMBOL(post_kprobe_handler);
163
155
static void setup_singlestep (struct kprobe * p , struct pt_regs * regs ,
164
156
struct kprobe_ctlblk * kcb , int reenter )
165
157
{
158
+ union loongarch_instruction insn ;
159
+
166
160
if (reenter ) {
167
161
save_previous_kprobe (kcb );
168
162
set_current_kprobe (p );
@@ -178,7 +172,8 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
178
172
regs -> csr_era = (unsigned long )p -> ainsn .insn ;
179
173
} else {
180
174
/* simulate single steping */
181
- arch_simulate_insn (p -> opcode , regs );
175
+ insn .word = p -> opcode ;
176
+ arch_simulate_insn (insn , regs );
182
177
/* now go for post processing */
183
178
post_kprobe_handler (p , kcb , regs );
184
179
}
@@ -253,7 +248,7 @@ bool kprobe_breakpoint_handler(struct pt_regs *regs)
253
248
}
254
249
}
255
250
256
- if (addr -> word != breakpoint_insn . word ) {
251
+ if (* addr != KPROBE_BP_INSN ) {
257
252
/*
258
253
* The breakpoint instruction was removed right
259
254
* after we hit it. Another cpu has removed
0 commit comments