* [PATCH 2/2] x86: add reenter_kprobe helper
@ 2007-12-18 23:19 Masami Hiramatsu
2007-12-19 10:21 ` Ingo Molnar
0 siblings, 1 reply; 2+ messages in thread
From: Masami Hiramatsu @ 2007-12-18 23:19 UTC (permalink / raw)
To: Ananth N Mavinakayanahalli, Jim Keniston, Ingo Molnar,
Harvey Harrison
Cc: Roland McGrath, Arjan van de Ven, prasanna, anil.s.keshavamurthy,
davem, systemtap-ml, LKML
Kprobe reenter logic from deeply indented section to helper function.
This improves code readability.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
---
Harvey, I picked up your patch and enhanced it.
I think this idea is good for improving readability.
arch/x86/kernel/kprobes.c | 68 +++++++++++++++++++++++-----------------------
1 file changed, 35 insertions(+), 33 deletions(-)
Index: b/arch/x86/kernel/kprobes.c
===================================================================
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -427,6 +427,38 @@ void __kprobes arch_prepare_kretprobe(st
/* Replace the return addr with trampoline addr */
*sara = (unsigned long) &kretprobe_trampoline;
}
+/*
+ * We have reentered the kprobe_handler(), since another probe was hit while
+ * within the handler. We save the original kprobes variables and just single
+ * step on the instruction of the new probe without calling any user handlers.
+ */
+static int __kprobes reenter_kprobe(struct kprobe *p, struct pt_regs *regs,
+ struct kprobe_ctlblk *kcb)
+{
+ if (kcb->kprobe_status == KPROBE_HIT_SS &&
+ *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
+ regs->flags &= ~X86_EFLAGS_TF;
+ regs->flags |= kcb->kprobe_saved_flags;
+ return 0;
+#ifdef CONFIG_X86_64
+ } else if (kcb->kprobe_status == KPROBE_HIT_SSDONE) {
+ /* TODO: Provide re-entrancy from post_kprobes_handler() and
+ * avoid exception stack corruption while single-stepping on
+ * the instruction of the new probe.
+ */
+ arch_disarm_kprobe(p);
+ regs->ip = (unsigned long)p->addr;
+ reset_current_kprobe();
+ return 1;
+#endif
+ }
+ save_previous_kprobe(kcb);
+ set_current_kprobe(p, regs, kcb);
+ kprobes_inc_nmissed_count(p);
+ prepare_singlestep(p, regs);
+ kcb->kprobe_status = KPROBE_REENTER;
+ return 1;
+}
/*
* Interrupts are disabled on entry as trap3 is an interrupt gate and they
@@ -451,39 +483,9 @@ static int __kprobes kprobe_handler(stru
/* Check we're not actually recursing */
if (kprobe_running()) {
p = get_kprobe(addr);
- if (p) {
- if (kcb->kprobe_status == KPROBE_HIT_SS &&
- *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
- regs->flags &= ~X86_EFLAGS_TF;
- regs->flags |= kcb->kprobe_saved_flags;
- goto no_kprobe;
-#ifdef CONFIG_X86_64
- } else if (kcb->kprobe_status == KPROBE_HIT_SSDONE) {
- /* TODO: Provide re-entrancy from
- * post_kprobes_handler() and avoid exception
- * stack corruption while single-stepping on
- * the instruction of the new probe.
- */
- arch_disarm_kprobe(p);
- regs->ip = (unsigned long)p->addr;
- reset_current_kprobe();
- ret = 1;
- goto no_kprobe;
-#endif
- }
- /* We have reentered the kprobe_handler(), since
- * another probe was hit while within the handler.
- * We here save the original kprobes variables and
- * just single step on the instruction of the new probe
- * without calling any user handlers.
- */
- save_previous_kprobe(kcb);
- set_current_kprobe(p, regs, kcb);
- kprobes_inc_nmissed_count(p);
- prepare_singlestep(p, regs);
- kcb->kprobe_status = KPROBE_REENTER;
- ret = 1;
- } else {
+ if (p)
+ ret = reenter_kprobe(p, regs, kcb);
+ else {
if (*addr != BREAKPOINT_INSTRUCTION) {
/* The breakpoint instruction was removed by
* another cpu right after we hit, no further
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com, masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] x86: add reenter_kprobe helper
2007-12-18 23:19 [PATCH 2/2] x86: add reenter_kprobe helper Masami Hiramatsu
@ 2007-12-19 10:21 ` Ingo Molnar
0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2007-12-19 10:21 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Ananth N Mavinakayanahalli, Jim Keniston, Harvey Harrison,
Roland McGrath, Arjan van de Ven, prasanna, anil.s.keshavamurthy,
davem, systemtap-ml, LKML
* Masami Hiramatsu <mhiramat@redhat.com> wrote:
> Kprobe reenter logic from deeply indented section to helper function.
> This improves code readability.
ok, this has dependencies on the previous fix, so i'll wait for a
revised version of that.
Ingo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-12-19 10:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-18 23:19 [PATCH 2/2] x86: add reenter_kprobe helper Masami Hiramatsu
2007-12-19 10:21 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox