From owner-freebsd-drivers@freebsd.org Mon Aug 24 08:23:35 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 41C8F9BF7AF for ; Mon, 24 Aug 2015 08:23:35 +0000 (UTC) (envelope-from noname.esst@yahoo.com) Received: from nm6.bullet.mail.ne1.yahoo.com (nm6.bullet.mail.ne1.yahoo.com [98.138.90.69]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 08C831D19 for ; Mon, 24 Aug 2015 08:23:34 +0000 (UTC) (envelope-from noname.esst@yahoo.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1440404223; bh=Fwn7qNF52nva9cOF438s+lgcLJ2q+/KWmjcGXNPxKmg=; h=Date:From:Reply-To:To:Subject:From:Subject; b=facpHqGgpQehUr9KBaQxWvSJPsgoc7fia+0SOWzTp+KxOPwx5C215n7xkZO16taSSDsm+jCoTcyaicgPBSOiU6OZzBWmYy21058NgyZ+MSBjAEHb5R7KRROd3icAKsD3KIETRl0p7F8QFFHsMeYK0GA74/tvbfo4m+IjrHOChQ3T1PdkK3kCVZV03VuT1PjchJJSIq1+MiBmVQ+E13FNxsusEpuUZgpPNa0SdNWV1O4wXTVsrmDTzdpnfu8NJuZJx7LzbD/FvdXCoTHDmbL3homkGRfO7H3ZZ84o2jFWDz5+TuxyIvEoxchrYh6iAkn37102JL1tVe4lnhXJ7HzlQQ== Received: from [98.138.100.103] by nm6.bullet.mail.ne1.yahoo.com with NNFMP; 24 Aug 2015 08:17:03 -0000 Received: from [98.138.89.169] by tm102.bullet.mail.ne1.yahoo.com with NNFMP; 24 Aug 2015 08:17:03 -0000 Received: from [127.0.0.1] by omp1025.mail.ne1.yahoo.com with NNFMP; 24 Aug 2015 08:17:03 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 157056.3041.bm@omp1025.mail.ne1.yahoo.com X-YMail-OSG: 0DFkF94VM1mcNMV.ZRtmpkjuVikTAGf7dMseeQ1zcvvtn4ILzGJ8D9z8_FqfAnh DzDmEN3x0xM8n1THPBGVqnLNQpPLRsmfpbsFqglRuxWbrxDse8IJv3iELtly62oiSv7MxdcnG6Wu I6vkPf29rSPB7cKMwPaMfx2wJKmTOeZJlViGjZY_jFyS8AZxJK.iBLqiCrGtQnk7LfdrRqeFoNdO AkFo37_SN_qzb41P5UbieSyu2fZWgglXPGjcIv1X3iBQ53edZWioWgIk3PkqAXw4Sou67No9STb8 Sx2rH99_pQ8lqqTpO8Se6OPZMGN7go3Lj5rvorSbD_Blt7At3vDEnJzAwqKzBuCj7ineoPDcDafx Q2S17.850YRnxoqkIwmPVPcIua5Z6JMrvWbA9mGX_2S8Gq_QkLziZatTVvrDSIC3OOOTcjgJozS2 5ld7aFfufPzs2T4XL7d4cMty.f97Y6vEIGGM77QzCZAHh2iY8bqMPmEsmGLWnoCbWK670j.w729s PspeVGRYmKRSM9w-- Received: by 98.138.101.164; Mon, 24 Aug 2015 08:17:02 +0000 Date: Mon, 24 Aug 2015 08:17:02 +0000 (UTC) From: Nomad Esst Reply-To: Nomad Esst To: "freebsd-drivers@freebsd.org" , Freebsd Hackers List Message-ID: <1473579278.716147.1440404222458.JavaMail.yahoo@mail.yahoo.com> Subject: Get pci slot number in driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2015 08:23:35 -0000 Is it possible to find out the pci slot number on which the card is mounted in driver? I tried pci_get_slot but it's always 0.Any ideas about doing this? regards From owner-freebsd-drivers@freebsd.org Mon Aug 24 15:19:01 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CAE7E9C0528; Mon, 24 Aug 2015 15:19:01 +0000 (UTC) (envelope-from jim.harris@gmail.com) Received: from mail-ob0-x22e.google.com (mail-ob0-x22e.google.com [IPv6:2607:f8b0:4003:c01::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 92B65E8D; Mon, 24 Aug 2015 15:19:01 +0000 (UTC) (envelope-from jim.harris@gmail.com) Received: by obbhe7 with SMTP id he7so116106716obb.0; Mon, 24 Aug 2015 08:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=LMBtQDc0jiAykPZLO6qyhd9WfY4trce0mp1qZvLrDpQ=; b=Wbp0drf7Cvh0NuBqu+Mv9dUP6GzUUNRFOC6LGPNXU0tYYEkOTCwUMI7xox7E+hi3kH 9/puZnBBz7AtLE6R7UsvPowxrzI7gfSjNVoF5chGHHevz5IHOqrBVysDiEm7EcfFWGo3 5ri/zoyfG8rhMa8p6T+tGRsOPPzTQex7t/NHIImxYxiH1/NbhOYyaWkshuvAWgGrgEwu LfCwsXVtHOjq/6eDwKUiEZCDsfS5ttmq7jB1JoOOBZW45rlReQt3W/TTIWZGTrhkpa+f iB1nPahZV/i6g8iw4IQuNTlFYo6BhYhpLTybhPBPCP0Pv4lZH2/GivaZKGCCJJp0fGnH vZOw== MIME-Version: 1.0 X-Received: by 10.182.33.38 with SMTP id o6mr21072474obi.41.1440429540928; Mon, 24 Aug 2015 08:19:00 -0700 (PDT) Received: by 10.202.212.76 with HTTP; Mon, 24 Aug 2015 08:19:00 -0700 (PDT) In-Reply-To: <1473579278.716147.1440404222458.JavaMail.yahoo@mail.yahoo.com> References: <1473579278.716147.1440404222458.JavaMail.yahoo@mail.yahoo.com> Date: Mon, 24 Aug 2015 08:19:00 -0700 Message-ID: Subject: Re: Get pci slot number in driver From: Jim Harris To: Nomad Esst Cc: "freebsd-drivers@freebsd.org" , Freebsd Hackers List Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2015 15:19:02 -0000 On Mon, Aug 24, 2015 at 1:17 AM, Nomad Esst via freebsd-drivers < freebsd-drivers@freebsd.org> wrote: > Is it possible to find out the pci slot number on which the card is > mounted in driver? I tried pci_get_slot but it's always 0.Any ideas about > doing this? > regards > What do the PCI bus, slot, and function numbers for this device show up as in "pciconf -l" output? For PCI Express endpoints, the PCI slot number (also sometimes referred to as PCI device number) is typically 0. These endpoints are more typically differentiated by their PCI bus number, not slot number. -Jim _______________________________________________ > freebsd-drivers@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-drivers > To unsubscribe, send any mail to "freebsd-drivers-unsubscribe@freebsd.org" > From owner-freebsd-drivers@freebsd.org Mon Aug 24 17:20:28 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3ED809C111A; Mon, 24 Aug 2015 17:20:28 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "gold.funkthat.com", Issuer "gold.funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 21AF4ECB; Mon, 24 Aug 2015 17:20:26 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.14.5/8.14.5) with ESMTP id t7OHKP3G000590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 24 Aug 2015 10:20:25 -0700 (PDT) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.14.5/8.14.5/Submit) id t7OHKPHs000589; Mon, 24 Aug 2015 10:20:25 -0700 (PDT) (envelope-from jmg) Date: Mon, 24 Aug 2015 10:20:25 -0700 From: John-Mark Gurney To: Nomad Esst Cc: "freebsd-drivers@freebsd.org" , Freebsd Hackers List Subject: Re: Get pci slot number in driver Message-ID: <20150824172025.GI33167@funkthat.com> References: <1473579278.716147.1440404222458.JavaMail.yahoo@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1473579278.716147.1440404222458.JavaMail.yahoo@mail.yahoo.com> X-Operating-System: FreeBSD 9.1-PRERELEASE amd64 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (gold.funkthat.com [127.0.0.1]); Mon, 24 Aug 2015 10:20:25 -0700 (PDT) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Aug 2015 17:20:28 -0000 Nomad Esst via freebsd-drivers wrote this message on Mon, Aug 24, 2015 at 08:17 +0000: > Is it possible to find out the pci slot number on which the card is mounted in driver? I tried pci_get_slot but it's always 0.Any ideas about doing this? > regards Are these PCIe add in cards? If so, check pciconv -lv, but most PCIe cards are slot 0 of the bus... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-drivers@freebsd.org Wed Aug 26 09:24:05 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0A4369C0D3A for ; Wed, 26 Aug 2015 09:24:05 +0000 (UTC) (envelope-from kumara.bsd@gmail.com) Received: from mail-io0-x241.google.com (mail-io0-x241.google.com [IPv6:2607:f8b0:4001:c06::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id CDFCDF8 for ; Wed, 26 Aug 2015 09:24:04 +0000 (UTC) (envelope-from kumara.bsd@gmail.com) Received: by iods203 with SMTP id s203so931749iod.2 for ; Wed, 26 Aug 2015 02:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=XLeynJJukLX959lnayDbcaPgobDbKhBGIGrx1z767Oc=; b=vv60MNm1aP5wbMI4z+K/e00GivCGnLlPQT7qwIAr0Is1yU+hNJQ3Th/q2suega8KkK hwGztaqrMx7Jcm649cCnP5EBB8g0weUbaC63IFMiTGVacTxCQOnU3zVGfTNu1o1ONTa/ tmEc5ipCoomVbcNkBAPtVMBzuGnW4q17bYSTMfFTIUIQLVZiv1TO9cxVWABsLU+JMVeO KGd/LEippm6DuvPgffPPxyxTi1wtqVOSfnPManFvxcGyd8nT+AdDo6m8n0flD48B9PEM iaNDuAOoLRjI8Dzk+s3bPctyzOdrf1uOh2xodtp1TzdDd2sErchdBEohWcib6YhCdRab UWPQ== MIME-Version: 1.0 X-Received: by 10.107.33.81 with SMTP id h78mr1994980ioh.108.1440581044197; Wed, 26 Aug 2015 02:24:04 -0700 (PDT) Received: by 10.64.25.234 with HTTP; Wed, 26 Aug 2015 02:24:04 -0700 (PDT) Date: Wed, 26 Aug 2015 14:54:04 +0530 Message-ID: Subject: IOCTL From: kumara rathnavel To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Aug 2015 09:24:05 -0000 Hello All, I have written a driver program for character device and I use ioctl from user space to communicate with the device. I am able to open the device and execute the command for the respective ioctl but the address the I am sending from the user space is different and the ioctl reutuns me a BAD ADDRESS.... Thank You,,......... From owner-freebsd-drivers@freebsd.org Wed Aug 26 17:12:04 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6503A9C32B8 for ; Wed, 26 Aug 2015 17:12:04 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "gold.funkthat.com", Issuer "gold.funkthat.com" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 46252D42 for ; Wed, 26 Aug 2015 17:12:03 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.14.5/8.14.5) with ESMTP id t7QHC3G3032977 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 26 Aug 2015 10:12:03 -0700 (PDT) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.14.5/8.14.5/Submit) id t7QHC3lY032975; Wed, 26 Aug 2015 10:12:03 -0700 (PDT) (envelope-from jmg) Date: Wed, 26 Aug 2015 10:12:03 -0700 From: John-Mark Gurney To: kumara rathnavel Cc: freebsd-drivers@freebsd.org Subject: Re: IOCTL Message-ID: <20150826171203.GR33167@funkthat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 9.1-PRERELEASE amd64 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.5.21 (2010-09-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.7 (gold.funkthat.com [127.0.0.1]); Wed, 26 Aug 2015 10:12:03 -0700 (PDT) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Aug 2015 17:12:04 -0000 kumara rathnavel wrote this message on Wed, Aug 26, 2015 at 14:54 +0530: > I have written a driver program for character device and I use ioctl from > user space to communicate with the device. I am able to open the device and > execute the command for the respective ioctl but the address the I am > sending from the user space is different and the ioctl reutuns me a BAD > ADDRESS.... Do you know if your ioctl is called or not? Also, what is the code that you are using to call the ioctl? Are you passing it a valid userland pointer? -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-drivers@freebsd.org Fri Aug 28 20:52:55 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8DEBB9C48DC for ; Fri, 28 Aug 2015 20:52:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4E99B88A; Fri, 28 Aug 2015 20:52:55 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 64B06B915; Fri, 28 Aug 2015 16:52:54 -0400 (EDT) From: John Baldwin To: Konstantin Belousov Cc: freebsd-drivers@freebsd.org, Leonardo Fogel , 'Konstantin Belousov' Subject: Re: Race conditions Date: Fri, 28 Aug 2015 13:34:58 -0700 Message-ID: <2785418.Nryjt2Jbzi@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: <20150819145239.GS2072@kib.kiev.ua> References: <1439923294.98963.YahooMailBasic@web120801.mail.ne1.yahoo.com> <6889344.0OebVsM7Q3@ralph.baldwin.cx> <20150819145239.GS2072@kib.kiev.ua> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 28 Aug 2015 16:52:54 -0400 (EDT) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2015 20:52:55 -0000 On Wednesday, August 19, 2015 05:52:39 PM Konstantin Belousov wrote: > On Wed, Aug 19, 2015 at 07:29:56AM -0700, John Baldwin wrote: > > A somewhat related race I ran into while trying to make cloning on /dev/tap > > more useful is that there isn't any way to "reserve" a cdev during clone such > > that only the current thread can try to open it (at least as far as I can > > tell), unless it is true that the cdev's d_open() method is guaranteed to be > > called once a cdev is returned from the clone handler (which it is not for > > the stat() case). It's a shame we can't pass down an 'ISOPEN' flag similar > > to that in namei to the clone handlers. > > > > (See https://reviews.freebsd.org/D2797 and related comments) > When the clone handler run, there is no even the cdev' associated vnode > known in the thread called the dev_clone event handler. So regardless > of whether you pass ISOPEN to the dev_clone, there is a possibility that > a parallel open would happens before the current lookup consumer has a > chance to proceed. Perhaps we could force cloning to serialize with opens? That is, use some sort of global lock in devfs such that any non-cloning opens use a shared lock but an exclusive lock is taken before running clone event handlers (and held until after d_open returns)? To really close this sort of race, the exclusive lock acquired when a clone is created in lookup() would have to be held until devfs_open() is called. That's rather gross. I suppose you could always aquire the lock in devfs_lookup() when ISOPEN is set (exclusive if you have to clone, otherwise shared) and then drop it in devfs_open() after d_open returns. > > > > I think I would probably prefer we add some sort of wrapper for make_dev > > > > that accepts the si_drv1 value (and possibly other values) as an argument to > > > > close this. I'm cc'ing kib@ to see if he has any suggestions or better ideas. > > > > > > Yes, this is a known issue in the cdev KPI, but of very low importance. > > > I agree that a change to cdev KPI is due. One of the existing issues is > > > that it is already bloated with > > > make_dev_credf > > > make_dev_cred > > > make_dev_p > > > make_dev > > > all grown organically to plug this and that uglyness in the KPI. I wanted > > > to combine all non-naming parameters to make_dev* into some structure, > > > so that the final function to create cdev is like > > > int make_dev_uber(struct cdev **res, struct make_dev_args *args, > > > const char *fmt, ...); > > > struct make_dev_args { > > > struct cdevsw *csw; > > > int flags; > > > struct ucred *cred; > > > ... > > > int si_drv0; > > > void *si_drv1, *si_drv2; <- eventually > > > }; > > > and a helper to do initialization of the structure. > > > > > > But as I said above, it is very low priority and I want to gather more > > > outstanding issues with the KPI before making any decisions there. > > > > This sounds like a good approach to me. You could version the args structure > > if you wanted (I think Glebius has done this for his ifnet work which uses a > > similar pattern) so you can extend it in the future. > > I thought about the following use: > struct make_dev_args args; > struct cdev *cdev; > > make_dev_args_prep(&args); > args.si_drv1 = softc; > error = make_dev_uber(&cdev, &args, "exhauster"); > So that the _prep() ensures that the _args structure extension is > invisible to the KPI consumers. I have no intent of keeping KBI stable. Ok. > Question is, do we need this now ? It is yet another churn in the > make_dev(9) area, where we already have four interfaces, and we must > keep them around for source compatibility. IMO si_drv1 issue does not > justify yet another bloat. If there is any other reason to modify > make_dev(9) group of functions, then I would agree with taking the _args > step. Well, we've had this race in most cdev drivers in the tree for a long time. It's a narrow one that doesn't get hit often (if at all) in practice, but if I were to do a sweep to patch all the open routines to handle it, I'd rather we do it this way instead. OTOH, I don't have a burning desire to patch all the open routines. -- John Baldwin From owner-freebsd-drivers@freebsd.org Sat Aug 29 10:30:56 2015 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 461299C45F8 for ; Sat, 29 Aug 2015 10:30:56 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B391D95B; Sat, 29 Aug 2015 10:30:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t7TAUnxS008089 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 29 Aug 2015 13:30:49 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua t7TAUnxS008089 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t7TAUn9Q008087; Sat, 29 Aug 2015 13:30:49 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 29 Aug 2015 13:30:49 +0300 From: Konstantin Belousov To: John Baldwin Cc: freebsd-drivers@freebsd.org, Leonardo Fogel Subject: Re: Race conditions Message-ID: <20150829103049.GA2072@kib.kiev.ua> References: <1439923294.98963.YahooMailBasic@web120801.mail.ne1.yahoo.com> <6889344.0OebVsM7Q3@ralph.baldwin.cx> <20150819145239.GS2072@kib.kiev.ua> <2785418.Nryjt2Jbzi@ralph.baldwin.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2785418.Nryjt2Jbzi@ralph.baldwin.cx> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Aug 2015 10:30:56 -0000 On Fri, Aug 28, 2015 at 01:34:58PM -0700, John Baldwin wrote: > Perhaps we could force cloning to serialize with opens? That is, use > some sort of global lock in devfs such that any non-cloning opens use > a shared lock but an exclusive lock is taken before running clone > event handlers (and held until after d_open returns)? To really > close this sort of race, the exclusive lock acquired when a clone > is created in lookup() would have to be held until devfs_open() is > called. That's rather gross. I suppose you could always aquire the > lock in devfs_lookup() when ISOPEN is set (exclusive if you have to > clone, otherwise shared) and then drop it in devfs_open() after d_open > returns. Hm, I do not think taking a lock in lookup(ISOPEN) is feasible. VFS migh not call VOP_OPEN() after the lookup, for misc. reasons (e.g. due to the permissions, or forced umount reclaiming vnode as two obvious cases). Also, I am not sure about the definition about non-cloning open. Other thread might race with the cloner and open the newly cloned node before the cloner has a chance to proceed. Do you want to prevent this situation ? If yes, then why ? si_drv1 issue should be handled by other means. > Well, we've had this race in most cdev drivers in the tree for a long > time. It's a narrow one that doesn't get hit often (if at all) in > practice, but if I were to do a sweep to patch all the open routines > to handle it, I'd rather we do it this way instead. OTOH, I don't have > a burning desire to patch all the open routines. For the race to be real, the device must be created after the userspace is running. I think that the main case there are pty. I do not see a possibility of removing existing make_dev*() after the make_dev_uber() is introduced, so there is no need for the whole tree sweep.