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 5/7] uprobes: change register_for_each_vma() to take mm->mmap_sem for writing
Date: Tue, 29 May 2012 21:29:28 +0200 [thread overview]
Message-ID: <20120529192928.GE8057@redhat.com> (raw)
In-Reply-To: <20120529192721.GA8048@redhat.com>
Change register_for_each_vma() to take mm->mmap_sem for writing.
This is a bit unfortunate but hopefully not too bad, this is the
slow path anyway.
This is needed to ensure that find_active_uprobe() can not race
with uprobe_register() which adds the new bp at the same bp_vaddr,
after find_uprobe() fails and before is_swbp_at_addr_fast() checks
the memory.
IOW, this is needed to ensure that if find_active_uprobe() returns
NULL but is_swbp == true, we can safely assume that it was the
"normal" int3 and we should send SIGTRAP.
There is another reason for this change. We are going to replace
uprobes_state->count with MMF_ flags set by register/unregister
and cleared by find_active_uprobe(), and set/clear shouldn't race
with each other.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/events/uprobes.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index ee3df70..a2ed82b 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -853,12 +853,12 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
}
mm = vi->mm;
- down_read(&mm->mmap_sem);
+ down_write(&mm->mmap_sem);
vma = find_vma(mm, (unsigned long)vi->vaddr);
if (!vma || !valid_vma(vma, is_register)) {
list_del(&vi->probe_list);
kfree(vi);
- up_read(&mm->mmap_sem);
+ up_write(&mm->mmap_sem);
mmput(mm);
continue;
}
@@ -867,7 +867,7 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
vaddr != vi->vaddr) {
list_del(&vi->probe_list);
kfree(vi);
- up_read(&mm->mmap_sem);
+ up_write(&mm->mmap_sem);
mmput(mm);
continue;
}
@@ -877,7 +877,7 @@ static int register_for_each_vma(struct uprobe *uprobe, bool is_register)
else
remove_breakpoint(uprobe, mm, vi->vaddr);
- up_read(&mm->mmap_sem);
+ up_write(&mm->mmap_sem);
mmput(mm);
if (is_register) {
if (ret && ret == -EEXIST)
--
1.5.5.1
next prev parent reply other threads:[~2012-05-29 19:33 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 ` Oleg Nesterov [this message]
2012-06-06 15:11 ` [tip:perf/core] uprobes: Change register_for_each_vma() to take mm-%3Emmap_sem for writing 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=20120529192928.GE8057@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