From: Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>
To: Jon Smirl <jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Linux I2C <i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org>,
Jonathan Corbet <corbet-T1hC0tSOHrs@public.gmane.org>
Subject: Re: i2c: cdev lock_kernel() pushdown
Date: Tue, 15 Jul 2008 18:33:44 +0100 [thread overview]
Message-ID: <20080715173344.GM30539@fluff.org.uk> (raw)
In-Reply-To: <9e4733910807151001r88ed121o4f13546e1d3d93ff-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
On Tue, Jul 15, 2008 at 01:01:07PM -0400, Jon Smirl wrote:
> On 7/15/08, Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> wrote:
> > On Tue, 15 Jul 2008 10:14:06 -0600, Jonathan Corbet wrote:
> > > Hi, Jean,
> > >
> > > > I am looking at this patch of yours:
> > > > http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3db633ee352bfe20d4a2b0c3c8a46ce31a6c7149
> > > >
> > > > I believe that no locking is needed in i2cdev_open(). Do you have any
> > > > reason to think it does? If not, can I simply revert this patch?
> > >
> > > Before now, i2cdev_open() has always had the protection of the BKL.
> > > When I pushed that locking down into the individual open() functions, I
> > > really had to take a pretty conservative approach and assume that the
> > > BKL was needed unless that was really obviously not the case. In
> > > i2cdev_open(), for example, there's:
> > >
> > > i2c_dev = i2c_dev_get_by_minor(minor);
> > >
> > > and I really don't know what keeps *i2c_dev from going away during the
> > > rest of the call. I'm *not* saying there is a problem here; I just
> > > don't know. So the only thing I could really do is to push the BKL
> > > down and let the maintainers sort it out.
> > >
> > > ...all of which is my long-winded way of saying that, if you're
> > > convinced that i2cdev_open() is safe in the absence of the BKL, feel
> > > free to take it out.
> >
> >
> > Good point. i2c_dev is guaranteed to stay thanks to the call to
> > i2c_get_adapter(), however it happens _after_ the call to
> > i2c_dev_get_by_minor(), so without additional locking, this is racy.
> > That being said, I'm not sure how lock_kernel() is supposed to help. Is
> > the BKL held when i2cdev_detach_adapter() is called? If not, then I
> > suspect that the current code is already racy.
> >
> > I'll look into this, thanks for the hint.
>
> Is i2c-dev vulnerable to the i2c device disappearing, for example
> rmmod it? Would combining i2c-dev into i2c core and integrating it
> with the core's lock protection make things easier to lock? You could
> make a compile time option to remove it for small systems. If it's in
> the core is attach/detach adapter still needed? I haven't looked at
> any of this in detail, but i2c-dev is only 6K of code. Half of the 6K
> might disappear if integrated into the core.
The i2c-dev code calls i2c_get_adapter() op open, so as long as the
device stays open the adapter should not be able to go away as
i2c_get_adater() calls try_module_get() on the adapter's module.
The i2c-dev has it's own THIS_MODULE in the fops field, so should
be kept as long as there is a file open.
> What happens if user space and an in-kernel user both try using the
> device? I've never tried doing that. Should the presence of an
> in-kernel user make the user space device disappear?
>
> --
> Jon Smirl
> jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>
> _______________________________________________
> i2c mailing list
> i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
> http://lists.lm-sensors.org/mailman/listinfo/i2c
--
Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/)
'a smiley only costs 4 bytes'
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
next prev parent reply other threads:[~2008-07-15 17:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-15 15:41 i2c: cdev lock_kernel() pushdown Jean Delvare
[not found] ` <20080715174155.2d52e6f6-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-15 16:14 ` Jonathan Corbet
[not found] ` <20080715101406.6b4517e3-vw3g6Xz/EtPk1uMJSBkQmQ@public.gmane.org>
2008-07-15 16:35 ` Jean Delvare
[not found] ` <20080715183552.7e1b797a-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-15 16:52 ` Jonathan Corbet
2008-07-15 17:01 ` Jon Smirl
[not found] ` <9e4733910807151001r88ed121o4f13546e1d3d93ff-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-07-15 17:33 ` Ben Dooks [this message]
2008-07-15 17:45 ` Jean Delvare
[not found] ` <20080715194550.79dbb226-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-15 18:58 ` Jon Smirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080715173344.GM30539@fluff.org.uk \
--to=ben-linux-elnmno+kys3ytjvyw6ydsg@public.gmane.org \
--cc=corbet-T1hC0tSOHrs@public.gmane.org \
--cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=jonsmirl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.