From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20626 invoked by alias); 26 Jan 2011 09:10:29 -0000 Received: (qmail 20613 invoked by uid 22791); 26 Jan 2011 09:10:28 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e34.co.us.ibm.com (HELO e34.co.us.ibm.com) (32.97.110.152) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 26 Jan 2011 09:10:23 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e34.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0Q8xE8V010996 for ; Wed, 26 Jan 2011 01:59:14 -0700 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0Q9AL7Q089100 for ; Wed, 26 Jan 2011 02:10:21 -0700 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0Q9AJ5H005743 for ; Wed, 26 Jan 2011 02:10:21 -0700 Received: from linux.vnet.ibm.com ([9.124.31.43]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id p0Q9ADCU005320; Wed, 26 Jan 2011 02:10:14 -0700 Date: Wed, 26 Jan 2011 09:10:00 -0000 From: Srikar Dronamraju To: Peter Zijlstra Cc: Ingo Molnar , Steven Rostedt , Linux-mm , Arnaldo Carvalho de Melo , Linus Torvalds , Ananth N Mavinakayanahalli , Christoph Hellwig , Masami Hiramatsu , Oleg Nesterov , LKML , SystemTap , Jim Keniston , Frederic Weisbecker , Andi Kleen , Andrew Morton , "Paul E. McKenney" Subject: Re: [RFC] [PATCH 2.6.37-rc5-tip 8/20] 8: uprobes: mmap and fork hooks. Message-ID: <20110126090346.GH19725@linux.vnet.ibm.com> Reply-To: Srikar Dronamraju References: <20101216095714.23751.52601.sendpatchset@localhost6.localdomain6> <20101216095848.23751.73144.sendpatchset@localhost6.localdomain6> <1295957739.28776.717.camel@laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1295957739.28776.717.camel@laptop> User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2011-q1/txt/msg00123.txt.bz2 > On Thu, 2010-12-16 at 15:28 +0530, Srikar Dronamraju wrote: > > +void uprobe_mmap(struct vm_area_struct *vma) > > +{ > > + struct list_head tmp_list; > > + struct uprobe *uprobe, *u; > > + struct mm_struct *mm; > > + struct inode *inode; > > + > > + if (!valid_vma(vma)) > > + return; > > + > > + INIT_LIST_HEAD(&tmp_list); > > + > > + /* > > + * The vma was just allocated and this routine gets called > > + * while holding write lock for mmap_sem. Function called > > + * in context of a thread that has a reference to mm. > > + * Hence no need to take a reference to mm > > + */ > > + mm = vma->vm_mm; > > + up_write(&mm->mmap_sem); > > Are you very very sure its a good thing to simply drop the mmap_sem > here? Also, why? > I actually dont like to release the write_lock and then reacquire it. write_opcode, which is called thro install_uprobe, i.e to insert the actual breakpoint instruction takes a read lock on the mmap_sem. Hence uprobe_mmap gets called in context with write lock on mmap_sem held, I had to release it before calling install_uprobe. Another solution, I thought of was to pass a context to write_opcode to say that map-sem is already acquired by us. But I am not sure that idea is good enuf. > > + mutex_lock(&uprobes_mutex); > > + > > + inode = vma->vm_file->f_mapping->host; > > Since you just dropped the mmap_sem, what's keeping that vma from going > away? > How about dropping the mmap_sem after add_to_temp_list and cachng the vma->vm_start value before calling add_to_temp_list? Or if you have better ideas, then that would be great. > > + add_to_temp_list(vma, inode, &tmp_list); > > + > > + list_for_each_entry_safe(uprobe, u, &tmp_list, pending_list) { > > + mm->uprobes_vaddr = vma->vm_start + uprobe->offset; > > + install_uprobe(mm, uprobe); > > + list_del(&uprobe->pending_list); > > + } > > + mutex_unlock(&uprobes_mutex); > > + down_write(&mm->mmap_sem); > > +} > >