svn commit: r268570 - head/sys/kern

Konstantin Belousov kostikbel at gmail.com
Sat Jul 12 17:10:27 UTC 2014


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
> > > 
> > > Log:
> > >   Clear nonblock and async on devctl close instaed of open.
> > >   
> > >   This is a purely cosmetic change.
> > > 
> > > Modified:
> > >   head/sys/kern/subr_bus.c
> > > 
> > > Modified: head/sys/kern/subr_bus.c
> > > ==============================================================================
> > > --- 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 = 1;
> > > -	devsoftc.nonblock = 0;
> > > -	devsoftc.async = 0;
> > >  	mtx_unlock(&devsoftc.mtx);
> > >  	return (0);
> > >  }
> > > @@ -450,6 +448,8 @@ devclose(struct cdev *dev, int fflag, in
> > >  
> > >  	mtx_lock(&devsoftc.mtx);
> > >  	devsoftc.inuse = 0;
> > > +	devsoftc.nonblock = 0;
> > > +	devsoftc.async = 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.
> > 
> > FWIW, I think that both old and new behaviour are bugs, and I am not
> > sure why changing one for another (instead of fix).
> 
> I don't see that, but maybe I'm misreading the code.
> 
> There can be only one 'struct file' for devctl and devclose is only
> called when it is about to be destroyed.
> 
> fd = open("/dev/devctl");
> close(dup(fd));
> 
> does not result in calling devclose.
> 
> If devclose is indeed reachable whlie fds are active this code needs
> serious help since devsoftc.inuse is of no use whatsoever.
> 
> There is no support for multiple readers in the sense that each event
> can be read only once, hence the restriction on open.
> 
> 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20140712/04cbe0d2/attachment.sig>


More information about the svn-src-head mailing list