From: "Jan Beulich" Subject: [PATCH] xen/pciback: use mutex rather than spinlock in passthrough backend Date: Mon, 19 Sep 2011 17:32:15 +0100 Message-ID: <4E778AAF0200007800056B63@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Konrad Rzeszutek Wilk Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org To accommodate the call to the callback function from __xen_pcibk_publish_pci_roots(), which so far dropped and the re- acquired the lock without checking that the list didn't actually change, convert the code to use a mutex instead (observing that the code taking the lock won't ever get called from non-sleepable context). As a result, drop the bogus use of list_for_each_entry_safe() and remove the inappropriate dropping of the lock. Signed-off-by: Jan Beulich --- drivers/xen/xen-pciback/passthrough.c | 32 +++++++++++++----------------= --- 1 file changed, 13 insertions(+), 19 deletions(-) --- 3.1-rc6/drivers/xen/xen-pciback/passthrough.c +++ 3.1-rc6-xen-pciback-passthr-mutex/drivers/xen/xen-pciback/passthrough.c= @@ -7,13 +7,13 @@ =20 #include #include -#include +#include #include "pciback.h" =20 struct passthrough_dev_data { /* Access to dev_list must be protected by lock */ struct list_head dev_list; - spinlock_t lock; + struct mutex lock; }; =20 static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device = *pdev, @@ -24,9 +24,8 @@ static struct pci_dev *__xen_pcibk_get_p struct passthrough_dev_data *dev_data =3D pdev->pci_dev_data; struct pci_dev_entry *dev_entry; struct pci_dev *dev =3D NULL; - unsigned long flags; =20 - spin_lock_irqsave(&dev_data->lock, flags); + mutex_lock(&dev_data->lock); =20 list_for_each_entry(dev_entry, &dev_data->dev_list, list) { if (domain =3D=3D (unsigned int)pci_domain_nr(dev_entry->de= v->bus) @@ -37,7 +36,7 @@ static struct pci_dev *__xen_pcibk_get_p } } =20 - spin_unlock_irqrestore(&dev_data->lock, flags); + mutex_unlock(&dev_data->lock); =20 return dev; } @@ -48,7 +47,6 @@ static int __xen_pcibk_add_pci_dev(struc { struct passthrough_dev_data *dev_data =3D pdev->pci_dev_data; struct pci_dev_entry *dev_entry; - unsigned long flags; unsigned int domain, bus, devfn; int err; =20 @@ -57,9 +55,9 @@ static int __xen_pcibk_add_pci_dev(struc return -ENOMEM; dev_entry->dev =3D dev; =20 - spin_lock_irqsave(&dev_data->lock, flags); + mutex_lock(&dev_data->lock); list_add_tail(&dev_entry->list, &dev_data->dev_list); - spin_unlock_irqrestore(&dev_data->lock, flags); + mutex_unlock(&dev_data->lock); =20 /* Publish this device. */ domain =3D (unsigned int)pci_domain_nr(dev->bus); @@ -76,9 +74,8 @@ static void __xen_pcibk_release_pci_dev( struct passthrough_dev_data *dev_data =3D pdev->pci_dev_data; struct pci_dev_entry *dev_entry, *t; struct pci_dev *found_dev =3D NULL; - unsigned long flags; =20 - spin_lock_irqsave(&dev_data->lock, flags); + mutex_lock(&dev_data->lock); =20 list_for_each_entry_safe(dev_entry, t, &dev_data->dev_list, list) = { if (dev_entry->dev =3D=3D dev) { @@ -88,7 +85,7 @@ static void __xen_pcibk_release_pci_dev( } } =20 - spin_unlock_irqrestore(&dev_data->lock, flags); + mutex_unlock(&dev_data->lock); =20 if (found_dev) pcistub_put_pci_dev(found_dev); @@ -102,7 +99,7 @@ static int __xen_pcibk_init_devices(stru if (!dev_data) return -ENOMEM; =20 - spin_lock_init(&dev_data->lock); + mutex_init(&dev_data->lock); =20 INIT_LIST_HEAD(&dev_data->dev_list); =20 @@ -116,14 +113,14 @@ static int __xen_pcibk_publish_pci_roots { int err =3D 0; struct passthrough_dev_data *dev_data =3D pdev->pci_dev_data; - struct pci_dev_entry *dev_entry, *e, *tmp; + struct pci_dev_entry *dev_entry, *e; struct pci_dev *dev; int found; unsigned int domain, bus; =20 - spin_lock(&dev_data->lock); + mutex_lock(&dev_data->lock); =20 - list_for_each_entry_safe(dev_entry, tmp, &dev_data->dev_list, = list) { + list_for_each_entry(dev_entry, &dev_data->dev_list, list) { /* Only publish this device as a root if none of its * parent bridges are exported */ @@ -142,16 +139,13 @@ static int __xen_pcibk_publish_pci_roots bus =3D (unsigned int)dev_entry->dev->bus->number; =20 if (!found) { - spin_unlock(&dev_data->lock); err =3D publish_root_cb(pdev, domain, bus); if (err) break; - spin_lock(&dev_data->lock); } } =20 - if (!err) - spin_unlock(&dev_data->lock); + mutex_unlock(&dev_data->lock); =20 return err; }