From: Duncan Sands <baldrick@free.fr>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: David Brownell <david-b@pacbell.net>, Vince <fuzzy77@free.fr>,
"Randy.Dunlap" <rddunlap@osdl.org>, <mfedyk@matchmail.com>,
<zwane@holomorphy.com>, <linux-kernel@vger.kernel.org>,
USB development list <linux-usb-devel@lists.sourceforge.net>
Subject: Re: [linux-usb-devel] Re: [OOPS, usbcore, releaseintf] 2.6.0-test10-mm1
Date: Tue, 9 Dec 2003 11:23:54 +0100 [thread overview]
Message-ID: <200312091123.54412.baldrick@free.fr> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0312081754480.2034-100000@ida.rowland.org>
> > Yes. ps->devsem is used to protect against disconnection: all top level
> > routines take it (as a read lock), and in driver_disconnect it is taken
> > as a write lock. Top level routines call lower level routines which
> > sometimes need to take dev->serialize (and do already in several places).
> >
> > Thus: ps->devsem taken, then dev->serialize.
> >
> > However, dev->serialize is taken by the USB core before calling
> > driver_disconnect.
> >
> > Thus: dev->serialize taken, then ps->devsem.
>
> This is a tricky situation, no doubt about it.
>
> Your situation is a little different from the usual one because ps->devsem
> locks the whole device, not just a single interface. It should still be
> able to work. But maybe you're right; since ps->devsem locks the same
> thing as ps->dev->serialize, maybe it's not needed. By the way, when
> usbfs takes ownership of a device, does it bind to the device's
> interfaces?
Well usbfs never owns anything really. What it does is allow you (from user
space) to claim and use an interface that nobody else has claimed yet. Thus
it needs to be able to look at the interfaces of any USB device, find out which
ones are already claimed and maybe claim any ones that are not in use.
> > Right. And why should (for example) dev->serialize not be held when it
> > calls usb_set_configuration? - because usb_set_configuration takes
> > dev->serialize. This is one of the places I mentioned above where
> > deadlock can occur right now.
>
> You may simply have to release the lock because calling
> usb_set_configuration and then reacquire it afterwards.
Right, I did this in my patch along with the other changes, but in fact it could
be fixed separately.
> That leads to the question of how to assure that the device doesn't go
> away before usb_set_configuration is called. Perhaps
> usb_set_configuration and usb_unbind_interface should be changed to
> require the caller to hold the serialize lock.
Well, you could just ensure you have a reference to the usb_device, and
change usb_set_configuration and friends so that they don't Oops if the
device has been disconnected. This should be done anyway by the way -
surely all core routines should behave themselves (eg: by failing with
an error code) when called with a not-yet-freed struct usb_device?
> > > If you call usb_ifnum_to_if() you ought to hold the serialize lock;
> > > otherwise the configuration might change out from under you. But it's
> > > not necessary. Likewise for usb_epnum_to_ep_desc if you're looking up
> > > an endpoint that isn't part of an interface you have bound.
> >
> > Why isn't it necessary? As far as I can see it is vital.
>
> I mean it won't cause an oops, although it might provide an invalid
> result. It's not _required_ by the API (maybe it should be).
It will cause an Oops - actconfig may be NULL. This is the case after
disconnect for example, and also momentarily the case doing configuration
changes.
> Actually, there's another sense in which it's not necessary. Since
> changing configurations first involves unbinding the existing drivers, if
> you hold a driver-private lock that will block your disconnect routine
> then you can safely call usb_ifnum_to_if even without holding
> dev->serialize.
The disconnect routine is only called if you have claimed an interface.
If usbfs is looking for an interface to claim (and hasn't yet claimed
one), then disconnect will not be called. There is code in inode.c that
informs usbfs when the device has been disconnected, but now that
disconnect is per-interface, that is not good enough.
> > > There's some sort of misunderstanding here. It's not fatal to do
> > > usb_put_dev() after disconnect, provided you called usb_get_dev()
> > > earlier. I'm not sure what the cause was of the oops you were getting,
> > > but it wasn't that.
> >
> > It was AFAICS, though of course it shouldn't be.
>
> I didn't note the reason for the oops. Was it a segmentation violation?
> The usb_device memory isn't deallocated until the reference count goes to
> 0. Maybe something was doing an extra usb_put_dev.
More on this in another email.
Ciao,
Duncan.
next prev parent reply other threads:[~2003-12-09 10:52 UTC|newest]
Thread overview: 113+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-26 16:51 [kernel panic @ reboot] 2.6.0-test10-mm1 Vince
2003-11-26 17:16 ` Zwane Mwaikambo
2003-11-26 17:34 ` Vince
2003-11-26 17:35 ` Randy.Dunlap
2003-11-26 17:40 ` Zwane Mwaikambo
2003-11-26 17:54 ` Vince
2003-11-26 18:18 ` Zwane Mwaikambo
2003-11-26 23:37 ` Mike Fedyk
2003-11-26 23:41 ` Vince
2003-12-03 0:03 ` Randy.Dunlap
2003-12-03 0:31 ` Mike Fedyk
2003-12-03 0:27 ` Randy.Dunlap
2003-12-03 13:28 ` Vince
2003-12-03 19:12 ` Zwane Mwaikambo
2003-12-04 1:01 ` Vince
2003-12-04 1:34 ` Mike Fedyk
2003-12-04 4:11 ` Randy.Dunlap
2003-12-04 10:59 ` [OOPS, usbcore, releaseintf] 2.6.0-test10-mm1 Vince
2003-12-04 11:14 ` Duncan Sands
2003-12-04 16:57 ` Randy.Dunlap
2003-12-05 7:38 ` Duncan Sands
2003-12-05 10:11 ` Vince
2003-12-05 10:18 ` Duncan Sands
2003-12-05 10:34 ` Vince
2003-12-07 0:25 ` Duncan Sands
2003-12-07 21:09 ` Vince
2003-12-07 21:24 ` Duncan Sands
2003-12-07 22:24 ` Vince
2003-12-07 22:54 ` Vince
2003-12-08 10:10 ` Duncan Sands
2003-12-08 16:03 ` [linux-usb-devel] " David Brownell
2003-12-08 16:15 ` Duncan Sands
2003-12-08 16:31 ` Alan Stern
2003-12-08 17:20 ` David Brownell
2003-12-08 17:59 ` Duncan Sands
2003-12-08 18:35 ` Alan Stern
2003-12-08 19:53 ` Duncan Sands
2003-12-08 21:32 ` Alan Stern
2003-12-08 21:55 ` Duncan Sands
2003-12-08 23:09 ` Alan Stern
2003-12-09 10:23 ` Duncan Sands [this message]
2003-12-09 15:55 ` Alan Stern
2003-12-09 20:36 ` Duncan Sands
2003-12-09 10:36 ` Duncan Sands
2003-12-09 16:08 ` Alan Stern
2003-12-09 20:24 ` Duncan Sands
2003-12-09 10:49 ` Duncan Sands
2003-12-09 15:47 ` Alan Stern
2003-12-09 21:12 ` Duncan Sands
2003-12-09 21:58 ` Alan Stern
2003-12-09 22:07 ` Duncan Sands
2003-12-09 22:25 ` David Brownell
2003-12-09 22:33 ` Duncan Sands
2003-12-10 3:12 ` David Brownell
2003-12-10 3:43 ` Alan Stern
2003-12-10 13:12 ` Duncan Sands
2003-12-10 15:13 ` Alan Stern
2003-12-10 15:30 ` Greg KH
2003-12-10 16:02 ` Duncan Sands
2003-12-10 20:53 ` Greg KH
2003-12-11 8:49 ` Duncan Sands
2003-12-11 9:23 ` Greg KH
2003-12-11 9:29 ` Duncan Sands
2003-12-10 17:25 ` Alan Stern
2003-12-10 20:46 ` Greg KH
2003-12-10 21:08 ` Greg KH
2003-12-11 2:10 ` Vince
2003-12-11 6:46 ` Greg KH
2003-12-10 22:08 ` Alan Stern
2003-12-11 6:47 ` Greg KH
2003-12-10 4:31 ` Vince
2003-12-10 1:49 ` Greg KH
2003-12-10 13:22 ` Duncan Sands
2003-12-10 16:20 ` Oliver Neukum
2003-12-10 16:49 ` Duncan Sands
2003-12-10 16:58 ` Oliver Neukum
2003-12-11 9:45 ` Duncan Sands
2003-12-11 10:19 ` Oliver Neukum
2003-12-11 21:43 ` Duncan Sands
2003-12-11 22:57 ` Oliver Neukum
2003-12-11 23:30 ` Duncan Sands
2003-12-12 0:02 ` David Brownell
2003-12-10 17:34 ` David Brownell
2003-12-10 17:54 ` Duncan Sands
2003-12-10 18:19 ` Alan Stern
2003-12-11 9:36 ` Duncan Sands
2003-12-11 15:19 ` Alan Stern
2003-12-11 21:23 ` Duncan Sands
2003-12-12 15:46 ` Alan Stern
2003-12-11 21:29 ` Duncan Sands
2003-12-12 16:18 ` Alan Stern
2003-12-12 18:37 ` David Brownell
2003-12-12 19:17 ` Alan Stern
2003-12-12 19:45 ` David Brownell
2003-12-12 20:48 ` Alan Stern
2003-12-12 21:01 ` Oliver Neukum
2003-12-12 21:27 ` Alan Stern
2003-12-12 23:36 ` Oliver Neukum
2003-12-13 1:10 ` Alan Stern
2003-12-13 11:52 ` Oliver Neukum
2003-12-12 18:50 ` Oliver Neukum
2003-12-10 19:43 ` David Brownell
2003-12-11 9:21 ` Duncan Sands
2003-12-10 17:21 ` David Brownell
2003-12-11 9:42 ` Duncan Sands
2003-12-12 2:21 ` David Brownell
2003-12-12 8:47 ` Duncan Sands
2003-12-12 15:35 ` bill davidsen
2003-12-05 0:08 ` [kernel panic @ reboot] 2.6.0-test10-mm1 Zwane Mwaikambo
2003-11-27 0:59 ` [kernel panic @ reboot in usbcore] 2.6.0-test10-mm1 (culprit: modem_run) Vince
2003-11-27 3:13 ` Zwane Mwaikambo
2003-11-27 8:14 ` Vince
2003-11-27 8:11 ` Duncan Sands
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=200312091123.54412.baldrick@free.fr \
--to=baldrick@free.fr \
--cc=david-b@pacbell.net \
--cc=fuzzy77@free.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
--cc=mfedyk@matchmail.com \
--cc=rddunlap@osdl.org \
--cc=stern@rowland.harvard.edu \
--cc=zwane@holomorphy.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome