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 6/7] uprobes: teach handle_swbp() to rely on "is_swbp" rather than uprobes_srcu
Date: Tue, 29 May 2012 21:29:47 +0200	[thread overview]
Message-ID: <20120529192947.GF8057@redhat.com> (raw)
In-Reply-To: <20120529192721.GA8048@redhat.com>

Currently handle_swbp() assumes that it can't race with unregister,
so it roughly does:

	if (find_uprobe(vaddr))
		process_uprobe();
	else
		send_sig(SIGTRAP);

This relies on the not-really-working uprobes_srcu code we are going
to remove, see the next patch.

With this patch we rely on the result of is_swbp_at_addr(bp_vaddr)
if find_uprobe() fails.

If is_swbp == 1, then we hit the normal int3, we should send SIGTRAP.

If is_swbp == 0, we raced with uprobe_unregister(), we simply restart
this insn again.

The "difficult" case is is_swbp == -EFAULT, when we can't read this
memory. In this case I think we should restart too, and this is more
correct compared to the current code which sends SIGTRAP.

Ignoring ENOMEM/etc from get_user_pages(), this can only happen if
another thread unmaps this memory before find_active_uprobe() takes
mmap_sem. It would be better to pretend it was unmapped before this
insn was executed, restart, and get SIGSEGV.

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

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index a2ed82b..1f02e3b 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1530,14 +1530,26 @@ static void handle_swbp(struct pt_regs *regs)
 	struct uprobe_task *utask;
 	struct uprobe *uprobe;
 	unsigned long bp_vaddr;
-	int is_swbp;
+	int uninitialized_var(is_swbp);
 
 	bp_vaddr = uprobe_get_swbp_addr(regs);
 	uprobe = find_active_uprobe(bp_vaddr, &is_swbp);
 
 	if (!uprobe) {
-		/* No matching uprobe; signal SIGTRAP. */
-		send_sig(SIGTRAP, current, 0);
+		if (is_swbp > 0) {
+			/* No matching uprobe; signal SIGTRAP. */
+			send_sig(SIGTRAP, current, 0);
+		} else {
+			/*
+			 * Either we raced with uprobe_unregister() or we can't
+			 * access this memory. The latter is only possible if
+			 * another thread plays with our ->mm. In both cases
+			 * we can simply restart. If this vma was unmapped we
+			 * can pretend this insn was not executed yet and get
+			 * the (correct) SIGSEGV after restart.
+			 */
+			instruction_pointer_set(regs, bp_vaddr);
+		}
 		return;
 	}
 
-- 
1.5.5.1



  parent reply	other threads:[~2012-05-29 19:32 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 ` [PATCH 3/7] uprobes: introduce find_active_uprobe() helper Oleg Nesterov
2012-06-06 15:10   ` [tip:perf/core] uprobes: Introduce " 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 ` Oleg Nesterov [this message]
2012-06-06 15:12   ` [tip:perf/core] uprobes: Teach handle_swbp() to rely on %22is_swbp%22 rather than uprobes_srcu 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=20120529192947.GF8057@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