Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+91 -20
+9 -1
MAINTAINERS
··· 5899 5899 F: Documentation/s390/kvm.txt 5900 5900 F: arch/s390/include/asm/kvm* 5901 5901 F: arch/s390/kvm/ 5902 - F: drivers/s390/kvm/ 5903 5902 5904 5903 KERNEL VIRTUAL MACHINE (KVM) FOR ARM 5905 5904 M: Christoffer Dall <christoffer.dall@linaro.org> ··· 10894 10895 F: drivers/block/virtio_blk.c 10895 10896 F: include/linux/virtio_*.h 10896 10897 F: include/uapi/linux/virtio_*.h 10898 + 10899 + VIRTIO DRIVERS FOR S390 10900 + M: Christian Borntraeger <borntraeger@de.ibm.com> 10901 + M: Cornelia Huck <cornelia.huck@de.ibm.com> 10902 + L: linux-s390@vger.kernel.org 10903 + L: virtualization@lists.linux-foundation.org 10904 + L: kvm@vger.kernel.org 10905 + S: Supported 10906 + F: drivers/s390/virtio/ 10897 10907 10898 10908 VIRTIO GPU DRIVER 10899 10909 M: David Airlie <airlied@linux.ie>
+1 -1
drivers/s390/Makefile
··· 2 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 7 drivers-y += drivers/s390/built-in.o 8 8
drivers/s390/kvm/Makefile drivers/s390/virtio/Makefile
drivers/s390/kvm/kvm_virtio.c drivers/s390/virtio/kvm_virtio.c
drivers/s390/kvm/virtio_ccw.c drivers/s390/virtio/virtio_ccw.c
+3 -1
drivers/scsi/virtio_scsi.c
··· 949 949 { 950 950 struct Scsi_Host *shost; 951 951 struct virtio_scsi *vscsi; 952 - int err, host_prot; 952 + int err; 953 953 u32 sg_elems, num_targets; 954 954 u32 cmd_per_lun; 955 955 u32 num_queues; ··· 1009 1009 1010 1010 #ifdef CONFIG_BLK_DEV_INTEGRITY 1011 1011 if (virtio_has_feature(vdev, VIRTIO_SCSI_F_T10_PI)) { 1012 + int host_prot; 1013 + 1012 1014 host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | 1013 1015 SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION | 1014 1016 SHOST_DIX_TYPE2_PROTECTION | SHOST_DIX_TYPE3_PROTECTION;
+51 -16
drivers/vhost/vhost.c
··· 22 22 #include <linux/file.h> 23 23 #include <linux/highmem.h> 24 24 #include <linux/slab.h> 25 + #include <linux/vmalloc.h> 25 26 #include <linux/kthread.h> 26 27 #include <linux/cgroup.h> 27 28 #include <linux/module.h> 29 + #include <linux/sort.h> 28 30 29 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 38 enum { 32 - VHOST_MEMORY_MAX_NREGIONS = 64, 33 39 VHOST_MEMORY_F_LOG = 0x1, 34 40 }; 35 41 ··· 549 543 fput(dev->log_file); 550 544 dev->log_file = NULL; 551 545 /* No one will access memory at this point */ 552 - kfree(dev->memory); 546 + kvfree(dev->memory); 553 547 dev->memory = NULL; 554 548 WARN_ON(!list_empty(&dev->work_list)); 555 549 if (dev->worker) { ··· 669 663 } 670 664 EXPORT_SYMBOL_GPL(vhost_vq_access_ok); 671 665 666 + static int vhost_memory_reg_sort_cmp(const void *p1, const void *p2) 667 + { 668 + const struct vhost_memory_region *r1 = p1, *r2 = p2; 669 + if (r1->guest_phys_addr < r2->guest_phys_addr) 670 + return 1; 671 + if (r1->guest_phys_addr > r2->guest_phys_addr) 672 + return -1; 673 + return 0; 674 + } 675 + 676 + static void *vhost_kvzalloc(unsigned long size) 677 + { 678 + void *n = kzalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT); 679 + 680 + if (!n) { 681 + n = vzalloc(size); 682 + if (!n) 683 + return ERR_PTR(-ENOMEM); 684 + } 685 + return n; 686 + } 687 + 672 688 static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) 673 689 { 674 690 struct vhost_memory mem, *newmem, *oldmem; ··· 701 673 return -EFAULT; 702 674 if (mem.padding) 703 675 return -EOPNOTSUPP; 704 - if (mem.nregions > VHOST_MEMORY_MAX_NREGIONS) 676 + if (mem.nregions > max_mem_regions) 705 677 return -E2BIG; 706 - newmem = kmalloc(size + mem.nregions * sizeof *m->regions, GFP_KERNEL); 678 + newmem = vhost_kvzalloc(size + mem.nregions * sizeof(*m->regions)); 707 679 if (!newmem) 708 680 return -ENOMEM; 709 681 710 682 memcpy(newmem, &mem, size); 711 683 if (copy_from_user(newmem->regions, m->regions, 712 684 mem.nregions * sizeof *m->regions)) { 713 - kfree(newmem); 685 + kvfree(newmem); 714 686 return -EFAULT; 715 687 } 688 + sort(newmem->regions, newmem->nregions, sizeof(*newmem->regions), 689 + vhost_memory_reg_sort_cmp, NULL); 716 690 717 691 if (!memory_access_ok(d, newmem, 0)) { 718 - kfree(newmem); 692 + kvfree(newmem); 719 693 return -EFAULT; 720 694 } 721 695 oldmem = d->memory; ··· 729 699 d->vqs[i]->memory = newmem; 730 700 mutex_unlock(&d->vqs[i]->mutex); 731 701 } 732 - kfree(oldmem); 702 + kvfree(oldmem); 733 703 return 0; 734 704 } 735 705 ··· 1022 992 static const struct vhost_memory_region *find_region(struct vhost_memory *mem, 1023 993 __u64 addr, __u32 len) 1024 994 { 1025 - struct vhost_memory_region *reg; 1026 - int i; 995 + const struct vhost_memory_region *reg; 996 + int start = 0, end = mem->nregions; 1027 997 1028 - /* linear search is not brilliant, but we really have on the order of 6 1029 - * regions in practice */ 1030 - for (i = 0; i < mem->nregions; ++i) { 1031 - reg = mem->regions + i; 1032 - if (reg->guest_phys_addr <= addr && 1033 - reg->guest_phys_addr + reg->memory_size - 1 >= addr) 1034 - return reg; 998 + while (start < end) { 999 + int slot = start + (end - start) / 2; 1000 + reg = mem->regions + slot; 1001 + if (addr >= reg->guest_phys_addr) 1002 + end = slot; 1003 + else 1004 + start = slot + 1; 1035 1005 } 1006 + 1007 + reg = mem->regions + start; 1008 + if (addr >= reg->guest_phys_addr && 1009 + reg->guest_phys_addr + reg->memory_size > addr) 1010 + return reg; 1036 1011 return NULL; 1037 1012 } 1038 1013
+16
include/uapi/linux/virtio_net.h
··· 34 34 /* The feature bitmap for virtio net */ 35 35 #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ 36 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 38 #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ 38 39 #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ 39 40 #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ ··· 226 225 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 227 226 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 228 227 #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 228 + 229 + /* 230 + * Control network offloads 231 + * 232 + * Reconfigures the network offloads that Guest can handle. 233 + * 234 + * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit. 235 + * 236 + * Command data format matches the feature bit mask exactly. 237 + * 238 + * See VIRTIO_NET_F_GUEST_* for the list of offloads 239 + * that can be enabled/disabled. 240 + */ 241 + #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5 242 + #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0 229 243 230 244 #endif /* _LINUX_VIRTIO_NET_H */
+6
include/uapi/linux/virtio_pci.h
··· 157 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 166 /* Macro versions of offsets for the Old Timers! */ 161 167 #define VIRTIO_PCI_CAP_VNDR 0 162 168 #define VIRTIO_PCI_CAP_NEXT 1
+4 -1
include/uapi/linux/virtio_ring.h
··· 31 31 * SUCH DAMAGE. 32 32 * 33 33 * Copyright Rusty Russell IBM Corporation 2007. */ 34 + #ifndef __KERNEL__ 35 + #include <stdint.h> 36 + #endif 34 37 #include <linux/types.h> 35 38 #include <linux/virtio_types.h> 36 39 ··· 146 143 vr->num = num; 147 144 vr->desc = p; 148 145 vr->avail = p + num*sizeof(struct vring_desc); 149 - vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(__virtio16) 146 + vr->used = (void *)(((uintptr_t)&vr->avail->ring[num] + sizeof(__virtio16) 150 147 + align-1) & ~(align - 1)); 151 148 } 152 149
+1
net/9p/trans_virtio.c
··· 704 704 705 705 mutex_unlock(&virtio_9p_lock); 706 706 707 + vdev->config->reset(vdev); 707 708 vdev->config->del_vqs(vdev); 708 709 709 710 sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);