aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-05-30 13:20:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-05-30 13:20:03 -0400
commitab8cd81830fef799177740d5ab709c0341e9ba5c (patch)
tree40c27d1cd27a436ec195174a105fa27c223ed6dd /drivers
parentf8356ed00ebcdc2f209504c02b4ab8ba9a8a7ebe (diff)
parent20887611523e749d99cc7d64ff6c97d27529fbae (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus: lguest: notify on empty virtio: force callback on empty. virtio_blk: fix endianess annotations virtio_config: fix len calculation of config elements virtio_net: another race with virtio_net and enable_cb virtio: An entropy device, as suggested by hpa. virtio_blk: allow read-only disks lguest: fix ugly <NULL> in /proc/interrupts virtio: set device index in common code. virtio: virtio_pci should not set bus_id. virtio: bus_id for devices should contain 'virtio' Fix crash in virtio_blk during modprobe ; rmmod ; modprobe lguest: use ioremap_cache, not ioremap
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/virtio_blk.c7
-rw-r--r--drivers/char/hw_random/Kconfig9
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/virtio-rng.c155
-rw-r--r--drivers/lguest/lguest_device.c25
-rw-r--r--drivers/s390/kvm/kvm_virtio.c18
-rw-r--r--drivers/virtio/virtio.c8
-rw-r--r--drivers/virtio/virtio_pci.c7
-rw-r--r--drivers/virtio/virtio_ring.c8
9 files changed, 194 insertions, 44 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 84e064ffee52..dd7ea203f940 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -260,6 +260,10 @@ static int virtblk_probe(struct virtio_device *vdev)
260 if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) 260 if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER))
261 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL); 261 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);
262 262
263 /* If disk is read-only in the host, the guest should obey */
264 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
265 set_disk_ro(vblk->disk, 1);
266
263 /* Host must always specify the capacity. */ 267 /* Host must always specify the capacity. */
264 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity), 268 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
265 &cap, sizeof(cap)); 269 &cap, sizeof(cap));
@@ -311,6 +315,7 @@ static void virtblk_remove(struct virtio_device *vdev)
311 /* Stop all the virtqueues. */ 315 /* Stop all the virtqueues. */
312 vdev->config->reset(vdev); 316 vdev->config->reset(vdev);
313 317
318 del_gendisk(vblk->disk);
314 blk_cleanup_queue(vblk->disk->queue); 319 blk_cleanup_queue(vblk->disk->queue);
315 put_disk(vblk->disk); 320 put_disk(vblk->disk);
316 mempool_destroy(vblk->pool); 321 mempool_destroy(vblk->pool);
@@ -325,7 +330,7 @@ static struct virtio_device_id id_table[] = {
325 330
326static unsigned int features[] = { 331static unsigned int features[] = {
327 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 332 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
328 VIRTIO_BLK_F_GEOMETRY, 333 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO,
329}; 334};
330 335
331static struct virtio_driver virtio_blk = { 336static struct virtio_driver virtio_blk = {
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 8d6c2089d2a8..efd0b4db7c8e 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -112,3 +112,12 @@ config HW_RANDOM_PASEMI
112 112
113 If unsure, say Y. 113 If unsure, say Y.
114 114
115config HW_RANDOM_VIRTIO
116 tristate "VirtIO Random Number Generator support"
117 depends on HW_RANDOM && VIRTIO
118 ---help---
119 This driver provides kernel-side support for the virtual Random Number
120 Generator hardware.
121
122 To compile this driver as a module, choose M here: the
123 module will be called virtio-rng. If unsure, say N.
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index c8b7300e2fb1..b4940ddbb35f 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
11obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 11obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
12obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 12obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
13obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o 13obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
14obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
new file mode 100644
index 000000000000..d0e563e4fc39
--- /dev/null
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -0,0 +1,155 @@
1/*
2 * Randomness driver for virtio
3 * Copyright (C) 2007, 2008 Rusty Russell IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#include <linux/err.h>
20#include <linux/hw_random.h>
21#include <linux/scatterlist.h>
22#include <linux/spinlock.h>
23#include <linux/virtio.h>
24#include <linux/virtio_rng.h>
25
26/* The host will fill any buffer we give it with sweet, sweet randomness. We
27 * give it 64 bytes at a time, and the hwrng framework takes it 4 bytes at a
28 * time. */
29#define RANDOM_DATA_SIZE 64
30
31static struct virtqueue *vq;
32static u32 *random_data;
33static unsigned int data_left;
34static DECLARE_COMPLETION(have_data);
35
36static void random_recv_done(struct virtqueue *vq)
37{
38 int len;
39
40 /* We never get spurious callbacks. */
41 if (!vq->vq_ops->get_buf(vq, &len))
42 BUG();
43
44 data_left = len / sizeof(random_data[0]);
45 complete(&have_data);
46}
47
48static void register_buffer(void)
49{
50 struct scatterlist sg;
51
52 sg_init_one(&sg, random_data, RANDOM_DATA_SIZE);
53 /* There should always be room for one buffer. */
54 if (vq->vq_ops->add_buf(vq, &sg, 0, 1, random_data) != 0)
55 BUG();
56 vq->vq_ops->kick(vq);
57}
58
59/* At least we don't udelay() in a loop like some other drivers. */
60static int virtio_data_present(struct hwrng *rng, int wait)
61{
62 if (data_left)
63 return 1;
64
65 if (!wait)
66 return 0;
67
68 wait_for_completion(&have_data);
69 return 1;
70}
71
72/* virtio_data_present() must have succeeded before this is called. */
73static int virtio_data_read(struct hwrng *rng, u32 *data)
74{
75 BUG_ON(!data_left);
76
77 *data = random_data[--data_left];
78
79 if (!data_left) {
80 init_completion(&have_data);
81 register_buffer();
82 }
83 return sizeof(*data);
84}
85
86static struct hwrng virtio_hwrng = {
87 .name = "virtio",
88 .data_present = virtio_data_present,
89 .data_read = virtio_data_read,
90};
91
92static int virtrng_probe(struct virtio_device *vdev)
93{
94 int err;
95
96 /* We expect a single virtqueue. */
97 vq = vdev->config->find_vq(vdev, 0, random_recv_done);
98 if (IS_ERR(vq))
99 return PTR_ERR(vq);
100
101 err = hwrng_register(&virtio_hwrng);
102 if (err) {
103 vdev->config->del_vq(vq);
104 return err;
105 }
106
107 register_buffer();
108 return 0;
109}
110
111static void virtrng_remove(struct virtio_device *vdev)
112{
113 vdev->config->reset(vdev);
114 hwrng_unregister(&virtio_hwrng);
115 vdev->config->del_vq(vq);
116}
117
118static struct virtio_device_id id_table[] = {
119 { VIRTIO_ID_RNG, VIRTIO_DEV_ANY_ID },
120 { 0 },
121};
122
123static struct virtio_driver virtio_rng = {
124 .driver.name = KBUILD_MODNAME,
125 .driver.owner = THIS_MODULE,
126 .id_table = id_table,
127 .probe = virtrng_probe,
128 .remove = __devexit_p(virtrng_remove),
129};
130
131static int __init init(void)
132{
133 int err;
134
135 random_data = kmalloc(RANDOM_DATA_SIZE, GFP_KERNEL);
136 if (!random_data)
137 return -ENOMEM;
138
139 err = register_virtio_driver(&virtio_rng);
140 if (err)
141 kfree(random_data);
142 return err;
143}
144
145static void __exit fini(void)
146{
147 kfree(random_data);
148 unregister_virtio_driver(&virtio_rng);
149}
150module_init(init);
151module_exit(fini);
152
153MODULE_DEVICE_TABLE(virtio, id_table);
154MODULE_DESCRIPTION("Virtio random number driver");
155MODULE_LICENSE("GPL");
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 8080249957af..1a8de57289eb 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -20,14 +20,11 @@
20/* The pointer to our (page) of device descriptions. */ 20/* The pointer to our (page) of device descriptions. */
21static void *lguest_devices; 21static void *lguest_devices;
22 22
23/* Unique numbering for lguest devices. */
24static unsigned int dev_index;
25
26/* For Guests, device memory can be used as normal memory, so we cast away the 23/* For Guests, device memory can be used as normal memory, so we cast away the
27 * __iomem to quieten sparse. */ 24 * __iomem to quieten sparse. */
28static inline void *lguest_map(unsigned long phys_addr, unsigned long pages) 25static inline void *lguest_map(unsigned long phys_addr, unsigned long pages)
29{ 26{
30 return (__force void *)ioremap(phys_addr, PAGE_SIZE*pages); 27 return (__force void *)ioremap_cache(phys_addr, PAGE_SIZE*pages);
31} 28}
32 29
33static inline void lguest_unmap(void *addr) 30static inline void lguest_unmap(void *addr)
@@ -325,8 +322,10 @@ static struct device lguest_root = {
325 * As Andrew Tridgell says, "Untested code is buggy code". 322 * As Andrew Tridgell says, "Untested code is buggy code".
326 * 323 *
327 * It's worth reading this carefully: we start with a pointer to the new device 324 * It's worth reading this carefully: we start with a pointer to the new device
328 * descriptor in the "lguest_devices" page. */ 325 * descriptor in the "lguest_devices" page, and the offset into the device
329static void add_lguest_device(struct lguest_device_desc *d) 326 * descriptor page so we can uniquely identify it if things go badly wrong. */
327static void add_lguest_device(struct lguest_device_desc *d,
328 unsigned int offset)
330{ 329{
331 struct lguest_device *ldev; 330 struct lguest_device *ldev;
332 331
@@ -334,18 +333,14 @@ static void add_lguest_device(struct lguest_device_desc *d)
334 * it. */ 333 * it. */
335 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); 334 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL);
336 if (!ldev) { 335 if (!ldev) {
337 printk(KERN_EMERG "Cannot allocate lguest dev %u\n", 336 printk(KERN_EMERG "Cannot allocate lguest dev %u type %u\n",
338 dev_index++); 337 offset, d->type);
339 return; 338 return;
340 } 339 }
341 340
342 /* This devices' parent is the lguest/ dir. */ 341 /* This devices' parent is the lguest/ dir. */
343 ldev->vdev.dev.parent = &lguest_root; 342 ldev->vdev.dev.parent = &lguest_root;
344 /* We have a unique device index thanks to the dev_index counter. */ 343 /* We have a unique device index thanks to the dev_index counter. */
345 ldev->vdev.index = dev_index++;
346 /* The device type comes straight from the descriptor. There's also a
347 * device vendor field in the virtio_device struct, which we leave as
348 * 0. */
349 ldev->vdev.id.device = d->type; 344 ldev->vdev.id.device = d->type;
350 /* We have a simple set of routines for querying the device's 345 /* We have a simple set of routines for querying the device's
351 * configuration information and setting its status. */ 346 * configuration information and setting its status. */
@@ -357,8 +352,8 @@ static void add_lguest_device(struct lguest_device_desc *d)
357 * virtio_device and calls device_register(). This makes the bus 352 * virtio_device and calls device_register(). This makes the bus
358 * infrastructure look for a matching driver. */ 353 * infrastructure look for a matching driver. */
359 if (register_virtio_device(&ldev->vdev) != 0) { 354 if (register_virtio_device(&ldev->vdev) != 0) {
360 printk(KERN_ERR "Failed to register lguest device %u\n", 355 printk(KERN_ERR "Failed to register lguest dev %u type %u\n",
361 ldev->vdev.index); 356 offset, d->type);
362 kfree(ldev); 357 kfree(ldev);
363 } 358 }
364} 359}
@@ -379,7 +374,7 @@ static void scan_devices(void)
379 break; 374 break;
380 375
381 printk("Device at %i has size %u\n", i, desc_size(d)); 376 printk("Device at %i has size %u\n", i, desc_size(d));
382 add_lguest_device(d); 377 add_lguest_device(d, i);
383 } 378 }
384} 379}
385 380
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 9f55ce6f3c78..5ab34340919b 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -31,11 +31,6 @@
31 */ 31 */
32static void *kvm_devices; 32static void *kvm_devices;
33 33
34/*
35 * Unique numbering for kvm devices.
36 */
37static unsigned int dev_index;
38
39struct kvm_device { 34struct kvm_device {
40 struct virtio_device vdev; 35 struct virtio_device vdev;
41 struct kvm_device_desc *desc; 36 struct kvm_device_desc *desc;
@@ -250,26 +245,25 @@ static struct device kvm_root = {
250 * adds a new device and register it with virtio 245 * adds a new device and register it with virtio
251 * appropriate drivers are loaded by the device model 246 * appropriate drivers are loaded by the device model
252 */ 247 */
253static void add_kvm_device(struct kvm_device_desc *d) 248static void add_kvm_device(struct kvm_device_desc *d, unsigned int offset)
254{ 249{
255 struct kvm_device *kdev; 250 struct kvm_device *kdev;
256 251
257 kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); 252 kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
258 if (!kdev) { 253 if (!kdev) {
259 printk(KERN_EMERG "Cannot allocate kvm dev %u\n", 254 printk(KERN_EMERG "Cannot allocate kvm dev %u type %u\n",
260 dev_index++); 255 offset, d->type);
261 return; 256 return;
262 } 257 }
263 258
264 kdev->vdev.dev.parent = &kvm_root; 259 kdev->vdev.dev.parent = &kvm_root;
265 kdev->vdev.index = dev_index++;
266 kdev->vdev.id.device = d->type; 260 kdev->vdev.id.device = d->type;
267 kdev->vdev.config = &kvm_vq_configspace_ops; 261 kdev->vdev.config = &kvm_vq_configspace_ops;
268 kdev->desc = d; 262 kdev->desc = d;
269 263
270 if (register_virtio_device(&kdev->vdev) != 0) { 264 if (register_virtio_device(&kdev->vdev) != 0) {
271 printk(KERN_ERR "Failed to register kvm device %u\n", 265 printk(KERN_ERR "Failed to register kvm device %u type %u\n",
272 kdev->vdev.index); 266 offset, d->type);
273 kfree(kdev); 267 kfree(kdev);
274 } 268 }
275} 269}
@@ -289,7 +283,7 @@ static void scan_devices(void)
289 if (d->type == 0) 283 if (d->type == 0)
290 break; 284 break;
291 285
292 add_kvm_device(d); 286 add_kvm_device(d, i);
293 } 287 }
294} 288}
295 289
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 13866789b356..0f3c2bb7bf35 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -2,6 +2,9 @@
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/virtio_config.h> 3#include <linux/virtio_config.h>
4 4
5/* Unique numbering for virtio devices. */
6static unsigned int dev_index;
7
5static ssize_t device_show(struct device *_d, 8static ssize_t device_show(struct device *_d,
6 struct device_attribute *attr, char *buf) 9 struct device_attribute *attr, char *buf)
7{ 10{
@@ -166,7 +169,10 @@ int register_virtio_device(struct virtio_device *dev)
166 int err; 169 int err;
167 170
168 dev->dev.bus = &virtio_bus; 171 dev->dev.bus = &virtio_bus;
169 sprintf(dev->dev.bus_id, "%u", dev->index); 172
173 /* Assign a unique device index and hence name. */
174 dev->index = dev_index++;
175 sprintf(dev->dev.bus_id, "virtio%u", dev->index);
170 176
171 /* We always start by resetting the device, in case a previous 177 /* We always start by resetting the device, in case a previous
172 * driver messed it up. This also tests that code path a little. */ 178 * driver messed it up. This also tests that code path a little. */
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 27e9fc9117cd..eae7236310e4 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -78,9 +78,6 @@ static struct device virtio_pci_root = {
78 .bus_id = "virtio-pci", 78 .bus_id = "virtio-pci",
79}; 79};
80 80
81/* Unique numbering for devices under the kvm root */
82static unsigned int dev_index;
83
84/* Convert a generic virtio device to our structure */ 81/* Convert a generic virtio device to our structure */
85static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev) 82static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev)
86{ 83{
@@ -325,10 +322,6 @@ static int __devinit virtio_pci_probe(struct pci_dev *pci_dev,
325 if (vp_dev == NULL) 322 if (vp_dev == NULL)
326 return -ENOMEM; 323 return -ENOMEM;
327 324
328 snprintf(vp_dev->vdev.dev.bus_id, BUS_ID_SIZE, "virtio%d", dev_index);
329 vp_dev->vdev.index = dev_index;
330 dev_index++;
331
332 vp_dev->vdev.dev.parent = &virtio_pci_root; 325 vp_dev->vdev.dev.parent = &virtio_pci_root;
333 vp_dev->vdev.config = &virtio_pci_config_ops; 326 vp_dev->vdev.config = &virtio_pci_config_ops;
334 vp_dev->pci_dev = pci_dev; 327 vp_dev->pci_dev = pci_dev;
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 937a49d6772c..72bf8bc09014 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -227,7 +227,6 @@ static bool vring_enable_cb(struct virtqueue *_vq)
227 struct vring_virtqueue *vq = to_vvq(_vq); 227 struct vring_virtqueue *vq = to_vvq(_vq);
228 228
229 START_USE(vq); 229 START_USE(vq);
230 BUG_ON(!(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT));
231 230
232 /* We optimistically turn back on interrupts, then check if there was 231 /* We optimistically turn back on interrupts, then check if there was
233 * more to do. */ 232 * more to do. */
@@ -254,13 +253,6 @@ irqreturn_t vring_interrupt(int irq, void *_vq)
254 if (unlikely(vq->broken)) 253 if (unlikely(vq->broken))
255 return IRQ_HANDLED; 254 return IRQ_HANDLED;
256 255
257 /* Other side may have missed us turning off the interrupt,
258 * but we should preserve disable semantic for virtio users. */
259 if (unlikely(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) {
260 pr_debug("virtqueue interrupt after disable for %p\n", vq);
261 return IRQ_HANDLED;
262 }
263
264 pr_debug("virtqueue callback for %p (%p)\n", vq, vq->vq.callback); 256 pr_debug("virtqueue callback for %p (%p)\n", vq, vq->vq.callback);
265 if (vq->vq.callback) 257 if (vq->vq.callback)
266 vq->vq.callback(&vq->vq); 258 vq->vq.callback(&vq->vq);