All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Felipe Balbi <felipe.balbi@linux.intel.com>
Cc: Mathias Nyman <mathias.nyman@linux.intel.com>,
	Linux USB <linux-usb@vger.kernel.org>
Subject: [02/20] usb: host: xhci: check DYING state earlier
Date: Wed, 2 May 2018 10:11:16 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1805021008200.1505-100000@iolanthe.rowland.org> (raw)

On Wed, 2 May 2018, Felipe Balbi wrote:

> >> Look at the result. With this change we don't need to take a lock,
> >> allocate memory, search for endpoint index, search for endpoint
> >> state. All of those are needed for proper operation of the function, but
> >> if the controller has already died, there's no point in going any
> >> further.
> >
> > But we might miss the fact that host died, and go even further, adding URB to list,
> > writing TRBs to ringbuffers etc.
> >
> > In code we save one line,
> > goto: free_priv
> 
> We're saving a lot more than that, actually. All of the following ends
> up being skipped. All of these are unnecessary work when xHC has already
> died:
> 
> 8<------------------------------------------------------------------------
> 
> slot_id = urb->dev->slot_id;
> ep_index = xhci_get_endpoint_index(&urb->ep->desc);
> ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state;
> 
> if (!HCD_HW_ACCESSIBLE(hcd)) {
>         if (!in_interrupt())
>                 xhci_dbg(xhci, "urb submitted during PCI suspend\n");
>         return -ESHUTDOWN;
> }
> 
> if (usb_endpoint_xfer_isoc(&urb->ep->desc))
>         num_tds = urb->number_of_packets;
> else if (usb_endpoint_is_bulk_out(&urb->ep->desc) &&
>     urb->transfer_buffer_length > 0 &&
>     urb->transfer_flags & URB_ZERO_PACKET &&
>     !(urb->transfer_buffer_length % usb_endpoint_maxp(&urb->ep->desc)))
>         num_tds = 2;
> else
>         num_tds = 1;
> 
> urb_priv = kzalloc(sizeof(struct urb_priv) +
>                    num_tds * sizeof(struct xhci_td), mem_flags);
> if (!urb_priv)
>         return -ENOMEM;
> 
> urb_priv->num_tds = num_tds;
> urb_priv->num_tds_done = 0;
> urb->hcpriv = urb_priv;
> 
> trace_xhci_urb_enqueue(urb);
> 
> if (usb_endpoint_xfer_control(&urb->ep->desc)) {
>         /* Check to see if the max packet size for the default control
>          * endpoint changed during FS device enumeration
>          */
>         if (urb->dev->speed == USB_SPEED_FULL) {
>                 ret = xhci_check_maxpacket(xhci, slot_id,
>                                 ep_index, urb);
>                 if (ret < 0) {
>                         xhci_urb_free_priv(urb_priv);
>                         urb->hcpriv = NULL;
>                         return ret;
>                 }
>         }
> }
> 
> spin_lock_irqsave(&xhci->lock, flags);
> 
> 8<------------------------------------------------------------------------

Regardless, how often does it happen that an xHCI host controller dies?  
A few times a day for every xHCI controller in the world seems like a
gross overestimate.

But even if it isn't, who cares if we end up executing the code above a
few extra times per day?  It's the "almost never used" path.  :-)

Alan Stern
---
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

             reply	other threads:[~2018-05-02 14:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02 14:11 Alan Stern [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-05-02 13:02 [02/20] usb: host: xhci: check DYING state earlier Mathias Nyman
2018-05-02 11:46 Felipe Balbi
2018-05-02 11:38 Mathias Nyman
2018-04-17  7:07 Felipe Balbi
2018-04-16 13:31 Mathias Nyman
2018-04-16 12:29 Felipe Balbi

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=Pine.LNX.4.44L0.1805021008200.1505-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=felipe.balbi@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.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 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.