Re: [RFC] [PATCH 2.6.37-rc5-tip 5/20] 5: Uprobes:register/unregister probes.

From: Peter Zijlstra
Date: Tue Jan 25 2011 - 07:16:28 EST


On Thu, 2010-12-16 at 15:28 +0530, Srikar Dronamraju wrote:
> +/* Returns 0 if it can install one probe */
> +int register_uprobe(struct inode *inode, unsigned long offset,
> + struct uprobe_consumer *consumer)
> +{
> + struct prio_tree_iter iter;
> + struct list_head tmp_list;
> + struct address_space *mapping;
> + struct mm_struct *mm, *tmpmm;
> + struct vm_area_struct *vma;
> + struct uprobe *uprobe;
> + int ret = -1;
> +
> + if (!inode || !consumer || consumer->next)
> + return -EINVAL;
> + uprobe = uprobes_add(inode, offset);
> + INIT_LIST_HEAD(&tmp_list);
> +
> + mapping = inode->i_mapping;
> +
> + mutex_lock(&uprobes_mutex);
> + if (uprobe->consumers) {
> + ret = 0;
> + goto consumers_add;
> + }
> +
> + spin_lock(&mapping->i_mmap_lock);
> + vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, 0, 0) {
> + if (!atomic_inc_not_zero(&vma->vm_mm->mm_users))
> + continue;
> +
> + mm = vma->vm_mm;
> + if (!valid_vma(vma)) {
> + mmput(mm);
> + continue;
> + }
> +
> + list_add(&mm->uprobes_list, &tmp_list);
> + mm->uprobes_vaddr = vma->vm_start + offset;
> + }
> + spin_unlock(&mapping->i_mmap_lock);

Both this and unregister are racy, what is to say:
- the vma didn't get removed from the mm
- no new matching vma got added

> + if (list_empty(&tmp_list)) {
> + ret = 0;
> + goto consumers_add;
> + }
> + list_for_each_entry_safe(mm, tmpmm, &tmp_list, uprobes_list) {
> + if (!install_uprobe(mm, uprobe))
> + ret = 0;
> + list_del(&mm->uprobes_list);
> + mmput(mm);
> + }
> +
> +consumers_add:
> + add_consumer(uprobe, consumer);
> + mutex_unlock(&uprobes_mutex);
> + put_uprobe(uprobe);
> + return ret;
> +}
> +
--
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/