From: <gregkh@linuxfoundation.org>
To: mathias.nyman@linux.intel.com, baolin.wang@linaro.org,
gregkh@linuxfoundation.org
Cc: <stable@vger.kernel.org>, <stable-commits@vger.kernel.org>
Subject: Patch "xhci: Handle command completion and timeout race" has been added to the 4.9-stable tree
Date: Mon, 09 Jan 2017 11:32:27 +0100 [thread overview]
Message-ID: <148395794710551@kroah.com> (raw)
This is a note to let you know that I've just added the patch titled
xhci: Handle command completion and timeout race
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
xhci-handle-command-completion-and-timeout-race.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
>From a5a1b9514154437aa1ed35c291191f82fd3e941a Mon Sep 17 00:00:00 2001
From: Mathias Nyman <mathias.nyman@linux.intel.com>
Date: Tue, 3 Jan 2017 18:28:48 +0200
Subject: xhci: Handle command completion and timeout race
From: Mathias Nyman <mathias.nyman@linux.intel.com>
commit a5a1b9514154437aa1ed35c291191f82fd3e941a upstream.
If we get a command completion event at the same time as the command
timeout work starts on another cpu we might end up aborting the wrong
command.
If the command completion takes the xhci lock before the timeout work, it
will handle the command, pick the next command, mark it as current_cmd, and
re-queue the timeout work. When the timeout work finally gets the lock
It will start aborting the wrong command.
This case can be resolved by checking if the timeout work is pending inside
the timeout function itself. A new timeout work can only be pending if the
command completed and a new command was queued.
If there are no more commands pending then command completion will set
the current_cmd to NULL, which is already handled in the timeout work.
Reported-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/usb/host/xhci-ring.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1273,7 +1273,11 @@ void xhci_handle_command_timeout(unsigne
spin_lock_irqsave(&xhci->lock, flags);
- if (!xhci->current_cmd) {
+ /*
+ * If timeout work is pending, or current_cmd is NULL, it means we
+ * raced with command completion. Command is handled so just return.
+ */
+ if (!xhci->current_cmd || timer_pending(&xhci->cmd_timer)) {
spin_unlock_irqrestore(&xhci->lock, flags);
return;
}
Patches currently in stable-queue which might be from mathias.nyman@linux.intel.com are
queue-4.9/usb-host-xhci-fix-possible-wild-pointer-when-handling-abort-command.patch
queue-4.9/xhci-handle-command-completion-and-timeout-race.patch
queue-4.9/usb-xhci-fix-possible-wild-pointer.patch
queue-4.9/xhci-free-xhci-virtual-devices-with-leaf-nodes-first.patch
queue-4.9/usb-return-error-code-when-platform_get_irq-fails.patch
queue-4.9/usb-xhci-fix-return-value-of-xhci_setup_device.patch
queue-4.9/usb-xhci-apply-xhci_pme_stuck_quirk-to-intel-apollo-lake.patch
queue-4.9/usb-xhci-hold-lock-over-xhci_abort_cmd_ring.patch
reply other threads:[~2017-01-09 10:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=148395794710551@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=baolin.wang@linaro.org \
--cc=mathias.nyman@linux.intel.com \
--cc=stable-commits@vger.kernel.org \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).