1. 18 5月, 2017 4 次提交
    • M
      xhci: Fix command ring stop regression in 4.11 · 604d02a2
      Mathias Nyman 提交于
      In 4.11 TRB completion codes were renamed to match spec.
      
      Completion codes for command ring stopped and endpoint stopped
      were mixed, leading to failures while handling a stopped command ring.
      
      Use the correct completion code for command ring stopped events.
      
      Fixes: 0b7c105a ("usb: host: xhci: rename completion codes to match spec")
      Cc: <stable@vger.kernel.org> # 4.11
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      604d02a2
    • A
      USB: xhci: fix lock-inversion problem · 63aea0db
      Alan Stern 提交于
      With threaded interrupts, bottom-half handlers are called with
      interrupts enabled.  Therefore they can't safely use spin_lock(); they
      have to use spin_lock_irqsave().  Lockdep warns about a violation
      occurring in xhci_irq():
      
      =========================================================
      [ INFO: possible irq lock inversion dependency detected ]
      4.11.0-rc8-dbg+ #1 Not tainted
      ---------------------------------------------------------
      swapper/7/0 just changed the state of lock:
       (&(&ehci->lock)->rlock){-.-...}, at: [<ffffffffa0130a69>]
      ehci_hrtimer_func+0x29/0xc0 [ehci_hcd]
      but this lock took another, HARDIRQ-unsafe lock in the past:
       (hcd_urb_list_lock){+.....}
      
      and interrupts could create inverse lock ordering between them.
      
      other info that might help us debug this:
       Possible interrupt unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(hcd_urb_list_lock);
                                     local_irq_disable();
                                     lock(&(&ehci->lock)->rlock);
                                     lock(hcd_urb_list_lock);
        <Interrupt>
          lock(&(&ehci->lock)->rlock);
       *** DEADLOCK ***
      
      no locks held by swapper/7/0.
      the shortest dependencies between 2nd lock and 1st lock:
       -> (hcd_urb_list_lock){+.....} ops: 252 {
          HARDIRQ-ON-W at:
                            __lock_acquire+0x602/0x1280
                            lock_acquire+0xd5/0x1c0
                            _raw_spin_lock+0x2f/0x40
                            usb_hcd_unlink_urb_from_ep+0x1b/0x60 [usbcore]
                            xhci_giveback_urb_in_irq.isra.45+0x70/0x1b0 [xhci_hcd]
                            finish_td.constprop.60+0x1d8/0x2e0 [xhci_hcd]
                            xhci_irq+0xdd6/0x1fa0 [xhci_hcd]
                            usb_hcd_irq+0x26/0x40 [usbcore]
                            irq_forced_thread_fn+0x2f/0x70
                            irq_thread+0x149/0x1d0
                            kthread+0x113/0x150
                            ret_from_fork+0x2e/0x40
      
      This patch fixes the problem.
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      Reported-and-tested-by: NBart Van Assche <bart.vanassche@sandisk.com>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      63aea0db
    • P
      usb: host: xhci-ring: don't need to clear interrupt pending for MSI enabled hcd · 6a29beef
      Peter Chen 提交于
      According to xHCI spec Figure 30: Interrupt Throttle Flow Diagram
      
      	If PCI Message Signaled Interrupts (MSI or MSI-X) are enabled,
             	then the assertion of the Interrupt Pending (IP) flag in Figure 30
             	generates a PCI Dword write. The IP flag is automatically cleared
             	by the completion of the PCI write.
      
      the MSI enabled HCs don't need to clear interrupt pending bit, but
      hcd->irq = 0 doesn't equal to MSI enabled HCD. At some Dual-role
      controller software designs, it sets hcd->irq as 0 to avoid HCD
      requesting interrupt, and they want to decide when to call usb_hcd_irq
      by software.
      Signed-off-by: NPeter Chen <peter.chen@nxp.com>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a29beef
    • M
      usb: xhci: trace URB before giving it back instead of after · 7bc5d5af
      Mathias Nyman 提交于
      Don't access any members of a URB after giving it back.
      URB might be freed by then already.
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bc5d5af
  2. 08 4月, 2017 8 次提交
  3. 29 3月, 2017 1 次提交
  4. 25 1月, 2017 23 次提交
  5. 11 1月, 2017 1 次提交
    • M
      xhci: fix deadlock at host remove by running watchdog correctly · d6169d04
      Mathias Nyman 提交于
      If a URB is killed while the host is removed we can end up in a situation
      where the hub thread takes the roothub device lock, and waits for
      the URB to be given back by xhci-hcd, blocking the host remove code.
      
      xhci-hcd tries to stop the endpoint and give back the urb, but can't
      as the host is removed from PCI bus at the same time, preventing the normal
      way of giving back urb.
      
      Instead we need to rely on the stop command timeout function to give back
      the urb. This xhci_stop_endpoint_command_watchdog() timeout function
      used a XHCI_STATE_DYING flag to indicate if the timeout function is already
      running, but later this flag has been taking into use in other places to
      mark that xhci is dying.
      
      Remove checks for XHCI_STATE_DYING in xhci_urb_dequeue. We are still
      checking that reading from pci state does not return 0xffffffff or that
      host is not halted before trying to stop the endpoint.
      
      This whole area of stopping endpoints, giving back URBs, and the wathdog
      timeout need rework, this fix focuses on solving a specific deadlock
      issue that we can then send to stable before any major rework.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d6169d04
  6. 04 1月, 2017 3 次提交
    • F
      usb: host: xhci: handle COMP_STOP from SETUP phase too · 29fc1aa4
      Felipe Balbi 提交于
      Stop Endpoint command can come at any point and we
      have no control of that. We should make sure to
      handle COMP_STOP on SETUP phase as well, otherwise
      urb->actual_length might be set to negative values
      in some occasions such as below:
      
       urb->length = 4;
       build_control_transfer_td_for(urb, ep);
      
       					stop_endpoint(ep);
      
      COMP_STOP:
      	[...]
      	urb->actual_length = urb->length - trb->length;
      
      trb->length is 8 for SETUP stage (8 control request
      bytes), so actual_length would be set to -4 in this
      case.
      
      While doing that, also make sure to use TRB_TYPE
      field of the actual TRB instead of matching pointers
      to figure out in which stage of the control transfer
      we got our completion event.
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: NFelipe Balbi <felipe.balbi@linux.intel.com>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      29fc1aa4
    • O
      xhci: Fix race related to abort operation · 1c111b6c
      OGAWA Hirofumi 提交于
      Current abort operation has race.
      
          xhci_handle_command_timeout()
            xhci_abort_cmd_ring()
              xhci_write_64(CMD_RING_ABORT)
              xhci_handshake(5s)
      	  do {
      	    check CMD_RING_RUNNING
                  udelay(1)
      					 ...
      					 COMP_CMD_ABORT event
      					 COMP_CMD_STOP event
      					 xhci_handle_stopped_cmd_ring()
      					   restart cmd_ring
                                                 CMD_RING_RUNNING become 1 again
      	  } while ()
                return -ETIMEDOUT
              xhci_write_64(CMD_RING_ABORT)
              /* can abort random command */
      
      To do abort operation correctly, we have to wait both of COMP_CMD_STOP
      event and negation of CMD_RING_RUNNING.
      
      But like above, while timeout handler is waiting negation of
      CMD_RING_RUNNING, event handler can restart cmd_ring. So timeout
      handler never be notice negation of CMD_RING_RUNNING, and retry of
      CMD_RING_ABORT can abort random command (BTW, I guess retry of
      CMD_RING_ABORT was workaround of this race).
      
      To fix this race, this moves xhci_handle_stopped_cmd_ring() to
      xhci_abort_cmd_ring().  And timeout handler waits COMP_CMD_STOP event.
      
      At this point, timeout handler is owner of cmd_ring, and safely
      restart cmd_ring by using xhci_handle_stopped_cmd_ring().
      
      [FWIW, as bonus, this way would be easily extend to add CMD_RING_PAUSE
      operation]
      
      [locks edited as patch is rebased on other locking fixes -Mathias]
      Signed-off-by: NOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1c111b6c
    • O
      xhci: Use delayed_work instead of timer for command timeout · cb4d5ce5
      OGAWA Hirofumi 提交于
      This is preparation to fix abort operation race (See "xhci: Fix race
      related to abort operation"). To make timeout sleepable, use
      delayed_work instead of timer.
      
      [change a newly added pending timer fix to pending work -Mathias]
      Signed-off-by: NOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
      Signed-off-by: NMathias Nyman <mathias.nyman@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cb4d5ce5