From: Dave Anderson <anderson@redhat.com> Date: Wed, 23 Jan 2008 15:18:30 -0500 Subject: [misc] kprobes: make probe handler stack unwind correct Message-id: 4797A116.7080601@redhat.com O-Subject: [RHEL5.2 PATCH 1/4] kprobes: BZ #232489: need kprobes improvement patches Bugzilla: 232489 BZ #232489: need kprobes improvement patches https://bugzilla.redhat.com/show_bug.cgi?id=232489 linux-2.6.git-3661999a17b0397c7a93c200b280c55958ba3593 Backport of this ia64-specific commit: commit 3661999a17b0397c7a93c200b280c55958ba3593 Author: Shaohua Li <shaohua.li@intel.com> Date: Tue Nov 13 14:55:20 2007 +0800 [IA64] kprobe: make kreturn probe handler stack unwind correct Restore regs->ccr_iip before kreturn probe handler runs. In this way, if probe handler does unwind, unwind can correctly get the stack trace. Fixes: http://sourceware.org/bugzilla/show_bug.cgi?id=5051 Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com> Tested on ia64 by: Masami Hiramatsu (mhiramat@redhat.com) diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c index 5fcfc6c..4f87e63 100644 --- a/arch/ia64/kernel/kprobes.c +++ b/arch/ia64/kernel/kprobes.c @@ -359,6 +359,23 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) /* another task is sharing our hash bucket */ continue; + orig_ret_address = (unsigned long)ri->ret_addr; + if (orig_ret_address != trampoline_address) + /* + * This is the real return address. Any other + * instances associated with this task are for + * other calls deeper on the call stack + */ + break; + } + + regs->cr_iip = orig_ret_address; + + hlist_for_each_entry_safe(ri, node, tmp, head, hlist) { + if (ri->task != current) + /* another task is sharing our hash bucket */ + continue; + if (ri->rp && ri->rp->handler) ri->rp->handler(ri, regs); @@ -375,7 +392,6 @@ int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs) } BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address)); - regs->cr_iip = orig_ret_address; reset_current_kprobe(); spin_unlock_irqrestore(&kretprobe_lock, flags);