From owner-svn-src-all@FreeBSD.ORG Sat Jul 12 17:10:27 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 29EEAB72; Sat, 12 Jul 2014 17:10:27 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BEFDD22C1; Sat, 12 Jul 2014 17:10:26 +0000 (UTC) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s6CHAGUl006607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 12 Jul 2014 20:10:16 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s6CHAGUl006607 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s6CHAFW2006605; Sat, 12 Jul 2014 20:10:15 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 12 Jul 2014 20:10:15 +0300 From: Konstantin Belousov To: Mateusz Guzik Subject: Re: svn commit: r268570 - head/sys/kern Message-ID: <20140712171015.GT93733@kib.kiev.ua> References: <201407121535.s6CFZ42f063120@svn.freebsd.org> <20140712161801.GS93733@kib.kiev.ua> <20140712165346.GA16884@dft-labs.eu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="a7SarfeDDnAelrrD" Content-Disposition: inline In-Reply-To: <20140712165346.GA16884@dft-labs.eu> 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.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Mateusz Guzik X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jul 2014 17:10:27 -0000 --a7SarfeDDnAelrrD Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Jul 12, 2014 at 06:53:47PM +0200, Mateusz Guzik wrote: > On Sat, Jul 12, 2014 at 07:18:01PM +0300, Konstantin Belousov wrote: > > On Sat, Jul 12, 2014 at 03:35:04PM +0000, Mateusz Guzik wrote: > > > Author: mjg > > > Date: Sat Jul 12 15:35:04 2014 > > > New Revision: 268570 > > > URL: http://svnweb.freebsd.org/changeset/base/268570 > > >=20 > > > Log: > > > Clear nonblock and async on devctl close instaed of open. > > > =20 > > > This is a purely cosmetic change. > > >=20 > > > Modified: > > > head/sys/kern/subr_bus.c > > >=20 > > > Modified: head/sys/kern/subr_bus.c > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > > --- head/sys/kern/subr_bus.c Sat Jul 12 15:19:30 2014 (r268569) > > > +++ head/sys/kern/subr_bus.c Sat Jul 12 15:35:04 2014 (r268570) > > > @@ -438,8 +438,6 @@ devopen(struct cdev *dev, int oflags, in > > > } > > > /* move to init */ > > > devsoftc.inuse =3D 1; > > > - devsoftc.nonblock =3D 0; > > > - devsoftc.async =3D 0; > > > mtx_unlock(&devsoftc.mtx); > > > return (0); > > > } > > > @@ -450,6 +448,8 @@ devclose(struct cdev *dev, int fflag, in > > > =20 > > > mtx_lock(&devsoftc.mtx); > > > devsoftc.inuse =3D 0; > > > + devsoftc.nonblock =3D 0; > > > + devsoftc.async =3D 0; > > > cv_broadcast(&devsoftc.cv); > > > funsetown(&devsoftc.sigio); > > > mtx_unlock(&devsoftc.mtx); > > This is not pure cosmetic. devctl does not track closes, so opens are > > not matched with close calls. Now any close clears nonblock and async, > > which is not how it was done before. Tracking close calls does not > > work reliably. > >=20 > > FWIW, I think that both old and new behaviour are bugs, and I am not > > sure why changing one for another (instead of fix). >=20 > I don't see that, but maybe I'm misreading the code. >=20 > There can be only one 'struct file' for devctl and devclose is only > called when it is about to be destroyed. >=20 > fd =3D open("/dev/devctl"); > close(dup(fd)); >=20 > does not result in calling devclose. >=20 > If devclose is indeed reachable whlie fds are active this code needs > serious help since devsoftc.inuse is of no use whatsoever. >=20 > There is no support for multiple readers in the sense that each event > can be read only once, hence the restriction on open. >=20 > On the other hand it is indeed possible to obtain multiple fds for > devctl which is harmless as far as consistency in the kernel goes. > Concurrent reads are serialized with a mutex and closes are invisible to > the device, except for the last one which destroys fp. Well, I argue that devsoftc.inuse is broken too. It was introduced in time when the only way of tracking the shared use of cdev was cloning. Note that it does not prevent multiple threads from simultaneously fall into the cdevsw methods; e.g. cv_wait_sig() in devread() drops devsoftc.mtx etc. IMO the right thing to do is to allow multiple opens and to keep non-blocking attribute and async bindings in the per-file structure. Then your change would be real nop. BTW, another, this time really big, user of the private (yes) cloning implementation is snd(4). The conversion of it to devfs_cdevpriv(9) would be also highly desirable. --a7SarfeDDnAelrrD Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJTwWv3AAoJEJDCuSvBvK1BKcEP+wYHWmSVzUnFJk81WrVgjch6 CKbCmceBa2UvzNc5tZ6NcNJxkWLZ7ISsFL0rMqpDbeJCOwbWddWty+RGwOmZ9mPS JXg6VTofyeBzsENGQoliEuyNIEU22lg7E17aENOmKQiLlFhVV1t7UBtysA+zYXio kommsAIA0gdQktt3KYGw7CmlwvQXfrFheiRHFMfLTX0tiotmrrfCd+8fuGbZgl6K ozGTgQ1PJqxXBiF4ttk9UDzTsp/Yv9YNLEDDfvjcTVQDvdt5weT6zvfa7SIYHYbk BPqxBLh3//YuvKF1s1C0g6q0/iGABh54eNa9hVc3JEkh7IKoVoztvKY2MWnj/2ps ci13zfF+S6JRXI1GOztvj5lnfwjvgmRy/o+8/c/DCR8zJSnialoIqjQI8kPZJYNp wnn/4CoF9Cc99naMuHWekqSZd9kilHVOy8NqeQMyJ8fviOcG6J/3YW0W5gAMc42C OcF7s/Aa99mIvNGgsCO7V/B75iAg13oWku8W/oftHksaIyzYZKeZIVGj1md9WCUf mSRbauFL3/doimjJO2w1T5w17UYDgzaSNwyqhcfwFBKaxnQcsheibZ9RSxVA1n8A 8gLd7rAemtssczB7FLQST2jWeT7OZLP6YK/xWDCHAZyKkSEjtzOudNsxSLfZ7qjh rL2scyCya01joojsXyQv =QQX7 -----END PGP SIGNATURE----- --a7SarfeDDnAelrrD--