summaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorJan Beulich <JBeulich@suse.com>2011-09-19 12:32:15 -0400
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-09-21 16:51:23 -0400
commit04df355227fa75c015491153cfc93e7ea7a80112 (patch)
tree99914c01f75b6ab728c568faeccb37ab4a7a4330 /drivers/xen
parent5fa99911a346e1f95c7932ff99a76693037e7927 (diff)
xen/pciback: use mutex rather than spinlock in passthrough backend
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 <jbeulich@suse.com> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/xen-pciback/passthrough.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/drivers/xen/xen-pciback/passthrough.c b/drivers/xen/xen-pciback/passthrough.c
index 1d32a9a42c01..e01e4b6ef267 100644
--- a/drivers/xen/xen-pciback/passthrough.c
+++ b/drivers/xen/xen-pciback/passthrough.c
@@ -7,13 +7,13 @@
7 7
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/spinlock.h> 10#include <linux/mutex.h>
11#include "pciback.h" 11#include "pciback.h"
12 12
13struct passthrough_dev_data { 13struct passthrough_dev_data {
14 /* Access to dev_list must be protected by lock */ 14 /* Access to dev_list must be protected by lock */
15 struct list_head dev_list; 15 struct list_head dev_list;
16 spinlock_t lock; 16 struct mutex lock;
17}; 17};
18 18
19static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev, 19static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
@@ -24,9 +24,8 @@ static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
24 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 24 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
25 struct pci_dev_entry *dev_entry; 25 struct pci_dev_entry *dev_entry;
26 struct pci_dev *dev = NULL; 26 struct pci_dev *dev = NULL;
27 unsigned long flags;
28 27
29 spin_lock_irqsave(&dev_data->lock, flags); 28 mutex_lock(&dev_data->lock);
30 29
31 list_for_each_entry(dev_entry, &dev_data->dev_list, list) { 30 list_for_each_entry(dev_entry, &dev_data->dev_list, list) {
32 if (domain == (unsigned int)pci_domain_nr(dev_entry->dev->bus) 31 if (domain == (unsigned int)pci_domain_nr(dev_entry->dev->bus)
@@ -37,7 +36,7 @@ static struct pci_dev *__xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev,
37 } 36 }
38 } 37 }
39 38
40 spin_unlock_irqrestore(&dev_data->lock, flags); 39 mutex_unlock(&dev_data->lock);
41 40
42 return dev; 41 return dev;
43} 42}
@@ -48,7 +47,6 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
48{ 47{
49 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 48 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
50 struct pci_dev_entry *dev_entry; 49 struct pci_dev_entry *dev_entry;
51 unsigned long flags;
52 unsigned int domain, bus, devfn; 50 unsigned int domain, bus, devfn;
53 int err; 51 int err;
54 52
@@ -57,9 +55,9 @@ static int __xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
57 return -ENOMEM; 55 return -ENOMEM;
58 dev_entry->dev = dev; 56 dev_entry->dev = dev;
59 57
60 spin_lock_irqsave(&dev_data->lock, flags); 58 mutex_lock(&dev_data->lock);
61 list_add_tail(&dev_entry->list, &dev_data->dev_list); 59 list_add_tail(&dev_entry->list, &dev_data->dev_list);
62 spin_unlock_irqrestore(&dev_data->lock, flags); 60 mutex_unlock(&dev_data->lock);
63 61
64 /* Publish this device. */ 62 /* Publish this device. */
65 domain = (unsigned int)pci_domain_nr(dev->bus); 63 domain = (unsigned int)pci_domain_nr(dev->bus);
@@ -76,9 +74,8 @@ static void __xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
76 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 74 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
77 struct pci_dev_entry *dev_entry, *t; 75 struct pci_dev_entry *dev_entry, *t;
78 struct pci_dev *found_dev = NULL; 76 struct pci_dev *found_dev = NULL;
79 unsigned long flags;
80 77
81 spin_lock_irqsave(&dev_data->lock, flags); 78 mutex_lock(&dev_data->lock);
82 79
83 list_for_each_entry_safe(dev_entry, t, &dev_data->dev_list, list) { 80 list_for_each_entry_safe(dev_entry, t, &dev_data->dev_list, list) {
84 if (dev_entry->dev == dev) { 81 if (dev_entry->dev == dev) {
@@ -88,7 +85,7 @@ static void __xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
88 } 85 }
89 } 86 }
90 87
91 spin_unlock_irqrestore(&dev_data->lock, flags); 88 mutex_unlock(&dev_data->lock);
92 89
93 if (found_dev) 90 if (found_dev)
94 pcistub_put_pci_dev(found_dev); 91 pcistub_put_pci_dev(found_dev);
@@ -102,7 +99,7 @@ static int __xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
102 if (!dev_data) 99 if (!dev_data)
103 return -ENOMEM; 100 return -ENOMEM;
104 101
105 spin_lock_init(&dev_data->lock); 102 mutex_init(&dev_data->lock);
106 103
107 INIT_LIST_HEAD(&dev_data->dev_list); 104 INIT_LIST_HEAD(&dev_data->dev_list);
108 105
@@ -116,14 +113,14 @@ static int __xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
116{ 113{
117 int err = 0; 114 int err = 0;
118 struct passthrough_dev_data *dev_data = pdev->pci_dev_data; 115 struct passthrough_dev_data *dev_data = pdev->pci_dev_data;
119 struct pci_dev_entry *dev_entry, *e, *tmp; 116 struct pci_dev_entry *dev_entry, *e;
120 struct pci_dev *dev; 117 struct pci_dev *dev;
121 int found; 118 int found;
122 unsigned int domain, bus; 119 unsigned int domain, bus;
123 120
124 spin_lock(&dev_data->lock); 121 mutex_lock(&dev_data->lock);
125 122
126 list_for_each_entry_safe(dev_entry, tmp, &dev_data->dev_list, list) { 123 list_for_each_entry(dev_entry, &dev_data->dev_list, list) {
127 /* Only publish this device as a root if none of its 124 /* Only publish this device as a root if none of its
128 * parent bridges are exported 125 * parent bridges are exported
129 */ 126 */
@@ -142,16 +139,13 @@ static int __xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
142 bus = (unsigned int)dev_entry->dev->bus->number; 139 bus = (unsigned int)dev_entry->dev->bus->number;
143 140
144 if (!found) { 141 if (!found) {
145 spin_unlock(&dev_data->lock);
146 err = publish_root_cb(pdev, domain, bus); 142 err = publish_root_cb(pdev, domain, bus);
147 if (err) 143 if (err)
148 break; 144 break;
149 spin_lock(&dev_data->lock);
150 } 145 }
151 } 146 }
152 147
153 if (!err) 148 mutex_unlock(&dev_data->lock);
154 spin_unlock(&dev_data->lock);
155 149
156 return err; 150 return err;
157} 151}