]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
xhci: Fix Link TRB DMA in command ring stopped completion event
authorFaisal Hassan <quic_faisalh@quicinc.com>
Tue, 22 Oct 2024 15:56:31 +0000 (21:26 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Nov 2024 15:25:54 +0000 (16:25 +0100)
commit 075919f6df5dd82ad0b1894898b315fbb3c29b84 upstream.

During the aborting of a command, the software receives a command
completion event for the command ring stopped, with the TRB pointing
to the next TRB after the aborted command.

If the command we abort is located just before the Link TRB in the
command ring, then during the 'command ring stopped' completion event,
the xHC gives the Link TRB in the event's cmd DMA, which causes a
mismatch in handling command completion event.

To address this situation, move the 'command ring stopped' completion
event check slightly earlier, since the specific command it stopped
on isn't of significant concern.

Fixes: 7f84eef0dafb ("USB: xhci: No-op command queueing and irq handler.")
Cc: stable@vger.kernel.org
Signed-off-by: Faisal Hassan <quic_faisalh@quicinc.com>
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20241022155631.1185-1-quic_faisalh@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c

index 15ffa16ba4473916df2d5f0a52a4b87f24cd439e..ad045eecc658831e504222dad9269782257ea369 100644 (file)
@@ -1769,6 +1769,14 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
 
        trace_xhci_handle_command(xhci->cmd_ring, &cmd_trb->generic);
 
+       cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status));
+
+       /* If CMD ring stopped we own the trbs between enqueue and dequeue */
+       if (cmd_comp_code == COMP_COMMAND_RING_STOPPED) {
+               complete_all(&xhci->cmd_ring_stop_completion);
+               return;
+       }
+
        cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
                        cmd_trb);
        /*
@@ -1785,14 +1793,6 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
 
        cancel_delayed_work(&xhci->cmd_timer);
 
-       cmd_comp_code = GET_COMP_CODE(le32_to_cpu(event->status));
-
-       /* If CMD ring stopped we own the trbs between enqueue and dequeue */
-       if (cmd_comp_code == COMP_COMMAND_RING_STOPPED) {
-               complete_all(&xhci->cmd_ring_stop_completion);
-               return;
-       }
-
        if (cmd->command_trb != xhci->cmd_ring->dequeue) {
                xhci_err(xhci,
                         "Command completion event does not match command\n");