From owner-freebsd-hackers@FreeBSD.ORG Sun Jan 30 15:01:50 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 84D02106566C; Sun, 30 Jan 2011 15:01:50 +0000 (UTC) (envelope-from nox@jelal.kn-bremen.de) Received: from smtp.kn-bremen.de (gelbbaer.kn-bremen.de [78.46.108.116]) by mx1.freebsd.org (Postfix) with ESMTP id 172D18FC14; Sun, 30 Jan 2011 15:01:49 +0000 (UTC) Received: by smtp.kn-bremen.de (Postfix, from userid 10) id 099361E0015E; Sun, 30 Jan 2011 16:01:49 +0100 (CET) Received: from triton8.kn-bremen.de (noident@localhost [127.0.0.1]) by triton8.kn-bremen.de (8.14.4/8.14.3) with ESMTP id p0UErgVi037042; Sun, 30 Jan 2011 15:53:42 +0100 (CET) (envelope-from nox@triton8.kn-bremen.de) Received: (from nox@localhost) by triton8.kn-bremen.de (8.14.4/8.14.3/Submit) id p0UErgt0037041; Sun, 30 Jan 2011 15:53:42 +0100 (CET) (envelope-from nox) From: Juergen Lock Date: Sun, 30 Jan 2011 15:53:41 +0100 To: Kostik Belousov Message-ID: <20110130145341.GA36312@triton8.kn-bremen.de> References: <20110129201000.GA10774@triton8.kn-bremen.de> <20110129205105.GI2518@deviant.kiev.zoral.com.ua> <20110129235448.GA15788@triton8.kn-bremen.de> <20110130103320.GO2518@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110130103320.GO2518@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.21 (2010-09-15) X-Mailman-Approved-At: Sun, 30 Jan 2011 15:31:42 +0000 Cc: freebsd-hackers@freebsd.org, freebsd-emulation@freebsd.org, Juergen Lock Subject: Re: Can vm_mmap()/vm_map_remove() be called with giant held? (linuxolator dvb patches) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Jan 2011 15:01:50 -0000 On Sun, Jan 30, 2011 at 12:33:20PM +0200, Kostik Belousov wrote: > On Sun, Jan 30, 2011 at 12:54:48AM +0100, Juergen Lock wrote: > > On Sat, Jan 29, 2011 at 10:51:05PM +0200, Kostik Belousov wrote: > > > On Sat, Jan 29, 2011 at 09:10:00PM +0100, Juergen Lock wrote: > > > > Hi! > > > > > > > > I was kinda hoping to be able to post a correct patch in public but > > > > getting an answer to ${Subject} seems to be more difficult than I > > > > thought... :) So, does anyone here know? copyout_map() and > > > You do not need Giant locked for vm_map* functions. > > > > > The question was more do I need to drop it first before calling them... > No, you do not need to drop Giant. > Ok, thanx! > [snip] > > > > + error = ENOMEM; > > > > + goto out2; > > > > + } > > > > + error = copyin((void *) vps.props, l_vp, l_propsiz); > > > > + if (error) > > > > + goto out2; > > > > + for (i = vps.num, l_p = l_vp, p = vp; i--; ++l_p, ++p) > > > > + linux_to_bsd_dtv_property(l_p, p); > > > > + > > > > + error = copyout_map(td, &uvp, propsiz); > > > > + if (error) > > > > + goto out2; > > > > + copyout(vp, (void *) uvp, propsiz); > > > > + > > > > + if ((error = fget(td, args->fd, &fp)) != 0) { > > > > + (void) copyout_unmap(td, uvp, propsiz); > > > > + goto out2; > > > > + } > > > > + vps.props = (void *) uvp; > > > > + if ((args->cmd & 0xffff) == LINUX_FE_SET_PROPERTY) > > > > + error = fo_ioctl(fp, FE_SET_PROPERTY, &vps, td->td_ucred, td); > > > > + else > > > > + error = fo_ioctl(fp, FE_GET_PROPERTY, &vps, td->td_ucred, td); > > > > + if (error) { > > > > + (void) copyout_unmap(td, uvp, propsiz); > > > > + goto out; > > > > + } > > > > + error = copyin((void *) uvp, vp, propsiz); > > > > + (void) copyout_unmap(td, uvp, propsiz); > > > No need in space between cast and expression. Bigger issue is that I > > > do not understand this fragment. You do copyout_map(), and then > > > immediately call copyout_unmap() for the address range returned > > > by copyout_map(), or am I missing something ? > > > > > The vm allocated by copyout_map() is only needed for the fo_ioctl() > > call because the struct passed to FE_[GS]ET_PROPERTY describes an > > array that the drivers then copyin() and (possibly) copyout() > > themselves. So that array needs to be translated from/to the 32bit > > Linux version to (possibly) 64bit on the host (linux_to_bsd_dtv_property), > > and the 64bit version is larger so it doesn't fit in the original > > place in the userland vm. > And am I right that the drivers can only take this array from the usermode ? Yes. And it's a Linux api and Linux code too (running in webcamd) so I changing it wouldn't make too much sense. > How is the compatibility for 32/64 bit mode is handled by native > FE_SET_PROPERTY handlers ? > I'm not sure but my impression is this currently isn't handled at all even on Linux. (And neither on FreeBSD.) > I could only say that the hack is atrocious. Might be, you indeed have > no choice there. > > I'm not going to disagree there... (This is actually the second api for this, i.e. FE_[GS]ET_PROPERTY are an api extension introduced to add dvb-s2 support to the Linux dvb api, the original proposal was different but wasn't accepted by the Linux people in charge. The array is an array of `commands' that are executed by the ioctl, and the unused pointer that's in there on top of the uint32_t reserved1[3] and that causes the sizes to differ between 32/64 bits looks like it has been added later too because without it I think each array element would have been exactly 64 bytes...) Cheers, Juergen