public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ingo Molnar <mingo@elte.hu>,
	Peter Zijlstra <peterz@infradead.org>,
	Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
	Anton Arapov <anton@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/7] uprobes: introduce find_active_uprobe() helper
Date: Tue, 29 May 2012 21:28:57 +0200	[thread overview]
Message-ID: <20120529192857.GC8057@redhat.com> (raw)
In-Reply-To: <20120529192721.GA8048@redhat.com>

No functional changes. Move the "find uprobe" code from
handle_swbp() to the new helper, find_active_uprobe().

Note: with or without this change, the find-active-uprobe logic
is not exactly right. We can race with another thread which unmaps
the memory with the valid uprobe before we take mm->mmap_sem. We
can't find this uprobe simply because find_vma() fails. In this
case we wrongly assume that this trap was not caused by uprobe
and send the erroneous SIGTRAP. See the next changes.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/events/uprobes.c |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index a0dbc87..eaf4d55 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1489,38 +1489,47 @@ static bool can_skip_sstep(struct uprobe *uprobe, struct pt_regs *regs)
 	return false;
 }
 
-/*
- * Run handler and ask thread to singlestep.
- * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
- */
-static void handle_swbp(struct pt_regs *regs)
+static struct uprobe *find_active_uprobe(unsigned long bp_vaddr)
 {
+	struct mm_struct *mm = current->mm;
+	struct uprobe *uprobe = NULL;
 	struct vm_area_struct *vma;
-	struct uprobe_task *utask;
-	struct uprobe *uprobe;
-	struct mm_struct *mm;
-	unsigned long bp_vaddr;
 
-	uprobe = NULL;
-	bp_vaddr = uprobe_get_swbp_addr(regs);
-	mm = current->mm;
 	down_read(&mm->mmap_sem);
 	vma = find_vma(mm, bp_vaddr);
 
-	if (vma && vma->vm_start <= bp_vaddr && valid_vma(vma, false)) {
-		struct inode *inode;
-		loff_t offset;
+	if (vma && vma->vm_start <= bp_vaddr) {
+		if (valid_vma(vma, false)) {
+			struct inode *inode;
+			loff_t offset;
 
-		inode = vma->vm_file->f_mapping->host;
-		offset = bp_vaddr - vma->vm_start;
-		offset += (vma->vm_pgoff << PAGE_SHIFT);
-		uprobe = find_uprobe(inode, offset);
+			inode = vma->vm_file->f_mapping->host;
+			offset = bp_vaddr - vma->vm_start;
+			offset += (vma->vm_pgoff << PAGE_SHIFT);
+			uprobe = find_uprobe(inode, offset);
+		}
 	}
 
 	srcu_read_unlock_raw(&uprobes_srcu, current->uprobe_srcu_id);
 	current->uprobe_srcu_id = -1;
 	up_read(&mm->mmap_sem);
 
+	return uprobe;
+}
+
+/*
+ * Run handler and ask thread to singlestep.
+ * Ensure all non-fatal signals cannot interrupt thread while it singlesteps.
+ */
+static void handle_swbp(struct pt_regs *regs)
+{
+	struct uprobe_task *utask;
+	struct uprobe *uprobe;
+	unsigned long bp_vaddr;
+
+	bp_vaddr = uprobe_get_swbp_addr(regs);
+	uprobe = find_active_uprobe(bp_vaddr);
+
 	if (!uprobe) {
 		/* No matching uprobe; signal SIGTRAP. */
 		send_sig(SIGTRAP, current, 0);
-- 
1.5.5.1



  parent reply	other threads:[~2012-05-29 19:30 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 19:27 [PATCH 0/7] uprobes: kill uprobes_srcu/uprobe_srcu_id Oleg Nesterov
2012-05-29 19:27 ` [PATCH 1/7] uprobes: optimize is_swbp_at_addr() for current->mm Oleg Nesterov
2012-06-06 15:08   ` [tip:perf/core] uprobes: Optimize is_swbp_at_addr() for current-%3Emm tip-bot for Oleg Nesterov
2012-06-06 16:05   ` [tip:perf/core] uprobes: Optimize is_swbp_at_addr() for current-> mm tip-bot for Oleg Nesterov
2012-05-29 19:27 ` [PATCH 2/7] uprobes: change read_opcode() to use FOLL_FORCE Oleg Nesterov
2012-06-06 15:09   ` [tip:perf/core] uprobes: Change " tip-bot for Oleg Nesterov
2012-06-06 16:06   ` tip-bot for Oleg Nesterov
2012-05-29 19:28 ` Oleg Nesterov [this message]
2012-06-06 15:10   ` [tip:perf/core] uprobes: Introduce find_active_uprobe() helper tip-bot for Oleg Nesterov
2012-06-06 16:07   ` tip-bot for Oleg Nesterov
2012-05-29 19:29 ` [PATCH 4/7] uprobes: teach find_active_uprobe() to provide the "is_swbp" info Oleg Nesterov
2012-06-06 15:10   ` [tip:perf/core] uprobes: Teach find_active_uprobe() to provide the %22is_swbp%22 info tip-bot for Oleg Nesterov
2012-06-06 16:08   ` [tip:perf/core] uprobes: Teach find_active_uprobe() to provide the "is_swbp" info tip-bot for Oleg Nesterov
2012-05-29 19:29 ` [PATCH 5/7] uprobes: change register_for_each_vma() to take mm->mmap_sem for writing Oleg Nesterov
2012-06-06 15:11   ` [tip:perf/core] uprobes: Change register_for_each_vma() to take mm-%3Emmap_sem " tip-bot for Oleg Nesterov
2012-06-06 16:09   ` [tip:perf/core] uprobes: Change register_for_each_vma() to take mm->mmap_sem " tip-bot for Oleg Nesterov
2012-05-29 19:29 ` [PATCH 6/7] uprobes: teach handle_swbp() to rely on "is_swbp" rather than uprobes_srcu Oleg Nesterov
2012-06-06 15:12   ` [tip:perf/core] uprobes: Teach handle_swbp() to rely on %22is_swbp%22 " tip-bot for Oleg Nesterov
2012-06-06 16:10   ` [tip:perf/core] uprobes: Teach handle_swbp() to rely on "is_swbp" " tip-bot for Oleg Nesterov
2012-05-29 19:30 ` [PATCH 7/7] uprobes: kill uprobes_srcu/uprobe_srcu_id Oleg Nesterov
2012-05-29 23:04   ` Peter Zijlstra
2012-05-30  1:51     ` Paul E. McKenney
2012-06-06 15:13   ` [tip:perf/core] uprobes: Kill uprobes_srcu/uprobe_srcu_id tip-bot for Oleg Nesterov
2012-06-06 16:10   ` tip-bot for Oleg Nesterov
2012-05-31  5:40 ` [PATCH 0/7] uprobes: kill uprobes_srcu/uprobe_srcu_id Srikar Dronamraju

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=20120529192857.GC8057@redhat.com \
    --to=oleg@redhat.com \
    --cc=ananth@in.ibm.com \
    --cc=anton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=torvalds@linux-foundation.org \
    /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