All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sudeep Holla <sudeep.holla@arm.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Felipe Balbi <balbi@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] usb: isp1760: fix possible deadlock in isp1760_udc_irq
Date: Thu, 05 Mar 2015 12:49:58 +0200	[thread overview]
Message-ID: <3620278.kWq4f83uKd@avalon> (raw)
In-Reply-To: <1425488877-1596-1-git-send-email-sudeep.holla@arm.com>

Hi Sudeep,

Thank you for the patch.

On Wednesday 04 March 2015 17:07:57 Sudeep Holla wrote:
> Use spin_{un,}lock_irq{save,restore} in isp1760_udc_{start,stop} to
> prevent following potentially deadlock scenario between
> isp1760_udc_{start,stop} and isp1760_udc_irq :
> 
> =================================
> [ INFO: inconsistent lock state ]
> 4.0.0-rc2-00004-gf7bb2ef60173 #51 Not tainted
> ---------------------------------
> inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage.
> in:imklog/2118 [HC1[1]:SC0[0]:HE0:SE1] takes:
>  (&(&udc->lock)->rlock){?.+...}, at: [<c0397a93>]
> isp1760_udc_irq+0x367/0x9dc {HARDIRQ-ON-W} state was registered at:
>   [<c05135b3>] _raw_spin_lock+0x23/0x30
>   [<c0396b87>] isp1760_udc_start+0x23/0xf8
>   [<c039dc21>] udc_bind_to_driver+0x71/0xb0
>   [<c039de4f>] usb_gadget_probe_driver+0x53/0x9c
>   [<bf80d0df>] usb_composite_probe+0x8a/0xa4 [libcomposite]
>   [<bf8311a7>] 0xbf8311a7
>   [<c00088c5>] do_one_initcall+0x8d/0x17c
>   [<c050b92d>] do_init_module+0x49/0x148
>   [<c0087323>] load_module+0xb7f/0xbc4
>   [<c0087471>] SyS_finit_module+0x51/0x74
>   [<c000d8c1>] ret_fast_syscall+0x1/0x68
> irq event stamp: 4966
> hardirqs last  enabled at (4965): [<c05137df>]
> _raw_spin_unlock_irq+0x1f/0x24 hardirqs last disabled at (4966):
> [<c00110b3>] __irq_svc+0x33/0x64 softirqs last  enabled at (4458):
> [<c0023475>] __do_softirq+0x23d/0x2d0 softirqs last disabled at (4389):
> [<c002380b>] irq_exit+0xef/0x15c
> 
> other info that might help us debug this:
>  Possible unsafe locking scenario:
> 
>        CPU0
>        ----
>   lock(&(&udc->lock)->rlock);
>   <Interrupt>
>     lock(&(&udc->lock)->rlock);
> 
>  *** DEADLOCK ***
> 
> 1 lock held by in:imklog/2118:
>  #0:  (&f->f_pos_lock){+.+.+.}, at: [<c010a101>] __fdget_pos+0x31/0x34
> 
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Felipe Balbi <balbi@ti.com>
> ---
>  drivers/usb/isp1760/isp1760-udc.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/isp1760/isp1760-udc.c
> b/drivers/usb/isp1760/isp1760-udc.c index 6d618b3fab07..fbfbd59aae64 100644
> --- a/drivers/usb/isp1760/isp1760-udc.c
> +++ b/drivers/usb/isp1760/isp1760-udc.c
> @@ -1191,6 +1191,7 @@ static int isp1760_udc_start(struct usb_gadget
> *gadget, struct usb_gadget_driver *driver)
>  {
>  	struct isp1760_udc *udc = gadget_to_udc(gadget);
> +	unsigned long flags;
> 
>  	/* The hardware doesn't support low speed. */
>  	if (driver->max_speed < USB_SPEED_FULL) {
> @@ -1198,7 +1199,7 @@ static int isp1760_udc_start(struct usb_gadget
> *gadget, return -EINVAL;
>  	}
> 
> -	spin_lock(&udc->lock);
> +	spin_lock_irqsave(&udc->lock, flags);

Strictly speaking spin_lock_irq() should be enough given that udc_start and 
udc_stop are called with interrupts enabled, but I suppose it doesn't hurt to 
be safe. I'll let you go with your preference. For both options,

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> 
>  	if (udc->driver) {
>  		dev_err(udc->isp->dev, "UDC already has a gadget driver\n");
> @@ -1208,7 +1209,7 @@ static int isp1760_udc_start(struct usb_gadget
> *gadget,
> 
>  	udc->driver = driver;
> 
> -	spin_unlock(&udc->lock);
> +	spin_unlock_irqrestore(&udc->lock, flags);
> 
>  	dev_dbg(udc->isp->dev, "starting UDC with driver %s\n",
>  		driver->function);
> @@ -1232,6 +1233,7 @@ static int isp1760_udc_start(struct usb_gadget
> *gadget, static int isp1760_udc_stop(struct usb_gadget *gadget)
>  {
>  	struct isp1760_udc *udc = gadget_to_udc(gadget);
> +	unsigned long flags;
> 
>  	dev_dbg(udc->isp->dev, "%s\n", __func__);
> 
> @@ -1239,9 +1241,9 @@ static int isp1760_udc_stop(struct usb_gadget *gadget)
> 
>  	isp1760_udc_write(udc, DC_MODE, 0);
> 
> -	spin_lock(&udc->lock);
> +	spin_lock_irqsave(&udc->lock, flags);
>  	udc->driver = NULL;
> -	spin_unlock(&udc->lock);
> +	spin_unlock_irqrestore(&udc->lock, flags);
> 
>  	return 0;
>  }

-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2015-03-05 10:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-04 17:07 [PATCH] usb: isp1760: fix possible deadlock in isp1760_udc_irq Sudeep Holla
2015-03-05 10:49 ` Laurent Pinchart [this message]
2015-03-05 10:52   ` Sudeep Holla

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=3620278.kWq4f83uKd@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sudeep.holla@arm.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.