linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB host: Fix lockdep warning in AMD PLL quirk
@ 2011-04-06 11:21 Joerg Roedel
  2011-04-06 15:16 ` Alan Stern
  0 siblings, 1 reply; 33+ messages in thread
From: Joerg Roedel @ 2011-04-06 11:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Sarah Sharp, Andiry Xu
  Cc: linux-usb, linux-kernel, Joerg Roedel, stable

Booting 2.6.38 on my test machine produces a lockdep warning
from the usb_amd_find_chipset_info() function:

 WARNING: at /data/lemmy/linux.trees.git/kernel/lockdep.c:2465 lockdep_trace_alloc+0x95/0xc2()
 Hardware name: Snook
 Modules linked in:
 Pid: 959, comm: work_for_cpu Not tainted 2.6.39-rc2+ #22
 Call Trace:
  [<ffffffff8103c0d4>] warn_slowpath_common+0x80/0x98
  [<ffffffff812387e6>] ? T.492+0x24/0x26
  [<ffffffff8103c101>] warn_slowpath_null+0x15/0x17
  [<ffffffff81068667>] lockdep_trace_alloc+0x95/0xc2
  [<ffffffff810ed9ac>] slab_pre_alloc_hook+0x18/0x3b
  [<ffffffff810ef227>] kmem_cache_alloc_trace+0x25/0xba
  [<ffffffff812387e6>] T.492+0x24/0x26
  [<ffffffff81238816>] pci_get_subsys+0x2e/0x73
 sr0: scsi3-mmc drive: 48x/48x writer dvd-ram cd/rw xa/form2 cdda tray
  [<ffffffff8123886c>] pci_get_device+0x11/0x13
  [<ffffffff814082a9>] usb_amd_find_chipset_info+0x3f/0x18a
...

It turns out that this function calls pci_get_device under a spin_lock
with irqs disabled, but the pci_get_device function is only allowed in
preemptible context.

This patch fixes this by using temporary variables in the quirk
algorithm and commiting them later to the struct under the lock. This
moves all pci_get_device() invocations out of the spin_lock and fixes
the lockdep warning for me.

Cc: stable@kernel.org
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 drivers/usb/host/pci-quirks.c |   67 +++++++++++++++++++++++-----------------
 1 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 1d586d4..d3e5cf3 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -84,64 +84,73 @@ int usb_amd_find_chipset_info(void)
 {
 	u8 rev = 0;
 	unsigned long flags;
+	struct pci_dev *nb_dev, *smbus_dev;
+	int nb_type, sb_type;
 
 	spin_lock_irqsave(&amd_lock, flags);
-
 	amd_chipset.probe_count++;
 	/* probe only once */
 	if (amd_chipset.probe_count > 1) {
 		spin_unlock_irqrestore(&amd_lock, flags);
 		return amd_chipset.probe_result;
 	}
+	spin_unlock_irqrestore(&amd_lock, flags);
 
-	amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
-	if (amd_chipset.smbus_dev) {
-		rev = amd_chipset.smbus_dev->revision;
+	sb_type   = 0;
+	smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL);
+	if (smbus_dev) {
+		rev = smbus_dev->revision;
 		if (rev >= 0x40)
-			amd_chipset.sb_type = 1;
+			sb_type = 1;
 		else if (rev >= 0x30 && rev <= 0x3b)
-			amd_chipset.sb_type = 3;
+			sb_type = 3;
 	} else {
-		amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
-							0x780b, NULL);
-		if (!amd_chipset.smbus_dev) {
+		smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x780b, NULL);
+		if (smbus_dev) {
+			spin_lock_irqsave(&amd_lock, flags);
+			amd_chipset.smbus_dev = smbus_dev;
 			spin_unlock_irqrestore(&amd_lock, flags);
 			return 0;
 		}
-		rev = amd_chipset.smbus_dev->revision;
+		rev = smbus_dev->revision;
 		if (rev >= 0x11 && rev <= 0x18)
-			amd_chipset.sb_type = 2;
+			sb_type = 2;
 	}
 
-	if (amd_chipset.sb_type == 0) {
-		if (amd_chipset.smbus_dev) {
-			pci_dev_put(amd_chipset.smbus_dev);
-			amd_chipset.smbus_dev = NULL;
+	if (sb_type == 0) {
+		if (smbus_dev) {
+			pci_dev_put(smbus_dev);
+			smbus_dev = NULL;
 		}
-		spin_unlock_irqrestore(&amd_lock, flags);
 		return 0;
 	}
 
-	amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
-	if (amd_chipset.nb_dev) {
-		amd_chipset.nb_type = 1;
+	nb_type = 0;
+	nb_dev  = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL);
+	if (nb_dev) {
+		nb_type = 1;
 	} else {
-		amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
-							0x1510, NULL);
-		if (amd_chipset.nb_dev) {
-			amd_chipset.nb_type = 2;
-		} else  {
-			amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
-								0x9600, NULL);
-			if (amd_chipset.nb_dev)
-				amd_chipset.nb_type = 3;
+		nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL);
+		if (nb_dev) {
+			nb_type = 2;
+		} else {
+			nb_dev = pci_get_device(PCI_VENDOR_ID_AMD,
+						0x9600, NULL);
+			if (nb_dev)
+				nb_type = 3;
 		}
 	}
 
+	spin_lock_irqsave(&amd_lock, flags);
+	amd_chipset.smbus_dev    = smbus_dev;
+	amd_chipset.sb_type      = sb_type;
+	amd_chipset.nb_dev       = nb_dev;
+	amd_chipset.nb_type      = nb_type;
 	amd_chipset.probe_result = 1;
+	spin_unlock_irqrestore(&amd_lock, flags);
+
 	printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
 
-	spin_unlock_irqrestore(&amd_lock, flags);
 	return amd_chipset.probe_result;
 }
 EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2011-04-13 14:44 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-06 11:21 [PATCH] USB host: Fix lockdep warning in AMD PLL quirk Joerg Roedel
2011-04-06 15:16 ` Alan Stern
2011-04-06 15:25   ` Roedel, Joerg
2011-04-07  2:21   ` Xu, Andiry
2011-04-07  7:50   ` Roedel, Joerg
2011-04-07  9:01     ` Xu, Andiry
2011-04-07 13:00       ` Roedel, Joerg
2011-04-07 15:01         ` Alan Stern
2011-04-07 20:22           ` Joerg Roedel
2011-04-08 14:26             ` [PATCH v4] " Joerg Roedel
2011-04-08 14:52               ` Alan Stern
2011-04-08 15:09                 ` Roedel, Joerg
2011-04-08 16:30                   ` Alan Stern
2011-04-07  8:26   ` [PATCH] " Joerg Roedel
2011-04-07  9:58     ` Xu, Andiry
2011-04-07 12:52       ` Roedel, Joerg
2011-04-07 13:14       ` Joerg Roedel
2011-04-11  6:26         ` Borislav Petkov
2011-04-11  6:43           ` Roedel, Joerg
2011-04-11  6:59           ` [PATCH v5] " Roedel, Joerg
2011-04-11 10:00             ` Sergei Shtylyov
2011-04-11 15:49             ` Alan Stern
2011-04-11 16:16               ` Roedel, Joerg
2011-04-11 16:25                 ` Alan Stern
2011-04-11 16:37                   ` Roedel, Joerg
2011-04-11 17:05                     ` Alan Stern
2011-04-12  6:41                       ` [PATCH v6] " Roedel, Joerg
2011-04-12 10:59                         ` Sergei Shtylyov
2011-04-12 11:13                           ` Roedel, Joerg
2011-04-13  6:38                           ` [PATCH v7] " Roedel, Joerg
2011-04-13 14:44                             ` Alan Stern
2011-04-07 14:35     ` [PATCH] " Alan Stern
2011-04-07 15:00       ` Roedel, Joerg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).