public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Becker <Stefan.Becker@nokia.com>
To: ext Alan Stern <stern@rowland.harvard.edu>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [REGRESSION] 2.6.24/25: random lockups when accessing external USB harddrive
Date: Wed, 25 Jun 2008 18:52:14 +0300	[thread overview]
Message-ID: <486269AE.7050006@nokia.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0806241702490.2166-100000@iolanthe.rowland.org>

[-- Attachment #1: Type: text/plain, Size: 1495 bytes --]

Hi,

ext Alan Stern wrote:
> On Tue, 24 Jun 2008, Stefan Becker wrote:
> 
>> So the lockup is caused by an already locked hcd_urb_list_lock. Is there 
>> a way to see the lock holder? Or any other suggestions how to proceed?
> 
> Good work!

Well, I guess I'm just lucky it didn't turn into a heisenbug with all 
those printk's in the code :-)

> The usage in usb_hcd_link_urb_to_ep() appears benign; the code doesn't 
> do anything that might hang while holding the lock.  All it does is 
> manipulate a linked list.

Unfortunately I could only run a small test today. I added some simple 
debugging code for the spinlock usage in hcd.c (see attached diff) and I 
get the following message at lockup (I tried it twice just to be sure):

HCD URB list locked by usb_hcd_link_urb_to_ep!

As far as I understand the matter this only can happen if 
usb_hcd_link_urb_to_ep() gets interrupted while holding the spinlock. 
But according to the contract at the header of the function it should be 
called with interrupts disabled!

I guess the obvious way forward from here is:

  - replace the spin_lock() in the function with the irqsave version

  - if that fixes the problem add debugging code to the function and 
panic with a stack trace when the interrupts aren't disabled one entry 
(don't know how to detect that yet, any suggestions?) That hopefully 
identifies the culprit that calls the function with interrupts enabled.

Regards,

	Stefan

---
Stefan Becker
E-Mail: Stefan.Becker@nokia.com

[-- Attachment #2: hcd.c.debug-patch --]
[-- Type: text/plain, Size: 2005 bytes --]

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 09a53e7..20db659 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -45,6 +45,12 @@
 #include "hcd.h"
 #include "hub.h"
 
+#ifdef DEBUG
+const char *_urb_list_holder = "NONE";
+#define URB_LIST_HOLDER(n) _urb_list_holder = #n;
+#else
+#define URB_LIST_HOLDER(n)
+#endif  
 
 /*-------------------------------------------------------------------------*/
 
@@ -1002,6 +1008,7 @@ int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
 	int		rc = 0;
 
 	spin_lock(&hcd_urb_list_lock);
+	URB_LIST_HOLDER(usb_hcd_link_urb_to_ep)
 
 	/* Check that the URB isn't being killed */
 	if (unlikely(urb->reject)) {
@@ -1107,7 +1114,15 @@ EXPORT_SYMBOL_GPL(usb_hcd_check_unlink_urb);
 void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb)
 {
 	/* clear all state linking urb to this dev (and hcd) */
+#ifdef DEBUG
+        if (!spin_trylock(&hcd_urb_list_lock)) {
+	  printk(KERN_CRIT "HCD URB list locked by %s!\n", _urb_list_holder);
+#endif
 	spin_lock(&hcd_urb_list_lock);
+	URB_LIST_HOLDER(usb_hcd_unlink_urb_from_ep)
+#ifdef DEBUG
+	}
+#endif
 	list_del_init(&urb->urb_list);
 	spin_unlock(&hcd_urb_list_lock);
 }
@@ -1448,6 +1463,7 @@ void usb_hcd_flush_endpoint(struct usb_device *udev,
 
 	/* No more submits can occur */
 	spin_lock_irq(&hcd_urb_list_lock);
+	URB_LIST_HOLDER(usb_hcd_flush_endpoint_INITIAL)
 rescan:
 	list_for_each_entry (urb, &ep->urb_list, urb_list) {
 		int	is_in;
@@ -1482,6 +1498,7 @@ rescan:
 
 		/* list contents may have changed */
 		spin_lock(&hcd_urb_list_lock);
+		URB_LIST_HOLDER(usb_hcd_flush_endpoint_RESCAN)
 		goto rescan;
 	}
 	spin_unlock_irq(&hcd_urb_list_lock);
@@ -1489,6 +1506,7 @@ rescan:
 	/* Wait until the endpoint queue is completely empty */
 	while (!list_empty (&ep->urb_list)) {
 		spin_lock_irq(&hcd_urb_list_lock);
+		URB_LIST_HOLDER(usb_hcd_flush_endpoint_LIST)
 
 		/* The list may have changed while we acquired the spinlock */
 		urb = NULL;

  reply	other threads:[~2008-06-25 16:05 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-22 16:55 [REGRESSION] 2.6.24/25: random lockups when accessing external USB harddrive Stefan Becker
2008-06-22 17:42 ` Rene Herman
2008-06-22 19:31   ` Alan Stern
2008-06-23 15:52     ` Stefan Becker
2008-06-23 18:10       ` Alan Stern
2008-06-24 18:41         ` Stefan Becker
2008-06-24 21:15           ` Alan Stern
2008-06-25 15:52             ` Stefan Becker [this message]
2008-06-25 18:38               ` Alan Stern
2008-06-26  6:31                 ` Stefan Becker
2008-06-26 14:25                   ` Alan Stern
2008-06-26 22:07                     ` Stefan Becker
2008-06-27 16:07                       ` David Brownell
2008-06-28 14:31                         ` Stefan Becker
2008-06-27 16:10                       ` Alan Stern
2008-06-28 14:36                         ` Stefan Becker
2008-06-28 15:39                         ` Stefan Becker
2008-06-28 16:53                           ` Alan Stern
2008-06-28 19:34                             ` BUG in 2.6.26-rc8 interrupt handling Becker Stefan (Nokia-D/Salo)
2008-06-28 19:51                               ` David Brownell
2008-06-29 14:57                                 ` PATCH: 2.6.26-rc8: Fix IRQF_DISABLED for shared interrupts Stefan Becker
2008-06-30  3:09                                   ` David Brownell
2008-06-30  5:22                                     ` Stefan Becker
2008-06-30 14:28                                       ` Henrique de Moraes Holschuh
2008-06-30 14:26                                         ` Alan Cox
2008-06-30  9:34                                     ` Stefan Becker
2008-06-30 11:15                                       ` David Brownell
2008-06-30 14:37                                         ` Alan Stern
2008-06-30 18:53                                           ` [PATCH] USB: fix interrupt disabling for HCDs with shared interrupt handlers Stefan Becker
2008-06-30 19:35                                             ` Alan Stern
2008-06-30 20:31                                               ` David Brownell
2008-06-30 21:26                                                 ` Stefan Becker
2008-07-01 14:11                                                   ` Alan Stern
2008-07-01 14:19                                                     ` Leonardo Chiquitto
2008-07-01 16:19                                                     ` Stefan Becker
2008-07-01 18:25                                                       ` Greg KH
2008-07-01 18:59                                                         ` Alan Stern
2008-07-01 19:13                                                           ` Greg KH
2008-07-01 19:21                                                           ` David Brownell
2008-07-01 19:15                                                         ` Stefan Becker
2008-07-01 19:51                                                           ` Greg KH
2008-07-01 16:22                                                     ` David Brownell
2008-06-30 21:29                                                 ` Alan Stern
2008-06-30 21:48                                                   ` David Brownell
2008-06-30 19:57                                         ` PATCH: 2.6.26-rc8: Fix IRQF_DISABLED for shared interrupts David Brownell

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=486269AE.7050006@nokia.com \
    --to=stefan.becker@nokia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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