diff options
author | Oleg Nesterov <oleg@redhat.com> | 2012-05-29 15:29:14 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-06-06 11:15:24 -0400 |
commit | d790d34653ab20c74034902f5f0889bba807949a (patch) | |
tree | 05d475d4e0f22a2ae0815c77eff5fbe2665d8fd8 /kernel/events | |
parent | 3a9ea0520f38def4a3915b91f82455b749f07d88 (diff) |
uprobes: Teach find_active_uprobe() to provide the "is_swbp" info
A separate patch to simplify the review, and for the
documentation.
The patch adds another "int *is_swbp" argument to
find_active_uprobe(), so far its only caller doesn't use this
info.
With this patch find_active_uprobe() additionally does:
- if find_vma() + ->vm_start check fails, *is_swbp = -EFAULT
- otherwise, if valid_vma() + find_uprobe() fails, it holds
the result of is_swbp_at_addr(), can be negative too. The
latter is only possible if we raced with another thread
which did munmap/etc after we hit this bp.
IOW. If find_active_uprobe(&is_swbp) returns NULL, the caller
can look at is_swbp to figure out whether the current insn is bp
or not, or detect the race with another thread if it is
negative.
Note: I think that performance-wise this change is fine. This
adds is_swbp_at_addr(), but only if we raced with
uprobe_unregister() or if we hit the "normal" int3 but this mm
has uprobes as well. And even in this case the slow
read_opcode() path is very unlikely, this insn recently
triggered do_int3(), __copy_from_user_inatomic() shouldn't fail
in the likely case.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anton Arapov <anton@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120529192914.GD8057@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/events')
-rw-r--r-- | kernel/events/uprobes.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index eaf4d55fd42..ee3df704e78 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
@@ -1489,7 +1489,7 @@ static bool can_skip_sstep(struct uprobe *uprobe, struct pt_regs *regs) | |||
1489 | return false; | 1489 | return false; |
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | static struct uprobe *find_active_uprobe(unsigned long bp_vaddr) | 1492 | static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) |
1493 | { | 1493 | { |
1494 | struct mm_struct *mm = current->mm; | 1494 | struct mm_struct *mm = current->mm; |
1495 | struct uprobe *uprobe = NULL; | 1495 | struct uprobe *uprobe = NULL; |
@@ -1497,7 +1497,6 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr) | |||
1497 | 1497 | ||
1498 | down_read(&mm->mmap_sem); | 1498 | down_read(&mm->mmap_sem); |
1499 | vma = find_vma(mm, bp_vaddr); | 1499 | vma = find_vma(mm, bp_vaddr); |
1500 | |||
1501 | if (vma && vma->vm_start <= bp_vaddr) { | 1500 | if (vma && vma->vm_start <= bp_vaddr) { |
1502 | if (valid_vma(vma, false)) { | 1501 | if (valid_vma(vma, false)) { |
1503 | struct inode *inode; | 1502 | struct inode *inode; |
@@ -1508,6 +1507,11 @@ static struct uprobe *find_active_uprobe(unsigned long bp_vaddr) | |||
1508 | offset += (vma->vm_pgoff << PAGE_SHIFT); | 1507 | offset += (vma->vm_pgoff << PAGE_SHIFT); |
1509 | uprobe = find_uprobe(inode, offset); | 1508 | uprobe = find_uprobe(inode, offset); |
1510 | } | 1509 | } |
1510 | |||
1511 | if (!uprobe) | ||
1512 | *is_swbp = is_swbp_at_addr(mm, bp_vaddr); | ||
1513 | } else { | ||
1514 | *is_swbp = -EFAULT; | ||
1511 | } | 1515 | } |
1512 | 1516 | ||
1513 | srcu_read_unlock_raw(&uprobes_srcu, current->uprobe_srcu_id); | 1517 | srcu_read_unlock_raw(&uprobes_srcu, current->uprobe_srcu_id); |
@@ -1526,9 +1530,10 @@ static void handle_swbp(struct pt_regs *regs) | |||
1526 | struct uprobe_task *utask; | 1530 | struct uprobe_task *utask; |
1527 | struct uprobe *uprobe; | 1531 | struct uprobe *uprobe; |
1528 | unsigned long bp_vaddr; | 1532 | unsigned long bp_vaddr; |
1533 | int is_swbp; | ||
1529 | 1534 | ||
1530 | bp_vaddr = uprobe_get_swbp_addr(regs); | 1535 | bp_vaddr = uprobe_get_swbp_addr(regs); |
1531 | uprobe = find_active_uprobe(bp_vaddr); | 1536 | uprobe = find_active_uprobe(bp_vaddr, &is_swbp); |
1532 | 1537 | ||
1533 | if (!uprobe) { | 1538 | if (!uprobe) { |
1534 | /* No matching uprobe; signal SIGTRAP. */ | 1539 | /* No matching uprobe; signal SIGTRAP. */ |