diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-07-23 16:07:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-07-23 16:07:04 -0400 |
commit | d1a343a0231ea34db16ab6773809f2874bcabcf8 (patch) | |
tree | fde1ec1fe66563bbbc92fc0c30b822d90e375896 | |
parent | b681268cb25f6242ea56efe6ea4b6467a92e2bac (diff) | |
parent | c9ce42f72fd0ba180fd35539829e4139dca31494 (diff) |
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio/vhost fixes from Michael Tsirkin:
"Bugfixes and documentation fixes.
Igor's patch that allows users to tweak memory table size is
borderline, but it does fix known crashes, so I merged it"
* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
vhost: add max_mem_regions module parameter
vhost: extend memory regions allocation to vmalloc
9p/trans_virtio: reset virtio device on remove
virtio/s390: rename drivers/s390/kvm -> drivers/s390/virtio
MAINTAINERS: separate section for s390 virtio drivers
virtio: define virtio_pci_cfg_cap in header.
virtio: Fix typecast of pointer in vring_init()
virtio scsi: fix unused variable warning
vhost: use binary search instead of linear in find_region()
virtio_net: document VIRTIO_NET_CTRL_GUEST_OFFLOADS
-rw-r--r-- | MAINTAINERS | 10 | ||||
-rw-r--r-- | drivers/s390/Makefile | 2 | ||||
-rw-r--r-- | drivers/s390/virtio/Makefile (renamed from drivers/s390/kvm/Makefile) | 0 | ||||
-rw-r--r-- | drivers/s390/virtio/kvm_virtio.c (renamed from drivers/s390/kvm/kvm_virtio.c) | 0 | ||||
-rw-r--r-- | drivers/s390/virtio/virtio_ccw.c (renamed from drivers/s390/kvm/virtio_ccw.c) | 0 | ||||
-rw-r--r-- | drivers/scsi/virtio_scsi.c | 4 | ||||
-rw-r--r-- | drivers/vhost/vhost.c | 67 | ||||
-rw-r--r-- | include/uapi/linux/virtio_net.h | 16 | ||||
-rw-r--r-- | include/uapi/linux/virtio_pci.h | 6 | ||||
-rw-r--r-- | include/uapi/linux/virtio_ring.h | 5 | ||||
-rw-r--r-- | net/9p/trans_virtio.c | 1 |
11 files changed, 91 insertions, 20 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index a2264167791a..2eb627252239 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -5899,7 +5899,6 @@ S: Supported | |||
5899 | F: Documentation/s390/kvm.txt | 5899 | F: Documentation/s390/kvm.txt |
5900 | F: arch/s390/include/asm/kvm* | 5900 | F: arch/s390/include/asm/kvm* |
5901 | F: arch/s390/kvm/ | 5901 | F: arch/s390/kvm/ |
5902 | F: drivers/s390/kvm/ | ||
5903 | 5902 | ||
5904 | KERNEL VIRTUAL MACHINE (KVM) FOR ARM | 5903 | KERNEL VIRTUAL MACHINE (KVM) FOR ARM |
5905 | M: Christoffer Dall <christoffer.dall@linaro.org> | 5904 | M: Christoffer Dall <christoffer.dall@linaro.org> |
@@ -10896,6 +10895,15 @@ F: drivers/block/virtio_blk.c | |||
10896 | F: include/linux/virtio_*.h | 10895 | F: include/linux/virtio_*.h |
10897 | F: include/uapi/linux/virtio_*.h | 10896 | F: include/uapi/linux/virtio_*.h |
10898 | 10897 | ||
10898 | VIRTIO DRIVERS FOR S390 | ||
10899 | M: Christian Borntraeger <borntraeger@de.ibm.com> | ||
10900 | M: Cornelia Huck <cornelia.huck@de.ibm.com> | ||
10901 | L: linux-s390@vger.kernel.org | ||
10902 | L: virtualization@lists.linux-foundation.org | ||
10903 | L: kvm@vger.kernel.org | ||
10904 | S: Supported | ||
10905 | F: drivers/s390/virtio/ | ||
10906 | |||
10899 | VIRTIO GPU DRIVER | 10907 | VIRTIO GPU DRIVER |
10900 | M: David Airlie <airlied@linux.ie> | 10908 | M: David Airlie <airlied@linux.ie> |
10901 | M: Gerd Hoffmann <kraxel@redhat.com> | 10909 | M: Gerd Hoffmann <kraxel@redhat.com> |
diff --git a/drivers/s390/Makefile b/drivers/s390/Makefile index 95bccfd3f169..e5225ad9c5b1 100644 --- a/drivers/s390/Makefile +++ b/drivers/s390/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for the S/390 specific device drivers | 2 | # Makefile for the S/390 specific device drivers |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y += cio/ block/ char/ crypto/ net/ scsi/ kvm/ | 5 | obj-y += cio/ block/ char/ crypto/ net/ scsi/ virtio/ |
6 | 6 | ||
7 | drivers-y += drivers/s390/built-in.o | 7 | drivers-y += drivers/s390/built-in.o |
8 | 8 | ||
diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/virtio/Makefile index 241891a57caf..241891a57caf 100644 --- a/drivers/s390/kvm/Makefile +++ b/drivers/s390/virtio/Makefile | |||
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/virtio/kvm_virtio.c index 53fb975c404b..53fb975c404b 100644 --- a/drivers/s390/kvm/kvm_virtio.c +++ b/drivers/s390/virtio/kvm_virtio.c | |||
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c index f8d8fdb26b72..f8d8fdb26b72 100644 --- a/drivers/s390/kvm/virtio_ccw.c +++ b/drivers/s390/virtio/virtio_ccw.c | |||
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 285f77544c36..7dbbb29d24c6 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c | |||
@@ -949,7 +949,7 @@ static int virtscsi_probe(struct virtio_device *vdev) | |||
949 | { | 949 | { |
950 | struct Scsi_Host *shost; | 950 | struct Scsi_Host *shost; |
951 | struct virtio_scsi *vscsi; | 951 | struct virtio_scsi *vscsi; |
952 | int err, host_prot; | 952 | int err; |
953 | u32 sg_elems, num_targets; | 953 | u32 sg_elems, num_targets; |
954 | u32 cmd_per_lun; | 954 | u32 cmd_per_lun; |
955 | u32 num_queues; | 955 | u32 num_queues; |
@@ -1009,6 +1009,8 @@ static int virtscsi_probe(struct virtio_device *vdev) | |||
1009 | 1009 | ||
1010 | #ifdef CONFIG_BLK_DEV_INTEGRITY | 1010 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
1011 | if (virtio_has_feature(vdev, VIRTIO_SCSI_F_T10_PI)) { | 1011 | if (virtio_has_feature(vdev, VIRTIO_SCSI_F_T10_PI)) { |
1012 | int host_prot; | ||
1013 | |||
1012 | host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | | 1014 | host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | |
1013 | SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION | | 1015 | SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION | |
1014 | SHOST_DIX_TYPE2_PROTECTION | SHOST_DIX_TYPE3_PROTECTION; | 1016 | SHOST_DIX_TYPE2_PROTECTION | SHOST_DIX_TYPE3_PROTECTION; |
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 9e8e004bb1c3..a9fe859f43c8 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c | |||
@@ -22,14 +22,20 @@ | |||
22 | #include <linux/file.h> | 22 | #include <linux/file.h> |
23 | #include <linux/highmem.h> | 23 | #include <linux/highmem.h> |
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/vmalloc.h> | ||
25 | #include <linux/kthread.h> | 26 | #include <linux/kthread.h> |
26 | #include <linux/cgroup.h> | 27 | #include <linux/cgroup.h> |
27 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/sort.h> | ||
28 | 30 | ||
29 | #include "vhost.h" | 31 | #include "vhost.h" |
30 | 32 | ||
33 | static ushort max_mem_regions = 64; | ||
34 | module_param(max_mem_regions, ushort, 0444); | ||
35 | MODULE_PARM_DESC(max_mem_regions, | ||
36 | "Maximum number of memory regions in memory map. (default: 64)"); | ||
37 | |||
31 | enum { | 38 | enum { |
32 | VHOST_MEMORY_MAX_NREGIONS = 64, | ||
33 | VHOST_MEMORY_F_LOG = 0x1, | 39 | VHOST_MEMORY_F_LOG = 0x1, |
34 | }; | 40 | }; |
35 | 41 | ||
@@ -543,7 +549,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev, bool locked) | |||
543 | fput(dev->log_file); | 549 | fput(dev->log_file); |
544 | dev->log_file = NULL; | 550 | dev->log_file = NULL; |
545 | /* No one will access memory at this point */ | 551 | /* No one will access memory at this point */ |
546 | kfree(dev->memory); | 552 | kvfree(dev->memory); |
547 | dev->memory = NULL; | 553 | dev->memory = NULL; |
548 | WARN_ON(!list_empty(&dev->work_list)); | 554 | WARN_ON(!list_empty(&dev->work_list)); |
549 | if (dev->worker) { | 555 | if (dev->worker) { |
@@ -663,6 +669,28 @@ int vhost_vq_access_ok(struct vhost_virtqueue *vq) | |||
663 | } | 669 | } |
664 | EXPORT_SYMBOL_GPL(vhost_vq_access_ok); | 670 | EXPORT_SYMBOL_GPL(vhost_vq_access_ok); |
665 | 671 | ||
672 | static int vhost_memory_reg_sort_cmp(const void *p1, const void *p2) | ||
673 | { | ||
674 | const struct vhost_memory_region *r1 = p1, *r2 = p2; | ||
675 | if (r1->guest_phys_addr < r2->guest_phys_addr) | ||
676 | return 1; | ||
677 | if (r1->guest_phys_addr > r2->guest_phys_addr) | ||
678 | return -1; | ||
679 | return 0; | ||
680 | } | ||
681 | |||
682 | static void *vhost_kvzalloc(unsigned long size) | ||
683 | { | ||
684 | void *n = kzalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT); | ||
685 | |||
686 | if (!n) { | ||
687 | n = vzalloc(size); | ||
688 | if (!n) | ||
689 | return ERR_PTR(-ENOMEM); | ||
690 | } | ||
691 | return n; | ||
692 | } | ||
693 | |||
666 | static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) | 694 | static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) |
667 | { | 695 | { |
668 | struct vhost_memory mem, *newmem, *oldmem; | 696 | struct vhost_memory mem, *newmem, *oldmem; |
@@ -673,21 +701,23 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) | |||
673 | return -EFAULT; | 701 | return -EFAULT; |
674 | if (mem.padding) | 702 | if (mem.padding) |
675 | return -EOPNOTSUPP; | 703 | return -EOPNOTSUPP; |
676 | if (mem.nregions > VHOST_MEMORY_MAX_NREGIONS) | 704 | if (mem.nregions > max_mem_regions) |
677 | return -E2BIG; | 705 | return -E2BIG; |
678 | newmem = kmalloc(size + mem.nregions * sizeof *m->regions, GFP_KERNEL); | 706 | newmem = vhost_kvzalloc(size + mem.nregions * sizeof(*m->regions)); |
679 | if (!newmem) | 707 | if (!newmem) |
680 | return -ENOMEM; | 708 | return -ENOMEM; |
681 | 709 | ||
682 | memcpy(newmem, &mem, size); | 710 | memcpy(newmem, &mem, size); |
683 | if (copy_from_user(newmem->regions, m->regions, | 711 | if (copy_from_user(newmem->regions, m->regions, |
684 | mem.nregions * sizeof *m->regions)) { | 712 | mem.nregions * sizeof *m->regions)) { |
685 | kfree(newmem); | 713 | kvfree(newmem); |
686 | return -EFAULT; | 714 | return -EFAULT; |
687 | } | 715 | } |
716 | sort(newmem->regions, newmem->nregions, sizeof(*newmem->regions), | ||
717 | vhost_memory_reg_sort_cmp, NULL); | ||
688 | 718 | ||
689 | if (!memory_access_ok(d, newmem, 0)) { | 719 | if (!memory_access_ok(d, newmem, 0)) { |
690 | kfree(newmem); | 720 | kvfree(newmem); |
691 | return -EFAULT; | 721 | return -EFAULT; |
692 | } | 722 | } |
693 | oldmem = d->memory; | 723 | oldmem = d->memory; |
@@ -699,7 +729,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) | |||
699 | d->vqs[i]->memory = newmem; | 729 | d->vqs[i]->memory = newmem; |
700 | mutex_unlock(&d->vqs[i]->mutex); | 730 | mutex_unlock(&d->vqs[i]->mutex); |
701 | } | 731 | } |
702 | kfree(oldmem); | 732 | kvfree(oldmem); |
703 | return 0; | 733 | return 0; |
704 | } | 734 | } |
705 | 735 | ||
@@ -992,17 +1022,22 @@ EXPORT_SYMBOL_GPL(vhost_dev_ioctl); | |||
992 | static const struct vhost_memory_region *find_region(struct vhost_memory *mem, | 1022 | static const struct vhost_memory_region *find_region(struct vhost_memory *mem, |
993 | __u64 addr, __u32 len) | 1023 | __u64 addr, __u32 len) |
994 | { | 1024 | { |
995 | struct vhost_memory_region *reg; | 1025 | const struct vhost_memory_region *reg; |
996 | int i; | 1026 | int start = 0, end = mem->nregions; |
997 | 1027 | ||
998 | /* linear search is not brilliant, but we really have on the order of 6 | 1028 | while (start < end) { |
999 | * regions in practice */ | 1029 | int slot = start + (end - start) / 2; |
1000 | for (i = 0; i < mem->nregions; ++i) { | 1030 | reg = mem->regions + slot; |
1001 | reg = mem->regions + i; | 1031 | if (addr >= reg->guest_phys_addr) |
1002 | if (reg->guest_phys_addr <= addr && | 1032 | end = slot; |
1003 | reg->guest_phys_addr + reg->memory_size - 1 >= addr) | 1033 | else |
1004 | return reg; | 1034 | start = slot + 1; |
1005 | } | 1035 | } |
1036 | |||
1037 | reg = mem->regions + start; | ||
1038 | if (addr >= reg->guest_phys_addr && | ||
1039 | reg->guest_phys_addr + reg->memory_size > addr) | ||
1040 | return reg; | ||
1006 | return NULL; | 1041 | return NULL; |
1007 | } | 1042 | } |
1008 | 1043 | ||
diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h index 7bbee79ca293..ec32293a00db 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h | |||
@@ -34,6 +34,7 @@ | |||
34 | /* The feature bitmap for virtio net */ | 34 | /* The feature bitmap for virtio net */ |
35 | #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ | 35 | #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ |
36 | #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ | 36 | #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ |
37 | #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */ | ||
37 | #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ | 38 | #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ |
38 | #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ | 39 | #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ |
39 | #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ | 40 | #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ |
@@ -226,4 +227,19 @@ struct virtio_net_ctrl_mq { | |||
226 | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 | 227 | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 |
227 | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 | 228 | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 |
228 | 229 | ||
230 | /* | ||
231 | * Control network offloads | ||
232 | * | ||
233 | * Reconfigures the network offloads that Guest can handle. | ||
234 | * | ||
235 | * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit. | ||
236 | * | ||
237 | * Command data format matches the feature bit mask exactly. | ||
238 | * | ||
239 | * See VIRTIO_NET_F_GUEST_* for the list of offloads | ||
240 | * that can be enabled/disabled. | ||
241 | */ | ||
242 | #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5 | ||
243 | #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0 | ||
244 | |||
229 | #endif /* _LINUX_VIRTIO_NET_H */ | 245 | #endif /* _LINUX_VIRTIO_NET_H */ |
diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h index 75301468359f..90007a1abcab 100644 --- a/include/uapi/linux/virtio_pci.h +++ b/include/uapi/linux/virtio_pci.h | |||
@@ -157,6 +157,12 @@ struct virtio_pci_common_cfg { | |||
157 | __le32 queue_used_hi; /* read-write */ | 157 | __le32 queue_used_hi; /* read-write */ |
158 | }; | 158 | }; |
159 | 159 | ||
160 | /* Fields in VIRTIO_PCI_CAP_PCI_CFG: */ | ||
161 | struct virtio_pci_cfg_cap { | ||
162 | struct virtio_pci_cap cap; | ||
163 | __u8 pci_cfg_data[4]; /* Data for BAR access. */ | ||
164 | }; | ||
165 | |||
160 | /* Macro versions of offsets for the Old Timers! */ | 166 | /* Macro versions of offsets for the Old Timers! */ |
161 | #define VIRTIO_PCI_CAP_VNDR 0 | 167 | #define VIRTIO_PCI_CAP_VNDR 0 |
162 | #define VIRTIO_PCI_CAP_NEXT 1 | 168 | #define VIRTIO_PCI_CAP_NEXT 1 |
diff --git a/include/uapi/linux/virtio_ring.h b/include/uapi/linux/virtio_ring.h index 915980ac68df..c07295969b7e 100644 --- a/include/uapi/linux/virtio_ring.h +++ b/include/uapi/linux/virtio_ring.h | |||
@@ -31,6 +31,9 @@ | |||
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
32 | * | 32 | * |
33 | * Copyright Rusty Russell IBM Corporation 2007. */ | 33 | * Copyright Rusty Russell IBM Corporation 2007. */ |
34 | #ifndef __KERNEL__ | ||
35 | #include <stdint.h> | ||
36 | #endif | ||
34 | #include <linux/types.h> | 37 | #include <linux/types.h> |
35 | #include <linux/virtio_types.h> | 38 | #include <linux/virtio_types.h> |
36 | 39 | ||
@@ -143,7 +146,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, | |||
143 | vr->num = num; | 146 | vr->num = num; |
144 | vr->desc = p; | 147 | vr->desc = p; |
145 | vr->avail = p + num*sizeof(struct vring_desc); | 148 | vr->avail = p + num*sizeof(struct vring_desc); |
146 | vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16) | 149 | vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) |
147 | + align-1) & ~(align - 1)); | 150 | + align-1) & ~(align - 1)); |
148 | } | 151 | } |
149 | 152 | ||
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index 9dd49ca67dbc..6e70ddb158b4 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
@@ -704,6 +704,7 @@ static void p9_virtio_remove(struct virtio_device *vdev) | |||
704 | 704 | ||
705 | mutex_unlock(&virtio_9p_lock); | 705 | mutex_unlock(&virtio_9p_lock); |
706 | 706 | ||
707 | vdev->config->reset(vdev); | ||
707 | vdev->config->del_vqs(vdev); | 708 | vdev->config->del_vqs(vdev); |
708 | 709 | ||
709 | sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); | 710 | sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); |