From owner-freebsd-current@FreeBSD.ORG Tue Aug 28 18:10:57 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A6B44106566B; Tue, 28 Aug 2012 18:10:57 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 756168FC17; Tue, 28 Aug 2012 18:10:57 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id B81D1B978; Tue, 28 Aug 2012 14:10:56 -0400 (EDT) From: John Baldwin To: Konstantin Belousov Date: Tue, 28 Aug 2012 13:38:13 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p17; KDE/4.5.5; amd64; ; ) References: <20120827073403.GA49223@onelab2.iet.unipi.it> <201208281240.29612.jhb@freebsd.org> <20120828172606.GR33100@deviant.kiev.zoral.com.ua> In-Reply-To: <20120828172606.GR33100@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201208281338.13612.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 28 Aug 2012 14:10:56 -0400 (EDT) Cc: freebsd-current@freebsd.org, Luigi Rizzo , current@freebsd.org, Andriy Gapon Subject: Re: per file descriptor device callbacks ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 28 Aug 2012 18:10:57 -0000 On Tuesday, August 28, 2012 1:26:06 pm Konstantin Belousov wrote: > On Tue, Aug 28, 2012 at 12:40:29PM -0400, John Baldwin wrote: > > On Tuesday, August 28, 2012 11:50:25 am Luigi Rizzo wrote: > > > On Mon, Aug 27, 2012 at 12:27:54PM -0400, John Baldwin wrote: > > > > On Monday, August 27, 2012 3:55:47 am Andriy Gapon wrote: > > > > > on 27/08/2012 10:34 Luigi Rizzo said the following: > > > > > > This requires to track calls to open/ioctl/poll/mmap/close. > > > > > > The difficulty i have is with mmap() and close(), because FreeBSD > > > > > > seems to handle these calls per-cdev rather than per-file-descriptor > > > > > > (for instance, no 'struct file' argument is available in mmap(), and > > > > > > the d_close method is only called on the last close() on the device). > > > > > > > > > > devfs_set_cdevpriv(9), etc > > > > > > > > mmap() is still problematic, but if you have the freedom to create your > > > > own VM objects, then d_mmap_single() can let you handle that fairly > > > > easily. > > > > > > Would dev_clone(9) be a better way to do what i need ? > > > > > > This way the struct cdev would be unique per file descriptor, > > > could be used as a key on the page fault callbacks > > > (i still do not have callbacks on dev_pager_ctor/dtor though). > > > > dev_clone() is rather gross and a lot harder to use than > > devfs_set_cdevpriv(). If you are fine with the inherent problems > > of the device pager (you can't ever make mappings go away), you can > > just assign each client a unique offset into your shared object's > > memory space. However, if you are exporting shared memory buffers, > > then a better model might be to let your clients use > > shm_open(SHM_ANON) to create buffers, then pass them into your driver > > via an ioctl() and use shm_map() to map them into the kernel. > > Well, there is a new OBJT_MGTDEVICE pager, which together with > d_mmap_single() allows to have even per-mapping data. i915kms uses it. > You do not need cdevpriv for the per-mapping data. > > Also, MGTDEVICE does track the mappings of the pages, so you can clean > up on device destruction. > > Normal callbacks of the device pager allows to execute ctr/dtr methods > at the time of mapping creation and tear down. These pages create PV entries so you can invalidate mappings when you invalidate a backing object, yes? That is part of the problem with the standard device pager (no way to invalidate existing mappings of an object). -- John Baldwin