summaryrefslogtreecommitdiffstats
path: root/drivers/vhost
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-02-08 13:41:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-08 13:41:00 -0500
commit846ade7dd2e630a309a8c57302046e8c4037b8df (patch)
tree021892148643db7cd0c898ad5939ecc7836a7330 /drivers/vhost
parent977e41524dae8fed9c82e3dd298f3b48282fc0b8 (diff)
parentd25cc43c6775bff6b8e3dad97c747954b805e421 (diff)
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio/vhost updates from Michael Tsirkin: "virtio, vhost: fixes, cleanups, features This includes the disk/cache memory stats for for the virtio balloon, as well as multiple fixes and cleanups" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: don't hold onto file pointer for VHOST_SET_LOG_FD vhost: don't hold onto file pointer for VHOST_SET_VRING_ERR vhost: don't hold onto file pointer for VHOST_SET_VRING_CALL ringtest: ring.c malloc & memset to calloc virtio_vop: don't kfree device on register failure virtio_pci: don't kfree device on register failure virtio: split device_register into device_initialize and device_add vhost: remove unused lock check flag in vhost_dev_cleanup() vhost: Remove the unused variable. virtio_blk: print capacity at probe time virtio: make VIRTIO a menuconfig to ease disabling it all virtio/ringtest: virtio_ring: fix up need_event math virtio/ringtest: fix up need_event math virtio: virtio_mmio: make of_device_ids const. firmware: Use PTR_ERR_OR_ZERO() virtio-mmio: Use PTR_ERR_OR_ZERO() vhost/scsi: Improve a size determination in four functions virtio_balloon: include disk/file caches memory statistics
Diffstat (limited to 'drivers/vhost')
-rw-r--r--drivers/vhost/net.c2
-rw-r--r--drivers/vhost/scsi.c11
-rw-r--r--drivers/vhost/test.c2
-rw-r--r--drivers/vhost/vhost.c68
-rw-r--r--drivers/vhost/vhost.h9
-rw-r--r--drivers/vhost/vsock.c2
6 files changed, 25 insertions, 69 deletions
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 9c3f8160ef24..c613d2e3d371 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1015,7 +1015,7 @@ static int vhost_net_release(struct inode *inode, struct file *f)
1015 vhost_net_stop(n, &tx_sock, &rx_sock); 1015 vhost_net_stop(n, &tx_sock, &rx_sock);
1016 vhost_net_flush(n); 1016 vhost_net_flush(n);
1017 vhost_dev_stop(&n->dev); 1017 vhost_dev_stop(&n->dev);
1018 vhost_dev_cleanup(&n->dev, false); 1018 vhost_dev_cleanup(&n->dev);
1019 vhost_net_vq_reset(n); 1019 vhost_net_vq_reset(n);
1020 if (tx_sock) 1020 if (tx_sock)
1021 sockfd_put(tx_sock); 1021 sockfd_put(tx_sock);
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 71517b3c5558..7ad57094d736 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -586,8 +586,7 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
586 sg = cmd->tvc_sgl; 586 sg = cmd->tvc_sgl;
587 prot_sg = cmd->tvc_prot_sgl; 587 prot_sg = cmd->tvc_prot_sgl;
588 pages = cmd->tvc_upages; 588 pages = cmd->tvc_upages;
589 memset(cmd, 0, sizeof(struct vhost_scsi_cmd)); 589 memset(cmd, 0, sizeof(*cmd));
590
591 cmd->tvc_sgl = sg; 590 cmd->tvc_sgl = sg;
592 cmd->tvc_prot_sgl = prot_sg; 591 cmd->tvc_prot_sgl = prot_sg;
593 cmd->tvc_upages = pages; 592 cmd->tvc_upages = pages;
@@ -1420,7 +1419,7 @@ static int vhost_scsi_release(struct inode *inode, struct file *f)
1420 mutex_unlock(&vs->dev.mutex); 1419 mutex_unlock(&vs->dev.mutex);
1421 vhost_scsi_clear_endpoint(vs, &t); 1420 vhost_scsi_clear_endpoint(vs, &t);
1422 vhost_dev_stop(&vs->dev); 1421 vhost_dev_stop(&vs->dev);
1423 vhost_dev_cleanup(&vs->dev, false); 1422 vhost_dev_cleanup(&vs->dev);
1424 /* Jobs can re-queue themselves in evt kick handler. Do extra flush. */ 1423 /* Jobs can re-queue themselves in evt kick handler. Do extra flush. */
1425 vhost_scsi_flush(vs); 1424 vhost_scsi_flush(vs);
1426 kfree(vs->dev.vqs); 1425 kfree(vs->dev.vqs);
@@ -1725,7 +1724,7 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
1725 return -EEXIST; 1724 return -EEXIST;
1726 } 1725 }
1727 1726
1728 tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL); 1727 tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL);
1729 if (!tv_nexus) { 1728 if (!tv_nexus) {
1730 mutex_unlock(&tpg->tv_tpg_mutex); 1729 mutex_unlock(&tpg->tv_tpg_mutex);
1731 pr_err("Unable to allocate struct vhost_scsi_nexus\n"); 1730 pr_err("Unable to allocate struct vhost_scsi_nexus\n");
@@ -1926,7 +1925,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
1926 if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET) 1925 if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET)
1927 return ERR_PTR(-EINVAL); 1926 return ERR_PTR(-EINVAL);
1928 1927
1929 tpg = kzalloc(sizeof(struct vhost_scsi_tpg), GFP_KERNEL); 1928 tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
1930 if (!tpg) { 1929 if (!tpg) {
1931 pr_err("Unable to allocate struct vhost_scsi_tpg"); 1930 pr_err("Unable to allocate struct vhost_scsi_tpg");
1932 return ERR_PTR(-ENOMEM); 1931 return ERR_PTR(-ENOMEM);
@@ -1980,7 +1979,7 @@ vhost_scsi_make_tport(struct target_fabric_configfs *tf,
1980 /* if (vhost_scsi_parse_wwn(name, &wwpn, 1) < 0) 1979 /* if (vhost_scsi_parse_wwn(name, &wwpn, 1) < 0)
1981 return ERR_PTR(-EINVAL); */ 1980 return ERR_PTR(-EINVAL); */
1982 1981
1983 tport = kzalloc(sizeof(struct vhost_scsi_tport), GFP_KERNEL); 1982 tport = kzalloc(sizeof(*tport), GFP_KERNEL);
1984 if (!tport) { 1983 if (!tport) {
1985 pr_err("Unable to allocate struct vhost_scsi_tport"); 1984 pr_err("Unable to allocate struct vhost_scsi_tport");
1986 return ERR_PTR(-ENOMEM); 1985 return ERR_PTR(-ENOMEM);
diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 3cc98c07dcd3..906b8f0f19f7 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -157,7 +157,7 @@ static int vhost_test_release(struct inode *inode, struct file *f)
157 157
158 vhost_test_stop(n, &private); 158 vhost_test_stop(n, &private);
159 vhost_test_flush(n); 159 vhost_test_flush(n);
160 vhost_dev_cleanup(&n->dev, false); 160 vhost_dev_cleanup(&n->dev);
161 /* We do an extra flush before freeing memory, 161 /* We do an extra flush before freeing memory,
162 * since jobs can re-queue themselves. */ 162 * since jobs can re-queue themselves. */
163 vhost_test_flush(n); 163 vhost_test_flush(n);
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 8d4374606756..2db5af8e8652 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -181,7 +181,6 @@ void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn)
181{ 181{
182 clear_bit(VHOST_WORK_QUEUED, &work->flags); 182 clear_bit(VHOST_WORK_QUEUED, &work->flags);
183 work->fn = fn; 183 work->fn = fn;
184 init_waitqueue_head(&work->done);
185} 184}
186EXPORT_SYMBOL_GPL(vhost_work_init); 185EXPORT_SYMBOL_GPL(vhost_work_init);
187 186
@@ -319,10 +318,8 @@ static void vhost_vq_reset(struct vhost_dev *dev,
319 vq->acked_features = 0; 318 vq->acked_features = 0;
320 vq->log_base = NULL; 319 vq->log_base = NULL;
321 vq->error_ctx = NULL; 320 vq->error_ctx = NULL;
322 vq->error = NULL;
323 vq->kick = NULL; 321 vq->kick = NULL;
324 vq->call_ctx = NULL; 322 vq->call_ctx = NULL;
325 vq->call = NULL;
326 vq->log_ctx = NULL; 323 vq->log_ctx = NULL;
327 vhost_reset_is_le(vq); 324 vhost_reset_is_le(vq);
328 vhost_disable_cross_endian(vq); 325 vhost_disable_cross_endian(vq);
@@ -422,7 +419,6 @@ void vhost_dev_init(struct vhost_dev *dev,
422 dev->nvqs = nvqs; 419 dev->nvqs = nvqs;
423 mutex_init(&dev->mutex); 420 mutex_init(&dev->mutex);
424 dev->log_ctx = NULL; 421 dev->log_ctx = NULL;
425 dev->log_file = NULL;
426 dev->umem = NULL; 422 dev->umem = NULL;
427 dev->iotlb = NULL; 423 dev->iotlb = NULL;
428 dev->mm = NULL; 424 dev->mm = NULL;
@@ -544,7 +540,7 @@ void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_umem *umem)
544{ 540{
545 int i; 541 int i;
546 542
547 vhost_dev_cleanup(dev, true); 543 vhost_dev_cleanup(dev);
548 544
549 /* Restore memory to default empty mapping. */ 545 /* Restore memory to default empty mapping. */
550 INIT_LIST_HEAD(&umem->umem_list); 546 INIT_LIST_HEAD(&umem->umem_list);
@@ -611,31 +607,23 @@ static void vhost_clear_msg(struct vhost_dev *dev)
611 spin_unlock(&dev->iotlb_lock); 607 spin_unlock(&dev->iotlb_lock);
612} 608}
613 609
614/* Caller should have device mutex if and only if locked is set */ 610void vhost_dev_cleanup(struct vhost_dev *dev)
615void vhost_dev_cleanup(struct vhost_dev *dev, bool locked)
616{ 611{
617 int i; 612 int i;
618 613
619 for (i = 0; i < dev->nvqs; ++i) { 614 for (i = 0; i < dev->nvqs; ++i) {
620 if (dev->vqs[i]->error_ctx) 615 if (dev->vqs[i]->error_ctx)
621 eventfd_ctx_put(dev->vqs[i]->error_ctx); 616 eventfd_ctx_put(dev->vqs[i]->error_ctx);
622 if (dev->vqs[i]->error)
623 fput(dev->vqs[i]->error);
624 if (dev->vqs[i]->kick) 617 if (dev->vqs[i]->kick)
625 fput(dev->vqs[i]->kick); 618 fput(dev->vqs[i]->kick);
626 if (dev->vqs[i]->call_ctx) 619 if (dev->vqs[i]->call_ctx)
627 eventfd_ctx_put(dev->vqs[i]->call_ctx); 620 eventfd_ctx_put(dev->vqs[i]->call_ctx);
628 if (dev->vqs[i]->call)
629 fput(dev->vqs[i]->call);
630 vhost_vq_reset(dev, dev->vqs[i]); 621 vhost_vq_reset(dev, dev->vqs[i]);
631 } 622 }
632 vhost_dev_free_iovecs(dev); 623 vhost_dev_free_iovecs(dev);
633 if (dev->log_ctx) 624 if (dev->log_ctx)
634 eventfd_ctx_put(dev->log_ctx); 625 eventfd_ctx_put(dev->log_ctx);
635 dev->log_ctx = NULL; 626 dev->log_ctx = NULL;
636 if (dev->log_file)
637 fput(dev->log_file);
638 dev->log_file = NULL;
639 /* No one will access memory at this point */ 627 /* No one will access memory at this point */
640 vhost_umem_clean(dev->umem); 628 vhost_umem_clean(dev->umem);
641 dev->umem = NULL; 629 dev->umem = NULL;
@@ -1492,38 +1480,24 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
1492 r = -EFAULT; 1480 r = -EFAULT;
1493 break; 1481 break;
1494 } 1482 }
1495 eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); 1483 ctx = f.fd == -1 ? NULL : eventfd_ctx_fdget(f.fd);
1496 if (IS_ERR(eventfp)) { 1484 if (IS_ERR(ctx)) {
1497 r = PTR_ERR(eventfp); 1485 r = PTR_ERR(ctx);
1498 break; 1486 break;
1499 } 1487 }
1500 if (eventfp != vq->call) { 1488 swap(ctx, vq->call_ctx);
1501 filep = vq->call;
1502 ctx = vq->call_ctx;
1503 vq->call = eventfp;
1504 vq->call_ctx = eventfp ?
1505 eventfd_ctx_fileget(eventfp) : NULL;
1506 } else
1507 filep = eventfp;
1508 break; 1489 break;
1509 case VHOST_SET_VRING_ERR: 1490 case VHOST_SET_VRING_ERR:
1510 if (copy_from_user(&f, argp, sizeof f)) { 1491 if (copy_from_user(&f, argp, sizeof f)) {
1511 r = -EFAULT; 1492 r = -EFAULT;
1512 break; 1493 break;
1513 } 1494 }
1514 eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); 1495 ctx = f.fd == -1 ? NULL : eventfd_ctx_fdget(f.fd);
1515 if (IS_ERR(eventfp)) { 1496 if (IS_ERR(ctx)) {
1516 r = PTR_ERR(eventfp); 1497 r = PTR_ERR(ctx);
1517 break; 1498 break;
1518 } 1499 }
1519 if (eventfp != vq->error) { 1500 swap(ctx, vq->error_ctx);
1520 filep = vq->error;
1521 vq->error = eventfp;
1522 ctx = vq->error_ctx;
1523 vq->error_ctx = eventfp ?
1524 eventfd_ctx_fileget(eventfp) : NULL;
1525 } else
1526 filep = eventfp;
1527 break; 1501 break;
1528 case VHOST_SET_VRING_ENDIAN: 1502 case VHOST_SET_VRING_ENDIAN:
1529 r = vhost_set_vring_endian(vq, argp); 1503 r = vhost_set_vring_endian(vq, argp);
@@ -1551,7 +1525,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
1551 if (pollstop && vq->handle_kick) 1525 if (pollstop && vq->handle_kick)
1552 vhost_poll_stop(&vq->poll); 1526 vhost_poll_stop(&vq->poll);
1553 1527
1554 if (ctx) 1528 if (!IS_ERR_OR_NULL(ctx))
1555 eventfd_ctx_put(ctx); 1529 eventfd_ctx_put(ctx);
1556 if (filep) 1530 if (filep)
1557 fput(filep); 1531 fput(filep);
@@ -1594,8 +1568,7 @@ EXPORT_SYMBOL_GPL(vhost_init_device_iotlb);
1594/* Caller must have device mutex */ 1568/* Caller must have device mutex */
1595long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) 1569long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
1596{ 1570{
1597 struct file *eventfp, *filep = NULL; 1571 struct eventfd_ctx *ctx;
1598 struct eventfd_ctx *ctx = NULL;
1599 u64 p; 1572 u64 p;
1600 long r; 1573 long r;
1601 int i, fd; 1574 int i, fd;
@@ -1641,19 +1614,12 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
1641 r = get_user(fd, (int __user *)argp); 1614 r = get_user(fd, (int __user *)argp);
1642 if (r < 0) 1615 if (r < 0)
1643 break; 1616 break;
1644 eventfp = fd == -1 ? NULL : eventfd_fget(fd); 1617 ctx = fd == -1 ? NULL : eventfd_ctx_fdget(fd);
1645 if (IS_ERR(eventfp)) { 1618 if (IS_ERR(ctx)) {
1646 r = PTR_ERR(eventfp); 1619 r = PTR_ERR(ctx);
1647 break; 1620 break;
1648 } 1621 }
1649 if (eventfp != d->log_file) { 1622 swap(ctx, d->log_ctx);
1650 filep = d->log_file;
1651 d->log_file = eventfp;
1652 ctx = d->log_ctx;
1653 d->log_ctx = eventfp ?
1654 eventfd_ctx_fileget(eventfp) : NULL;
1655 } else
1656 filep = eventfp;
1657 for (i = 0; i < d->nvqs; ++i) { 1623 for (i = 0; i < d->nvqs; ++i) {
1658 mutex_lock(&d->vqs[i]->mutex); 1624 mutex_lock(&d->vqs[i]->mutex);
1659 d->vqs[i]->log_ctx = d->log_ctx; 1625 d->vqs[i]->log_ctx = d->log_ctx;
@@ -1661,8 +1627,6 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
1661 } 1627 }
1662 if (ctx) 1628 if (ctx)
1663 eventfd_ctx_put(ctx); 1629 eventfd_ctx_put(ctx);
1664 if (filep)
1665 fput(filep);
1666 break; 1630 break;
1667 default: 1631 default:
1668 r = -ENOIOCTLCMD; 1632 r = -ENOIOCTLCMD;
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 7876a3d7d1b3..ac4b6056f19a 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -20,10 +20,6 @@ typedef void (*vhost_work_fn_t)(struct vhost_work *work);
20struct vhost_work { 20struct vhost_work {
21 struct llist_node node; 21 struct llist_node node;
22 vhost_work_fn_t fn; 22 vhost_work_fn_t fn;
23 wait_queue_head_t done;
24 int flushing;
25 unsigned queue_seq;
26 unsigned done_seq;
27 unsigned long flags; 23 unsigned long flags;
28}; 24};
29 25
@@ -96,8 +92,6 @@ struct vhost_virtqueue {
96 struct vring_used __user *used; 92 struct vring_used __user *used;
97 const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS]; 93 const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS];
98 struct file *kick; 94 struct file *kick;
99 struct file *call;
100 struct file *error;
101 struct eventfd_ctx *call_ctx; 95 struct eventfd_ctx *call_ctx;
102 struct eventfd_ctx *error_ctx; 96 struct eventfd_ctx *error_ctx;
103 struct eventfd_ctx *log_ctx; 97 struct eventfd_ctx *log_ctx;
@@ -163,7 +157,6 @@ struct vhost_dev {
163 struct mutex mutex; 157 struct mutex mutex;
164 struct vhost_virtqueue **vqs; 158 struct vhost_virtqueue **vqs;
165 int nvqs; 159 int nvqs;
166 struct file *log_file;
167 struct eventfd_ctx *log_ctx; 160 struct eventfd_ctx *log_ctx;
168 struct llist_head work_list; 161 struct llist_head work_list;
169 struct task_struct *worker; 162 struct task_struct *worker;
@@ -181,7 +174,7 @@ bool vhost_dev_has_owner(struct vhost_dev *dev);
181long vhost_dev_check_owner(struct vhost_dev *); 174long vhost_dev_check_owner(struct vhost_dev *);
182struct vhost_umem *vhost_dev_reset_owner_prepare(void); 175struct vhost_umem *vhost_dev_reset_owner_prepare(void);
183void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_umem *); 176void vhost_dev_reset_owner(struct vhost_dev *, struct vhost_umem *);
184void vhost_dev_cleanup(struct vhost_dev *, bool locked); 177void vhost_dev_cleanup(struct vhost_dev *);
185void vhost_dev_stop(struct vhost_dev *); 178void vhost_dev_stop(struct vhost_dev *);
186long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp); 179long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
187long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp); 180long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp);
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 5a5e981bd8e4..0d14e2ff19f1 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -599,7 +599,7 @@ static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
599 } 599 }
600 spin_unlock_bh(&vsock->send_pkt_list_lock); 600 spin_unlock_bh(&vsock->send_pkt_list_lock);
601 601
602 vhost_dev_cleanup(&vsock->dev, false); 602 vhost_dev_cleanup(&vsock->dev);
603 kfree(vsock->dev.vqs); 603 kfree(vsock->dev.vqs);
604 vhost_vsock_free(vsock); 604 vhost_vsock_free(vsock);
605 return 0; 605 return 0;