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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio/vhost fixes and cleanups from Michael Tsirkin:
"Fixes and cleanups all over the place"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
vhost/scsi: Use copy_to_iter() to send control queue response
vhost: return EINVAL if iovecs size does not match the message size
virtio-balloon: tweak config_changed implementation
virtio: don't allocate vqs when names[i] = NULL
virtio_pci: use queue idx instead of array idx to set up the vq
virtio: document virtio_config_ops restrictions
virtio: fix virtio_config_ops description

+126 -60
+7 -2
drivers/misc/mic/vop/vop_main.c
··· 394 394 struct _vop_vdev *vdev = to_vopvdev(dev); 395 395 struct vop_device *vpdev = vdev->vpdev; 396 396 struct mic_device_ctrl __iomem *dc = vdev->dc; 397 - int i, err, retry; 397 + int i, err, retry, queue_idx = 0; 398 398 399 399 /* We must have this many virtqueues. */ 400 400 if (nvqs > ioread8(&vdev->desc->num_vq)) 401 401 return -ENOENT; 402 402 403 403 for (i = 0; i < nvqs; ++i) { 404 + if (!names[i]) { 405 + vqs[i] = NULL; 406 + continue; 407 + } 408 + 404 409 dev_dbg(_vop_dev(vdev), "%s: %d: %s\n", 405 410 __func__, i, names[i]); 406 - vqs[i] = vop_find_vq(dev, i, callbacks[i], names[i], 411 + vqs[i] = vop_find_vq(dev, queue_idx++, callbacks[i], names[i], 407 412 ctx ? ctx[i] : false); 408 413 if (IS_ERR(vqs[i])) { 409 414 err = PTR_ERR(vqs[i]);
+7 -2
drivers/remoteproc/remoteproc_virtio.c
··· 153 153 const bool * ctx, 154 154 struct irq_affinity *desc) 155 155 { 156 - int i, ret; 156 + int i, ret, queue_idx = 0; 157 157 158 158 for (i = 0; i < nvqs; ++i) { 159 - vqs[i] = rp_find_vq(vdev, i, callbacks[i], names[i], 159 + if (!names[i]) { 160 + vqs[i] = NULL; 161 + continue; 162 + } 163 + 164 + vqs[i] = rp_find_vq(vdev, queue_idx++, callbacks[i], names[i], 160 165 ctx ? ctx[i] : false); 161 166 if (IS_ERR(vqs[i])) { 162 167 ret = PTR_ERR(vqs[i]);
+9 -3
drivers/s390/virtio/virtio_ccw.c
··· 635 635 { 636 636 struct virtio_ccw_device *vcdev = to_vc_device(vdev); 637 637 unsigned long *indicatorp = NULL; 638 - int ret, i; 638 + int ret, i, queue_idx = 0; 639 639 struct ccw1 *ccw; 640 640 641 641 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); ··· 643 643 return -ENOMEM; 644 644 645 645 for (i = 0; i < nvqs; ++i) { 646 - vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i], 647 - ctx ? ctx[i] : false, ccw); 646 + if (!names[i]) { 647 + vqs[i] = NULL; 648 + continue; 649 + } 650 + 651 + vqs[i] = virtio_ccw_setup_vq(vdev, queue_idx++, callbacks[i], 652 + names[i], ctx ? ctx[i] : false, 653 + ccw); 648 654 if (IS_ERR(vqs[i])) { 649 655 ret = PTR_ERR(vqs[i]); 650 656 vqs[i] = NULL;
+12 -8
drivers/vhost/scsi.c
··· 1127 1127 struct vhost_virtqueue *vq, 1128 1128 struct vhost_scsi_ctx *vc) 1129 1129 { 1130 - struct virtio_scsi_ctrl_tmf_resp __user *resp; 1131 1130 struct virtio_scsi_ctrl_tmf_resp rsp; 1131 + struct iov_iter iov_iter; 1132 1132 int ret; 1133 1133 1134 1134 pr_debug("%s\n", __func__); 1135 1135 memset(&rsp, 0, sizeof(rsp)); 1136 1136 rsp.response = VIRTIO_SCSI_S_FUNCTION_REJECTED; 1137 - resp = vq->iov[vc->out].iov_base; 1138 - ret = __copy_to_user(resp, &rsp, sizeof(rsp)); 1139 - if (!ret) 1137 + 1138 + iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp)); 1139 + 1140 + ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); 1141 + if (likely(ret == sizeof(rsp))) 1140 1142 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); 1141 1143 else 1142 1144 pr_err("Faulted on virtio_scsi_ctrl_tmf_resp\n"); ··· 1149 1147 struct vhost_virtqueue *vq, 1150 1148 struct vhost_scsi_ctx *vc) 1151 1149 { 1152 - struct virtio_scsi_ctrl_an_resp __user *resp; 1153 1150 struct virtio_scsi_ctrl_an_resp rsp; 1151 + struct iov_iter iov_iter; 1154 1152 int ret; 1155 1153 1156 1154 pr_debug("%s\n", __func__); 1157 1155 memset(&rsp, 0, sizeof(rsp)); /* event_actual = 0 */ 1158 1156 rsp.response = VIRTIO_SCSI_S_OK; 1159 - resp = vq->iov[vc->out].iov_base; 1160 - ret = __copy_to_user(resp, &rsp, sizeof(rsp)); 1161 - if (!ret) 1157 + 1158 + iov_iter_init(&iov_iter, READ, &vq->iov[vc->out], vc->in, sizeof(rsp)); 1159 + 1160 + ret = copy_to_iter(&rsp, sizeof(rsp), &iov_iter); 1161 + if (likely(ret == sizeof(rsp))) 1162 1162 vhost_add_used_and_signal(&vs->dev, vq, vc->head, 0); 1163 1163 else 1164 1164 pr_err("Faulted on virtio_scsi_ctrl_an_resp\n");
+6 -2
drivers/vhost/vhost.c
··· 1034 1034 int type, ret; 1035 1035 1036 1036 ret = copy_from_iter(&type, sizeof(type), from); 1037 - if (ret != sizeof(type)) 1037 + if (ret != sizeof(type)) { 1038 + ret = -EINVAL; 1038 1039 goto done; 1040 + } 1039 1041 1040 1042 switch (type) { 1041 1043 case VHOST_IOTLB_MSG: ··· 1056 1054 1057 1055 iov_iter_advance(from, offset); 1058 1056 ret = copy_from_iter(&msg, sizeof(msg), from); 1059 - if (ret != sizeof(msg)) 1057 + if (ret != sizeof(msg)) { 1058 + ret = -EINVAL; 1060 1059 goto done; 1060 + } 1061 1061 if (vhost_process_iotlb_msg(dev, &msg)) { 1062 1062 ret = -EFAULT; 1063 1063 goto done;
+65 -33
drivers/virtio/virtio_balloon.c
··· 61 61 VIRTIO_BALLOON_VQ_MAX 62 62 }; 63 63 64 + enum virtio_balloon_config_read { 65 + VIRTIO_BALLOON_CONFIG_READ_CMD_ID = 0, 66 + }; 67 + 64 68 struct virtio_balloon { 65 69 struct virtio_device *vdev; 66 70 struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_page_vq; ··· 81 77 /* Prevent updating balloon when it is being canceled. */ 82 78 spinlock_t stop_update_lock; 83 79 bool stop_update; 80 + /* Bitmap to indicate if reading the related config fields are needed */ 81 + unsigned long config_read_bitmap; 84 82 85 83 /* The list of allocated free pages, waiting to be given back to mm */ 86 84 struct list_head free_page_list; 87 85 spinlock_t free_page_list_lock; 88 86 /* The number of free page blocks on the above list */ 89 87 unsigned long num_free_page_blocks; 90 - /* The cmd id received from host */ 91 - u32 cmd_id_received; 88 + /* 89 + * The cmd id received from host. 90 + * Read it via virtio_balloon_cmd_id_received to get the latest value 91 + * sent from host. 92 + */ 93 + u32 cmd_id_received_cache; 92 94 /* The cmd id that is actively in use */ 93 95 __virtio32 cmd_id_active; 94 96 /* Buffer to store the stop sign */ ··· 400 390 return num_returned; 401 391 } 402 392 393 + static void virtio_balloon_queue_free_page_work(struct virtio_balloon *vb) 394 + { 395 + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) 396 + return; 397 + 398 + /* No need to queue the work if the bit was already set. */ 399 + if (test_and_set_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID, 400 + &vb->config_read_bitmap)) 401 + return; 402 + 403 + queue_work(vb->balloon_wq, &vb->report_free_page_work); 404 + } 405 + 403 406 static void virtballoon_changed(struct virtio_device *vdev) 404 407 { 405 408 struct virtio_balloon *vb = vdev->priv; 406 409 unsigned long flags; 407 - s64 diff = towards_target(vb); 408 410 409 - if (diff) { 410 - spin_lock_irqsave(&vb->stop_update_lock, flags); 411 - if (!vb->stop_update) 412 - queue_work(system_freezable_wq, 413 - &vb->update_balloon_size_work); 414 - spin_unlock_irqrestore(&vb->stop_update_lock, flags); 411 + spin_lock_irqsave(&vb->stop_update_lock, flags); 412 + if (!vb->stop_update) { 413 + queue_work(system_freezable_wq, 414 + &vb->update_balloon_size_work); 415 + virtio_balloon_queue_free_page_work(vb); 415 416 } 416 - 417 - if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) { 418 - virtio_cread(vdev, struct virtio_balloon_config, 419 - free_page_report_cmd_id, &vb->cmd_id_received); 420 - if (vb->cmd_id_received == VIRTIO_BALLOON_CMD_ID_DONE) { 421 - /* Pass ULONG_MAX to give back all the free pages */ 422 - return_free_pages_to_mm(vb, ULONG_MAX); 423 - } else if (vb->cmd_id_received != VIRTIO_BALLOON_CMD_ID_STOP && 424 - vb->cmd_id_received != 425 - virtio32_to_cpu(vdev, vb->cmd_id_active)) { 426 - spin_lock_irqsave(&vb->stop_update_lock, flags); 427 - if (!vb->stop_update) { 428 - queue_work(vb->balloon_wq, 429 - &vb->report_free_page_work); 430 - } 431 - spin_unlock_irqrestore(&vb->stop_update_lock, flags); 432 - } 433 - } 417 + spin_unlock_irqrestore(&vb->stop_update_lock, flags); 434 418 } 435 419 436 420 static void update_balloon_size(struct virtio_balloon *vb) ··· 531 527 return 0; 532 528 } 533 529 530 + static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb) 531 + { 532 + if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID, 533 + &vb->config_read_bitmap)) 534 + virtio_cread(vb->vdev, struct virtio_balloon_config, 535 + free_page_report_cmd_id, 536 + &vb->cmd_id_received_cache); 537 + 538 + return vb->cmd_id_received_cache; 539 + } 540 + 534 541 static int send_cmd_id_start(struct virtio_balloon *vb) 535 542 { 536 543 struct scatterlist sg; ··· 552 537 while (virtqueue_get_buf(vq, &unused)) 553 538 ; 554 539 555 - vb->cmd_id_active = cpu_to_virtio32(vb->vdev, vb->cmd_id_received); 540 + vb->cmd_id_active = virtio32_to_cpu(vb->vdev, 541 + virtio_balloon_cmd_id_received(vb)); 556 542 sg_init_one(&sg, &vb->cmd_id_active, sizeof(vb->cmd_id_active)); 557 543 err = virtqueue_add_outbuf(vq, &sg, 1, &vb->cmd_id_active, GFP_KERNEL); 558 544 if (!err) ··· 636 620 * stop the reporting. 637 621 */ 638 622 cmd_id_active = virtio32_to_cpu(vb->vdev, vb->cmd_id_active); 639 - if (cmd_id_active != vb->cmd_id_received) 623 + if (unlikely(cmd_id_active != 624 + virtio_balloon_cmd_id_received(vb))) 640 625 break; 641 626 642 627 /* ··· 654 637 return 0; 655 638 } 656 639 657 - static void report_free_page_func(struct work_struct *work) 640 + static void virtio_balloon_report_free_page(struct virtio_balloon *vb) 658 641 { 659 642 int err; 660 - struct virtio_balloon *vb = container_of(work, struct virtio_balloon, 661 - report_free_page_work); 662 643 struct device *dev = &vb->vdev->dev; 663 644 664 645 /* Start by sending the received cmd id to host with an outbuf. */ ··· 672 657 err = send_cmd_id_stop(vb); 673 658 if (unlikely(err)) 674 659 dev_err(dev, "Failed to send a stop id, err = %d\n", err); 660 + } 661 + 662 + static void report_free_page_func(struct work_struct *work) 663 + { 664 + struct virtio_balloon *vb = container_of(work, struct virtio_balloon, 665 + report_free_page_work); 666 + u32 cmd_id_received; 667 + 668 + cmd_id_received = virtio_balloon_cmd_id_received(vb); 669 + if (cmd_id_received == VIRTIO_BALLOON_CMD_ID_DONE) { 670 + /* Pass ULONG_MAX to give back all the free pages */ 671 + return_free_pages_to_mm(vb, ULONG_MAX); 672 + } else if (cmd_id_received != VIRTIO_BALLOON_CMD_ID_STOP && 673 + cmd_id_received != 674 + virtio32_to_cpu(vb->vdev, vb->cmd_id_active)) { 675 + virtio_balloon_report_free_page(vb); 676 + } 675 677 } 676 678 677 679 #ifdef CONFIG_BALLOON_COMPACTION ··· 917 885 goto out_del_vqs; 918 886 } 919 887 INIT_WORK(&vb->report_free_page_work, report_free_page_func); 920 - vb->cmd_id_received = VIRTIO_BALLOON_CMD_ID_STOP; 888 + vb->cmd_id_received_cache = VIRTIO_BALLOON_CMD_ID_STOP; 921 889 vb->cmd_id_active = cpu_to_virtio32(vb->vdev, 922 890 VIRTIO_BALLOON_CMD_ID_STOP); 923 891 vb->cmd_id_stop = cpu_to_virtio32(vb->vdev,
+7 -2
drivers/virtio/virtio_mmio.c
··· 468 468 { 469 469 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); 470 470 unsigned int irq = platform_get_irq(vm_dev->pdev, 0); 471 - int i, err; 471 + int i, err, queue_idx = 0; 472 472 473 473 err = request_irq(irq, vm_interrupt, IRQF_SHARED, 474 474 dev_name(&vdev->dev), vm_dev); ··· 476 476 return err; 477 477 478 478 for (i = 0; i < nvqs; ++i) { 479 - vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i], 479 + if (!names[i]) { 480 + vqs[i] = NULL; 481 + continue; 482 + } 483 + 484 + vqs[i] = vm_setup_vq(vdev, queue_idx++, callbacks[i], names[i], 480 485 ctx ? ctx[i] : false); 481 486 if (IS_ERR(vqs[i])) { 482 487 vm_del_vqs(vdev);
+4 -4
drivers/virtio/virtio_pci_common.c
··· 285 285 { 286 286 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 287 287 u16 msix_vec; 288 - int i, err, nvectors, allocated_vectors; 288 + int i, err, nvectors, allocated_vectors, queue_idx = 0; 289 289 290 290 vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL); 291 291 if (!vp_dev->vqs) ··· 321 321 msix_vec = allocated_vectors++; 322 322 else 323 323 msix_vec = VP_MSIX_VQ_VECTOR; 324 - vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i], 324 + vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i], 325 325 ctx ? ctx[i] : false, 326 326 msix_vec); 327 327 if (IS_ERR(vqs[i])) { ··· 356 356 const char * const names[], const bool *ctx) 357 357 { 358 358 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 359 - int i, err; 359 + int i, err, queue_idx = 0; 360 360 361 361 vp_dev->vqs = kcalloc(nvqs, sizeof(*vp_dev->vqs), GFP_KERNEL); 362 362 if (!vp_dev->vqs) ··· 374 374 vqs[i] = NULL; 375 375 continue; 376 376 } 377 - vqs[i] = vp_setup_vq(vdev, i, callbacks[i], names[i], 377 + vqs[i] = vp_setup_vq(vdev, queue_idx++, callbacks[i], names[i], 378 378 ctx ? ctx[i] : false, 379 379 VIRTIO_MSI_NO_VECTOR); 380 380 if (IS_ERR(vqs[i])) {
+9 -4
include/linux/virtio_config.h
··· 12 12 13 13 /** 14 14 * virtio_config_ops - operations for configuring a virtio device 15 + * Note: Do not assume that a transport implements all of the operations 16 + * getting/setting a value as a simple read/write! Generally speaking, 17 + * any of @get/@set, @get_status/@set_status, or @get_features/ 18 + * @finalize_features are NOT safe to be called from an atomic 19 + * context. 15 20 * @get: read the value of a configuration field 16 21 * vdev: the virtio_device 17 22 * offset: the offset of the configuration field ··· 27 22 * offset: the offset of the configuration field 28 23 * buf: the buffer to read the field value from. 29 24 * len: the length of the buffer 30 - * @generation: config generation counter 25 + * @generation: config generation counter (optional) 31 26 * vdev: the virtio_device 32 27 * Returns the config generation counter 33 28 * @get_status: read the status byte ··· 53 48 * @del_vqs: free virtqueues found by find_vqs(). 54 49 * @get_features: get the array of feature bits for this device. 55 50 * vdev: the virtio_device 56 - * Returns the first 32 feature bits (all we currently need). 51 + * Returns the first 64 feature bits (all we currently need). 57 52 * @finalize_features: confirm what device features we'll be using. 58 53 * vdev: the virtio_device 59 54 * This gives the final feature bits for the device: it can change 60 55 * the dev->feature bits if it wants. 61 56 * Returns 0 on success or error status 62 - * @bus_name: return the bus name associated with the device 57 + * @bus_name: return the bus name associated with the device (optional) 63 58 * vdev: the virtio_device 64 59 * This returns a pointer to the bus name a la pci_name from which 65 60 * the caller can then copy. 66 - * @set_vq_affinity: set the affinity for a virtqueue. 61 + * @set_vq_affinity: set the affinity for a virtqueue (optional). 67 62 * @get_vq_affinity: get the affinity for a virtqueue (optional). 68 63 */ 69 64 typedef void vq_callback_t(struct virtqueue *);