Skip to content

Commit

Permalink
xen/pciback: use mutex rather than spinlock in vpci backend
Browse files Browse the repository at this point in the history
Similar to the "xen/pciback: use mutex rather than spinlock in passthrough backend"
this patch converts the vpci backend to use a mutex instead of
a spinlock. Note that the code taking the lock won't ever get called
from non-sleepable context

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
  • Loading branch information
Konrad Rzeszutek Wilk committed Sep 21, 2011
1 parent b1766b6 commit 74d33de
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions drivers/xen/xen-pciback/vpci.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/pci.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include "pciback.h"

#define PCI_SLOT_MAX 32

struct vpci_dev_data {
/* Access to dev_list must be protected by lock */
struct list_head dev_list[PCI_SLOT_MAX];
spinlock_t lock;
struct mutex lock;
};

static inline struct list_head *list_first(struct list_head *head)
Expand All @@ -32,13 +32,12 @@ static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
struct pci_dev_entry *entry;
struct pci_dev *dev = NULL;
struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
unsigned long flags;

if (domain != 0 || bus != 0)
return NULL;

if (PCI_SLOT(devfn) < PCI_SLOT_MAX) {
spin_lock_irqsave(&vpci_dev->lock, flags);
mutex_lock(&vpci_dev->lock);

list_for_each_entry(entry,
&vpci_dev->dev_list[PCI_SLOT(devfn)],
Expand All @@ -49,7 +48,7 @@ static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
}
}

spin_unlock_irqrestore(&vpci_dev->lock, flags);
mutex_unlock(&vpci_dev->lock);
}
return dev;
}
Expand All @@ -70,7 +69,6 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
int err = 0, slot, func = -1;
struct pci_dev_entry *t, *dev_entry;
struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
unsigned long flags;

if ((dev->class >> 24) == PCI_BASE_CLASS_BRIDGE) {
err = -EFAULT;
Expand All @@ -89,7 +87,7 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,

dev_entry->dev = dev;

spin_lock_irqsave(&vpci_dev->lock, flags);
mutex_lock(&vpci_dev->lock);

/* Keep multi-function devices together on the virtual PCI bus */
for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
Expand Down Expand Up @@ -128,7 +126,7 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
"No more space on root virtual PCI bus");

unlock:
spin_unlock_irqrestore(&vpci_dev->lock, flags);
mutex_unlock(&vpci_dev->lock);

/* Publish this device. */
if (!err)
Expand All @@ -144,9 +142,8 @@ static void __xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
int slot;
struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
struct pci_dev *found_dev = NULL;
unsigned long flags;

spin_lock_irqsave(&vpci_dev->lock, flags);
mutex_lock(&vpci_dev->lock);

for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
struct pci_dev_entry *e;
Expand All @@ -162,7 +159,7 @@ static void __xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
}

out:
spin_unlock_irqrestore(&vpci_dev->lock, flags);
mutex_unlock(&vpci_dev->lock);

if (found_dev)
pcistub_put_pci_dev(found_dev);
Expand All @@ -177,7 +174,7 @@ static int __xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
if (!vpci_dev)
return -ENOMEM;

spin_lock_init(&vpci_dev->lock);
mutex_init(&vpci_dev->lock);

for (slot = 0; slot < PCI_SLOT_MAX; slot++)
INIT_LIST_HEAD(&vpci_dev->dev_list[slot]);
Expand Down Expand Up @@ -221,10 +218,9 @@ static int __xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
struct pci_dev_entry *entry;
struct pci_dev *dev = NULL;
struct vpci_dev_data *vpci_dev = pdev->pci_dev_data;
unsigned long flags;
int found = 0, slot;

spin_lock_irqsave(&vpci_dev->lock, flags);
mutex_lock(&vpci_dev->lock);
for (slot = 0; slot < PCI_SLOT_MAX; slot++) {
list_for_each_entry(entry,
&vpci_dev->dev_list[slot],
Expand All @@ -242,7 +238,7 @@ static int __xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
}
}
}
spin_unlock_irqrestore(&vpci_dev->lock, flags);
mutex_lock(&vpci_dev->lock);
return found;
}

Expand Down

0 comments on commit 74d33de

Please sign in to comment.