Skip to content

Commit 64056a9

Browse files
committed
Merge tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull virtio updates from Rusty Russell: "Nothing exciting: virtio-blk users might see a bit of a boost from the doubling of the default queue length though" * tag 'virtio-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: virtio-blk: base queue-depth on virtqueue ringsize or module param Revert a02bbb1: MAINTAINERS: add virtio-dev ML for virtio virtio: fail adding buffer on broken queues. virtio-rng: don't crash if virtqueue is broken. virtio_balloon: don't crash if virtqueue is broken. virtio_blk: don't crash, report error if virtqueue is broken. virtio_net: don't crash if virtqueue is broken. virtio_balloon: don't softlockup on huge balloon changes. virtio: Use pci_enable_msix_exact() instead of pci_enable_msix() MAINTAINERS: virtio-dev is subscribers only tools/virtio: add a missing ) tools/virtio: fix missing kmemleak_ignore symbol tools/virtio: update internal copies of headers
2 parents 7474043 + fc4324b commit 64056a9

10 files changed

Lines changed: 45 additions & 24 deletions

File tree

‎MAINTAINERS‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9432,7 +9432,6 @@ F: include/media/videobuf2-*
94329432

94339433
VIRTIO CONSOLE DRIVER
94349434
M: Amit Shah <amit.shah@redhat.com>
9435-
L: virtio-dev@lists.oasis-open.org
94369435
L: virtualization@lists.linux-foundation.org
94379436
S: Maintained
94389437
F: drivers/char/virtio_console.c
@@ -9442,7 +9441,6 @@ F: include/uapi/linux/virtio_console.h
94429441
VIRTIO CORE, NET AND BLOCK DRIVERS
94439442
M: Rusty Russell <rusty@rustcorp.com.au>
94449443
M: "Michael S. Tsirkin" <mst@redhat.com>
9445-
L: virtio-dev@lists.oasis-open.org
94469444
L: virtualization@lists.linux-foundation.org
94479445
S: Maintained
94489446
F: drivers/virtio/
@@ -9455,7 +9453,6 @@ F: include/uapi/linux/virtio_*.h
94559453
VIRTIO HOST (VHOST)
94569454
M: "Michael S. Tsirkin" <mst@redhat.com>
94579455
L: kvm@vger.kernel.org
9458-
L: virtio-dev@lists.oasis-open.org
94599456
L: virtualization@lists.linux-foundation.org
94609457
L: netdev@vger.kernel.org
94619458
S: Maintained

‎drivers/block/virtio_blk.c‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
158158
unsigned long flags;
159159
unsigned int num;
160160
const bool last = (req->cmd_flags & REQ_END) != 0;
161+
int err;
161162

162163
BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
163164

@@ -198,11 +199,16 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
198199
}
199200

200201
spin_lock_irqsave(&vblk->vq_lock, flags);
201-
if (__virtblk_add_req(vblk->vq, vbr, vbr->sg, num) < 0) {
202+
err = __virtblk_add_req(vblk->vq, vbr, vbr->sg, num);
203+
if (err) {
202204
virtqueue_kick(vblk->vq);
203205
spin_unlock_irqrestore(&vblk->vq_lock, flags);
204206
blk_mq_stop_hw_queue(hctx);
205-
return BLK_MQ_RQ_QUEUE_BUSY;
207+
/* Out of mem doesn't actually happen, since we fall back
208+
* to direct descriptors */
209+
if (err == -ENOMEM || err == -ENOSPC)
210+
return BLK_MQ_RQ_QUEUE_BUSY;
211+
return BLK_MQ_RQ_QUEUE_ERROR;
206212
}
207213

208214
if (last)
@@ -485,10 +491,11 @@ static struct blk_mq_ops virtio_mq_ops = {
485491
static struct blk_mq_reg virtio_mq_reg = {
486492
.ops = &virtio_mq_ops,
487493
.nr_hw_queues = 1,
488-
.queue_depth = 64,
494+
.queue_depth = 0, /* Set in virtblk_probe */
489495
.numa_node = NUMA_NO_NODE,
490496
.flags = BLK_MQ_F_SHOULD_MERGE,
491497
};
498+
module_param_named(queue_depth, virtio_mq_reg.queue_depth, uint, 0444);
492499

493500
static int virtblk_init_vbr(void *data, struct blk_mq_hw_ctx *hctx,
494501
struct request *rq, unsigned int nr)
@@ -553,6 +560,13 @@ static int virtblk_probe(struct virtio_device *vdev)
553560
goto out_free_vq;
554561
}
555562

563+
/* Default queue sizing is to fill the ring. */
564+
if (!virtio_mq_reg.queue_depth) {
565+
virtio_mq_reg.queue_depth = vblk->vq->num_free;
566+
/* ... but without indirect descs, we use 2 descs per req */
567+
if (!virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC))
568+
virtio_mq_reg.queue_depth /= 2;
569+
}
556570
virtio_mq_reg.cmd_size =
557571
sizeof(struct virtblk_req) +
558572
sizeof(struct scatterlist) * sg_elems;

‎drivers/char/hw_random/virtio-rng.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ static void register_buffer(u8 *buf, size_t size)
4747
sg_init_one(&sg, buf, size);
4848

4949
/* There should always be room for one buffer. */
50-
if (virtqueue_add_inbuf(vq, &sg, 1, buf, GFP_KERNEL) < 0)
51-
BUG();
50+
virtqueue_add_inbuf(vq, &sg, 1, buf, GFP_KERNEL);
5251

5352
virtqueue_kick(vq);
5453
}

‎drivers/net/virtio_net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
938938
sgs[out_num] = &stat;
939939

940940
BUG_ON(out_num + 1 > ARRAY_SIZE(sgs));
941-
BUG_ON(virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC) < 0);
941+
virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC);
942942

943943
if (unlikely(!virtqueue_kick(vi->cvq)))
944944
return status == VIRTIO_NET_OK;

‎drivers/virtio/virtio_balloon.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
108108
sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns);
109109

110110
/* We should always be able to add one buffer to an empty queue. */
111-
if (virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL) < 0)
112-
BUG();
111+
virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL);
113112
virtqueue_kick(vq);
114113

115114
/* When host has read buffer, this completes via balloon_ack */
@@ -258,8 +257,7 @@ static void stats_handle_request(struct virtio_balloon *vb)
258257
if (!virtqueue_get_buf(vq, &len))
259258
return;
260259
sg_init_one(&sg, vb->stats, sizeof(vb->stats));
261-
if (virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL) < 0)
262-
BUG();
260+
virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL);
263261
virtqueue_kick(vq);
264262
}
265263

@@ -310,6 +308,12 @@ static int balloon(void *_vballoon)
310308
else if (diff < 0)
311309
leak_balloon(vb, -diff);
312310
update_balloon_size(vb);
311+
312+
/*
313+
* For large balloon changes, we could spend a lot of time
314+
* and always have work to do. Be nice if preempt disabled.
315+
*/
316+
cond_resched();
313317
}
314318
return 0;
315319
}
@@ -338,7 +342,7 @@ static int init_vqs(struct virtio_balloon *vb)
338342

339343
/*
340344
* Prime this virtqueue with one buffer so the hypervisor can
341-
* use it to signal us later.
345+
* use it to signal us later (it can't be broken yet!).
342346
*/
343347
sg_init_one(&sg, vb->stats, sizeof vb->stats);
344348
if (virtqueue_add_outbuf(vb->stats_vq, &sg, 1, vb, GFP_KERNEL)

‎drivers/virtio/virtio_pci.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,8 @@ static int vp_request_msix_vectors(struct virtio_device *vdev, int nvectors,
333333
for (i = 0; i < nvectors; ++i)
334334
vp_dev->msix_entries[i].entry = i;
335335

336-
/* pci_enable_msix returns positive if we can't get this many. */
337-
err = pci_enable_msix(vp_dev->pci_dev, vp_dev->msix_entries, nvectors);
338-
if (err > 0)
339-
err = -ENOSPC;
336+
err = pci_enable_msix_exact(vp_dev->pci_dev,
337+
vp_dev->msix_entries, nvectors);
340338
if (err)
341339
goto error;
342340
vp_dev->msix_enabled = 1;

‎drivers/virtio/virtio_ring.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/slab.h>
2424
#include <linux/module.h>
2525
#include <linux/hrtimer.h>
26+
#include <linux/kmemleak.h>
2627

2728
#ifdef DEBUG
2829
/* For development, we want to crash whenever the ring is screwed. */
@@ -203,6 +204,11 @@ static inline int virtqueue_add(struct virtqueue *_vq,
203204

204205
BUG_ON(data == NULL);
205206

207+
if (unlikely(vq->broken)) {
208+
END_USE(vq);
209+
return -EIO;
210+
}
211+
206212
#ifdef DEBUG
207213
{
208214
ktime_t now = ktime_get();
@@ -309,7 +315,7 @@ static inline int virtqueue_add(struct virtqueue *_vq,
309315
* Caller must ensure we don't call this with other virtqueue operations
310316
* at the same time (except where noted).
311317
*
312-
* Returns zero or a negative error (ie. ENOSPC, ENOMEM).
318+
* Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
313319
*/
314320
int virtqueue_add_sgs(struct virtqueue *_vq,
315321
struct scatterlist *sgs[],
@@ -347,7 +353,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_sgs);
347353
* Caller must ensure we don't call this with other virtqueue operations
348354
* at the same time (except where noted).
349355
*
350-
* Returns zero or a negative error (ie. ENOSPC, ENOMEM).
356+
* Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
351357
*/
352358
int virtqueue_add_outbuf(struct virtqueue *vq,
353359
struct scatterlist sg[], unsigned int num,
@@ -369,7 +375,7 @@ EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
369375
* Caller must ensure we don't call this with other virtqueue operations
370376
* at the same time (except where noted).
371377
*
372-
* Returns zero or a negative error (ie. ENOSPC, ENOMEM).
378+
* Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
373379
*/
374380
int virtqueue_add_inbuf(struct virtqueue *vq,
375381
struct scatterlist sg[], unsigned int num,

‎tools/virtio/linux/kmemleak.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
static inline void kmemleak_ignore(const void *ptr)
2+
{
3+
}

‎tools/virtio/linux/virtio.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int virtqueue_add_inbuf(struct virtqueue *vq,
6363
void *data,
6464
gfp_t gfp);
6565

66-
void virtqueue_kick(struct virtqueue *vq);
66+
bool virtqueue_kick(struct virtqueue *vq);
6767

6868
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
6969

@@ -79,7 +79,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int index,
7979
struct virtio_device *vdev,
8080
bool weak_barriers,
8181
void *pages,
82-
void (*notify)(struct virtqueue *vq),
82+
bool (*notify)(struct virtqueue *vq),
8383
void (*callback)(struct virtqueue *vq),
8484
const char *name);
8585
void vring_del_virtqueue(struct virtqueue *vq);

‎tools/virtio/virtio_test.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq,
172172
GFP_ATOMIC);
173173
if (likely(r == 0)) {
174174
++started;
175-
if (unlikely(!virtqueue_kick(vq->vq))
175+
if (unlikely(!virtqueue_kick(vq->vq)))
176176
r = -1;
177177
}
178178
} else

0 commit comments

Comments
 (0)