Skip to content

Commit 3d2c3da

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Move three functions from kprobes.c to inst.c
The three functions insns_not_supported(), insns_need_simulation() and arch_simulate_insn() will be used for uprobes, move them from kprobes.c to inst.c, this is preparation for later patch, no functionality change. Tested-by: Jeff Xie <[email protected]> Signed-off-by: Tiezhu Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 7b0a096 commit 3d2c3da

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

arch/loongarch/include/asm/inst.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ static inline bool is_self_loop_ins(union loongarch_instruction *ip, struct pt_r
444444
void simu_pc(struct pt_regs *regs, union loongarch_instruction insn);
445445
void simu_branch(struct pt_regs *regs, union loongarch_instruction insn);
446446

447+
bool insns_not_supported(union loongarch_instruction insn);
448+
bool insns_need_simulation(union loongarch_instruction insn);
449+
void arch_simulate_insn(union loongarch_instruction insn, struct pt_regs *regs);
450+
447451
int larch_insn_read(void *addr, u32 *insnp);
448452
int larch_insn_write(void *addr, u32 insn);
449453
int larch_insn_patch_text(void *addr, u32 insn);

arch/loongarch/kernel/inst.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,45 @@ void simu_branch(struct pt_regs *regs, union loongarch_instruction insn)
133133
}
134134
}
135135

136+
bool insns_not_supported(union loongarch_instruction insn)
137+
{
138+
switch (insn.reg2i14_format.opcode) {
139+
case llw_op:
140+
case lld_op:
141+
case scw_op:
142+
case scd_op:
143+
pr_notice("ll and sc instructions are not supported\n");
144+
return true;
145+
}
146+
147+
switch (insn.reg1i21_format.opcode) {
148+
case bceqz_op:
149+
pr_notice("bceqz and bcnez instructions are not supported\n");
150+
return true;
151+
}
152+
153+
return false;
154+
}
155+
156+
bool insns_need_simulation(union loongarch_instruction insn)
157+
{
158+
if (is_pc_ins(&insn))
159+
return true;
160+
161+
if (is_branch_ins(&insn))
162+
return true;
163+
164+
return false;
165+
}
166+
167+
void arch_simulate_insn(union loongarch_instruction insn, struct pt_regs *regs)
168+
{
169+
if (is_pc_ins(&insn))
170+
simu_pc(regs, insn);
171+
else if (is_branch_ins(&insn))
172+
simu_branch(regs, insn);
173+
}
174+
136175
int larch_insn_read(void *addr, u32 *insnp)
137176
{
138177
int ret;

arch/loongarch/kernel/kprobes.c

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,6 @@ static const union loongarch_instruction singlestep_insn = {
2121
DEFINE_PER_CPU(struct kprobe *, current_kprobe);
2222
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
2323

24-
static bool insns_not_supported(union loongarch_instruction insn)
25-
{
26-
switch (insn.reg2i14_format.opcode) {
27-
case llw_op:
28-
case lld_op:
29-
case scw_op:
30-
case scd_op:
31-
pr_notice("kprobe: ll and sc instructions are not supported\n");
32-
return true;
33-
}
34-
35-
switch (insn.reg1i21_format.opcode) {
36-
case bceqz_op:
37-
pr_notice("kprobe: bceqz and bcnez instructions are not supported\n");
38-
return true;
39-
}
40-
41-
return false;
42-
}
43-
NOKPROBE_SYMBOL(insns_not_supported);
44-
45-
static bool insns_need_simulation(struct kprobe *p)
46-
{
47-
if (is_pc_ins(&p->opcode))
48-
return true;
49-
50-
if (is_branch_ins(&p->opcode))
51-
return true;
52-
53-
return false;
54-
}
55-
NOKPROBE_SYMBOL(insns_need_simulation);
56-
57-
static void arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
58-
{
59-
if (is_pc_ins(&p->opcode))
60-
simu_pc(regs, p->opcode);
61-
else if (is_branch_ins(&p->opcode))
62-
simu_branch(regs, p->opcode);
63-
}
64-
NOKPROBE_SYMBOL(arch_simulate_insn);
65-
6624
static void arch_prepare_ss_slot(struct kprobe *p)
6725
{
6826
p->ainsn.insn[0] = *p->addr;
@@ -89,7 +47,7 @@ int arch_prepare_kprobe(struct kprobe *p)
8947
if (insns_not_supported(p->opcode))
9048
return -EINVAL;
9149

92-
if (insns_need_simulation(p)) {
50+
if (insns_need_simulation(p->opcode)) {
9351
p->ainsn.insn = NULL;
9452
} else {
9553
p->ainsn.insn = get_insn_slot();
@@ -220,7 +178,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
220178
regs->csr_era = (unsigned long)p->ainsn.insn;
221179
} else {
222180
/* simulate single steping */
223-
arch_simulate_insn(p, regs);
181+
arch_simulate_insn(p->opcode, regs);
224182
/* now go for post processing */
225183
post_kprobe_handler(p, kcb, regs);
226184
}

0 commit comments

Comments
 (0)