Skip to content

Commit 54d7989

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull vhost updates from Michael Tsirkin: "virtio, vhost: optimizations, fixes Looks like a quiet cycle for vhost/virtio, just a couple of minor tweaks. Most notable is automatic interrupt affinity for blk and scsi. Hopefully other devices are not far behind" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio-console: avoid DMA from stack vhost: introduce O(1) vq metadata cache virtio_scsi: use virtio IRQ affinity virtio_blk: use virtio IRQ affinity blk-mq: provide a default queue mapping for virtio device virtio: provide a method to get the IRQ affinity mask for a virtqueue virtio: allow drivers to request IRQ affinity when creating VQs virtio_pci: simplify MSI-X setup virtio_pci: don't duplicate the msix_enable flag in struct pci_dev virtio_pci: use shared interrupts for virtqueues virtio_pci: remove struct virtio_pci_vq_info vhost: try avoiding avail index access when getting descriptor virtio_mmio: expose header to userspace
2 parents 0f221a3 + c4baad5 commit 54d7989

31 files changed

Lines changed: 456 additions & 454 deletions

‎block/Kconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,9 @@ config BLK_MQ_PCI
189189
depends on BLOCK && PCI
190190
default y
191191

192+
config BLK_MQ_VIRTIO
193+
bool
194+
depends on BLOCK && VIRTIO
195+
default y
196+
192197
source block/Kconfig.iosched

‎block/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ obj-$(CONFIG_BLOCK_COMPAT) += compat_ioctl.o
2525
obj-$(CONFIG_BLK_CMDLINE_PARSER) += cmdline-parser.o
2626
obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o blk-integrity.o t10-pi.o
2727
obj-$(CONFIG_BLK_MQ_PCI) += blk-mq-pci.o
28+
obj-$(CONFIG_BLK_MQ_VIRTIO) += blk-mq-virtio.o
2829
obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o
2930
obj-$(CONFIG_BLK_WBT) += blk-wbt.o
3031
obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o

‎block/blk-mq-virtio.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2016 Christoph Hellwig.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*/
13+
#include <linux/device.h>
14+
#include <linux/blk-mq.h>
15+
#include <linux/blk-mq-virtio.h>
16+
#include <linux/virtio_config.h>
17+
#include <linux/module.h>
18+
#include "blk-mq.h"
19+
20+
/**
21+
* blk_mq_virtio_map_queues - provide a default queue mapping for virtio device
22+
* @set: tagset to provide the mapping for
23+
* @vdev: virtio device associated with @set.
24+
* @first_vec: first interrupt vectors to use for queues (usually 0)
25+
*
26+
* This function assumes the virtio device @vdev has at least as many available
27+
* interrupt vetors as @set has queues. It will then queuery the vector
28+
* corresponding to each queue for it's affinity mask and built queue mapping
29+
* that maps a queue to the CPUs that have irq affinity for the corresponding
30+
* vector.
31+
*/
32+
int blk_mq_virtio_map_queues(struct blk_mq_tag_set *set,
33+
struct virtio_device *vdev, int first_vec)
34+
{
35+
const struct cpumask *mask;
36+
unsigned int queue, cpu;
37+
38+
if (!vdev->config->get_vq_affinity)
39+
goto fallback;
40+
41+
for (queue = 0; queue < set->nr_hw_queues; queue++) {
42+
mask = vdev->config->get_vq_affinity(vdev, first_vec + queue);
43+
if (!mask)
44+
goto fallback;
45+
46+
for_each_cpu(cpu, mask)
47+
set->mq_map[cpu] = queue;
48+
}
49+
50+
return 0;
51+
fallback:
52+
return blk_mq_map_queues(set);
53+
}
54+
EXPORT_SYMBOL_GPL(blk_mq_virtio_map_queues);

‎drivers/block/virtio_blk.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#include <linux/hdreg.h>
66
#include <linux/module.h>
77
#include <linux/mutex.h>
8+
#include <linux/interrupt.h>
89
#include <linux/virtio.h>
910
#include <linux/virtio_blk.h>
1011
#include <linux/scatterlist.h>
1112
#include <linux/string_helpers.h>
1213
#include <scsi/scsi_cmnd.h>
1314
#include <linux/idr.h>
1415
#include <linux/blk-mq.h>
16+
#include <linux/blk-mq-virtio.h>
1517
#include <linux/numa.h>
1618

1719
#define PART_BITS 4
@@ -426,6 +428,7 @@ static int init_vq(struct virtio_blk *vblk)
426428
struct virtqueue **vqs;
427429
unsigned short num_vqs;
428430
struct virtio_device *vdev = vblk->vdev;
431+
struct irq_affinity desc = { 0, };
429432

430433
err = virtio_cread_feature(vdev, VIRTIO_BLK_F_MQ,
431434
struct virtio_blk_config, num_queues,
@@ -452,7 +455,8 @@ static int init_vq(struct virtio_blk *vblk)
452455
}
453456

454457
/* Discover virtqueues and write information to configuration. */
455-
err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names);
458+
err = vdev->config->find_vqs(vdev, num_vqs, vqs, callbacks, names,
459+
&desc);
456460
if (err)
457461
goto out;
458462

@@ -586,10 +590,18 @@ static int virtblk_init_request(void *data, struct request *rq,
586590
return 0;
587591
}
588592

593+
static int virtblk_map_queues(struct blk_mq_tag_set *set)
594+
{
595+
struct virtio_blk *vblk = set->driver_data;
596+
597+
return blk_mq_virtio_map_queues(set, vblk->vdev, 0);
598+
}
599+
589600
static struct blk_mq_ops virtio_mq_ops = {
590601
.queue_rq = virtio_queue_rq,
591602
.complete = virtblk_request_done,
592603
.init_request = virtblk_init_request,
604+
.map_queues = virtblk_map_queues,
593605
};
594606

595607
static unsigned int virtblk_queue_depth;

‎drivers/char/virtio_console.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ static int put_chars(u32 vtermno, const char *buf, int count)
11361136
{
11371137
struct port *port;
11381138
struct scatterlist sg[1];
1139+
void *data;
1140+
int ret;
11391141

11401142
if (unlikely(early_put_chars))
11411143
return early_put_chars(vtermno, buf, count);
@@ -1144,8 +1146,14 @@ static int put_chars(u32 vtermno, const char *buf, int count)
11441146
if (!port)
11451147
return -EPIPE;
11461148

1147-
sg_init_one(sg, buf, count);
1148-
return __send_to_port(port, sg, 1, count, (void *)buf, false);
1149+
data = kmemdup(buf, count, GFP_ATOMIC);
1150+
if (!data)
1151+
return -ENOMEM;
1152+
1153+
sg_init_one(sg, data, count);
1154+
ret = __send_to_port(port, sg, 1, count, data, false);
1155+
kfree(data);
1156+
return ret;
11491157
}
11501158

11511159
/*
@@ -1939,7 +1947,7 @@ static int init_vqs(struct ports_device *portdev)
19391947
/* Find the queues. */
19401948
err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
19411949
io_callbacks,
1942-
(const char **)io_names);
1950+
(const char **)io_names, NULL);
19431951
if (err)
19441952
goto free;
19451953

‎drivers/crypto/virtio/virtio_crypto_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
120120
}
121121

122122
ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
123-
names);
123+
names, NULL);
124124
if (ret)
125125
goto err_find;
126126

‎drivers/gpu/drm/virtio/virtgpu_kms.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ int virtio_gpu_driver_load(struct drm_device *dev, unsigned long flags)
176176
#endif
177177

178178
ret = vgdev->vdev->config->find_vqs(vgdev->vdev, 2, vqs,
179-
callbacks, names);
179+
callbacks, names, NULL);
180180
if (ret) {
181181
DRM_ERROR("failed to find virt queues\n");
182182
goto err_vqs;

‎drivers/misc/mic/vop/vop_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static struct virtqueue *vop_find_vq(struct virtio_device *dev,
374374
static int vop_find_vqs(struct virtio_device *dev, unsigned nvqs,
375375
struct virtqueue *vqs[],
376376
vq_callback_t *callbacks[],
377-
const char * const names[])
377+
const char * const names[], struct irq_affinity *desc)
378378
{
379379
struct _vop_vdev *vdev = to_vopvdev(dev);
380380
struct vop_device *vpdev = vdev->vpdev;

‎drivers/net/caif/caif_virtio.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ static int cfv_probe(struct virtio_device *vdev)
679679
goto err;
680680

681681
/* Get the TX virtio ring. This is a "guest side vring". */
682-
err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names);
682+
err = vdev->config->find_vqs(vdev, 1, &cfv->vq_tx, &vq_cbs, &names,
683+
NULL);
683684
if (err)
684685
goto err;
685686

‎drivers/net/virtio_net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
20802080
}
20812081

20822082
ret = vi->vdev->config->find_vqs(vi->vdev, total_vqs, vqs, callbacks,
2083-
names);
2083+
names, NULL);
20842084
if (ret)
20852085
goto err_find;
20862086

0 commit comments

Comments
 (0)