aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/s390/virtio/virtio_ccw.c52
-rw-r--r--drivers/vhost/scsi.c1
-rw-r--r--drivers/virtio/virtio_ring.c28
-rw-r--r--include/linux/virtio.h17
-rw-r--r--tools/virtio/ringtest/ptr_ring.c1
5 files changed, 40 insertions, 59 deletions
diff --git a/drivers/s390/virtio/virtio_ccw.c b/drivers/s390/virtio/virtio_ccw.c
index 991420caa4f2..6a3076881321 100644
--- a/drivers/s390/virtio/virtio_ccw.c
+++ b/drivers/s390/virtio/virtio_ccw.c
@@ -66,6 +66,7 @@ struct virtio_ccw_device {
66 bool device_lost; 66 bool device_lost;
67 unsigned int config_ready; 67 unsigned int config_ready;
68 void *airq_info; 68 void *airq_info;
69 u64 dma_mask;
69}; 70};
70 71
71struct vq_info_block_legacy { 72struct vq_info_block_legacy {
@@ -108,7 +109,6 @@ struct virtio_rev_info {
108struct virtio_ccw_vq_info { 109struct virtio_ccw_vq_info {
109 struct virtqueue *vq; 110 struct virtqueue *vq;
110 int num; 111 int num;
111 void *queue;
112 union { 112 union {
113 struct vq_info_block s; 113 struct vq_info_block s;
114 struct vq_info_block_legacy l; 114 struct vq_info_block_legacy l;
@@ -423,7 +423,6 @@ static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
423 struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev); 423 struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
424 struct virtio_ccw_vq_info *info = vq->priv; 424 struct virtio_ccw_vq_info *info = vq->priv;
425 unsigned long flags; 425 unsigned long flags;
426 unsigned long size;
427 int ret; 426 int ret;
428 unsigned int index = vq->index; 427 unsigned int index = vq->index;
429 428
@@ -461,8 +460,6 @@ static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
461 ret, index); 460 ret, index);
462 461
463 vring_del_virtqueue(vq); 462 vring_del_virtqueue(vq);
464 size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
465 free_pages_exact(info->queue, size);
466 kfree(info->info_block); 463 kfree(info->info_block);
467 kfree(info); 464 kfree(info);
468} 465}
@@ -494,8 +491,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
494 int err; 491 int err;
495 struct virtqueue *vq = NULL; 492 struct virtqueue *vq = NULL;
496 struct virtio_ccw_vq_info *info; 493 struct virtio_ccw_vq_info *info;
497 unsigned long size = 0; /* silence the compiler */ 494 u64 queue;
498 unsigned long flags; 495 unsigned long flags;
496 bool may_reduce;
499 497
500 /* Allocate queue. */ 498 /* Allocate queue. */
501 info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL); 499 info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
@@ -516,37 +514,34 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
516 err = info->num; 514 err = info->num;
517 goto out_err; 515 goto out_err;
518 } 516 }
519 size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN)); 517 may_reduce = vcdev->revision > 0;
520 info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); 518 vq = vring_create_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN,
521 if (info->queue == NULL) { 519 vdev, true, may_reduce, ctx,
522 dev_warn(&vcdev->cdev->dev, "no queue\n"); 520 virtio_ccw_kvm_notify, callback, name);
523 err = -ENOMEM;
524 goto out_err;
525 }
526 521
527 vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
528 true, ctx, info->queue, virtio_ccw_kvm_notify,
529 callback, name);
530 if (!vq) { 522 if (!vq) {
531 /* For now, we fail if we can't get the requested size. */ 523 /* For now, we fail if we can't get the requested size. */
532 dev_warn(&vcdev->cdev->dev, "no vq\n"); 524 dev_warn(&vcdev->cdev->dev, "no vq\n");
533 err = -ENOMEM; 525 err = -ENOMEM;
534 goto out_err; 526 goto out_err;
535 } 527 }
528 /* it may have been reduced */
529 info->num = virtqueue_get_vring_size(vq);
536 530
537 /* Register it with the host. */ 531 /* Register it with the host. */
532 queue = virtqueue_get_desc_addr(vq);
538 if (vcdev->revision == 0) { 533 if (vcdev->revision == 0) {
539 info->info_block->l.queue = (__u64)info->queue; 534 info->info_block->l.queue = queue;
540 info->info_block->l.align = KVM_VIRTIO_CCW_RING_ALIGN; 535 info->info_block->l.align = KVM_VIRTIO_CCW_RING_ALIGN;
541 info->info_block->l.index = i; 536 info->info_block->l.index = i;
542 info->info_block->l.num = info->num; 537 info->info_block->l.num = info->num;
543 ccw->count = sizeof(info->info_block->l); 538 ccw->count = sizeof(info->info_block->l);
544 } else { 539 } else {
545 info->info_block->s.desc = (__u64)info->queue; 540 info->info_block->s.desc = queue;
546 info->info_block->s.index = i; 541 info->info_block->s.index = i;
547 info->info_block->s.num = info->num; 542 info->info_block->s.num = info->num;
548 info->info_block->s.avail = (__u64)virtqueue_get_avail(vq); 543 info->info_block->s.avail = (__u64)virtqueue_get_avail_addr(vq);
549 info->info_block->s.used = (__u64)virtqueue_get_used(vq); 544 info->info_block->s.used = (__u64)virtqueue_get_used_addr(vq);
550 ccw->count = sizeof(info->info_block->s); 545 ccw->count = sizeof(info->info_block->s);
551 } 546 }
552 ccw->cmd_code = CCW_CMD_SET_VQ; 547 ccw->cmd_code = CCW_CMD_SET_VQ;
@@ -572,8 +567,6 @@ out_err:
572 if (vq) 567 if (vq)
573 vring_del_virtqueue(vq); 568 vring_del_virtqueue(vq);
574 if (info) { 569 if (info) {
575 if (info->queue)
576 free_pages_exact(info->queue, size);
577 kfree(info->info_block); 570 kfree(info->info_block);
578 } 571 }
579 kfree(info); 572 kfree(info);
@@ -780,12 +773,8 @@ out_free:
780static void ccw_transport_features(struct virtio_device *vdev) 773static void ccw_transport_features(struct virtio_device *vdev)
781{ 774{
782 /* 775 /*
783 * Packed ring isn't enabled on virtio_ccw for now, 776 * Currently nothing to do here.
784 * because virtio_ccw uses some legacy accessors,
785 * e.g. virtqueue_get_avail() and virtqueue_get_used()
786 * which aren't available in packed ring currently.
787 */ 777 */
788 __virtio_clear_bit(vdev, VIRTIO_F_RING_PACKED);
789} 778}
790 779
791static int virtio_ccw_finalize_features(struct virtio_device *vdev) 780static int virtio_ccw_finalize_features(struct virtio_device *vdev)
@@ -1266,6 +1255,16 @@ static int virtio_ccw_online(struct ccw_device *cdev)
1266 ret = -ENOMEM; 1255 ret = -ENOMEM;
1267 goto out_free; 1256 goto out_free;
1268 } 1257 }
1258
1259 vcdev->vdev.dev.parent = &cdev->dev;
1260 cdev->dev.dma_mask = &vcdev->dma_mask;
1261 /* we are fine with common virtio infrastructure using 64 bit DMA */
1262 ret = dma_set_mask_and_coherent(&cdev->dev, DMA_BIT_MASK(64));
1263 if (ret) {
1264 dev_warn(&cdev->dev, "Failed to enable 64-bit DMA.\n");
1265 goto out_free;
1266 }
1267
1269 vcdev->config_block = kzalloc(sizeof(*vcdev->config_block), 1268 vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
1270 GFP_DMA | GFP_KERNEL); 1269 GFP_DMA | GFP_KERNEL);
1271 if (!vcdev->config_block) { 1270 if (!vcdev->config_block) {
@@ -1280,7 +1279,6 @@ static int virtio_ccw_online(struct ccw_device *cdev)
1280 1279
1281 vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */ 1280 vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */
1282 1281
1283 vcdev->vdev.dev.parent = &cdev->dev;
1284 vcdev->vdev.dev.release = virtio_ccw_release_dev; 1282 vcdev->vdev.dev.release = virtio_ccw_release_dev;
1285 vcdev->vdev.config = &virtio_ccw_config_ops; 1283 vcdev->vdev.config = &virtio_ccw_config_ops;
1286 vcdev->cdev = cdev; 1284 vcdev->cdev = cdev;
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 618fb6461017..c090d177bd75 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1443,7 +1443,6 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1443 tpg->tv_tpg_vhost_count++; 1443 tpg->tv_tpg_vhost_count++;
1444 tpg->vhost_scsi = vs; 1444 tpg->vhost_scsi = vs;
1445 vs_tpg[tpg->tport_tpgt] = tpg; 1445 vs_tpg[tpg->tport_tpgt] = tpg;
1446 smp_mb__after_atomic();
1447 match = true; 1446 match = true;
1448 } 1447 }
1449 mutex_unlock(&tpg->tv_tpg_mutex); 1448 mutex_unlock(&tpg->tv_tpg_mutex);
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 5df92c308286..0a7b3ce3fb75 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1004,6 +1004,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
1004 1004
1005 if (unlikely(vq->vq.num_free < 1)) { 1005 if (unlikely(vq->vq.num_free < 1)) {
1006 pr_debug("Can't add buf len 1 - avail = 0\n"); 1006 pr_debug("Can't add buf len 1 - avail = 0\n");
1007 kfree(desc);
1007 END_USE(vq); 1008 END_USE(vq);
1008 return -ENOSPC; 1009 return -ENOSPC;
1009 } 1010 }
@@ -1718,10 +1719,10 @@ static inline int virtqueue_add(struct virtqueue *_vq,
1718 1719
1719/** 1720/**
1720 * virtqueue_add_sgs - expose buffers to other end 1721 * virtqueue_add_sgs - expose buffers to other end
1721 * @vq: the struct virtqueue we're talking about. 1722 * @_vq: the struct virtqueue we're talking about.
1722 * @sgs: array of terminated scatterlists. 1723 * @sgs: array of terminated scatterlists.
1723 * @out_num: the number of scatterlists readable by other side 1724 * @out_sgs: the number of scatterlists readable by other side
1724 * @in_num: the number of scatterlists which are writable (after readable ones) 1725 * @in_sgs: the number of scatterlists which are writable (after readable ones)
1725 * @data: the token identifying the buffer. 1726 * @data: the token identifying the buffer.
1726 * @gfp: how to do memory allocations (if necessary). 1727 * @gfp: how to do memory allocations (if necessary).
1727 * 1728 *
@@ -1821,7 +1822,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);
1821 1822
1822/** 1823/**
1823 * virtqueue_kick_prepare - first half of split virtqueue_kick call. 1824 * virtqueue_kick_prepare - first half of split virtqueue_kick call.
1824 * @vq: the struct virtqueue 1825 * @_vq: the struct virtqueue
1825 * 1826 *
1826 * Instead of virtqueue_kick(), you can do: 1827 * Instead of virtqueue_kick(), you can do:
1827 * if (virtqueue_kick_prepare(vq)) 1828 * if (virtqueue_kick_prepare(vq))
@@ -1841,7 +1842,7 @@ EXPORT_SYMBOL_GPL(virtqueue_kick_prepare);
1841 1842
1842/** 1843/**
1843 * virtqueue_notify - second half of split virtqueue_kick call. 1844 * virtqueue_notify - second half of split virtqueue_kick call.
1844 * @vq: the struct virtqueue 1845 * @_vq: the struct virtqueue
1845 * 1846 *
1846 * This does not need to be serialized. 1847 * This does not need to be serialized.
1847 * 1848 *
@@ -1885,8 +1886,9 @@ EXPORT_SYMBOL_GPL(virtqueue_kick);
1885 1886
1886/** 1887/**
1887 * virtqueue_get_buf - get the next used buffer 1888 * virtqueue_get_buf - get the next used buffer
1888 * @vq: the struct virtqueue we're talking about. 1889 * @_vq: the struct virtqueue we're talking about.
1889 * @len: the length written into the buffer 1890 * @len: the length written into the buffer
1891 * @ctx: extra context for the token
1890 * 1892 *
1891 * If the device wrote data into the buffer, @len will be set to the 1893 * If the device wrote data into the buffer, @len will be set to the
1892 * amount written. This means you don't need to clear the buffer 1894 * amount written. This means you don't need to clear the buffer
@@ -1916,7 +1918,7 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
1916EXPORT_SYMBOL_GPL(virtqueue_get_buf); 1918EXPORT_SYMBOL_GPL(virtqueue_get_buf);
1917/** 1919/**
1918 * virtqueue_disable_cb - disable callbacks 1920 * virtqueue_disable_cb - disable callbacks
1919 * @vq: the struct virtqueue we're talking about. 1921 * @_vq: the struct virtqueue we're talking about.
1920 * 1922 *
1921 * Note that this is not necessarily synchronous, hence unreliable and only 1923 * Note that this is not necessarily synchronous, hence unreliable and only
1922 * useful as an optimization. 1924 * useful as an optimization.
@@ -1936,7 +1938,7 @@ EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
1936 1938
1937/** 1939/**
1938 * virtqueue_enable_cb_prepare - restart callbacks after disable_cb 1940 * virtqueue_enable_cb_prepare - restart callbacks after disable_cb
1939 * @vq: the struct virtqueue we're talking about. 1941 * @_vq: the struct virtqueue we're talking about.
1940 * 1942 *
1941 * This re-enables callbacks; it returns current queue state 1943 * This re-enables callbacks; it returns current queue state
1942 * in an opaque unsigned value. This value should be later tested by 1944 * in an opaque unsigned value. This value should be later tested by
@@ -1957,7 +1959,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_prepare);
1957 1959
1958/** 1960/**
1959 * virtqueue_poll - query pending used buffers 1961 * virtqueue_poll - query pending used buffers
1960 * @vq: the struct virtqueue we're talking about. 1962 * @_vq: the struct virtqueue we're talking about.
1961 * @last_used_idx: virtqueue state (from call to virtqueue_enable_cb_prepare). 1963 * @last_used_idx: virtqueue state (from call to virtqueue_enable_cb_prepare).
1962 * 1964 *
1963 * Returns "true" if there are pending used buffers in the queue. 1965 * Returns "true" if there are pending used buffers in the queue.
@@ -1976,7 +1978,7 @@ EXPORT_SYMBOL_GPL(virtqueue_poll);
1976 1978
1977/** 1979/**
1978 * virtqueue_enable_cb - restart callbacks after disable_cb. 1980 * virtqueue_enable_cb - restart callbacks after disable_cb.
1979 * @vq: the struct virtqueue we're talking about. 1981 * @_vq: the struct virtqueue we're talking about.
1980 * 1982 *
1981 * This re-enables callbacks; it returns "false" if there are pending 1983 * This re-enables callbacks; it returns "false" if there are pending
1982 * buffers in the queue, to detect a possible race between the driver 1984 * buffers in the queue, to detect a possible race between the driver
@@ -1995,7 +1997,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
1995 1997
1996/** 1998/**
1997 * virtqueue_enable_cb_delayed - restart callbacks after disable_cb. 1999 * virtqueue_enable_cb_delayed - restart callbacks after disable_cb.
1998 * @vq: the struct virtqueue we're talking about. 2000 * @_vq: the struct virtqueue we're talking about.
1999 * 2001 *
2000 * This re-enables callbacks but hints to the other side to delay 2002 * This re-enables callbacks but hints to the other side to delay
2001 * interrupts until most of the available buffers have been processed; 2003 * interrupts until most of the available buffers have been processed;
@@ -2017,7 +2019,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);
2017 2019
2018/** 2020/**
2019 * virtqueue_detach_unused_buf - detach first unused buffer 2021 * virtqueue_detach_unused_buf - detach first unused buffer
2020 * @vq: the struct virtqueue we're talking about. 2022 * @_vq: the struct virtqueue we're talking about.
2021 * 2023 *
2022 * Returns NULL or the "data" token handed to virtqueue_add_*(). 2024 * Returns NULL or the "data" token handed to virtqueue_add_*().
2023 * This is not valid on an active queue; it is useful only for device 2025 * This is not valid on an active queue; it is useful only for device
@@ -2249,7 +2251,7 @@ EXPORT_SYMBOL_GPL(vring_transport_features);
2249 2251
2250/** 2252/**
2251 * virtqueue_get_vring_size - return the size of the virtqueue's vring 2253 * virtqueue_get_vring_size - return the size of the virtqueue's vring
2252 * @vq: the struct virtqueue containing the vring of interest. 2254 * @_vq: the struct virtqueue containing the vring of interest.
2253 * 2255 *
2254 * Returns the size of the vring. This is mainly used for boasting to 2256 * Returns the size of the vring. This is mainly used for boasting to
2255 * userspace. Unlike other operations, this need not be serialized. 2257 * userspace. Unlike other operations, this need not be serialized.
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 673fe3ef3607..15f906e4a748 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -90,23 +90,6 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);
90dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq); 90dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq);
91dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq); 91dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq);
92 92
93/*
94 * Legacy accessors -- in almost all cases, these are the wrong functions
95 * to use.
96 */
97static inline void *virtqueue_get_desc(struct virtqueue *vq)
98{
99 return virtqueue_get_vring(vq)->desc;
100}
101static inline void *virtqueue_get_avail(struct virtqueue *vq)
102{
103 return virtqueue_get_vring(vq)->avail;
104}
105static inline void *virtqueue_get_used(struct virtqueue *vq)
106{
107 return virtqueue_get_vring(vq)->used;
108}
109
110/** 93/**
111 * virtio_device - representation of a device using virtio 94 * virtio_device - representation of a device using virtio
112 * @index: unique position on the virtio bus 95 * @index: unique position on the virtio bus
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c
index 2d566fbd236b..c9b26335f891 100644
--- a/tools/virtio/ringtest/ptr_ring.c
+++ b/tools/virtio/ringtest/ptr_ring.c
@@ -18,7 +18,6 @@
18#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a)) 18#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
19#define SIZE_MAX (~(size_t)0) 19#define SIZE_MAX (~(size_t)0)
20#define KMALLOC_MAX_SIZE SIZE_MAX 20#define KMALLOC_MAX_SIZE SIZE_MAX
21#define BUG_ON(x) assert(x)
22 21
23typedef pthread_spinlock_t spinlock_t; 22typedef pthread_spinlock_t spinlock_t;
24 23