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

+225 -53
+10 -2
Documentation/lguest/lguest.c
··· 157 157 158 158 /* The routine to call when the Guest pings us. */ 159 159 void (*handle_output)(int fd, struct virtqueue *me); 160 + 161 + /* Outstanding buffers */ 162 + unsigned int inflight; 160 163 }; 161 164 162 165 /* Remember the arguments to the program so we can "reboot" */ ··· 705 702 errx(1, "Looped descriptor"); 706 703 } while ((i = next_desc(vq, i)) != vq->vring.num); 707 704 705 + vq->inflight++; 708 706 return head; 709 707 } 710 708 ··· 723 719 /* Make sure buffer is written before we update index. */ 724 720 wmb(); 725 721 vq->vring.used->idx++; 722 + vq->inflight--; 726 723 } 727 724 728 725 /* This actually sends the interrupt for this virtqueue */ ··· 731 726 { 732 727 unsigned long buf[] = { LHREQ_IRQ, vq->config.irq }; 733 728 734 - /* If they don't want an interrupt, don't send one. */ 735 - if (vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) 729 + /* If they don't want an interrupt, don't send one, unless empty. */ 730 + if ((vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT) 731 + && vq->inflight) 736 732 return; 737 733 738 734 /* Send the Guest an interrupt tell them we used something up. */ ··· 1113 1107 vq->next = NULL; 1114 1108 vq->last_avail_idx = 0; 1115 1109 vq->dev = dev; 1110 + vq->inflight = 0; 1116 1111 1117 1112 /* Initialize the configuration. */ 1118 1113 vq->config.num = num_descs; ··· 1375 1368 1376 1369 /* Tell Guest what MAC address to use. */ 1377 1370 add_feature(dev, VIRTIO_NET_F_MAC); 1371 + add_feature(dev, VIRTIO_F_NOTIFY_ON_EMPTY); 1378 1372 set_config(dev, sizeof(conf), &conf); 1379 1373 1380 1374 /* We don't need the socket any more; setup is done. */
+3 -2
arch/x86/lguest/boot.c
··· 582 582 int vector = FIRST_EXTERNAL_VECTOR + i; 583 583 if (vector != SYSCALL_VECTOR) { 584 584 set_intr_gate(vector, interrupt[i]); 585 - set_irq_chip_and_handler(i, &lguest_irq_controller, 586 - handle_level_irq); 585 + set_irq_chip_and_handler_name(i, &lguest_irq_controller, 586 + handle_level_irq, 587 + "level"); 587 588 } 588 589 } 589 590 /* This call is required to set up for 4k stacks, where we have
+6 -1
drivers/block/virtio_blk.c
··· 260 260 if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) 261 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 267 /* Host must always specify the capacity. */ 264 268 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity), 265 269 &cap, sizeof(cap)); ··· 315 311 /* Stop all the virtqueues. */ 316 312 vdev->config->reset(vdev); 317 313 314 + del_gendisk(vblk->disk); 318 315 blk_cleanup_queue(vblk->disk->queue); 319 316 put_disk(vblk->disk); 320 317 mempool_destroy(vblk->pool); ··· 330 325 331 326 static unsigned int features[] = { 332 327 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 333 - VIRTIO_BLK_F_GEOMETRY, 328 + VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, 334 329 }; 335 330 336 331 static struct virtio_driver virtio_blk = {
+9
drivers/char/hw_random/Kconfig
··· 112 112 113 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.
+1
drivers/char/hw_random/Makefile
··· 11 11 obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 12 12 obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 13 13 obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o 14 + obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
+155
drivers/char/hw_random/virtio-rng.c
··· 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");
+10 -15
drivers/lguest/lguest_device.c
··· 20 20 /* The pointer to our (page) of device descriptions. */ 21 21 static void *lguest_devices; 22 22 23 - /* Unique numbering for lguest devices. */ 24 - static unsigned int dev_index; 25 - 26 23 /* For Guests, device memory can be used as normal memory, so we cast away the 27 24 * __iomem to quieten sparse. */ 28 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 30 static inline void lguest_unmap(void *addr) ··· 322 325 * As Andrew Tridgell says, "Untested code is buggy code". 323 326 * 324 327 * It's worth reading this carefully: we start with a pointer to the new device 325 - * descriptor in the "lguest_devices" page. */ 326 - static void add_lguest_device(struct lguest_device_desc *d) 328 + * descriptor in the "lguest_devices" page, and the offset into the device 329 + * descriptor page so we can uniquely identify it if things go badly wrong. */ 330 + static void add_lguest_device(struct lguest_device_desc *d, 331 + unsigned int offset) 327 332 { 328 333 struct lguest_device *ldev; 329 334 ··· 333 334 * it. */ 334 335 ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); 335 336 if (!ldev) { 336 - printk(KERN_EMERG "Cannot allocate lguest dev %u\n", 337 - dev_index++); 337 + printk(KERN_EMERG "Cannot allocate lguest dev %u type %u\n", 338 + offset, d->type); 338 339 return; 339 340 } 340 341 341 342 /* This devices' parent is the lguest/ dir. */ 342 343 ldev->vdev.dev.parent = &lguest_root; 343 344 /* We have a unique device index thanks to the dev_index counter. */ 344 - ldev->vdev.index = dev_index++; 345 - /* The device type comes straight from the descriptor. There's also a 346 - * device vendor field in the virtio_device struct, which we leave as 347 - * 0. */ 348 345 ldev->vdev.id.device = d->type; 349 346 /* We have a simple set of routines for querying the device's 350 347 * configuration information and setting its status. */ ··· 352 357 * virtio_device and calls device_register(). This makes the bus 353 358 * infrastructure look for a matching driver. */ 354 359 if (register_virtio_device(&ldev->vdev) != 0) { 355 - printk(KERN_ERR "Failed to register lguest device %u\n", 356 - ldev->vdev.index); 360 + printk(KERN_ERR "Failed to register lguest dev %u type %u\n", 361 + offset, d->type); 357 362 kfree(ldev); 358 363 } 359 364 } ··· 374 379 break; 375 380 376 381 printk("Device at %i has size %u\n", i, desc_size(d)); 377 - add_lguest_device(d); 382 + add_lguest_device(d, i); 378 383 } 379 384 } 380 385
+6 -12
drivers/s390/kvm/kvm_virtio.c
··· 31 31 */ 32 32 static void *kvm_devices; 33 33 34 - /* 35 - * Unique numbering for kvm devices. 36 - */ 37 - static unsigned int dev_index; 38 - 39 34 struct kvm_device { 40 35 struct virtio_device vdev; 41 36 struct kvm_device_desc *desc; ··· 245 250 * adds a new device and register it with virtio 246 251 * appropriate drivers are loaded by the device model 247 252 */ 248 - static void add_kvm_device(struct kvm_device_desc *d) 253 + static void add_kvm_device(struct kvm_device_desc *d, unsigned int offset) 249 254 { 250 255 struct kvm_device *kdev; 251 256 252 257 kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); 253 258 if (!kdev) { 254 - printk(KERN_EMERG "Cannot allocate kvm dev %u\n", 255 - dev_index++); 259 + printk(KERN_EMERG "Cannot allocate kvm dev %u type %u\n", 260 + offset, d->type); 256 261 return; 257 262 } 258 263 259 264 kdev->vdev.dev.parent = &kvm_root; 260 - kdev->vdev.index = dev_index++; 261 265 kdev->vdev.id.device = d->type; 262 266 kdev->vdev.config = &kvm_vq_configspace_ops; 263 267 kdev->desc = d; 264 268 265 269 if (register_virtio_device(&kdev->vdev) != 0) { 266 - printk(KERN_ERR "Failed to register kvm device %u\n", 267 - kdev->vdev.index); 270 + printk(KERN_ERR "Failed to register kvm device %u type %u\n", 271 + offset, d->type); 268 272 kfree(kdev); 269 273 } 270 274 } ··· 283 289 if (d->type == 0) 284 290 break; 285 291 286 - add_kvm_device(d); 292 + add_kvm_device(d, i); 287 293 } 288 294 } 289 295
+7 -1
drivers/virtio/virtio.c
··· 2 2 #include <linux/spinlock.h> 3 3 #include <linux/virtio_config.h> 4 4 5 + /* Unique numbering for virtio devices. */ 6 + static unsigned int dev_index; 7 + 5 8 static ssize_t device_show(struct device *_d, 6 9 struct device_attribute *attr, char *buf) 7 10 { ··· 169 166 int err; 170 167 171 168 dev->dev.bus = &virtio_bus; 172 - sprintf(dev->dev.bus_id, "%u", dev->index); 169 + 170 + /* Assign a unique device index and hence name. */ 171 + dev->index = dev_index++; 172 + sprintf(dev->dev.bus_id, "virtio%u", dev->index); 173 173 174 174 /* We always start by resetting the device, in case a previous 175 175 * driver messed it up. This also tests that code path a little. */
-7
drivers/virtio/virtio_pci.c
··· 78 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 81 /* Convert a generic virtio device to our structure */ 85 82 static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev) 86 83 { ··· 321 324 vp_dev = kzalloc(sizeof(struct virtio_pci_device), GFP_KERNEL); 322 325 if (vp_dev == NULL) 323 326 return -ENOMEM; 324 - 325 - snprintf(vp_dev->vdev.dev.bus_id, BUS_ID_SIZE, "virtio%d", dev_index); 326 - vp_dev->vdev.index = dev_index; 327 - dev_index++; 328 327 329 328 vp_dev->vdev.dev.parent = &virtio_pci_root; 330 329 vp_dev->vdev.config = &virtio_pci_config_ops;
-8
drivers/virtio/virtio_ring.c
··· 227 227 struct vring_virtqueue *vq = to_vvq(_vq); 228 228 229 229 START_USE(vq); 230 - BUG_ON(!(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)); 231 230 232 231 /* We optimistically turn back on interrupts, then check if there was 233 232 * more to do. */ ··· 252 253 253 254 if (unlikely(vq->broken)) 254 255 return IRQ_HANDLED; 255 - 256 - /* Other side may have missed us turning off the interrupt, 257 - * but we should preserve disable semantic for virtio users. */ 258 - if (unlikely(vq->vring.avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) { 259 - pr_debug("virtqueue interrupt after disable for %p\n", vq); 260 - return IRQ_HANDLED; 261 - } 262 256 263 257 pr_debug("virtqueue callback for %p (%p)\n", vq, vq->vq.callback); 264 258 if (vq->vq.callback)
+5 -4
include/linux/virtio_blk.h
··· 10 10 #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ 11 11 #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ 12 12 #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ 13 + #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ 13 14 14 15 struct virtio_blk_config 15 16 { 16 17 /* The capacity (in 512-byte sectors). */ 17 - __le64 capacity; 18 + __u64 capacity; 18 19 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 19 - __le32 size_max; 20 + __u32 size_max; 20 21 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 21 - __le32 seg_max; 22 + __u32 seg_max; 22 23 /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ 23 24 struct virtio_blk_geometry { 24 - __le16 cylinders; 25 + __u16 cylinders; 25 26 __u8 heads; 26 27 __u8 sectors; 27 28 } geometry;
+5 -1
include/linux/virtio_config.h
··· 15 15 /* We've given up on this device. */ 16 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 22 #ifdef __KERNEL__ 19 23 #include <linux/virtio.h> 20 24 ··· 103 99 * The return value is -ENOENT if the feature doesn't exist. Otherwise 104 100 * the config value is copied into whatever is pointed to by v. */ 105 101 #define virtio_config_val(vdev, fbit, offset, v) \ 106 - virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v)) 102 + virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(*v)) 107 103 108 104 static inline int virtio_config_buf(struct virtio_device *vdev, 109 105 unsigned int fbit,
+8
include/linux/virtio_rng.h
··· 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 */