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.