Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 35c99ff

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: - enable packed ring support for s390 - several fixes * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio/s390: enable packed ring virtio/s390: DMA support for virtio-ccw virtio/s390: use vring_create_virtqueue virtio/virtio_ring: do some comment fixes vhost-scsi: remove incorrect memory barrier tools/virtio/ringtest: Remove bogus definition of BUG_ON() virtio_ring: Fix potential mem leak in virtqueue_add_indirect_packed
2 parents 8141377 + 050f4c4 commit 35c99ff

File tree

5 files changed

+40
-59
lines changed

5 files changed

+40
-59
lines changed

drivers/s390/virtio/virtio_ccw.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct virtio_ccw_device {
6666
bool device_lost;
6767
unsigned int config_ready;
6868
void *airq_info;
69+
u64 dma_mask;
6970
};
7071

7172
struct vq_info_block_legacy {
@@ -108,7 +109,6 @@ struct virtio_rev_info {
108109
struct virtio_ccw_vq_info {
109110
struct virtqueue *vq;
110111
int num;
111-
void *queue;
112112
union {
113113
struct vq_info_block s;
114114
struct vq_info_block_legacy l;
@@ -423,7 +423,6 @@ static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
423423
struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
424424
struct virtio_ccw_vq_info *info = vq->priv;
425425
unsigned long flags;
426-
unsigned long size;
427426
int ret;
428427
unsigned int index = vq->index;
429428

@@ -461,8 +460,6 @@ static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
461460
ret, index);
462461

463462
vring_del_virtqueue(vq);
464-
size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
465-
free_pages_exact(info->queue, size);
466463
kfree(info->info_block);
467464
kfree(info);
468465
}
@@ -494,8 +491,9 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
494491
int err;
495492
struct virtqueue *vq = NULL;
496493
struct virtio_ccw_vq_info *info;
497-
unsigned long size = 0; /* silence the compiler */
494+
u64 queue;
498495
unsigned long flags;
496+
bool may_reduce;
499497

500498
/* Allocate queue. */
501499
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,
516514
err = info->num;
517515
goto out_err;
518516
}
519-
size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
520-
info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
521-
if (info->queue == NULL) {
522-
dev_warn(&vcdev->cdev->dev, "no queue\n");
523-
err = -ENOMEM;
524-
goto out_err;
525-
}
517+
may_reduce = vcdev->revision > 0;
518+
vq = vring_create_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN,
519+
vdev, true, may_reduce, ctx,
520+
virtio_ccw_kvm_notify, callback, name);
526521

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);
530522
if (!vq) {
531523
/* For now, we fail if we can't get the requested size. */
532524
dev_warn(&vcdev->cdev->dev, "no vq\n");
533525
err = -ENOMEM;
534526
goto out_err;
535527
}
528+
/* it may have been reduced */
529+
info->num = virtqueue_get_vring_size(vq);
536530

537531
/* Register it with the host. */
532+
queue = virtqueue_get_desc_addr(vq);
538533
if (vcdev->revision == 0) {
539-
info->info_block->l.queue = (__u64)info->queue;
534+
info->info_block->l.queue = queue;
540535
info->info_block->l.align = KVM_VIRTIO_CCW_RING_ALIGN;
541536
info->info_block->l.index = i;
542537
info->info_block->l.num = info->num;
543538
ccw->count = sizeof(info->info_block->l);
544539
} else {
545-
info->info_block->s.desc = (__u64)info->queue;
540+
info->info_block->s.desc = queue;
546541
info->info_block->s.index = i;
547542
info->info_block->s.num = info->num;
548-
info->info_block->s.avail = (__u64)virtqueue_get_avail(vq);
549-
info->info_block->s.used = (__u64)virtqueue_get_used(vq);
543+
info->info_block->s.avail = (__u64)virtqueue_get_avail_addr(vq);
544+
info->info_block->s.used = (__u64)virtqueue_get_used_addr(vq);
550545
ccw->count = sizeof(info->info_block->s);
551546
}
552547
ccw->cmd_code = CCW_CMD_SET_VQ;
@@ -572,8 +567,6 @@ static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
572567
if (vq)
573568
vring_del_virtqueue(vq);
574569
if (info) {
575-
if (info->queue)
576-
free_pages_exact(info->queue, size);
577570
kfree(info->info_block);
578571
}
579572
kfree(info);
@@ -780,12 +773,8 @@ static u64 virtio_ccw_get_features(struct virtio_device *vdev)
780773
static void ccw_transport_features(struct virtio_device *vdev)
781774
{
782775
/*
783-
* Packed ring isn't enabled on virtio_ccw for now,
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.
776+
* Currently nothing to do here.
787777
*/
788-
__virtio_clear_bit(vdev, VIRTIO_F_RING_PACKED);
789778
}
790779

791780
static int virtio_ccw_finalize_features(struct virtio_device *vdev)
@@ -1266,6 +1255,16 @@ static int virtio_ccw_online(struct ccw_device *cdev)
12661255
ret = -ENOMEM;
12671256
goto out_free;
12681257
}
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+
12691268
vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
12701269
GFP_DMA | GFP_KERNEL);
12711270
if (!vcdev->config_block) {
@@ -1280,7 +1279,6 @@ static int virtio_ccw_online(struct ccw_device *cdev)
12801279

12811280
vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */
12821281

1283-
vcdev->vdev.dev.parent = &cdev->dev;
12841282
vcdev->vdev.dev.release = virtio_ccw_release_dev;
12851283
vcdev->vdev.config = &virtio_ccw_config_ops;
12861284
vcdev->cdev = cdev;

drivers/vhost/scsi.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,6 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
14431443
tpg->tv_tpg_vhost_count++;
14441444
tpg->vhost_scsi = vs;
14451445
vs_tpg[tpg->tport_tpgt] = tpg;
1446-
smp_mb__after_atomic();
14471446
match = true;
14481447
}
14491448
mutex_unlock(&tpg->tv_tpg_mutex);

drivers/virtio/virtio_ring.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
10041004

10051005
if (unlikely(vq->vq.num_free < 1)) {
10061006
pr_debug("Can't add buf len 1 - avail = 0\n");
1007+
kfree(desc);
10071008
END_USE(vq);
10081009
return -ENOSPC;
10091010
}
@@ -1718,10 +1719,10 @@ static inline int virtqueue_add(struct virtqueue *_vq,
17181719

17191720
/**
17201721
* 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.
17221723
* @sgs: array of terminated scatterlists.
1723-
* @out_num: the number of scatterlists readable by other side
1724-
* @in_num: the number of scatterlists which are writable (after readable ones)
1724+
* @out_sgs: the number of scatterlists readable by other side
1725+
* @in_sgs: the number of scatterlists which are writable (after readable ones)
17251726
* @data: the token identifying the buffer.
17261727
* @gfp: how to do memory allocations (if necessary).
17271728
*
@@ -1821,7 +1822,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);
18211822

18221823
/**
18231824
* virtqueue_kick_prepare - first half of split virtqueue_kick call.
1824-
* @vq: the struct virtqueue
1825+
* @_vq: the struct virtqueue
18251826
*
18261827
* Instead of virtqueue_kick(), you can do:
18271828
* if (virtqueue_kick_prepare(vq))
@@ -1841,7 +1842,7 @@ EXPORT_SYMBOL_GPL(virtqueue_kick_prepare);
18411842

18421843
/**
18431844
* virtqueue_notify - second half of split virtqueue_kick call.
1844-
* @vq: the struct virtqueue
1845+
* @_vq: the struct virtqueue
18451846
*
18461847
* This does not need to be serialized.
18471848
*
@@ -1885,8 +1886,9 @@ EXPORT_SYMBOL_GPL(virtqueue_kick);
18851886

18861887
/**
18871888
* 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.
18891890
* @len: the length written into the buffer
1891+
* @ctx: extra context for the token
18901892
*
18911893
* If the device wrote data into the buffer, @len will be set to the
18921894
* 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)
19161918
EXPORT_SYMBOL_GPL(virtqueue_get_buf);
19171919
/**
19181920
* virtqueue_disable_cb - disable callbacks
1919-
* @vq: the struct virtqueue we're talking about.
1921+
* @_vq: the struct virtqueue we're talking about.
19201922
*
19211923
* Note that this is not necessarily synchronous, hence unreliable and only
19221924
* useful as an optimization.
@@ -1936,7 +1938,7 @@ EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
19361938

19371939
/**
19381940
* 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.
19401942
*
19411943
* This re-enables callbacks; it returns current queue state
19421944
* in an opaque unsigned value. This value should be later tested by
@@ -1957,7 +1959,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_prepare);
19571959

19581960
/**
19591961
* virtqueue_poll - query pending used buffers
1960-
* @vq: the struct virtqueue we're talking about.
1962+
* @_vq: the struct virtqueue we're talking about.
19611963
* @last_used_idx: virtqueue state (from call to virtqueue_enable_cb_prepare).
19621964
*
19631965
* Returns "true" if there are pending used buffers in the queue.
@@ -1976,7 +1978,7 @@ EXPORT_SYMBOL_GPL(virtqueue_poll);
19761978

19771979
/**
19781980
* 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.
19801982
*
19811983
* This re-enables callbacks; it returns "false" if there are pending
19821984
* buffers in the queue, to detect a possible race between the driver
@@ -1995,7 +1997,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
19951997

19961998
/**
19971999
* 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.
19992001
*
20002002
* This re-enables callbacks but hints to the other side to delay
20012003
* interrupts until most of the available buffers have been processed;
@@ -2017,7 +2019,7 @@ EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);
20172019

20182020
/**
20192021
* 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.
20212023
*
20222024
* Returns NULL or the "data" token handed to virtqueue_add_*().
20232025
* This is not valid on an active queue; it is useful only for device
@@ -2249,7 +2251,7 @@ EXPORT_SYMBOL_GPL(vring_transport_features);
22492251

22502252
/**
22512253
* 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.
22532255
*
22542256
* Returns the size of the vring. This is mainly used for boasting to
22552257
* userspace. Unlike other operations, this need not be serialized.

include/linux/virtio.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,6 @@ dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);
9090
dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq);
9191
dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq);
9292

93-
/*
94-
* Legacy accessors -- in almost all cases, these are the wrong functions
95-
* to use.
96-
*/
97-
static inline void *virtqueue_get_desc(struct virtqueue *vq)
98-
{
99-
return virtqueue_get_vring(vq)->desc;
100-
}
101-
static inline void *virtqueue_get_avail(struct virtqueue *vq)
102-
{
103-
return virtqueue_get_vring(vq)->avail;
104-
}
105-
static inline void *virtqueue_get_used(struct virtqueue *vq)
106-
{
107-
return virtqueue_get_vring(vq)->used;
108-
}
109-
11093
/**
11194
* virtio_device - representation of a device using virtio
11295
* @index: unique position on the virtio bus

tools/virtio/ringtest/ptr_ring.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
1919
#define SIZE_MAX (~(size_t)0)
2020
#define KMALLOC_MAX_SIZE SIZE_MAX
21-
#define BUG_ON(x) assert(x)
2221

2322
typedef pthread_spinlock_t spinlock_t;
2423

0 commit comments

Comments
 (0)