All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: Mathias Nyman
	<mathias.nyman-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Greg KH
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	lukaszx.szulc-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	Andy Shevchenko
	<andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Andy Shevchenko
	<andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>,
	Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>,
	Sudip Mukherjee
	<sudipm.mukherjee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: usb HC busted?
Date: Fri, 20 Jul 2018 14:46:20 +0300	[thread overview]
Message-ID: <f8cfa055-cfd8-db66-a386-72bf904e17cd@linux.intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1807191046180.1308-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>

On 19.07.2018 17:57, Alan Stern wrote:
> On Thu, 19 Jul 2018, Mathias Nyman wrote:
> 
>> xhci driver will set up all the endpoints for the new altsetting already in
>> usb_hcd_alloc_bandwidth().
>>
>> New endpoints will be ready and rings running after this. I don't know the exact
>> history behind this, but I assume it is because xhci does all of the steps to
>> drop/add, disable/enable endpoints and check bandwidth in a single configure
>> endpoint command, that will return errors if there is not enough bandwidth.
> 
> That's right; Sarah and I spent some time going over this while she was
> working on it.  But it looks like the approach isn't adequate.
> 
>> This command is issued in hcd->driver->check_bandwidth()
>> This means that xhci doesn't really do much in hcd->driver->endpoint_disable or
>> hcd->driver->endpoint_enable
>>
>> It also means that xhci driver assumes rings are empty when
>> hcd->driver->check_bandwidth is called. It will bluntly free dropped rings.
>> If there are URBs left on a endpoint ring that was dropped+added
>> (freed+reallocated) then those URBs will contain pointers to freed ring,
>> causing issues when usb_hcd_flush_endpoint() cancels those URBs.
>>
>> usb_set_interface()
>>     usb_hcd_alloc_bandwidth()
>>       hcd->driver->drop_endpoint()
>>       hcd->driver->add_endpoint() // allocates new rings
>>       hcd->driver->check_bandwidth() // issues configure endpoint command, free rings.
>>     usb_disable_interface(iface, true)
>>       usb_disable_endpoint()
>>         usb_hcd_flush_endpoint() // will access freed ring if URBs found!!
>>         usb_hcd_disable_endpoint()
>>           hcd->driver->endpoint_disable()  // xhci does nothing
>>     usb_enable_interface(iface, true)
>>       usb_enable_endpoint(ep_addrss, true) // not really doing much on xhci side.
>>
>> As first aid I could try to implement checks that make sure the flushed URBs
>> trb pointers really are on the current endpoint ring, and also add some warning
>> if we are we are dropping endpoints with URBs still queued.
>>
>> But we need to fix this properly as well.
>> xhci needs to be more in sync with usb core in usb_set_interface(), currently xhci
>> has the altssetting up and running when usb core hasn't event started flushing endpoints.
> 
> Absolutely.  The core tries to be compatible with host controller
> drivers that either allocate bandwidth as it is requested or else
> allocate bandwidth all at once when an altsetting is installed.
> 
> xhci-hcd falls into the second category.  However, this approach
> requires the bandwidth verification for the new altsetting to be
> performed before the old altsetting has been disabled, and the xHCI
> hardware can't do this.
> 
> We may need to change the core so that the old endpoints are disabled
> before the bandwidth check is done, instead of after.  Of course, this
> leads to an awkward situation if the check fails -- we'd probably have
> to go back and re-install the old altsetting.

That would help xhci a lot.

If we want to avoid the awkward altsetting re-install after bandwidth failure
then adding a extra endpoint flush before checking the bandwidth would already help a lot.

The endpoint disabling can then be remain after bandwidth checking.
Does that work for other host controllers?

-Mathias

WARNING: multiple messages have this Message-ID (diff)
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	linux-usb@vger.kernel.org, lukaszx.szulc@intel.com,
	Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	iommu@lists.linux-foundation.org
Subject: usb HC busted?
Date: Fri, 20 Jul 2018 14:46:20 +0300	[thread overview]
Message-ID: <f8cfa055-cfd8-db66-a386-72bf904e17cd@linux.intel.com> (raw)

On 19.07.2018 17:57, Alan Stern wrote:
> On Thu, 19 Jul 2018, Mathias Nyman wrote:
> 
>> xhci driver will set up all the endpoints for the new altsetting already in
>> usb_hcd_alloc_bandwidth().
>>
>> New endpoints will be ready and rings running after this. I don't know the exact
>> history behind this, but I assume it is because xhci does all of the steps to
>> drop/add, disable/enable endpoints and check bandwidth in a single configure
>> endpoint command, that will return errors if there is not enough bandwidth.
> 
> That's right; Sarah and I spent some time going over this while she was
> working on it.  But it looks like the approach isn't adequate.
> 
>> This command is issued in hcd->driver->check_bandwidth()
>> This means that xhci doesn't really do much in hcd->driver->endpoint_disable or
>> hcd->driver->endpoint_enable
>>
>> It also means that xhci driver assumes rings are empty when
>> hcd->driver->check_bandwidth is called. It will bluntly free dropped rings.
>> If there are URBs left on a endpoint ring that was dropped+added
>> (freed+reallocated) then those URBs will contain pointers to freed ring,
>> causing issues when usb_hcd_flush_endpoint() cancels those URBs.
>>
>> usb_set_interface()
>>     usb_hcd_alloc_bandwidth()
>>       hcd->driver->drop_endpoint()
>>       hcd->driver->add_endpoint() // allocates new rings
>>       hcd->driver->check_bandwidth() // issues configure endpoint command, free rings.
>>     usb_disable_interface(iface, true)
>>       usb_disable_endpoint()
>>         usb_hcd_flush_endpoint() // will access freed ring if URBs found!!
>>         usb_hcd_disable_endpoint()
>>           hcd->driver->endpoint_disable()  // xhci does nothing
>>     usb_enable_interface(iface, true)
>>       usb_enable_endpoint(ep_addrss, true) // not really doing much on xhci side.
>>
>> As first aid I could try to implement checks that make sure the flushed URBs
>> trb pointers really are on the current endpoint ring, and also add some warning
>> if we are we are dropping endpoints with URBs still queued.
>>
>> But we need to fix this properly as well.
>> xhci needs to be more in sync with usb core in usb_set_interface(), currently xhci
>> has the altssetting up and running when usb core hasn't event started flushing endpoints.
> 
> Absolutely.  The core tries to be compatible with host controller
> drivers that either allocate bandwidth as it is requested or else
> allocate bandwidth all at once when an altsetting is installed.
> 
> xhci-hcd falls into the second category.  However, this approach
> requires the bandwidth verification for the new altsetting to be
> performed before the old altsetting has been disabled, and the xHCI
> hardware can't do this.
> 
> We may need to change the core so that the old endpoints are disabled
> before the bandwidth check is done, instead of after.  Of course, this
> leads to an awkward situation if the check fails -- we'd probably have
> to go back and re-install the old altsetting.

That would help xhci a lot.

If we want to avoid the awkward altsetting re-install after bandwidth failure
then adding a extra endpoint flush before checking the bandwidth would already help a lot.

The endpoint disabling can then be remain after bandwidth checking.
Does that work for other host controllers?

-Mathias
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-07-20 11:46 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180518100650.kfw6wijpncpvqx7j@debian>
     [not found] ` <6790b352-add3-5531-115c-15db6c9c744d@intel.com>
     [not found]   ` <20180518130458.v73syr3fltdzdzzi@debian>
     [not found]     ` <881d576b-c7c1-ef74-c6bc-68b81371e7e0@intel.com>
     [not found]       ` <20180523212956.n4ztasdffg2aeaku@debian>
2018-05-24 13:35         ` usb HC busted? Mathias Nyman
2018-06-04 15:28           ` Sudip Mukherjee
2018-06-06 14:12             ` Mathias Nyman
2018-06-06 14:12               ` Mathias Nyman
     [not found]               ` <06226ecb-baad-cc36-e9e3-797dabb0aa5e-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-06 15:36                 ` Andy Shevchenko
2018-06-06 15:36                   ` Andy Shevchenko
     [not found]                   ` <42ec4ab07d96b4302b875ac9c5eb76675bf85690.camel-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-06 16:45                     ` Sudip Mukherjee
2018-06-06 16:45                       ` Sudip Mukherjee
2018-06-07  7:40                       ` Mathias Nyman
2018-06-07  7:40                         ` Mathias Nyman
     [not found]                         ` <2e8829c2-850d-6bca-5f0c-58a809dc9499-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-08  9:07                           ` Sudip Mukherjee
2018-06-08  9:07                             ` Sudip Mukherjee
2018-06-21  0:53                           ` Sudip Mukherjee
2018-06-21  0:53                             ` Sudip Mukherjee
2018-06-21 11:01                             ` Mathias Nyman
2018-06-21 11:01                               ` Mathias Nyman
     [not found]                               ` <2b4fe87a-3706-0aa8-2b61-a9c1d1352a7a-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-25 16:15                                 ` Sudip Mukherjee
2018-06-25 16:15                                   ` Sudip Mukherjee
2018-06-27 11:59                                   ` Sudip Mukherjee
2018-06-27 11:59                                     ` Sudip Mukherjee
2018-06-27 12:20                                     ` Sudip Mukherjee
2018-06-27 12:20                                       ` Sudip Mukherjee
2018-06-29 11:41                                     ` Mathias Nyman
2018-06-29 11:41                                       ` Mathias Nyman
     [not found]                                       ` <4b269009-7593-a41f-9f0f-203ee174b52e-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-06-30 21:07                                         ` Sudip Mukherjee
2018-06-30 21:07                                           ` Sudip Mukherjee
2018-07-17 11:41                                           ` Sudip Mukherjee
2018-07-17 11:41                                             ` Sudip Mukherjee
2018-07-17 12:04                                             ` Greg KH
2018-07-17 12:04                                               ` Greg Kroah-Hartman
     [not found]                                               ` <20180717120411.GB28592-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2018-07-17 13:20                                                 ` Sudip Mukherjee
2018-07-17 13:20                                                   ` Sudip Mukherjee
2018-07-17 13:53                                                   ` Greg KH
2018-07-17 13:53                                                     ` Greg Kroah-Hartman
2018-07-17 14:31                                                 ` Alan Stern
2018-07-17 14:31                                                   ` Alan Stern
     [not found]                                                   ` <Pine.LNX.4.44L0.1807171029310.1689-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2018-07-17 15:52                                                     ` Greg KH
2018-07-17 15:52                                                       ` Greg Kroah-Hartman
     [not found]                                                       ` <20180717155259.GB2416-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2018-07-17 15:59                                                         ` Sudip Mukherjee
2018-07-17 15:59                                                           ` Sudip Mukherjee
2018-07-17 17:01                                                           ` Sudip Mukherjee
2018-07-17 17:01                                                             ` Sudip Mukherjee
2018-07-17 14:28                                             ` Alan Stern
2018-07-17 14:28                                               ` Alan Stern
     [not found]                                               ` <Pine.LNX.4.44L0.1807171022001.1689-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2018-07-17 14:40                                                 ` Sudip Mukherjee
2018-07-17 14:40                                                   ` Sudip Mukherjee
2018-07-17 14:49                                                   ` Sudip Mukherjee
2018-07-17 14:49                                                     ` Sudip Mukherjee
2018-07-17 15:08                                                     ` Alan Stern
2018-07-17 15:08                                                       ` Alan Stern
2018-07-17 15:10                                                     ` Sudip Mukherjee
2018-07-17 15:10                                                       ` Sudip Mukherjee
2018-07-19 10:59                                                       ` Mathias Nyman
2018-07-19 10:59                                                         ` Mathias Nyman
     [not found]                                                         ` <f7801c24-fa98-6338-0b26-33a0ac9498bb-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-19 11:34                                                           ` Sudip Mukherjee
2018-07-19 11:34                                                             ` Sudip Mukherjee
2018-07-19 15:42                                                             ` Mathias Nyman
2018-07-19 15:42                                                               ` Mathias Nyman
     [not found]                                                               ` <ab814c88-0857-5444-57da-34c21b8d7f6c-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-19 17:32                                                                 ` Sudip Mukherjee
2018-07-19 17:32                                                                   ` Sudip Mukherjee
2018-07-20 11:10                                                                   ` Mathias Nyman
2018-07-20 11:10                                                                     ` Mathias Nyman
     [not found]                                                                     ` <d3f5575c-c75b-ea16-6da9-b2fe3cc9c102-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-20 12:54                                                                       ` Sudip Mukherjee
2018-07-20 12:54                                                                         ` Sudip Mukherjee
2018-07-21 10:55                                                                         ` Sudip Mukherjee
2018-07-21 10:55                                                                           ` Sudip Mukherjee
2018-07-19 14:57                                                           ` Alan Stern
2018-07-19 14:57                                                             ` Alan Stern
     [not found]                                                             ` <Pine.LNX.4.44L0.1807191046180.1308-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2018-07-20 11:46                                                               ` Mathias Nyman [this message]
2018-07-20 11:46                                                                 ` Mathias Nyman
     [not found]                                                                 ` <f8cfa055-cfd8-db66-a386-72bf904e17cd-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-20 14:09                                                                   ` Alan Stern
2018-07-20 14:09                                                                     ` Alan Stern
2018-06-06 16:42                 ` Sudip Mukherjee
2018-06-06 16:42                   ` Sudip Mukherjee
2018-06-03 19:37 Sudip Mukherjee

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=f8cfa055-cfd8-db66-a386-72bf904e17cd@linux.intel.com \
    --to=mathias.nyman-vuqaysv1563yd54fqh9/ca@public.gmane.org \
    --cc=andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
    --cc=andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=hch-jcswGhMUV9g@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lukaszx.szulc-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=mathias.nyman-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
    --cc=sudipm.mukherjee-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.