diff options
| author | Srikar Dronamraju <srikar@linux.vnet.ibm.com> | 2012-04-11 06:35:27 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2012-04-14 07:25:48 -0400 |
| commit | cbc91f71b51b8335f1fc7ccfca8011f31a717367 (patch) | |
| tree | 31bc32a4ee512c9056c93e8c46d58bc217d31bc2 | |
| parent | 7396fa818d6278694a44840f389ddc40a3269a9a (diff) | |
uprobes/core: Decrement uprobe count before the pages are unmapped
Uprobes has a callback (uprobe_munmap()) in the unmap path to
maintain the uprobes count.
In the exit path this callback gets called in unlink_file_vma().
However by the time unlink_file_vma() is called, the pages would
have been unmapped (in unmap_vmas()) and the task->rss_stat counts
accounted (in zap_pte_range()).
If the exiting process has probepoints, uprobe_munmap() checks if
the breakpoint instruction was around before decrementing the probe
count.
This results in a file backed page being reread by uprobe_munmap()
and hence it does not find the breakpoint.
This patch fixes this problem by moving the callback to
unmap_single_vma(). Since unmap_single_vma() may not unmap the
complete vma, add start and end parameters to uprobe_munmap().
This bug became apparent courtesy of commit c3f0327f8e9d
("mm: add rss counters consistency check").
Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Jim Keniston <jkenisto@linux.vnet.ibm.com>
Cc: Linux-mm <linux-mm@kvack.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Anton Arapov <anton@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120411103527.23245.9835.sendpatchset@srdronam.in.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
| -rw-r--r-- | include/linux/uprobes.h | 5 | ||||
| -rw-r--r-- | kernel/events/uprobes.c | 4 | ||||
| -rw-r--r-- | mm/memory.c | 3 | ||||
| -rw-r--r-- | mm/mmap.c | 8 |
4 files changed, 12 insertions, 8 deletions
diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index d594d3b3ad4..efe4b3308c7 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h | |||
| @@ -107,7 +107,7 @@ extern bool __weak is_swbp_insn(uprobe_opcode_t *insn); | |||
| 107 | extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); | 107 | extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); |
| 108 | extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); | 108 | extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc); |
| 109 | extern int uprobe_mmap(struct vm_area_struct *vma); | 109 | extern int uprobe_mmap(struct vm_area_struct *vma); |
| 110 | extern void uprobe_munmap(struct vm_area_struct *vma); | 110 | extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end); |
| 111 | extern void uprobe_free_utask(struct task_struct *t); | 111 | extern void uprobe_free_utask(struct task_struct *t); |
| 112 | extern void uprobe_copy_process(struct task_struct *t); | 112 | extern void uprobe_copy_process(struct task_struct *t); |
| 113 | extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs); | 113 | extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs); |
| @@ -134,7 +134,8 @@ static inline int uprobe_mmap(struct vm_area_struct *vma) | |||
| 134 | { | 134 | { |
| 135 | return 0; | 135 | return 0; |
| 136 | } | 136 | } |
| 137 | static inline void uprobe_munmap(struct vm_area_struct *vma) | 137 | static inline void |
| 138 | uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) | ||
| 138 | { | 139 | { |
| 139 | } | 140 | } |
| 140 | static inline void uprobe_notify_resume(struct pt_regs *regs) | 141 | static inline void uprobe_notify_resume(struct pt_regs *regs) |
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index c5caeecea1d..985be4d80fe 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c | |||
| @@ -1112,7 +1112,7 @@ int uprobe_mmap(struct vm_area_struct *vma) | |||
| 1112 | /* | 1112 | /* |
| 1113 | * Called in context of a munmap of a vma. | 1113 | * Called in context of a munmap of a vma. |
| 1114 | */ | 1114 | */ |
| 1115 | void uprobe_munmap(struct vm_area_struct *vma) | 1115 | void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end) |
| 1116 | { | 1116 | { |
| 1117 | struct list_head tmp_list; | 1117 | struct list_head tmp_list; |
| 1118 | struct uprobe *uprobe, *u; | 1118 | struct uprobe *uprobe, *u; |
| @@ -1138,7 +1138,7 @@ void uprobe_munmap(struct vm_area_struct *vma) | |||
| 1138 | list_del(&uprobe->pending_list); | 1138 | list_del(&uprobe->pending_list); |
| 1139 | vaddr = vma_address(vma, uprobe->offset); | 1139 | vaddr = vma_address(vma, uprobe->offset); |
| 1140 | 1140 | ||
| 1141 | if (vaddr >= vma->vm_start && vaddr < vma->vm_end) { | 1141 | if (vaddr >= start && vaddr < end) { |
| 1142 | /* | 1142 | /* |
| 1143 | * An unregister could have removed the probe before | 1143 | * An unregister could have removed the probe before |
| 1144 | * unmap. So check before we decrement the count. | 1144 | * unmap. So check before we decrement the count. |
diff --git a/mm/memory.c b/mm/memory.c index 6105f475fa8..bf8b4035277 100644 --- a/mm/memory.c +++ b/mm/memory.c | |||
| @@ -1307,6 +1307,9 @@ static void unmap_single_vma(struct mmu_gather *tlb, | |||
| 1307 | if (end <= vma->vm_start) | 1307 | if (end <= vma->vm_start) |
| 1308 | return; | 1308 | return; |
| 1309 | 1309 | ||
| 1310 | if (vma->vm_file) | ||
| 1311 | uprobe_munmap(vma, start, end); | ||
| 1312 | |||
| 1310 | if (vma->vm_flags & VM_ACCOUNT) | 1313 | if (vma->vm_flags & VM_ACCOUNT) |
| 1311 | *nr_accounted += (end - start) >> PAGE_SHIFT; | 1314 | *nr_accounted += (end - start) >> PAGE_SHIFT; |
| 1312 | 1315 | ||
| @@ -218,7 +218,6 @@ void unlink_file_vma(struct vm_area_struct *vma) | |||
| 218 | mutex_lock(&mapping->i_mmap_mutex); | 218 | mutex_lock(&mapping->i_mmap_mutex); |
| 219 | __remove_shared_vm_struct(vma, file, mapping); | 219 | __remove_shared_vm_struct(vma, file, mapping); |
| 220 | mutex_unlock(&mapping->i_mmap_mutex); | 220 | mutex_unlock(&mapping->i_mmap_mutex); |
| 221 | uprobe_munmap(vma); | ||
| 222 | } | 221 | } |
| 223 | } | 222 | } |
| 224 | 223 | ||
| @@ -548,10 +547,11 @@ again: remove_next = 1 + (end > next->vm_end); | |||
| 548 | mapping = file->f_mapping; | 547 | mapping = file->f_mapping; |
| 549 | if (!(vma->vm_flags & VM_NONLINEAR)) { | 548 | if (!(vma->vm_flags & VM_NONLINEAR)) { |
| 550 | root = &mapping->i_mmap; | 549 | root = &mapping->i_mmap; |
| 551 | uprobe_munmap(vma); | 550 | uprobe_munmap(vma, vma->vm_start, vma->vm_end); |
| 552 | 551 | ||
| 553 | if (adjust_next) | 552 | if (adjust_next) |
| 554 | uprobe_munmap(next); | 553 | uprobe_munmap(next, next->vm_start, |
| 554 | next->vm_end); | ||
| 555 | } | 555 | } |
| 556 | 556 | ||
| 557 | mutex_lock(&mapping->i_mmap_mutex); | 557 | mutex_lock(&mapping->i_mmap_mutex); |
| @@ -632,7 +632,7 @@ again: remove_next = 1 + (end > next->vm_end); | |||
| 632 | 632 | ||
| 633 | if (remove_next) { | 633 | if (remove_next) { |
| 634 | if (file) { | 634 | if (file) { |
| 635 | uprobe_munmap(next); | 635 | uprobe_munmap(next, next->vm_start, next->vm_end); |
| 636 | fput(file); | 636 | fput(file); |
| 637 | if (next->vm_flags & VM_EXECUTABLE) | 637 | if (next->vm_flags & VM_EXECUTABLE) |
| 638 | removed_exe_file_vma(mm); | 638 | removed_exe_file_vma(mm); |
