From owner-freebsd-current@FreeBSD.ORG Fri Jun 14 22:00:05 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E9EECA2D for ; Fri, 14 Jun 2013 22:00:05 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id DB0F01ACB for ; Fri, 14 Jun 2013 22:00:05 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-67-180-208-218.hsd1.ca.comcast.net [67.180.208.218]) by elvis.mu.org (Postfix) with ESMTPSA id B477A1A3C1C for ; Fri, 14 Jun 2013 15:00:03 -0700 (PDT) Message-ID: <51BB925D.2000609@mu.org> Date: Fri, 14 Jun 2013 14:59:57 -0700 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Re: copyin()/copyout() constraints ? References: <20130612180115.GA27892@onelab2.iet.unipi.it> <51B8BFC4.303@mu.org> <201306141207.29779.jhb@freebsd.org> <20130614163812.GA50980@onelab2.iet.unipi.it> In-Reply-To: <20130614163812.GA50980@onelab2.iet.unipi.it> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Jun 2013 22:00:06 -0000 On 6/14/13 9:38 AM, Luigi Rizzo wrote: > On Fri, Jun 14, 2013 at 12:07:29PM -0400, John Baldwin wrote: >> On Wednesday, June 12, 2013 2:36:52 pm Alfred Perlstein wrote: >>> On 6/12/13 11:01 AM, Luigi Rizzo wrote: >>>> hi, >>>> is it possible to run copyin() or copyout() in one of these cases: >>>> 1. while holding a spinlock >>>> 2. while holding a regular mutex/lock >>>> 3. while holding a read lock (on an RWLOCK or RMLOCK) >>>> 4. while holding a write lock (on an RWLOCK or RMLOCK) >>>> >>>> I suspect #1 is forbidden, but am a bit unclear for the >>>> other cases. >>> No on all of the above unless the memory is wired. > ok i suppose i'll move to an sx lock, which i have been told > allows me to sleep ? > > My use case is that while i run the copyin(), and possibly take a > page fault, nobody destroys the destination buffer. So i wanted > to hold a read lock (sx_slock() ?) in the thread doing the copy > (there may be several writers to different parts of the destination), > and a write lock (sx_xlock() ?) for the other thread which may > destroy the buffer. We may be putting cart before horse, or horse into cart or something. :) You may want to just wire the user buffer so it can't get ripped out from under you. See John's email which may be helpful to do that. -- Alfred Perlstein VP Software Engineering, iXsystems