]> git.baikalelectronics.ru Git - kernel.git/commitdiff
xhci: Fix command ring pointer corruption while aborting a command
authorPavankumar Kondeti <pkondeti@codeaurora.org>
Fri, 8 Oct 2021 09:25:46 +0000 (12:25 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Oct 2021 09:40:13 +0000 (11:40 +0200)
commit ff0e50d3564f33b7f4b35cadeabd951d66cfc570 upstream.

The command ring pointer is located at [6:63] bits of the command
ring control register (CRCR). All the control bits like command stop,
abort are located at [0:3] bits. While aborting a command, we read the
CRCR and set the abort bit and write to the CRCR. The read will always
give command ring pointer as all zeros. So we essentially write only
the control bits. Since we split the 64 bit write into two 32 bit writes,
there is a possibility of xHC command ring stopped before the upper
dword (all zeros) is written. If that happens, xHC updates the upper
dword of its internal command ring pointer with all zeros. Next time,
when the command ring is restarted, we see xHC memory access failures.
Fix this issue by only writing to the lower dword of CRCR where all
control bits are located.

Cc: stable@vger.kernel.org
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20211008092547.3996295-5-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c

index 1228b3d92db0600308da379bcef94072964f9988..2c92fd19e782206ed0e7ac1f571fb6f2eb343542 100644 (file)
@@ -339,16 +339,22 @@ static void xhci_handle_stopped_cmd_ring(struct xhci_hcd *xhci,
 /* Must be called with xhci->lock held, releases and aquires lock back */
 static int xhci_abort_cmd_ring(struct xhci_hcd *xhci, unsigned long flags)
 {
-       u64 temp_64;
+       u32 temp_32;
        int ret;
 
        xhci_dbg(xhci, "Abort command ring\n");
 
        reinit_completion(&xhci->cmd_ring_stop_completion);
 
-       temp_64 = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
-       xhci_write_64(xhci, temp_64 | CMD_RING_ABORT,
-                       &xhci->op_regs->cmd_ring);
+       /*
+        * The control bits like command stop, abort are located in lower
+        * dword of the command ring control register. Limit the write
+        * to the lower dword to avoid corrupting the command ring pointer
+        * in case if the command ring is stopped by the time upper dword
+        * is written.
+        */
+       temp_32 = readl(&xhci->op_regs->cmd_ring);
+       writel(temp_32 | CMD_RING_ABORT, &xhci->op_regs->cmd_ring);
 
        /* Section 4.6.1.2 of xHCI 1.0 spec says software should also time the
         * completion of the Command Abort operation. If CRR is not negated in 5