From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Aaron Ma <aaron.ma@canonical.com>,
mathias.nyman@intel.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status
Date: Tue, 23 Oct 2018 13:39:43 +0300 [thread overview]
Message-ID: <8b36fa3a-7999-a2e2-ec01-aa459ec89867@linux.intel.com> (raw)
On 22.10.2018 20:53, Aaron Ma wrote:
>
>
> On 10/22/18 9:12 PM, Mathias Nyman wrote:
>> On 21.10.2018 20:08, Aaron Ma wrote:
>>> Realtek USB3.0 Card Reader [0bda:0328] reports wrong port status on
>>> Cannon lake PCH USB3.1 xHCI [8086:a36d] after resume from S3,
>>> after clear port reset it works fine.
>>>
>>> Since this device is registered on USB3 roothub at boot,
>>> when port status reports not superspeed, xhci_get_port_status will call
>>> an uninitialized completion in bus_state[0].
>>> Kernel will hang because of NULL pointer.
>>>
>>> Restrict the USB2 resume status check in USB2 roothub to fix hang issue.
>>> No harm to initialize USB3 bus_state[0] in case it is called.
>>>
>>> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
>>> ---
>>> drivers/usb/host/xhci-hub.c | 2 +-
>>> drivers/usb/host/xhci-mem.c | 1 >>> drivers/usb/host/xhci-ring.c | 2 +-
>>> 3 files changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
>>> index 7e2a531ba321..d30ca6ceffc9 100644
>>> --- a/drivers/usb/host/xhci-hub.c
>>> +++ b/drivers/usb/host/xhci-hub.c
>>> @@ -876,7 +876,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
>>> status |= USB_PORT_STAT_SUSPEND;
>>> }
>>> if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME &&
>>> - !DEV_SUPERSPEED_ANY(raw_port_status)) {
>>> + !DEV_SUPERSPEED_ANY(raw_port_status) && 1 == hcd_index(hcd)) {
>>> if ((raw_port_status & PORT_RESET) ||
>>> !(raw_port_status & PORT_PE))
>>> return 0xffffffff;
>>
>> The original !DEV_SUPERSPEED_ANY() check was not suitable here.
>> It checks the port-speed field of portsc register (bits 13:10), which
>> are only valid for USB3
>> ports if all link training is done and port reached its "enabled" state.
>> Otherwise it will return 0, and USB3 ports may be mistaken for USB2 ports.
>
> PORT_ENABLE should be already set to one.
> The same device ID card reader doesn't have issue on Sunrise Point.
> Maybe it is related to Cannon lake PCH USB controller?
>
Ok, thanks for the info
>
> V2 sent out. Cc-ed stable.
>
>> Any chance you to check if the refactored code works with the Realtek
>> device?
>> I just created a "get_port_status_refactor" branch for it:
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git
>> get_port_status_refactor
>
> The hang issue is not reproduced on this kernel branch.
>
Great, thanks for testing it
-Mathias
WARNING: multiple messages have this Message-ID (diff)
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Aaron Ma <aaron.ma@canonical.com>,
mathias.nyman@intel.com, gregkh@linuxfoundation.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status
Date: Tue, 23 Oct 2018 13:39:43 +0300 [thread overview]
Message-ID: <8b36fa3a-7999-a2e2-ec01-aa459ec89867@linux.intel.com> (raw)
In-Reply-To: <edd66255-4998-1cf4-2d9b-6185963a4ece@canonical.com>
On 22.10.2018 20:53, Aaron Ma wrote:
>
>
> On 10/22/18 9:12 PM, Mathias Nyman wrote:
>> On 21.10.2018 20:08, Aaron Ma wrote:
>>> Realtek USB3.0 Card Reader [0bda:0328] reports wrong port status on
>>> Cannon lake PCH USB3.1 xHCI [8086:a36d] after resume from S3,
>>> after clear port reset it works fine.
>>>
>>> Since this device is registered on USB3 roothub at boot,
>>> when port status reports not superspeed, xhci_get_port_status will call
>>> an uninitialized completion in bus_state[0].
>>> Kernel will hang because of NULL pointer.
>>>
>>> Restrict the USB2 resume status check in USB2 roothub to fix hang issue.
>>> No harm to initialize USB3 bus_state[0] in case it is called.
>>>
>>> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
>>> ---
>>> drivers/usb/host/xhci-hub.c | 2 +-
>>> drivers/usb/host/xhci-mem.c | 1 >>> drivers/usb/host/xhci-ring.c | 2 +-
>>> 3 files changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
>>> index 7e2a531ba321..d30ca6ceffc9 100644
>>> --- a/drivers/usb/host/xhci-hub.c
>>> +++ b/drivers/usb/host/xhci-hub.c
>>> @@ -876,7 +876,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
>>> status |= USB_PORT_STAT_SUSPEND;
>>> }
>>> if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME &&
>>> - !DEV_SUPERSPEED_ANY(raw_port_status)) {
>>> + !DEV_SUPERSPEED_ANY(raw_port_status) && 1 == hcd_index(hcd)) {
>>> if ((raw_port_status & PORT_RESET) ||
>>> !(raw_port_status & PORT_PE))
>>> return 0xffffffff;
>>
>> The original !DEV_SUPERSPEED_ANY() check was not suitable here.
>> It checks the port-speed field of portsc register (bits 13:10), which
>> are only valid for USB3
>> ports if all link training is done and port reached its "enabled" state.
>> Otherwise it will return 0, and USB3 ports may be mistaken for USB2 ports.
>
> PORT_ENABLE should be already set to one.
> The same device ID card reader doesn't have issue on Sunrise Point.
> Maybe it is related to Cannon lake PCH USB controller?
>
Ok, thanks for the info
>
> V2 sent out. Cc-ed stable.
>
>> Any chance you to check if the refactored code works with the Realtek
>> device?
>> I just created a "get_port_status_refactor" branch for it:
>>
>> git://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git
>> get_port_status_refactor
>
> The hang issue is not reproduced on this kernel branch.
>
Great, thanks for testing it
-Mathias
next reply other threads:[~2018-10-23 10:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-23 10:39 Mathias Nyman [this message]
2018-10-23 10:39 ` [PATCH 1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Mathias Nyman
-- strict thread matches above, loose matches on Subject: below --
2018-10-22 17:53 [1/2] " Aaron Ma
2018-10-22 17:53 ` [PATCH 1/2] " Aaron Ma
2018-10-22 13:23 [1/2] " Aaron Ma
2018-10-22 13:23 ` [PATCH 1/2] " Aaron Ma
2018-10-22 13:12 [1/2] " Mathias Nyman
2018-10-22 13:12 ` [PATCH 1/2] " Mathias Nyman
2018-10-22 3:37 [2/2] usb: xhci: fix timeout for transition from RExit to U0 Aaron Ma
2018-10-22 3:37 ` [PATCH 2/2] " Aaron Ma
2018-10-21 18:21 [2/2] " Greg Kroah-Hartman
2018-10-21 18:21 ` [PATCH 2/2] " Greg KH
2018-10-21 17:08 [2/2] " Aaron Ma
2018-10-21 17:08 ` [PATCH 2/2] " Aaron Ma
2018-10-21 17:08 [1/2] usb: xhci: fix uninitialized completion when USB3 port got wrong status Aaron Ma
2018-10-21 17:08 ` [PATCH 1/2] " Aaron Ma
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=8b36fa3a-7999-a2e2-ec01-aa459ec89867@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=aaron.ma@canonical.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@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.