From: Johan Hovold <jhovold@gmail.com>
To: Peter Hurley <peter@hurleysoftware.com>,
Alan Stern <stern@rowland.harvard.edu>
Cc: Johan Hovold <jhovold@gmail.com>,
Greg KH <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-serial@vger.kernel.org
Subject: USB: serial: port lifetimes (was: Re: USB Ooops PL2303 when unplug while use (linux v3.7.3))
Date: Fri, 22 Feb 2013 11:03:39 +0100 [thread overview]
Message-ID: <20130222100339.GB6640@localhost> (raw)
In-Reply-To: <20130214174336.GA2581@localhost>
On Thu, Feb 14, 2013 at 06:43:36PM +0100, Johan Hovold wrote:
> On Wed, Feb 13, 2013 at 01:40:08PM -0500, Peter Hurley wrote:
[...]
> > Looks to me like a bug the usb serial mini-port interface design.
> > A usb bus disconnect has the pl2303 (and every other) mini-port freeing
> > the private data (before unregistering with tty anyway -- not that
> > putting that first would fix the problem).
[...]
> > The tty layer (and its port implementation) can't protect the pl2303
> > mini-port from this behavior/interface design.
> >
> > It's the glue layer's responsibility to correctly manage the differing
> > lifetimes of its bus devices with tty devices (and tty_ports, if used).
> >
> > Meaning, that if the physical device disconnects from the bus, the ports
> > must simply become in-operative; they can't disappear.
[...]
> > BTW, just fixing this one part won't work because the usb serial driver
> > is also abruptly deleting the usb_serial_port device as well:
> >
> > static void usb_serial_disconnect(struct usb_interface *interface)
> > {
> > [...]
> >
> > for (i = 0; i < serial->num_ports; ++i) {
> > port = serial->port[i];
> > if (port) {
> > struct tty_struct *tty = tty_port_tty_get(&port->port);
> > if (tty) {
> > tty_vhangup(tty);
> > tty_kref_put(tty);
> > }
> > kill_traffic(port);
> > cancel_work_sync(&port->work);
> > if (device_is_registered(&port->dev))
> > ========> device_del(&port->dev);
> > }
> > }
> >
> > [...]
> > }
> >
> > Ummm, wasn't that where the port private data pointer was?
>
> Indeed.
We keep the usb-serial-port structure around until the last tty
reference is dropped, but the port private data is freed as part of
unregistering from the bus in disconnect. [ The subdrivers aren't
supposed to access the ports after port_remove is called as part of
unregistration. ]
This wasn't always the case, but unregistering in serial_cleanup (when
the last tty reference is dropped) had other issues. In particular, we
would end up unregistering the parent device before its child (the
interface and usb device are unregistered when disconnect returns)
resulting in broken uevent devpaths:
KERNEL[794.849051] remove /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4.1/1-4.1:1.0 (usb)
KERNEL[794.851649] remove /devices/pci0000:00/0000:00:1a.7/usb1/1-4/1-4.1 (usb)
KERNEL[795.115623] remove /1-4.1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
KERNEL[795.117429] remove /1-4.1:1.0/ttyUSB0 (usb-serial)
This was reported here
https://bugs.freedesktop.org/show_bug.cgi?id=20703
and fixed by Alan Stern in 2d93148ab6 (USB: serial: fix lifetime and
locking problems) by moving unregistration to disconnect.
So we end up with an unregistered device still possibly referenced by
tty instead, and I suspect we can't do much else than deal with any
post-disconnect callbacks. [ These should be few, especially with my
latest TTY-patches applied. ]
Alan, do you see any way around this? It's not possible (or desirable)
to pin the parent device (interface) until the last reference is
dropped, is it?
Other drivers, such as cdc-acm, do unregister when the last reference is
dropped, but could potentially also generate broken uevents:
KERNEL[3042.388951] remove /devices/pci0000:00/0000:00:1d.7/usb2/2-1/2-1:3.1 (usb)
KERNEL[3042.390242] remove /2-1:3.1/tty/ttyACM0 (tty)
[ To trigger this I had to move the tty_kref_put to the end of
disconnect(). As the tty ref is dropped in a workqueue, the disconnect
then returns before cleanup is called, but any outstanding reference
would have the same effect. ]
Johan
next prev parent reply other threads:[~2013-02-22 10:04 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <510B2C09.7020700@gtsys.com.hk>
2013-02-13 14:25 ` USB Ooops PL2303 when unplug while use (linux v3.7.3) Johan Hovold
2013-02-13 14:28 ` [PATCH] USB: serial: fix null-pointer dereferences on disconnect Johan Hovold
[not found] ` <1360765731-23164-1-git-send-email-jhovold-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-02-13 14:34 ` Felipe Balbi
2013-02-13 14:48 ` Johan Hovold
2013-02-13 16:41 ` Greg KH
2013-02-13 16:53 ` [PATCH resend] " Johan Hovold
2013-02-13 17:27 ` [RFC 0/4] tty: port hangup and close issues Johan Hovold
2013-02-13 17:27 ` [RFC 1/4] tty: clean up port shutdown Johan Hovold
2013-02-13 17:27 ` [RFC 2/4] tty: fix DTR/RTS not being dropped on hang up Johan Hovold
[not found] ` <1360776446-31371-3-git-send-email-jhovold-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-02-13 18:06 ` [RFC v2 " Johan Hovold
2013-02-13 19:32 ` [RFC " Peter Hurley
[not found] ` <1360783973.8499.48.camel-AsKIXgLx6sE@public.gmane.org>
2013-02-14 1:11 ` Peter Hurley
[not found] ` <1360804273.3385.23.camel-AsKIXgLx6sE@public.gmane.org>
2013-02-14 9:04 ` Johan Hovold
2013-02-13 17:27 ` [RFC 3/4] tty: clean up port drain-delay handling Johan Hovold
2013-02-14 1:39 ` Peter Hurley
2013-02-14 9:12 ` Johan Hovold
2013-02-13 17:27 ` [RFC 4/4] tty: fix close of uninitialised ports Johan Hovold
2013-02-13 17:36 ` [RFC 0/4] tty: port hangup and close issues Alan Cox
[not found] ` <20130213173630.63e29b47-+KEw/ACL1GZE/aiTQr5FLb0Ud+EcFu5g@public.gmane.org>
2013-02-13 18:05 ` Johan Hovold
[not found] ` <1360776446-31371-1-git-send-email-jhovold-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-02-20 16:02 ` [PATCH 0/4] TTY: port hangup and close fixes Johan Hovold
2013-02-20 16:02 ` [PATCH 1/4] TTY: clean up port shutdown Johan Hovold
2013-02-20 16:02 ` [PATCH 2/4] TTY: fix DTR not being dropped on hang up Johan Hovold
2013-02-23 14:18 ` Peter Hurley
2013-02-26 10:59 ` Johan Hovold
2013-02-20 16:02 ` [PATCH 3/4] TTY: clean up port drain-delay handling Johan Hovold
[not found] ` <1361376172-31860-1-git-send-email-jhovold-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-02-20 16:02 ` [PATCH 4/4] TTY: fix close of uninitialised ports Johan Hovold
2013-02-21 1:53 ` [PATCH 0/4] TTY: port hangup and close fixes Peter Hurley
2013-02-13 18:40 ` USB Ooops PL2303 when unplug while use (linux v3.7.3) Peter Hurley
[not found] ` <1360780808.8499.43.camel-AsKIXgLx6sE@public.gmane.org>
2013-02-14 17:43 ` Johan Hovold
2013-02-22 10:03 ` Johan Hovold [this message]
2013-02-22 15:17 ` USB: serial: port lifetimes (was: Re: USB Ooops PL2303 when unplug while use (linux v3.7.3)) Alan Stern
2013-02-22 17:11 ` Johan Hovold
2013-02-22 17:35 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1302221218270.1365-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2013-02-22 17:44 ` Greg KH
2013-02-22 18:21 ` Peter Hurley
[not found] ` <1361557284.5752.25.camel-AsKIXgLx6sE@public.gmane.org>
2013-02-22 18:57 ` Alan Stern
2013-02-23 16:05 ` Johan Hovold
2013-02-23 16:23 ` Johan Hovold
2013-02-23 16:34 ` Johan Hovold
2013-02-23 17:31 ` Alan Stern
2013-02-23 18:12 ` Johan Hovold
2013-02-23 21:20 ` Alan Stern
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=20130222100339.GB6640@localhost \
--to=jhovold@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter@hurleysoftware.com \
--cc=stern@rowland.harvard.edu \
/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