From: liudingyuan <liudingyuan@huawei.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"patchwork-bot@kernel.org" <patchwork-bot@kernel.org>,
"mricon@kernel.org" <mricon@kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Cc: "Fangjian (Jay)" <f.fangjian@huawei.com>,
Kangfenglong <kangfenglong@huawei.com>,
yangxingui <yangxingui@huawei.com>,
"fengsheng (A)" <fengsheng5@huawei.com>,
lingmingqiang <lingmingqiang@huawei.com>,
liulongfang <liulongfang@huawei.com>,
zhonghaoquan <zhonghaoquan@hisilicon.com>,
"yanzhili (A)" <yanzhili7@huawei.com>,
"huyihua (A)" <huyihua4@huawei.com>,
"Zengtao (B)" <prime.zeng@hisilicon.com>,
"shenjian (K)" <shenjian15@huawei.com>,
liuyonglong <liuyonglong@huawei.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>
Subject: re: [RFT PATCH] xhci: Limit time spent with interrupts disabled during bus resume
Date: Fri, 21 Mar 2025 03:22:23 +0000 [thread overview]
Message-ID: <910319d13c01430480d26841ac0f79b1@huawei.com> (raw)
Hi
Applying the patch based on the 6.14-rc6 kernel, we conducted verification and found that this patch can
resolve the issue of interrupt loss when a USB3 controller is connected only to a USB2 device.
Additionally, by constructing a scenario with a lower probability where a USB3 controller is connected only
to a USB3 device, causing the USB2 port to enter the resume process and leading to interrupt loss, we confirmed
that the operation of disabling interrupts through IE configuration in this patch can solve the problem of the
controller being unable to trigger new interrupts after interrupt enablement.
Thank you very much! I believe this fix solution has been verified to be acceptable.
We also conducted more USB basic functionality tests , including connecting mice, keyboards, hard drives,
and other devices, as well as read/write functions and multi-level USB device testing. Based on the current
results, this patch does not seem to affect the basic functionality of USB.
Hope these test results can help get the patch pushed to the mainline.
Thanks.
Best regards!
Devyn
>
> [RFT PATCH] xhci: Limit time spent with interrupts disabled during
> bus resume
>
> Current xhci bus resume implementation prevents xHC host from generating interrupts during high-speed USB 2 and super-speed USB 3 bus resume.
>
> Only reason to disable interrupts during bus resume would be to prevent the interrupt handler from interfering with the resume process of USB 2 ports.
>
> Host initiated resume of USB 2 ports is done in two stages.
>
> The xhci driver first transitions the port from 'U3' to 'Resume' state, then wait in Resume for 20ms, and finally moves port to U0 state.
> xhci driver can't prevent interrupts by taking and keeping the xhci spinlock with spin_lock_irqsave() due to this 20ms sleep.
>
> Limit interrupt disabling to the USB 2 port resume case only.
> resuming USB 2 ports in bus resume is only done in special cases where USB 2 ports had to be forced to suspend during bus suspend.
>
> The current way of preventing interrupts by clearing the 'Interrupt Enable' (INTE) bit in USBCMD register won't prevent the Interrupter registers 'Interrupt Pending' (IP), 'Event Handler Busy' (EHB) and USBSTS register Event Interrupt (EINT) bits from being set.
>
> New interrupts can't be issued before those bits are properly clered.
>
> This way IP, EHB and INTE won't be set before IE is enabled again and a new interrupt is triggered.
>
> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
> ---
> drivers/usb/host/xhci-hub.c | 30 ++++++++++++++++--------------
> drivers/usb/host/xhci.c | 4 ++--
> drivers/usb/host/xhci.h | 2 ++
> 3 files changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-hub.c
> b/drivers/usb/host/xhci-hub.c index 9693464c0520..d11b60f705bb 100644
> --- a/drivers/usb/host/xhci-hub.c
> +++ b/drivers/usb/host/xhci-hub.c
> @@ -1870,9 +1870,10 @@ int xhci_bus_resume(struct usb_hcd *hcd)
> int max_ports, port_index;
> int sret;
> u32 next_state;
> - u32 temp, portsc;
> + u32 portsc;
> struct xhci_hub *rhub;
> struct xhci_port **ports;
> + bool disabled_irq = false;
>
> rhub = xhci_get_rhub(hcd);
> ports = rhub->ports;
> @@ -1888,17 +1889,20 @@ int xhci_bus_resume(struct usb_hcd *hcd)
> return -ESHUTDOWN;
> }
>
> - /* delay the irqs */
> - temp = readl(&xhci->op_regs->command);
> - temp &= ~CMD_EIE;
> - writel(temp, &xhci->op_regs->command);
> -
> /* bus specific resume for ports we suspended at bus_suspend */
> - if (hcd->speed >= HCD_USB3)
> + if (hcd->speed >= HCD_USB3) {
> next_state = XDEV_U0;
> - else
> + } else {
> next_state = XDEV_RESUME;
> -
> + if (bus_state->bus_suspended) {
> + /*
> + * prevent port event interrupts from interfering
> + * with usb2 port resume process
> + */
> + xhci_disable_interrupter(xhci->interrupters[0]);
> + disabled_irq = true;
> + }
> + }
> port_index = max_ports;
> while (port_index--) {
> portsc = readl(ports[port_index]->addr); @@ -1966,11 +1970,9 @@ int xhci_bus_resume(struct usb_hcd *hcd)
> (void) readl(&xhci->op_regs->command);
>
> bus_state->next_statechange = jiffies + msecs_to_jiffies(5);
> - /* re-enable irqs */
> - temp = readl(&xhci->op_regs->command);
> - temp |= CMD_EIE;
> - writel(temp, &xhci->op_regs->command);
> - temp = readl(&xhci->op_regs->command);
> + /* re-enable interrupter */
> + if (disabled_irq)
> + xhci_enable_interrupter(xhci->interrupters[0]);
>
> spin_unlock_irqrestore(&xhci->lock, flags);
> return 0;
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index
> 0c22b78358b9..ad229cb9a90b 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -322,7 +322,7 @@ static void xhci_zero_64b_regs(struct xhci_hcd *xhci)
> xhci_info(xhci, "Fault detected\n");
> }
>
> -static int xhci_enable_interrupter(struct xhci_interrupter *ir)
> +int xhci_enable_interrupter(struct xhci_interrupter *ir)
>
> u32 iman;
>
> @@ -335,7 +335,7 @@ static int xhci_enable_interrupter(struct xhci_interrupter *ir)
> return 0;
> }
>
> -static int xhci_disable_interrupter(struct xhci_interrupter *ir)
> +int xhci_disable_interrupter(struct xhci_interrupter *ir)
> {
> u32 iman;
>
> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index
> 6c00062a9acc..10572336fabe 100644
> --- a/drivers/usb/host/xhci.h
> +++ b/drivers/usb/host/xhci.h
> @@ -1891,6 +1891,8 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci,
> struct usb_tt *tt, gfp_t mem_flags);
> int xhci_set_interrupter_moderation(struct xhci_interrupter *ir,
> u32 imod_interval);
> +int xhci_enable_interrupter(struct xhci_interrupter *ir); int
> +xhci_disable_interrupter(struct xhci_interrupter *ir);
>
> /* xHCI ring, segment, TRB, and TD functions */ dma_addr_t
> xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
> --
> 2.43.0
next reply other threads:[~2025-03-21 3:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-21 3:22 liudingyuan [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-24 2:05 [RFT PATCH] xhci: Limit time spent with interrupts disabled during bus resume liudingyuan
2025-03-21 6:47 liudingyuan
2025-03-21 10:06 ` Mathias Nyman
2025-03-11 12:10 liudingyuan
2025-03-07 16:20 [PROBLEM] usb: xhci_bus_resume cause irq lost issue Mathias Nyman
2025-03-10 15:11 ` [RFT PATCH] xhci: Limit time spent with interrupts disabled during bus resume Mathias Nyman
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=910319d13c01430480d26841ac0f79b1@huawei.com \
--to=liudingyuan@huawei.com \
--cc=f.fangjian@huawei.com \
--cc=fengsheng5@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=huyihua4@huawei.com \
--cc=jonathan.cameron@huawei.com \
--cc=kangfenglong@huawei.com \
--cc=lingmingqiang@huawei.com \
--cc=linux-usb@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=liuyonglong@huawei.com \
--cc=mathias.nyman@linux.intel.com \
--cc=mricon@kernel.org \
--cc=patchwork-bot@kernel.org \
--cc=prime.zeng@hisilicon.com \
--cc=shenjian15@huawei.com \
--cc=yangxingui@huawei.com \
--cc=yanzhili7@huawei.com \
--cc=zhonghaoquan@hisilicon.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