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 <mhiramat@kernel.org> Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Acked-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20201103134900.337243-2-jean-philippe@linaro.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
This commit is contained in:
Родитель
f8394f232b
Коммит
ba090f9caf
|
@ -28,18 +28,11 @@ struct prev_kprobe {
|
||||||
unsigned int status;
|
unsigned int status;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Single step context for kprobe */
|
|
||||||
struct kprobe_step_ctx {
|
|
||||||
unsigned long ss_pending;
|
|
||||||
unsigned long match_addr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* per-cpu kprobe control block */
|
/* per-cpu kprobe control block */
|
||||||
struct kprobe_ctlblk {
|
struct kprobe_ctlblk {
|
||||||
unsigned int kprobe_status;
|
unsigned int kprobe_status;
|
||||||
unsigned long saved_irqflag;
|
unsigned long saved_irqflag;
|
||||||
struct prev_kprobe prev_kprobe;
|
struct prev_kprobe prev_kprobe;
|
||||||
struct kprobe_step_ctx ss_ctx;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void arch_remove_kprobe(struct kprobe *);
|
void arch_remove_kprobe(struct kprobe *);
|
||||||
|
|
|
@ -34,7 +34,7 @@ DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
|
||||||
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
|
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
|
||||||
|
|
||||||
static void __kprobes
|
static void __kprobes
|
||||||
post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *);
|
post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
|
||||||
|
|
||||||
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
|
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
|
||||||
p->ainsn.api.handler((u32)p->opcode, (long)p->addr, regs);
|
p->ainsn.api.handler((u32)p->opcode, (long)p->addr, regs);
|
||||||
|
|
||||||
/* single step simulated, now go for post processing */
|
/* single step simulated, now go for post processing */
|
||||||
post_kprobe_handler(kcb, regs);
|
post_kprobe_handler(p, kcb, regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int __kprobes arch_prepare_kprobe(struct kprobe *p)
|
int __kprobes arch_prepare_kprobe(struct kprobe *p)
|
||||||
|
@ -177,19 +177,6 @@ static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb,
|
||||||
regs->pstate |= kcb->saved_irqflag;
|
regs->pstate |= kcb->saved_irqflag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes
|
|
||||||
set_ss_context(struct kprobe_ctlblk *kcb, unsigned long addr)
|
|
||||||
{
|
|
||||||
kcb->ss_ctx.ss_pending = true;
|
|
||||||
kcb->ss_ctx.match_addr = addr + sizeof(kprobe_opcode_t);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __kprobes clear_ss_context(struct kprobe_ctlblk *kcb)
|
|
||||||
{
|
|
||||||
kcb->ss_ctx.ss_pending = false;
|
|
||||||
kcb->ss_ctx.match_addr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __kprobes setup_singlestep(struct kprobe *p,
|
static void __kprobes setup_singlestep(struct kprobe *p,
|
||||||
struct pt_regs *regs,
|
struct pt_regs *regs,
|
||||||
struct kprobe_ctlblk *kcb, int reenter)
|
struct kprobe_ctlblk *kcb, int reenter)
|
||||||
|
@ -209,7 +196,6 @@ static void __kprobes setup_singlestep(struct kprobe *p,
|
||||||
/* prepare for single stepping */
|
/* prepare for single stepping */
|
||||||
slot = (unsigned long)p->ainsn.api.insn;
|
slot = (unsigned long)p->ainsn.api.insn;
|
||||||
|
|
||||||
set_ss_context(kcb, slot); /* mark pending ss */
|
|
||||||
kprobes_save_local_irqflag(kcb, regs);
|
kprobes_save_local_irqflag(kcb, regs);
|
||||||
instruction_pointer_set(regs, slot);
|
instruction_pointer_set(regs, slot);
|
||||||
} else {
|
} else {
|
||||||
|
@ -243,13 +229,8 @@ static int __kprobes reenter_kprobe(struct kprobe *p,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __kprobes
|
static void __kprobes
|
||||||
post_kprobe_handler(struct kprobe_ctlblk *kcb, struct pt_regs *regs)
|
post_kprobe_handler(struct kprobe *cur, struct kprobe_ctlblk *kcb, struct pt_regs *regs)
|
||||||
{
|
{
|
||||||
struct kprobe *cur = kprobe_running();
|
|
||||||
|
|
||||||
if (!cur)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* return addr restore if non-branching insn */
|
/* return addr restore if non-branching insn */
|
||||||
if (cur->ainsn.api.restore != 0)
|
if (cur->ainsn.api.restore != 0)
|
||||||
instruction_pointer_set(regs, cur->ainsn.api.restore);
|
instruction_pointer_set(regs, cur->ainsn.api.restore);
|
||||||
|
@ -364,33 +345,23 @@ static void __kprobes kprobe_handler(struct pt_regs *regs)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __kprobes
|
|
||||||
kprobe_ss_hit(struct kprobe_ctlblk *kcb, unsigned long addr)
|
|
||||||
{
|
|
||||||
if ((kcb->ss_ctx.ss_pending)
|
|
||||||
&& (kcb->ss_ctx.match_addr == addr)) {
|
|
||||||
clear_ss_context(kcb); /* clear pending ss */
|
|
||||||
return DBG_HOOK_HANDLED;
|
|
||||||
}
|
|
||||||
/* not ours, kprobes should ignore it */
|
|
||||||
return DBG_HOOK_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __kprobes
|
static int __kprobes
|
||||||
kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned int esr)
|
kprobe_breakpoint_ss_handler(struct pt_regs *regs, unsigned int esr)
|
||||||
{
|
{
|
||||||
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
|
||||||
int retval;
|
unsigned long addr = instruction_pointer(regs);
|
||||||
|
struct kprobe *cur = kprobe_running();
|
||||||
|
|
||||||
/* return error if this is not our step */
|
if (cur && (kcb->kprobe_status == KPROBE_HIT_SS)
|
||||||
retval = kprobe_ss_hit(kcb, instruction_pointer(regs));
|
&& ((unsigned long)&cur->ainsn.api.insn[1] == addr)) {
|
||||||
|
|
||||||
if (retval == DBG_HOOK_HANDLED) {
|
|
||||||
kprobes_restore_local_irqflag(kcb, regs);
|
kprobes_restore_local_irqflag(kcb, regs);
|
||||||
post_kprobe_handler(kcb, regs);
|
post_kprobe_handler(cur, kcb, regs);
|
||||||
|
|
||||||
|
return DBG_HOOK_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
/* not ours, kprobes should ignore it */
|
||||||
|
return DBG_HOOK_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct break_hook kprobes_break_ss_hook = {
|
static struct break_hook kprobes_break_ss_hook = {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче