From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: 胡连勤 <hulianqin@vivo.com>, "Michal Pecio" <michal.pecio@gmail.com>
Cc: Selvarasu Ganesan <selvarasu.g@samsung.com>,
Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"quic_wcheng@quicinc.com" <quic_wcheng@quicinc.com>,
"broonie@kernel.org" <broonie@kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"cpgs@samsung.com" <cpgs@samsung.com>,
"alim.akhtar@samsung.com" <alim.akhtar@samsung.com>,
"thiagu.r@samsung.com" <thiagu.r@samsung.com>,
Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: Re: 答复: [PATCH] xhci: sideband: check vdev liveness before removing endpoints on unregister
Date: Mon, 14 Sep 2026 16:09:33 +0300 [thread overview]
Message-ID: <c6c9890f-46d8-42f1-a7e7-8a5d551fa22c@linux.intel.com> (raw)
In-Reply-To: <TYUPR06MB62170DB4AB23F7A79E8DA466D2BB2@TYUPR06MB6217.apcprd06.prod.outlook.com>
On 9/14/26 15:24, 胡连勤 wrote:
> Hi Michal,
>
>>> Thanks for the analysis. A clarification on the hub_event() reference
>>> in my patch:
>>>
>>> The crash trace shows hub_event() at the top because that's the actual
>>> crash call stack from the failing device. The full sequence is:
>>>
>>> hub_event()
>>> -> port_event() [hub.c:5966]
>>> -> usb_reset_device(udev) [hub.c:5875]
>>> -> usb_reset_and_verify_device() [hub.c:6183]
>>> -> hub_port_init() [hub.c:6228]
>>> -> hcd->driver->address_device() [hub.c:4781]
>>> -> xhci_setup_device() <-- COMP_USB_TRANSACTION_ERROR
>>> -> xhci_disable_and_free_slot() [xhci.c:4438]
>>> -> xhci_free_virt_device() <-- frees vdev here
>>
>> So not a mistake and this is indeed a dangerous case. And AFAICT, in
>> this path udev's pre_reset() routine isn't called and therefore can't
>> be used to fix your issue, unless USB core is patched to call it.
>>
> Actually it is. The crash path goes through usb_reset_device()
> (hub.c:5875), which calls drv->pre_reset() at hub.c:6412 before
> usb_reset_and_verify_device(). So pre_reset/post_reset is viable —
> if the sideband client is a USB interface driver.
>
>> But xhci_discover_or_reset_device() is called: before hub_port_init()
>> calls problematic hub_enable_device() / hub_address_device() functions,
>> it calls hub_port_reset(), which calls hcd->driver->reset_device().
>>
>> But I'm not entirely sure what happens if reset fails before this call
>> is made and then hub_port_init() jumps to re_enumerate. The function
>> bails out, but sooner or later somebody will try to free this device in
>> some manner, I suppose, so what happens then?
>>
> By the time we reach re_enumerate (hub.c:6235), xhci_setup_device()
> has already freed vdev+rings via xhci_disable_and_free_slot()
> (xhci.c:4438) without notifying sideband. The later xhci_free_dev()
> is a no-op because xhci->devs[slot_id] is already NULL. So the
> dangerous window is between xhci_discover_or_reset_device() (with
> callback) and xhci_setup_device() failure (without callback).
> Given pre_reset() is available, the proposed fix:
>
> 1. Sideband client implements pre_reset() to unregister and stop
> ring access before reset.
Sounds good, call xhci_sideband_remove_endpoint() for every offloaded endpoint.
If possible then maybe even unregister sideband for this device completely here.
> 2. Add a sideband callback in xhci_free_virt_device() for defense
> in depth.
Selvarasu Ganesan pointed out that xhci 'core' in fact doesn't include
xhci-sideband.h yet. If possible I'd like to keep it that way.
Setting xhci->sideband->vdev to NULL, or calling a callback here changes this
and is the first time we then intertwine xhci core with sideband.
Long term solution is to not reallocate vdev just because we try to disable and
re-enable the slot to recover from a failed address device command.
Usb core doesn't free and reallocate udev during device reset either.
Niklas just started looking at decoupling vdev allocation and initalization.
Meanwhile we could try a bandaid like:
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index a9e47e178c28..0b5152a1a301 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4435,11 +4435,15 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
dev_warn(&udev->dev, "Device not responding to setup %s.\n", act);
mutex_unlock(&xhci->mutex);
- ret = xhci_disable_and_free_slot(xhci, udev->slot_id);
- if (!ret) {
- if (xhci_alloc_dev(hcd, udev) == 1)
- xhci_setup_addressable_virt_dev(xhci, udev);
+
+ if (!virt_dev->sideband) {
+ ret = xhci_disable_and_free_slot(xhci, udev->slot_id);
+ if (!ret) {
+ if (xhci_alloc_dev(hcd, udev) == 1)
+ xhci_setup_addressable_virt_dev(xhci, udev);
+ }
}
+
kfree(command->completion);
kfree(command);
return -EPROTO;
Does this work in your case?
Can you see any negative side-effects with this solution like never re-enumerating and
recovering after a failed address device command?
Thanks
Mathias
next prev parent reply other threads:[~2026-09-14 13:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 12:24 胡连勤
2026-09-10 9:34 ` Mathias Nyman
2026-09-10 11:10 ` Selvarasu Ganesan
2026-09-10 12:11 ` 答复: " 胡连勤
2026-09-10 13:50 ` Mathias Nyman
2026-09-11 5:10 ` Selvarasu Ganesan
2026-09-11 7:29 ` 答复: " 胡连勤
2026-09-11 8:41 ` Selvarasu Ganesan
2026-09-11 13:10 ` Mathias Nyman
2026-09-11 14:49 ` 答复: " 胡连勤
2026-09-12 12:18 ` Michal Pecio
2026-09-14 7:04 ` 答复: " 胡连勤
2026-09-14 9:09 ` Michal Pecio
2026-09-14 12:24 ` 答复: " 胡连勤
2026-09-14 13:09 ` Mathias Nyman [this message]
2026-09-14 14:06 ` Mathias Nyman
2026-09-14 15:34 ` Michal Pecio
2026-09-14 12:26 ` Mathias Nyman
2026-09-14 13:00 ` 答复: " 胡连勤
2026-09-14 13:40 ` Mathias Nyman
2026-09-14 13:46 ` Michal Pecio
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=c6c9890f-46d8-42f1-a7e7-8a5d551fa22c@linux.intel.com \
--to=mathias.nyman@linux.intel.com \
--cc=alim.akhtar@samsung.com \
--cc=broonie@kernel.org \
--cc=cpgs@samsung.com \
--cc=gregkh@linuxfoundation.org \
--cc=hulianqin@vivo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=michal.pecio@gmail.com \
--cc=niklas.neronin@linux.intel.com \
--cc=quic_wcheng@quicinc.com \
--cc=selvarasu.g@samsung.com \
--cc=thiagu.r@samsung.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 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®