From: Pawel Laszczak <pawell@cadence.com>
To: "stern@rowland.harvard.edu" <stern@rowland.harvard.edu>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"krzysztof.kozlowski@linaro.org" <krzysztof.kozlowski@linaro.org>,
"christophe.jaillet@wanadoo.fr" <christophe.jaillet@wanadoo.fr>,
"javier.carrasco@wolfvision.net" <javier.carrasco@wolfvision.net>,
"make_ruc2021@163.com" <make_ruc2021@163.com>,
"peter.chen@nxp.com" <peter.chen@nxp.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Pawel Eichler <peichler@cadence.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: RE: [PATCH v2] usb: xhci: lack of clearing xHC resources
Date: Thu, 27 Feb 2025 07:05:17 +0000 [thread overview]
Message-ID: <PH7PR07MB9538F28D5F4F6706363CC78EDDCD2@PH7PR07MB9538.namprd07.prod.outlook.com> (raw)
In-Reply-To: <a78164bc-67c4-4f31-bbe1-609e19134ddf@rowland.harvard.edu>
>> The xHC resources allocated for USB devices are not released in
>> correct order after resuming in case when while suspend device was
>reconnected.
>>
>> This issue has been detected during the fallowing scenario:
>> - connect hub HS to root port
>> - connect LS/FS device to hub port
>> - wait for enumeration to finish
>> - force host to suspend
>> - reconnect hub attached to root port
>> - wake host
>>
>> For this scenario during enumeration of USB LS/FS device the Cadence
>> xHC reports completion error code for xHC commands because the xHC
>> resources used for devices has not been property released.
>
>s/property/properly/
>
>> XHCI specification doesn't mention that device can be reset in any
>> order so, we should not treat this issue as Cadence xHC controller bug.
>> Similar as during disconnecting in this case the device resources
>> should be cleared starting form the last usb device in tree toward the root
>hub.
>> To fix this issue usbcore driver should call hcd->driver->reset_device
>> for all USB devices connected to hub which was reconnected while
>> suspending.
>>
>> Fixes: 3d82904559f4 ("usb: cdnsp: cdns3 Add main part of Cadence
>> USBSSP DRD Driver")
>> cc: <stable@vger.kernel.org>
>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>>
>> ---
>> Changelog:
>> v2:
>> - Replaced disconnection procedure with releasing only the xHC
>> resources
>>
>> drivers/usb/core/hub.c | 33 +++++++++++++++++++++++++++++++++
>> 1 file changed, 33 insertions(+)
>>
>> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index
>> a76bb50b6202..d3f89528a414 100644
>> --- a/drivers/usb/core/hub.c
>> +++ b/drivers/usb/core/hub.c
>> @@ -6065,6 +6065,36 @@ void usb_hub_cleanup(void)
>> usb_deregister(&hub_driver);
>> } /* usb_hub_cleanup() */
>>
>> +/**
>> + * hub_hc_release_resources - clear resources used by host controller
>> + * @pdev: pointer to device being released
>> + *
>> + * Context: task context, might sleep
>> + *
>> + * Function releases the host controller resources in correct order
>> +before
>> + * making any operation on resuming usb device. The host controller
>> +resources
>> + * allocated for devices in tree should be released starting from the
>> +last
>> + * usb device in tree toward the root hub. This function is used only
>> +during
>> + * resuming device when usb device require reinitialization - that
>> +is, when
>> + * flag udev->reset_resume is set.
>> + *
>> + * This call is synchronous, and may not be used in an interrupt context.
>> + */
>> +static void hub_hc_release_resources(struct usb_device *udev) {
>> + struct usb_hub *hub = usb_hub_to_struct_hub(udev);
>> + struct usb_hcd *hcd = bus_to_hcd(udev->bus);
>> + int i;
>> +
>> + /* Release up resources for all children before this device */
>> + for (i = 0; i < udev->maxchild; i++)
>> + if (hub->ports[i]->child)
>> + hub_hc_release_resources(hub->ports[i]->child);
>> +
>> + if (hcd->driver->reset_device)
>> + hcd->driver->reset_device(hcd, udev); }
>> +
>> /**
>> * usb_reset_and_verify_device - perform a USB port reset to reinitialize a
>device
>> * @udev: device to reset (not in SUSPENDED or NOTATTACHED state) @@
>> -6131,6 +6161,9 @@ static int usb_reset_and_verify_device(struct
>> usb_device *udev)
>>
>> mutex_lock(hcd->address0_mutex);
>>
>> + if (udev->reset_resume)
>> + hub_hc_release_resources(udev);
>
>Don't you want to do this before taking the address0_mutex lock?
I will move it.
>
>> +
>> for (i = 0; i < PORT_INIT_TRIES; ++i) {
>> if (hub_port_stop_enumerate(parent_hub, port1, i)) {
>> ret = -ENODEV;
>
>Doing it this way, you will call hcd->driver->reset_device() multiple times for the
>same device: once for the hub(s) above the device and then once for the device
>itself. But since this isn't a hot path, maybe that doesn't matter.
Yes, it true but the function xhci_discover_or_reset_device which is associated with
hcd->driver->reset_device() include the checking whether device is in SLOT_STATE_DISABLED.
It allows to detect whether device has been already reset and do not repeat the
reset procedure.
Thanks
Pawel Laszczak
>
>Alan Stern
next prev parent reply other threads:[~2025-02-27 7:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250226071646.4034220-1-pawell@cadence.com>
2025-02-26 7:23 ` Pawel Laszczak
2025-02-26 15:47 ` stern
2025-02-27 7:05 ` Pawel Laszczak [this message]
2025-02-27 15:12 ` stern
2025-02-27 8:10 ` kernel test robot
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=PH7PR07MB9538F28D5F4F6706363CC78EDDCD2@PH7PR07MB9538.namprd07.prod.outlook.com \
--to=pawell@cadence.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=gregkh@linuxfoundation.org \
--cc=javier.carrasco@wolfvision.net \
--cc=krzysztof.kozlowski@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=make_ruc2021@163.com \
--cc=peichler@cadence.com \
--cc=peter.chen@nxp.com \
--cc=stable@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®