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 updates from Michael Tsirkin:
"Some bug fixes/cleanups.

The deprecated scsi passthrough for virtio_blk is removed"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
virtio_balloon: Fix memory leaks on errors in virtballoon_probe()
virtio-balloon: Fix memory leak when unloading while hinting is in progress
virtio_balloon: prevent pfn array overflow
virtio-blk: remove VIRTIO_BLK_F_SCSI support
virtio-pci: check name when counting MSI-X vectors
virtio-balloon: initialize all vq callbacks
virtio-mmio: convert to devm_platform_ioremap_resource

+22 -145
-1
arch/powerpc/configs/guest.config
··· 1 1 CONFIG_VIRTIO_BLK=y 2 - CONFIG_VIRTIO_BLK_SCSI=y 3 2 CONFIG_SCSI_VIRTIO=y 4 3 CONFIG_VIRTIO_NET=y 5 4 CONFIG_NET_FAILOVER=y
-10
drivers/block/Kconfig
··· 432 432 This is the virtual block driver for virtio. It can be used with 433 433 QEMU based VMMs (like KVM or Xen). Say Y or M. 434 434 435 - config VIRTIO_BLK_SCSI 436 - bool "SCSI passthrough request for the Virtio block driver" 437 - depends on VIRTIO_BLK 438 - select BLK_SCSI_REQUEST 439 - ---help--- 440 - Enable support for SCSI passthrough (e.g. the SG_IO ioctl) on 441 - virtio-blk devices. This is only supported for the legacy 442 - virtio protocol and not enabled by default by any hypervisor. 443 - You probably want to use virtio-scsi instead. 444 - 445 435 config BLK_DEV_RBD 446 436 tristate "Rados block device (RBD)" 447 437 depends on INET && BLOCK
+1 -117
drivers/block/virtio_blk.c
··· 11 11 #include <linux/virtio_blk.h> 12 12 #include <linux/scatterlist.h> 13 13 #include <linux/string_helpers.h> 14 - #include <scsi/scsi_cmnd.h> 15 14 #include <linux/idr.h> 16 15 #include <linux/blk-mq.h> 17 16 #include <linux/blk-mq-virtio.h> ··· 55 56 }; 56 57 57 58 struct virtblk_req { 58 - #ifdef CONFIG_VIRTIO_BLK_SCSI 59 - struct scsi_request sreq; /* for SCSI passthrough, must be first */ 60 - u8 sense[SCSI_SENSE_BUFFERSIZE]; 61 - struct virtio_scsi_inhdr in_hdr; 62 - #endif 63 59 struct virtio_blk_outhdr out_hdr; 64 60 u8 status; 65 61 struct scatterlist sg[]; ··· 71 77 return BLK_STS_IOERR; 72 78 } 73 79 } 74 - 75 - /* 76 - * If this is a packet command we need a couple of additional headers. Behind 77 - * the normal outhdr we put a segment with the scsi command block, and before 78 - * the normal inhdr we put the sense data and the inhdr with additional status 79 - * information. 80 - */ 81 - #ifdef CONFIG_VIRTIO_BLK_SCSI 82 - static int virtblk_add_req_scsi(struct virtqueue *vq, struct virtblk_req *vbr, 83 - struct scatterlist *data_sg, bool have_data) 84 - { 85 - struct scatterlist hdr, status, cmd, sense, inhdr, *sgs[6]; 86 - unsigned int num_out = 0, num_in = 0; 87 - 88 - sg_init_one(&hdr, &vbr->out_hdr, sizeof(vbr->out_hdr)); 89 - sgs[num_out++] = &hdr; 90 - sg_init_one(&cmd, vbr->sreq.cmd, vbr->sreq.cmd_len); 91 - sgs[num_out++] = &cmd; 92 - 93 - if (have_data) { 94 - if (vbr->out_hdr.type & cpu_to_virtio32(vq->vdev, VIRTIO_BLK_T_OUT)) 95 - sgs[num_out++] = data_sg; 96 - else 97 - sgs[num_out + num_in++] = data_sg; 98 - } 99 - 100 - sg_init_one(&sense, vbr->sense, SCSI_SENSE_BUFFERSIZE); 101 - sgs[num_out + num_in++] = &sense; 102 - sg_init_one(&inhdr, &vbr->in_hdr, sizeof(vbr->in_hdr)); 103 - sgs[num_out + num_in++] = &inhdr; 104 - sg_init_one(&status, &vbr->status, sizeof(vbr->status)); 105 - sgs[num_out + num_in++] = &status; 106 - 107 - return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC); 108 - } 109 - 110 - static inline void virtblk_scsi_request_done(struct request *req) 111 - { 112 - struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); 113 - struct virtio_blk *vblk = req->q->queuedata; 114 - struct scsi_request *sreq = &vbr->sreq; 115 - 116 - sreq->resid_len = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.residual); 117 - sreq->sense_len = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.sense_len); 118 - sreq->result = virtio32_to_cpu(vblk->vdev, vbr->in_hdr.errors); 119 - } 120 - 121 - static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, 122 - unsigned int cmd, unsigned long data) 123 - { 124 - struct gendisk *disk = bdev->bd_disk; 125 - struct virtio_blk *vblk = disk->private_data; 126 - 127 - /* 128 - * Only allow the generic SCSI ioctls if the host can support it. 129 - */ 130 - if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI)) 131 - return -ENOTTY; 132 - 133 - return scsi_cmd_blk_ioctl(bdev, mode, cmd, 134 - (void __user *)data); 135 - } 136 - #else 137 - static inline int virtblk_add_req_scsi(struct virtqueue *vq, 138 - struct virtblk_req *vbr, struct scatterlist *data_sg, 139 - bool have_data) 140 - { 141 - return -EIO; 142 - } 143 - static inline void virtblk_scsi_request_done(struct request *req) 144 - { 145 - } 146 - #define virtblk_ioctl NULL 147 - #endif /* CONFIG_VIRTIO_BLK_SCSI */ 148 80 149 81 static int virtblk_add_req(struct virtqueue *vq, struct virtblk_req *vbr, 150 82 struct scatterlist *data_sg, bool have_data) ··· 134 214 if (req->rq_flags & RQF_SPECIAL_PAYLOAD) { 135 215 kfree(page_address(req->special_vec.bv_page) + 136 216 req->special_vec.bv_offset); 137 - } 138 - 139 - switch (req_op(req)) { 140 - case REQ_OP_SCSI_IN: 141 - case REQ_OP_SCSI_OUT: 142 - virtblk_scsi_request_done(req); 143 - break; 144 217 } 145 218 146 219 blk_mq_end_request(req, virtblk_result(vbr)); ··· 212 299 type = VIRTIO_BLK_T_WRITE_ZEROES; 213 300 unmap = !(req->cmd_flags & REQ_NOUNMAP); 214 301 break; 215 - case REQ_OP_SCSI_IN: 216 - case REQ_OP_SCSI_OUT: 217 - type = VIRTIO_BLK_T_SCSI_CMD; 218 - break; 219 302 case REQ_OP_DRV_IN: 220 303 type = VIRTIO_BLK_T_GET_ID; 221 304 break; ··· 242 333 } 243 334 244 335 spin_lock_irqsave(&vblk->vqs[qid].lock, flags); 245 - if (blk_rq_is_scsi(req)) 246 - err = virtblk_add_req_scsi(vblk->vqs[qid].vq, vbr, vbr->sg, num); 247 - else 248 - err = virtblk_add_req(vblk->vqs[qid].vq, vbr, vbr->sg, num); 336 + err = virtblk_add_req(vblk->vqs[qid].vq, vbr, vbr->sg, num); 249 337 if (err) { 250 338 virtqueue_kick(vblk->vqs[qid].vq); 251 339 blk_mq_stop_hw_queue(hctx); ··· 310 404 } 311 405 312 406 static const struct block_device_operations virtblk_fops = { 313 - .ioctl = virtblk_ioctl, 314 - #ifdef CONFIG_COMPAT 315 - .compat_ioctl = blkdev_compat_ptr_ioctl, 316 - #endif 317 407 .owner = THIS_MODULE, 318 408 .getgeo = virtblk_getgeo, 319 409 }; ··· 588 686 struct virtio_blk *vblk = set->driver_data; 589 687 struct virtblk_req *vbr = blk_mq_rq_to_pdu(rq); 590 688 591 - #ifdef CONFIG_VIRTIO_BLK_SCSI 592 - vbr->sreq.sense = vbr->sense; 593 - #endif 594 689 sg_init_table(vbr->sg, vblk->sg_elems); 595 690 return 0; 596 691 } ··· 600 701 vblk->vdev, 0); 601 702 } 602 703 603 - #ifdef CONFIG_VIRTIO_BLK_SCSI 604 - static void virtblk_initialize_rq(struct request *req) 605 - { 606 - struct virtblk_req *vbr = blk_mq_rq_to_pdu(req); 607 - 608 - scsi_req_init(&vbr->sreq); 609 - } 610 - #endif 611 - 612 704 static const struct blk_mq_ops virtio_mq_ops = { 613 705 .queue_rq = virtio_queue_rq, 614 706 .commit_rqs = virtio_commit_rqs, 615 707 .complete = virtblk_request_done, 616 708 .init_request = virtblk_init_request, 617 - #ifdef CONFIG_VIRTIO_BLK_SCSI 618 - .initialize_rq_fn = virtblk_initialize_rq, 619 - #endif 620 709 .map_queues = virtblk_map_queues, 621 710 }; 622 711 ··· 881 994 static unsigned int features_legacy[] = { 882 995 VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY, 883 996 VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, 884 - #ifdef CONFIG_VIRTIO_BLK_SCSI 885 - VIRTIO_BLK_F_SCSI, 886 - #endif 887 997 VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE, 888 998 VIRTIO_BLK_F_MQ, VIRTIO_BLK_F_DISCARD, VIRTIO_BLK_F_WRITE_ZEROES, 889 999 }
+17 -4
drivers/virtio/virtio_balloon.c
··· 158 158 { 159 159 unsigned int i; 160 160 161 + BUILD_BUG_ON(VIRTIO_BALLOON_PAGES_PER_PAGE > VIRTIO_BALLOON_ARRAY_PFNS_MAX); 162 + 161 163 /* 162 164 * Set balloon pfns pointing at this page. 163 165 * Note that the first pfn points at start of the page. ··· 477 475 names[VIRTIO_BALLOON_VQ_INFLATE] = "inflate"; 478 476 callbacks[VIRTIO_BALLOON_VQ_DEFLATE] = balloon_ack; 479 477 names[VIRTIO_BALLOON_VQ_DEFLATE] = "deflate"; 478 + callbacks[VIRTIO_BALLOON_VQ_STATS] = NULL; 480 479 names[VIRTIO_BALLOON_VQ_STATS] = NULL; 480 + callbacks[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL; 481 481 names[VIRTIO_BALLOON_VQ_FREE_PAGE] = NULL; 482 482 483 483 if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) { ··· 903 899 vb->vb_dev_info.inode = alloc_anon_inode(balloon_mnt->mnt_sb); 904 900 if (IS_ERR(vb->vb_dev_info.inode)) { 905 901 err = PTR_ERR(vb->vb_dev_info.inode); 906 - kern_unmount(balloon_mnt); 907 - goto out_del_vqs; 902 + goto out_kern_unmount; 908 903 } 909 904 vb->vb_dev_info.inode->i_mapping->a_ops = &balloon_aops; 910 905 #endif ··· 914 911 */ 915 912 if (virtqueue_get_vring_size(vb->free_page_vq) < 2) { 916 913 err = -ENOSPC; 917 - goto out_del_vqs; 914 + goto out_iput; 918 915 } 919 916 vb->balloon_wq = alloc_workqueue("balloon-wq", 920 917 WQ_FREEZABLE | WQ_CPU_INTENSIVE, 0); 921 918 if (!vb->balloon_wq) { 922 919 err = -ENOMEM; 923 - goto out_del_vqs; 920 + goto out_iput; 924 921 } 925 922 INIT_WORK(&vb->report_free_page_work, report_free_page_func); 926 923 vb->cmd_id_received_cache = VIRTIO_BALLOON_CMD_ID_STOP; ··· 954 951 out_del_balloon_wq: 955 952 if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) 956 953 destroy_workqueue(vb->balloon_wq); 954 + out_iput: 955 + #ifdef CONFIG_BALLOON_COMPACTION 956 + iput(vb->vb_dev_info.inode); 957 + out_kern_unmount: 958 + kern_unmount(balloon_mnt); 959 + #endif 957 960 out_del_vqs: 958 961 vdev->config->del_vqs(vdev); 959 962 out_free_vb: ··· 974 965 while (vb->num_pages) 975 966 leak_balloon(vb, vb->num_pages); 976 967 update_balloon_size(vb); 968 + 969 + /* There might be free pages that are being reported: release them. */ 970 + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) 971 + return_free_pages_to_mm(vb, ULONG_MAX); 977 972 978 973 /* Now we reset the device so we can clean up the queues. */ 979 974 vb->vdev->config->reset(vb->vdev);
+3 -12
drivers/virtio/virtio_mmio.c
··· 531 531 static int virtio_mmio_probe(struct platform_device *pdev) 532 532 { 533 533 struct virtio_mmio_device *vm_dev; 534 - struct resource *mem; 535 534 unsigned long magic; 536 535 int rc; 537 - 538 - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 539 - if (!mem) 540 - return -EINVAL; 541 - 542 - if (!devm_request_mem_region(&pdev->dev, mem->start, 543 - resource_size(mem), pdev->name)) 544 - return -EBUSY; 545 536 546 537 vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL); 547 538 if (!vm_dev) ··· 545 554 INIT_LIST_HEAD(&vm_dev->virtqueues); 546 555 spin_lock_init(&vm_dev->lock); 547 556 548 - vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); 549 - if (vm_dev->base == NULL) 550 - return -EFAULT; 557 + vm_dev->base = devm_platform_ioremap_resource(pdev, 0); 558 + if (IS_ERR(vm_dev->base)) 559 + return PTR_ERR(vm_dev->base); 551 560 552 561 /* Check magic value */ 553 562 magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
+1 -1
drivers/virtio/virtio_pci_common.c
··· 294 294 /* Best option: one for change interrupt, one per vq. */ 295 295 nvectors = 1; 296 296 for (i = 0; i < nvqs; ++i) 297 - if (callbacks[i]) 297 + if (names[i] && callbacks[i]) 298 298 ++nvectors; 299 299 } else { 300 300 /* Second best: one for change, shared for all vqs. */