Skip to content

Commit ba090f9

Browse files
mhiramatctmarinas
authored andcommitted
arm64: kprobes: Remove redundant kprobe_step_ctx
The kprobe_step_ctx (kcb->ss_ctx) has ss_pending and match_addr, but those are redundant because those can be replaced by KPROBE_HIT_SS and &cur_kprobe->ainsn.api.insn[1] respectively. To simplify the code, remove the kprobe_step_ctx. Signed-off-by: Masami Hiramatsu <[email protected]> Reviewed-by: Jean-Philippe Brucker <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent f8394f2 commit ba090f9

File tree

2 files changed

+12
-48
lines changed

2 files changed

+12
-48
lines changed

arch/arm64/include/asm/kprobes.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@ struct prev_kprobe {
2828
unsigned int status;
2929
};
3030

31-
/* Single step context for kprobe */
32-
struct kprobe_step_ctx {
33-
unsigned long ss_pending;
34-
unsigned long match_addr;
35-
};
36-
3731
/* per-cpu kprobe control block */
3832
struct kprobe_ctlblk {
3933
unsigned int kprobe_status;
4034
unsigned long saved_irqflag;
4135
struct prev_kprobe prev_kprobe;
42-
struct kprobe_step_ctx ss_ctx;
4336
};
4437

4538
void arch_remove_kprobe(struct kprobe *);

arch/arm64/kernel/probes/kprobes.c

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
3434
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
3535

3636
static void __kprobes
37-
post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
37+
post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
3838

3939
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
4040
{
@@ -68,7 +68,7 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
6868
p->ainsn.api.handler((u32)p->opcode, (long)p->addr, regs);
6969

7070
/* single step simulated, now go for post processing */
71-
post_kprobe_handler(kcb, regs);
71+
post_kprobe_handler(p, kcb, regs);
7272
}
7373

7474
int __kprobes arch_prepare_kprobe(struct kprobe *p)
@@ -177,19 +177,6 @@ static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb,
177177
regs->pstate |= kcb->saved_irqflag;
178178
}
179179

180-
static void __kprobes
181-
set_ss_context(struct kprobe_ctlblk *kcb, unsigned long addr)
182-
{
183-
kcb->ss_ctx.ss_pending = true;
184-
kcb->ss_ctx.match_addr = addr + sizeof(kprobe_opcode_t);
185-
}
186-
187-
static void __kprobes clear_ss_context(struct kprobe_ctlblk *kcb)
188-
{
189-
kcb->ss_ctx.ss_pending = false;
190-
kcb->ss_ctx.match_addr = 0;
191-
}
192-
193180
static void __kprobes setup_singlestep(struct kprobe *p,
194181
struct pt_regs *regs,
195182
struct kprobe_ctlblk *kcb, int reenter)
@@ -209,7 +196,6 @@ static void __kprobes setup_singlestep(struct kprobe *p,
209196
/* prepare for single stepping */
210197
slot = (unsigned long)p->ainsn.api.insn;
211198

212-
set_ss_context(kcb, slot); /* mark pending ss */
213199
kprobes_save_local_irqflag(kcb, regs);
214200
instruction_pointer_set(regs, slot);
215201
} else {
@@ -243,13 +229,8 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
243229
}
244230

245231
static void __kprobes
246-
post_kprobe_handler(struct kprobe_ctlblk *kcb, struct pt_regs *regs)
232+
post_kprobe_handler(struct kprobe *cur, struct kprobe_ctlblk *kcb, struct pt_regs *regs)
247233
{
248-
struct kprobe *cur = kprobe_running();
249-
250-
if (!cur)
251-
return;
252-
253234
/* return addr restore if non-branching insn */
254235
if (cur->ainsn.api.restore != 0)
255236
instruction_pointer_set(regs, cur->ainsn.api.restore);
@@ -364,33 +345,23 @@ static void __kprobes kprobe_handler(struct pt_regs *regs)
364345
*/
365346
}
366347

367-
static int __kprobes
368-
kprobe_ss_hit(struct kprobe_ctlblk *kcb, unsigned long addr)
369-
{
370-
if ((kcb->ss_ctx.ss_pending)
371-
&& (kcb->ss_ctx.match_addr == addr)) {
372-
clear_ss_context(kcb); /* clear pending ss */
373-
return DBG_HOOK_HANDLED;
374-
}
375-
/* not ours, kprobes should ignore it */
376-
return DBG_HOOK_ERROR;
377-
}
378-
379348
static int __kprobes
380349
kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned int esr)
381350
{
382351
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
383-
int retval;
384-
385-
/* return error if this is not our step */
386-
retval = kprobe_ss_hit(kcb, instruction_pointer(regs));
352+
unsigned long addr = instruction_pointer(regs);
353+
struct kprobe *cur = kprobe_running();
387354

388-
if (retval == DBG_HOOK_HANDLED) {
355+
if (cur && (kcb->kprobe_status == KPROBE_HIT_SS)
356+
&& ((unsigned long)&cur->ainsn.api.insn[1] == addr)) {
389357
kprobes_restore_local_irqflag(kcb, regs);
390-
post_kprobe_handler(kcb, regs);
358+
post_kprobe_handler(cur, kcb, regs);
359+
360+
return DBG_HOOK_HANDLED;
391361
}
392362

393-
return retval;
363+
/* not ours, kprobes should ignore it */
364+
return DBG_HOOK_ERROR;
394365
}
395366

396367
static struct break_hook kprobes_break_ss_hook = {

0 commit comments

Comments
 (0)