Linux USB
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Ziheng Wei <zihengw03@163.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: xhci: drop xhci->lock around pm_runtime calls in test mode
Date: Mon, 30 Nov 2026 12:11:28 +0100	[thread overview]
Message-ID: <2026113017-enquirer-trusting-6582@gregkh> (raw)
In-Reply-To: <20261130103455.1384163-1-zihengw03@163.com>

On Mon, Nov 30, 2026 at 06:34:55PM +0800, Ziheng Wei wrote:
> xhci_enter_test_mode() calls pm_runtime_forbid() and xhci_exit_test_mode()
> calls pm_runtime_allow() while holding the IRQ-safe spinlock xhci->lock.
> Both runtime PM helpers take dev->power.lock with spin_lock_irq() and
> unconditionally re-enable hard IRQs (and may sleep if the controller is
> not irq-safe), triggering lockdep HARDIRQ-ON-W warnings and potential
> deadlock.
> 
> Drop and reacquire xhci->lock around pm_runtime_forbid() and
> pm_runtime_allow(), matching the existing lock-drop pattern in
> xhci_enter_test_mode().
> 
> Found by LLM-assisted static analysis; the xhci_enter_test_mode()
> HARDIRQ-ON-W lockdep warning was reproduced in QEMU with PROVE_LOCKING
> and the fix was compile-tested on x86_64.
> 
> Fixes: 0f1d832ed1fb ("usb: xhci: Add port test modes support for usb2.")
> Signed-off-by: Ziheng Wei <zihengw03@163.com>
> ---
>  drivers/usb/host/xhci-hub.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
> index 470bafe18..4d76f7857 100644
> --- a/drivers/usb/host/xhci-hub.c
> +++ b/drivers/usb/host/xhci-hub.c
> @@ -722,14 +722,17 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci, u16 test_mode, int portnu
>  	if (retval)
>  		return retval;
>  	/* Disable runtime PM for test mode */
> +	spin_unlock_irqrestore(&xhci->lock, *flags);
>  	pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller);
> +	spin_lock_irqsave(&xhci->lock, *flags);
>  	/* Set PORTPMSC.PTC field to enter selected test mode */
>  	xhci_dbg(xhci, "Enter Test Mode: %u, Port_id=%d\n", test_mode, portnum + 1);
>  	xhci_port_set_test_mode(xhci, test_mode, portnum);
>  	return retval;
>  }
>  
> -static int xhci_exit_test_mode(struct xhci_hcd *xhci)
> +static int xhci_exit_test_mode(struct xhci_hcd *xhci, unsigned long *flags)
> +	__must_hold(&xhci->lock)
>  {
>  	int retval;
>  
> @@ -743,7 +746,9 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci)
>  		if (retval)
>  			return retval;
>  	}
> +	spin_unlock_irqrestore(&xhci->lock, *flags);
>  	pm_runtime_allow(xhci_to_hcd(xhci)->self.controller);
> +	spin_lock_irqsave(&xhci->lock, *flags);
>  	xhci->test_mode = 0;
>  	return xhci_reset(xhci, XHCI_RESET_SHORT_USEC);
>  }
> @@ -1584,7 +1589,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
>  			xhci_set_port_power(xhci, port, false, &flags);
>  			break;
>  		case USB_PORT_FEAT_TEST:
> -			retval = xhci_exit_test_mode(xhci);
> +			retval = xhci_exit_test_mode(xhci, &flags);
>  			break;
>  		default:
>  			goto error;
> 
> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
> -- 
> 2.43.0
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- You have marked a patch with a "Fixes:" tag for a commit that is in an
  older released kernel, yet you do not have a cc: stable line in the
  signed-off-by area at all, which means that the patch will not be
  applied to any older kernel releases.  To properly fix this, please
  follow the documented rules in the
  Documentation/process/stable-kernel-rules.rst file for how to resolve
  this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

      parent reply	other threads:[~2026-11-30 11:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:34 [PATCH] usb: xhci: drop xhci->lock around pm_runtime calls in test mode Ziheng Wei
2026-11-30 10:40 ` sashiko-bot
2026-11-30 11:11 ` Greg Kroah-Hartman [this message]

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=2026113017-enquirer-trusting-6582@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=zihengw03@163.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