public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Arapov <anton@redhat.com>
To: Anton Arapov <anton@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Josh Stone <jistone@redhat.com>, Frank Eigler <fche@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Subject: [RFC PATCH v3 5/6] uretprobes: invoke return probe handlers
Date: Thu, 28 Feb 2013 12:00:14 +0100	[thread overview]
Message-ID: <1362049215-5780-6-git-send-email-anton@redhat.com> (raw)
In-Reply-To: <1362049215-5780-1-git-send-email-anton@redhat.com>

  Uretprobe handlers are invoked when the trampoline is hit, on completion the
trampoline is replaced with the saved return address and the uretprobe instance
deleted.

v3:
 - protected uprobe with refcounter. See put_uprobe() in handle_uretprobe()
that reflects increment in prepare_uretprobe()
v2:
 - get rid of ->return_consumers member from struct uprobe, introduce
rp_handler() in consumer instead

Signed-off-by: Anton Arapov <anton@redhat.com>
---
 arch/x86/include/asm/uprobes.h |  5 +++++
 kernel/events/uprobes.c        | 50 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/uprobes.h b/arch/x86/include/asm/uprobes.h
index c353555..fa9d9de 100644
--- a/arch/x86/include/asm/uprobes.h
+++ b/arch/x86/include/asm/uprobes.h
@@ -56,4 +56,9 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
 extern int  arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long rp_trampoline_vaddr, struct pt_regs *regs);
+
+static inline unsigned long arch_uretprobe_get_sp(struct pt_regs *regs)
+{
+	return (unsigned long)regs->sp;
+}
 #endif	/* _ASM_UPROBES_H */
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 57f70cd..deacb35 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1561,6 +1561,52 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
 	up_read(&uprobe->register_rwsem);
 }
 
+static void handler_uretprobe_chain(struct uprobe *uprobe, struct pt_regs *regs)
+{
+	struct uprobe_consumer *uc;
+
+	down_read(&uprobe->register_rwsem);
+	for (uc = uprobe->consumers; uc; uc = uc->next) {
+		if (uc->rp_handler)
+			uc->rp_handler(uc, regs);
+	}
+	up_read(&uprobe->register_rwsem);
+}
+
+static void handle_uretprobe(struct pt_regs *regs)
+{
+	struct hlist_head *head;
+	struct hlist_node *tmp;
+	struct xol_area *area;
+	struct return_uprobe_i *ri;
+	struct uprobe_task *utask;
+
+	/* TODO: uretprobe bypass logic */
+
+	area = get_xol_area();
+	utask = get_utask();
+	head = &utask->return_uprobes;
+	hlist_for_each_entry_safe(ri, tmp, head, hlist) {
+		if (ri->uprobe->consumers) {
+			instruction_pointer_set(regs, ri->orig_ret_vaddr);
+			handler_uretprobe_chain(ri->uprobe, regs);
+		}
+
+		put_uprobe(ri->uprobe);
+		hlist_del(&ri->hlist);
+		kfree(ri);
+
+		if (ri->orig_ret_vaddr != area->rp_trampoline_vaddr)
+			return;
+	}
+
+	/* TODO: change the message */
+	printk(KERN_ERR "uprobe: no instance found! pid/tgid=%d/%d",
+			current->pid, current->tgid);
+	/* TODO: May be sigtrap? if possible to restore utask */
+	send_sig(SIGSEGV, current, 0);
+}
+
 /*
  * Run handler and ask thread to singlestep.
  * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
@@ -1576,8 +1622,8 @@ static void handle_swbp(struct pt_regs *regs)
 
 	if (!uprobe) {
 		if (is_swbp > 0) {
-			/* No matching uprobe; signal SIGTRAP. */
-			send_sig(SIGTRAP, current, 0);
+			/* No matching uprobe; Try with uretprobe */
+			handle_uretprobe(regs);
 		} else {
 			/*
 			 * Either we raced with uprobe_unregister() or we can't
-- 
1.8.1.2


  parent reply	other threads:[~2013-02-28 11:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-28 11:00 [RFC PATCH v3 0/6] uprobes: return probe implementation Anton Arapov
2013-02-28 11:00 ` [RFC PATCH v3 1/6] uretprobes: preparation patch Anton Arapov
2013-02-28 11:00 ` [RFC PATCH v3 2/6] uretprobes/x86: hijack return address Anton Arapov
2013-03-01  5:45   ` Ananth N Mavinakayanahalli
2013-03-01 11:00     ` Anton Arapov
2013-03-01 11:21       ` Ananth N Mavinakayanahalli
2013-02-28 11:00 ` [RFC PATCH v3 3/6] uretprobes: generalize xol_get_insn_slot() Anton Arapov
2013-02-28 20:01   ` Oleg Nesterov
2013-02-28 11:00 ` [RFC PATCH v3 4/6] uretprobes: return probe entry, prepare uretprobe Anton Arapov
2013-02-28 20:10   ` Oleg Nesterov
2013-03-04 14:14     ` Anton Arapov
2013-03-02 18:26   ` Oleg Nesterov
2013-03-03 16:40   ` Oleg Nesterov
2013-03-04 10:49     ` Anton Arapov
2013-02-28 11:00 ` Anton Arapov [this message]
2013-03-02 18:09   ` [RFC PATCH v3 5/6] uretprobes: invoke return probe handlers Oleg Nesterov
2013-02-28 11:00 ` [RFC PATCH v3 6/6] uretprobes: implemented, thus remove -ENOSYS Anton Arapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362049215-5780-6-git-send-email-anton@redhat.com \
    --to=anton@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=fche@redhat.com \
    --cc=jistone@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox