Skip to content

Commit 6e32036

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Use larch_insn_gen_break() for kprobes
For now, we can use larch_insn_gen_break() to define KPROBE_BP_INSN and KPROBE_SSTEPBP_INSN. Because larch_insn_gen_break() returns instruction word, define kprobe_opcode_t as u32, then do some small changes related with type conversion, no functional change intended. Tested-by: Jeff Xie <[email protected]> Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 49ed320 commit 6e32036

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

arch/loongarch/include/asm/kprobes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ do { \
2222

2323
#define kretprobe_blacklist_size 0
2424

25-
typedef union loongarch_instruction kprobe_opcode_t;
25+
typedef u32 kprobe_opcode_t;
2626

2727
/* Architecture specific copy of original instruction */
2828
struct arch_specific_insn {

arch/loongarch/kernel/kprobes.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,16 @@
44
#include <linux/preempt.h>
55
#include <asm/break.h>
66

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)
209

2110
DEFINE_PER_CPU(struct kprobe *, current_kprobe);
2211
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
2312

2413
static void arch_prepare_ss_slot(struct kprobe *p)
2514
{
2615
p->ainsn.insn[0] = *p->addr;
27-
p->ainsn.insn[1] = singlestep_insn;
16+
p->ainsn.insn[1] = KPROBE_SSTEPBP_INSN;
2817
p->ainsn.restore = (unsigned long)p->addr + LOONGARCH_INSN_SIZE;
2918
}
3019
NOKPROBE_SYMBOL(arch_prepare_ss_slot);
@@ -37,17 +26,20 @@ NOKPROBE_SYMBOL(arch_prepare_simulate);
3726

3827
int arch_prepare_kprobe(struct kprobe *p)
3928
{
29+
union loongarch_instruction insn;
30+
4031
if ((unsigned long)p->addr & 0x3)
4132
return -EILSEQ;
4233

4334
/* copy instruction */
4435
p->opcode = *p->addr;
36+
insn.word = p->opcode;
4537

4638
/* decode instruction */
47-
if (insns_not_supported(p->opcode))
39+
if (insns_not_supported(insn))
4840
return -EINVAL;
4941

50-
if (insns_need_simulation(p->opcode)) {
42+
if (insns_need_simulation(insn)) {
5143
p->ainsn.insn = NULL;
5244
} else {
5345
p->ainsn.insn = get_insn_slot();
@@ -68,7 +60,7 @@ NOKPROBE_SYMBOL(arch_prepare_kprobe);
6860
/* Install breakpoint in text */
6961
void arch_arm_kprobe(struct kprobe *p)
7062
{
71-
*p->addr = breakpoint_insn;
63+
*p->addr = KPROBE_BP_INSN;
7264
flush_insn_slot(p);
7365
}
7466
NOKPROBE_SYMBOL(arch_arm_kprobe);
@@ -163,6 +155,8 @@ NOKPROBE_SYMBOL(post_kprobe_handler);
163155
static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
164156
struct kprobe_ctlblk *kcb, int reenter)
165157
{
158+
union loongarch_instruction insn;
159+
166160
if (reenter) {
167161
save_previous_kprobe(kcb);
168162
set_current_kprobe(p);
@@ -178,7 +172,8 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
178172
regs->csr_era = (unsigned long)p->ainsn.insn;
179173
} else {
180174
/* simulate single steping */
181-
arch_simulate_insn(p->opcode, regs);
175+
insn.word = p->opcode;
176+
arch_simulate_insn(insn, regs);
182177
/* now go for post processing */
183178
post_kprobe_handler(p, kcb, regs);
184179
}
@@ -253,7 +248,7 @@ bool kprobe_breakpoint_handler(struct pt_regs *regs)
253248
}
254249
}
255250

256-
if (addr->word != breakpoint_insn.word) {
251+
if (*addr != KPROBE_BP_INSN) {
257252
/*
258253
* The breakpoint instruction was removed right
259254
* after we hit it. Another cpu has removed

0 commit comments

Comments
 (0)