Re: [PATCH v9 3.2 0/9] Uprobes patchset with perf probe support

From: Srikar Dronamraju
Date: Mon Jan 16 2012 - 10:38:10 EST


* Ingo Molnar <mingo@xxxxxxx> [2012-01-16 09:34:42]:

>
> * Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx> wrote:
>
> > This patchset implements Uprobes which enables you to
> > dynamically probe any routine in a user space application and
> > collect information non-disruptively.
>
> Did all review feedback get addressed in your latest tree?

I think this question would be better answered by Peter, Oleg and
Masami. For my part, I have fixed all comments till now. Also uprobes
has been part of -next for quite sometime.

>
> If yes then it would be nice to hear the opinion of Andrew about
> this bit:
>
> > mm/mmap.c | 33 +-
>
> The relevant portion of the patch is:
>
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -30,6 +30,7 @@
> > #include <linux/perf_event.h>
> > #include <linux/audit.h>
> > #include <linux/khugepaged.h>
> > +#include <linux/uprobes.h>
> >
> > #include <asm/uaccess.h>
> > #include <asm/cacheflush.h>
> > @@ -616,6 +617,13 @@ again: remove_next = 1 + (end > next->vm_end);
> > if (mapping)
> > mutex_unlock(&mapping->i_mmap_mutex);
> >
> > + if (root) {
> > + mmap_uprobe(vma);
> > +
> > + if (adjust_next)
> > + mmap_uprobe(next);
> > + }
> > +
> > if (remove_next) {
> > if (file) {
> > fput(file);
> > @@ -637,6 +645,8 @@ again: remove_next = 1 + (end > next->vm_end);
> > goto again;
> > }
> > }
> > + if (insert && file)
> > + mmap_uprobe(insert);
> >
> > validate_mm(mm);
> >
> > @@ -1329,6 +1339,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> > mm->locked_vm += (len >> PAGE_SHIFT);
> > } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
> > make_pages_present(addr, addr + len);
> > +
> > + if (file && mmap_uprobe(vma))
> > + /* matching probes but cannot insert */
> > + goto unmap_and_free_vma;
> > +
> > return addr;
> >
> > unmap_and_free_vma:
> > @@ -2305,6 +2320,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
> > if ((vma->vm_flags & VM_ACCOUNT) &&
> > security_vm_enough_memory_mm(mm, vma_pages(vma)))
> > return -ENOMEM;
> > +
> > + if (vma->vm_file && mmap_uprobe(vma))
> > + return -EINVAL;
> > +
> > vma_link(mm, vma, prev, rb_link, rb_parent);
> > return 0;
> > }
> > @@ -2356,6 +2375,10 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> > new_vma->vm_pgoff = pgoff;
> > if (new_vma->vm_file) {
> > get_file(new_vma->vm_file);
> > +
> > + if (mmap_uprobe(new_vma))
> > + goto out_free_mempol;
> > +
> > if (vma->vm_flags & VM_EXECUTABLE)
> > added_exe_file_vma(mm);
> > }
>
> it's named mmap_uprobe(), which makes it rather single-purpose.
> The uprobes code wants to track vma life-time so that it can
> manage uprobes breakpoints installed here, correct?
>

Yes,

> We already have some other vma tracking goodies in perf itself
> (see perf_event_mmap() et al) - would it make sense to merge the
> two vma instrumentation facilities and not burden mm/ with two
> separate sets of callbacks?

Atleast for file backed vmas, perf_event_mmap seems to be interested in
just the new vma creations. Uprobes would also be interested in the size
changes like the vma growing/shrinking/remap. Is perf_event_mmap
interested in such changes? From what i could see, perf_event_mmap seems
to be interested in stack vma size changes but not file vma size
changes.

Also mmap_uprobe gets called in fork path. Currently we have a hook in
copy_mm/dup_mm so that we get to know the context of each vma that gets
added to the child and add its breakpoints. At dup_mm/dup_mmap we would
have taken mmap_sem for both parent and child so there is no way we
could have missed a register/unregister in the parent not reflected in
the child.

I see the perf_event_fork but that would have to enhanced to do a lot
more to help us do a mmap_uprobe.

>
> If all such issues are resolved then i guess we could queue up
> uprobes in -tip, conditional on it remaining sufficiently
> regression-, problem- and NAK-free.

Okay. Accepting uprobes into tip, would provide more testing/feedback.

>
> Also, it would be nice to hear Arnaldo's opinion about the
> tools/perf/ bits.

Whatever comments Arnaldo/Masami have given till now have been resolved.

--
Thanks and Regards
Srikar

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/