diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-30 13:20:03 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-05-30 13:20:03 -0400 |
commit | ab8cd81830fef799177740d5ab709c0341e9ba5c (patch) | |
tree | 40c27d1cd27a436ec195174a105fa27c223ed6dd | |
parent | f8356ed00ebcdc2f209504c02b4ab8ba9a8a7ebe (diff) | |
parent | 20887611523e749d99cc7d64ff6c97d27529fbae (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
-rw-r--r-- | Documentation/lguest/lguest.c | 12 | ||||
-rw-r--r-- | arch/x86/lguest/boot.c | 5 | ||||
-rw-r--r-- | drivers/block/virtio_blk.c | 7 | ||||
-rw-r--r-- | drivers/char/hw_random/Kconfig | 9 | ||||
-rw-r--r-- | drivers/char/hw_random/Makefile | 1 | ||||
-rw-r--r-- | drivers/char/hw_random/virtio-rng.c | 155 | ||||
-rw-r--r-- | drivers/lguest/lguest_device.c | 25 | ||||
-rw-r--r-- | drivers/s390/kvm/kvm_virtio.c | 18 | ||||
-rw-r--r-- | drivers/virtio/virtio.c | 8 | ||||
-rw-r--r-- | drivers/virtio/virtio_pci.c | 7 | ||||
-rw-r--r-- | drivers/virtio/virtio_ring.c | 8 | ||||
-rw-r--r-- | include/linux/virtio_blk.h | 9 | ||||
-rw-r--r-- | include/linux/virtio_config.h | 6 | ||||
-rw-r--r-- | include/linux/virtio_rng.h | 8 |
14 files changed, 225 insertions, 53 deletions
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c index 3be8ab2a886a..82fafe0429fe 100644 --- a/Documentation/lguest/lguest.c +++ b/Documentation/lguest/lguest.c | |||
@@ -157,6 +157,9 @@ struct virtqueue | |||
157 | 157 | ||
158 | /* The routine to call when the Guest pings us. */ | 158 | /* The routine to call when the Guest pings us. */ |
159 | void (*handle_output)(int fd, struct virtqueue *me); | 159 | void (*handle_output)(int fd, struct virtqueue *me); |
160 | |||
161 | /* Outstanding buffers */ | ||
162 | unsigned int inflight; | ||
160 | }; | 163 | }; |
161 | 164 | ||
162 | /* Remember the arguments to the program so we can "reboot" */ | 165 | /* Remember the arguments to the program so we can "reboot" */ |
@@ -702,6 +705,7 @@ static unsigned get_vq_desc(struct virtqueue *vq, | |||
702 | errx(1, "Looped descriptor"); | 705 | errx(1, "Looped descriptor"); |
703 | } while ((i = next_desc(vq, i)) != vq->vring.num); | 706 | } while ((i = next_desc(vq, i)) != vq->vring.num); |
704 | 707 | ||
708 | vq->inflight++; | ||
705 | return head; | 709 | return head; |
706 | } | 710 | } |
707 | 711 | ||
@@ -719,6 +723,7 @@ static void add_used(struct virtqueue *vq, unsigned int head, int len) | |||
719 | /* Make sure buffer is written before we update index. */ | 723 | /* Make sure buffer is written before we update index. */ |
720 | wmb(); | 724 | wmb(); |
721 | vq->vring.used->idx++; | 725 | vq->vring.used->idx++; |
726 | vq->inflight--; | ||
722 | } | 727 | } |
723 | 728 | ||
724 | /* This actually sends the interrupt for this virtqueue */ | 729 | /* This actually sends the interrupt for this virtqueue */ |
@@ -726,8 +731,9 @@ static void trigger_irq(int fd, struct virtqueue *vq) | |||
726 | { | 731 | { |
727 | unsigned long buf[] = { LHREQ_IRQ, vq->config.irq }; | 732 | unsigned long buf[] = { LHREQ_IRQ, vq->config.irq }; |
728 | 733 | ||
729 | /* If they don't want an interrupt, don't send one. */ | 734 | /* If they don't want an interrupt, don't send one, unless empty. */ |
730 | if (vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) | 735 | if ((vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) |
736 | && vq->inflight) | ||
731 | return; | 737 | return; |
732 | 738 | ||
733 | /* Send the Guest an interrupt tell them we used something up. */ | 739 | /* Send the Guest an interrupt tell them we used something up. */ |
@@ -1107,6 +1113,7 @@ static void add_virtqueue(struct device *dev, unsigned int num_descs, | |||
1107 | vq->next = NULL; | 1113 | vq->next = NULL; |
1108 | vq->last_avail_idx = 0; | 1114 | vq->last_avail_idx = 0; |
1109 | vq->dev = dev; | 1115 | vq->dev = dev; |
1116 | vq->inflight = 0; | ||
1110 | 1117 | ||
1111 | /* Initialize the configuration. */ | 1118 | /* Initialize the configuration. */ |
1112 | vq->config.num = num_descs; | 1119 | vq->config.num = num_descs; |
@@ -1368,6 +1375,7 @@ static void setup_tun_net(const char *arg) | |||
1368 | 1375 | ||
1369 | /* Tell Guest what MAC address to use. */ | 1376 | /* Tell Guest what MAC address to use. */ |
1370 | add_feature(dev, VIRTIO_NET_F_MAC); | 1377 | add_feature(dev, VIRTIO_NET_F_MAC); |
1378 | add_feature(dev, VIRTIO_F_NOTIFY_ON_EMPTY); | ||
1371 | set_config(dev, sizeof(conf), &conf); | 1379 | set_config(dev, sizeof(conf), &conf); |
1372 | 1380 | ||
1373 | /* We don't need the socket any more; setup is done. */ | 1381 | /* We don't need the socket any more; setup is done. */ |
diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c index af65b2da3ba0..5c7e2fd52075 100644 --- a/arch/x86/lguest/boot.c +++ b/arch/x86/lguest/boot.c | |||
@@ -582,8 +582,9 @@ static void __init lguest_init_IRQ(void) | |||
582 | int vector = FIRST_EXTERNAL_VECTOR + i; | 582 | int vector = FIRST_EXTERNAL_VECTOR + i; |
583 | if (vector != SYSCALL_VECTOR) { | 583 | if (vector != SYSCALL_VECTOR) { |
584 | set_intr_gate(vector, interrupt[i]); | 584 | set_intr_gate(vector, interrupt[i]); |
585 | set_irq_chip_and_handler(i, &lguest_irq_controller, | 585 | set_irq_chip_and_handler_name(i, &lguest_irq_controller, |
586 | handle_level_irq); | 586 | handle_level_irq, |
587 | "level"); | ||
587 | } | 588 | } |
588 | } | 589 | } |
589 | /* This call is required to set up for 4k stacks, where we have | 590 | /* This call is required to set up for 4k stacks, where we have |
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 | ||
326 | static unsigned int features[] = { | 331 | static 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 | ||
331 | static struct virtio_driver virtio_blk = { | 336 | static 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 | ||
115 | config 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 | |||
11 | obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o | 11 | obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o |
12 | obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o | 12 | obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o |
13 | obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o | 13 | obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o |
14 | obj-$(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 | |||
31 | static struct virtqueue *vq; | ||
32 | static u32 *random_data; | ||
33 | static unsigned int data_left; | ||
34 | static DECLARE_COMPLETION(have_data); | ||
35 | |||
36 | static 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 | |||
48 | static 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. */ | ||
60 | static 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. */ | ||
73 | static 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 | |||
86 | static struct hwrng virtio_hwrng = { | ||
87 | .name = "virtio", | ||
88 | .data_present = virtio_data_present, | ||
89 | .data_read = virtio_data_read, | ||
90 | }; | ||
91 | |||
92 | static 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 | |||
111 | static 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 | |||
118 | static struct virtio_device_id id_table[] = { | ||
119 | { VIRTIO_ID_RNG, VIRTIO_DEV_ANY_ID }, | ||
120 | { 0 }, | ||
121 | }; | ||
122 | |||
123 | static 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 | |||
131 | static 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 | |||
145 | static void __exit fini(void) | ||
146 | { | ||
147 | kfree(random_data); | ||
148 | unregister_virtio_driver(&virtio_rng); | ||
149 | } | ||
150 | module_init(init); | ||
151 | module_exit(fini); | ||
152 | |||
153 | MODULE_DEVICE_TABLE(virtio, id_table); | ||
154 | MODULE_DESCRIPTION("Virtio random number driver"); | ||
155 | MODULE_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. */ |
21 | static void *lguest_devices; | 21 | static void *lguest_devices; |
22 | 22 | ||
23 | /* Unique numbering for lguest devices. */ | ||
24 | static 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. */ |
28 | static inline void *lguest_map(unsigned long phys_addr, unsigned long pages) | 25 | static 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 | ||
33 | static inline void lguest_unmap(void *addr) | 30 | static 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 |
329 | static void add_lguest_device(struct lguest_device_desc *d) | 326 | * descriptor page so we can uniquely identify it if things go badly wrong. */ |
327 | static 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 | */ |
32 | static void *kvm_devices; | 32 | static void *kvm_devices; |
33 | 33 | ||
34 | /* | ||
35 | * Unique numbering for kvm devices. | ||
36 | */ | ||
37 | static unsigned int dev_index; | ||
38 | |||
39 | struct kvm_device { | 34 | struct 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 | */ |
253 | static void add_kvm_device(struct kvm_device_desc *d) | 248 | static 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. */ | ||
6 | static unsigned int dev_index; | ||
7 | |||
5 | static ssize_t device_show(struct device *_d, | 8 | static 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 */ | ||
82 | static unsigned int dev_index; | ||
83 | |||
84 | /* Convert a generic virtio device to our structure */ | 81 | /* Convert a generic virtio device to our structure */ |
85 | static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev) | 82 | static 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); |
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h index d4695a3356d0..5f79a5f9de79 100644 --- a/include/linux/virtio_blk.h +++ b/include/linux/virtio_blk.h | |||
@@ -10,18 +10,19 @@ | |||
10 | #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ | 10 | #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ |
11 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ | 11 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ |
12 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ | 12 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ |
13 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ | ||
13 | 14 | ||
14 | struct virtio_blk_config | 15 | struct virtio_blk_config |
15 | { | 16 | { |
16 | /* The capacity (in 512-byte sectors). */ | 17 | /* The capacity (in 512-byte sectors). */ |
17 | __le64 capacity; | 18 | __u64 capacity; |
18 | /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ | 19 | /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ |
19 | __le32 size_max; | 20 | __u32 size_max; |
20 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ | 21 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ |
21 | __le32 seg_max; | 22 | __u32 seg_max; |
22 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ | 23 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ |
23 | struct virtio_blk_geometry { | 24 | struct virtio_blk_geometry { |
24 | __le16 cylinders; | 25 | __u16 cylinders; |
25 | __u8 heads; | 26 | __u8 heads; |
26 | __u8 sectors; | 27 | __u8 sectors; |
27 | } geometry; | 28 | } geometry; |
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index 50db245c81ad..f364bbf63c34 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
@@ -15,6 +15,10 @@ | |||
15 | /* We've given up on this device. */ | 15 | /* We've given up on this device. */ |
16 | #define VIRTIO_CONFIG_S_FAILED 0x80 | 16 | #define VIRTIO_CONFIG_S_FAILED 0x80 |
17 | 17 | ||
18 | /* Do we get callbacks when the ring is completely used, even if we've | ||
19 | * suppressed them? */ | ||
20 | #define VIRTIO_F_NOTIFY_ON_EMPTY 24 | ||
21 | |||
18 | #ifdef __KERNEL__ | 22 | #ifdef __KERNEL__ |
19 | #include <linux/virtio.h> | 23 | #include <linux/virtio.h> |
20 | 24 | ||
@@ -99,7 +103,7 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev, | |||
99 | * The return value is -ENOENT if the feature doesn't exist. Otherwise | 103 | * The return value is -ENOENT if the feature doesn't exist. Otherwise |
100 | * the config value is copied into whatever is pointed to by v. */ | 104 | * the config value is copied into whatever is pointed to by v. */ |
101 | #define virtio_config_val(vdev, fbit, offset, v) \ | 105 | #define virtio_config_val(vdev, fbit, offset, v) \ |
102 | virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v)) | 106 | virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(*v)) |
103 | 107 | ||
104 | static inline int virtio_config_buf(struct virtio_device *vdev, | 108 | static inline int virtio_config_buf(struct virtio_device *vdev, |
105 | unsigned int fbit, | 109 | unsigned int fbit, |
diff --git a/include/linux/virtio_rng.h b/include/linux/virtio_rng.h new file mode 100644 index 000000000000..331afb6c9f62 --- /dev/null +++ b/include/linux/virtio_rng.h | |||
@@ -0,0 +1,8 @@ | |||
1 | #ifndef _LINUX_VIRTIO_RNG_H | ||
2 | #define _LINUX_VIRTIO_RNG_H | ||
3 | #include <linux/virtio_config.h> | ||
4 | |||
5 | /* The ID for virtio_rng */ | ||
6 | #define VIRTIO_ID_RNG 4 | ||
7 | |||
8 | #endif /* _LINUX_VIRTIO_RNG_H */ | ||