Skip to content

Commit 0803e04

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio/vhost updates from Michael Tsirkin: - new vsock device support in host and guest - platform IOMMU support in host and guest, including compatibility quirks for legacy systems. - misc fixes and cleanups. * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: VSOCK: Use kvfree() vhost: split out vringh Kconfig vhost: detect 32 bit integer wrap around vhost: new device IOTLB API vhost: drop vringh dependency vhost: convert pre sorted vhost memory array to interval tree vhost: introduce vhost memory accessors VSOCK: Add Makefile and Kconfig VSOCK: Introduce vhost_vsock.ko VSOCK: Introduce virtio_transport.ko VSOCK: Introduce virtio_vsock_common.ko VSOCK: defer sock removal to transports VSOCK: transport-specific vsock_transport functions vhost: drop vringh dependency vop: pull in vhost Kconfig virtio: new feature to detect IOMMU device quirk balloon: check the number of available pages in leak balloon vhost: lockless enqueuing vhost: simplify work flushing
2 parents 80fac0f + b226aca commit 0803e04

28 files changed

+3765
-201
lines changed

MAINTAINERS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12419,6 +12419,19 @@ S: Maintained
1241912419
F: drivers/media/v4l2-core/videobuf2-*
1242012420
F: include/media/videobuf2-*
1242112421

12422+
VIRTIO AND VHOST VSOCK DRIVER
12423+
M: Stefan Hajnoczi <stefanha@redhat.com>
12424+
L: kvm@vger.kernel.org
12425+
L: virtualization@lists.linux-foundation.org
12426+
L: netdev@vger.kernel.org
12427+
S: Maintained
12428+
F: include/linux/virtio_vsock.h
12429+
F: include/uapi/linux/virtio_vsock.h
12430+
F: net/vmw_vsock/virtio_transport_common.c
12431+
F: net/vmw_vsock/virtio_transport.c
12432+
F: drivers/vhost/vsock.c
12433+
F: drivers/vhost/vsock.h
12434+
1242212435
VIRTUAL SERIO DEVICE DRIVER
1242312436
M: Stephen Chandler Paul <thatslyude@gmail.com>
1242412437
S: Maintained

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ obj-$(CONFIG_OF) += of/
138138
obj-$(CONFIG_SSB) += ssb/
139139
obj-$(CONFIG_BCMA) += bcma/
140140
obj-$(CONFIG_VHOST_RING) += vhost/
141+
obj-$(CONFIG_VHOST) += vhost/
141142
obj-$(CONFIG_VLYNQ) += vlynq/
142143
obj-$(CONFIG_STAGING) += staging/
143144
obj-y += platform/

drivers/misc/mic/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@ config VOP
146146
More information about the Intel MIC family as well as the Linux
147147
OS and tools for MIC to use with this driver are available from
148148
<http://software.intel.com/en-us/mic-developer>.
149+
150+
if VOP
151+
source "drivers/vhost/Kconfig.vringh"
152+
endif

drivers/net/caif/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ config CAIF_VIRTIO
5252
The caif driver for CAIF over Virtio.
5353

5454
if CAIF_VIRTIO
55-
source "drivers/vhost/Kconfig"
55+
source "drivers/vhost/Kconfig.vringh"
5656
endif

drivers/vhost/Kconfig

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ config VHOST_NET
22
tristate "Host kernel accelerator for virtio net"
33
depends on NET && EVENTFD && (TUN || !TUN) && (MACVTAP || !MACVTAP)
44
select VHOST
5-
select VHOST_RING
65
---help---
76
This kernel module can be loaded in host kernel to accelerate
87
guest networking with virtio_net. Not to be confused with virtio_net
@@ -15,17 +14,24 @@ config VHOST_SCSI
1514
tristate "VHOST_SCSI TCM fabric driver"
1615
depends on TARGET_CORE && EVENTFD && m
1716
select VHOST
18-
select VHOST_RING
1917
default n
2018
---help---
2119
Say M here to enable the vhost_scsi TCM fabric module
2220
for use with virtio-scsi guests
2321

24-
config VHOST_RING
25-
tristate
22+
config VHOST_VSOCK
23+
tristate "vhost virtio-vsock driver"
24+
depends on VSOCKETS && EVENTFD
25+
select VIRTIO_VSOCKETS_COMMON
26+
select VHOST
27+
default n
2628
---help---
27-
This option is selected by any driver which needs to access
28-
the host side of a virtio ring.
29+
This kernel module can be loaded in the host kernel to provide AF_VSOCK
30+
sockets for communicating with guests. The guests must have the
31+
virtio_transport.ko driver loaded to use the virtio-vsock device.
32+
33+
To compile this driver as a module, choose M here: the module will be called
34+
vhost_vsock.
2935

3036
config VHOST
3137
tristate

drivers/vhost/Kconfig.vringh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
config VHOST_RING
2+
tristate
3+
---help---
4+
This option is selected by any driver which needs to access
5+
the host side of a virtio ring.

drivers/vhost/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ vhost_net-y := net.o
44
obj-$(CONFIG_VHOST_SCSI) += vhost_scsi.o
55
vhost_scsi-y := scsi.o
66

7+
obj-$(CONFIG_VHOST_VSOCK) += vhost_vsock.o
8+
vhost_vsock-y := vsock.o
9+
710
obj-$(CONFIG_VHOST_RING) += vringh.o
11+
812
obj-$(CONFIG_VHOST) += vhost.o

drivers/vhost/net.c

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
6161
enum {
6262
VHOST_NET_FEATURES = VHOST_FEATURES |
6363
(1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
64-
(1ULL << VIRTIO_NET_F_MRG_RXBUF)
64+
(1ULL << VIRTIO_NET_F_MRG_RXBUF) |
65+
(1ULL << VIRTIO_F_IOMMU_PLATFORM)
6566
};
6667

6768
enum {
@@ -334,7 +335,7 @@ static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
334335
{
335336
unsigned long uninitialized_var(endtime);
336337
int r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov),
337-
out_num, in_num, NULL, NULL);
338+
out_num, in_num, NULL, NULL);
338339

339340
if (r == vq->num && vq->busyloop_timeout) {
340341
preempt_disable();
@@ -344,7 +345,7 @@ static int vhost_net_tx_get_vq_desc(struct vhost_net *net,
344345
cpu_relax_lowlatency();
345346
preempt_enable();
346347
r = vhost_get_vq_desc(vq, vq->iov, ARRAY_SIZE(vq->iov),
347-
out_num, in_num, NULL, NULL);
348+
out_num, in_num, NULL, NULL);
348349
}
349350

350351
return r;
@@ -377,6 +378,9 @@ static void handle_tx(struct vhost_net *net)
377378
if (!sock)
378379
goto out;
379380

381+
if (!vq_iotlb_prefetch(vq))
382+
goto out;
383+
380384
vhost_disable_notify(&net->dev, vq);
381385

382386
hdr_size = nvq->vhost_hlen;
@@ -652,6 +656,10 @@ static void handle_rx(struct vhost_net *net)
652656
sock = vq->private_data;
653657
if (!sock)
654658
goto out;
659+
660+
if (!vq_iotlb_prefetch(vq))
661+
goto out;
662+
655663
vhost_disable_notify(&net->dev, vq);
656664
vhost_net_disable_vq(net, vq);
657665

@@ -1052,20 +1060,20 @@ static long vhost_net_reset_owner(struct vhost_net *n)
10521060
struct socket *tx_sock = NULL;
10531061
struct socket *rx_sock = NULL;
10541062
long err;
1055-
struct vhost_memory *memory;
1063+
struct vhost_umem *umem;
10561064

10571065
mutex_lock(&n->dev.mutex);
10581066
err = vhost_dev_check_owner(&n->dev);
10591067
if (err)
10601068
goto done;
1061-
memory = vhost_dev_reset_owner_prepare();
1062-
if (!memory) {
1069+
umem = vhost_dev_reset_owner_prepare();
1070+
if (!umem) {
10631071
err = -ENOMEM;
10641072
goto done;
10651073
}
10661074
vhost_net_stop(n, &tx_sock, &rx_sock);
10671075
vhost_net_flush(n);
1068-
vhost_dev_reset_owner(&n->dev, memory);
1076+
vhost_dev_reset_owner(&n->dev, umem);
10691077
vhost_net_vq_reset(n);
10701078
done:
10711079
mutex_unlock(&n->dev.mutex);
@@ -1096,10 +1104,14 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)
10961104
}
10971105
mutex_lock(&n->dev.mutex);
10981106
if ((features & (1 << VHOST_F_LOG_ALL)) &&
1099-
!vhost_log_access_ok(&n->dev)) {
1100-
mutex_unlock(&n->dev.mutex);
1101-
return -EFAULT;
1107+
!vhost_log_access_ok(&n->dev))
1108+
goto out_unlock;
1109+
1110+
if ((features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) {
1111+
if (vhost_init_device_iotlb(&n->dev, true))
1112+
goto out_unlock;
11021113
}
1114+
11031115
for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
11041116
mutex_lock(&n->vqs[i].vq.mutex);
11051117
n->vqs[i].vq.acked_features = features;
@@ -1109,6 +1121,10 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)
11091121
}
11101122
mutex_unlock(&n->dev.mutex);
11111123
return 0;
1124+
1125+
out_unlock:
1126+
mutex_unlock(&n->dev.mutex);
1127+
return -EFAULT;
11121128
}
11131129

11141130
static long vhost_net_set_owner(struct vhost_net *n)
@@ -1182,9 +1198,40 @@ static long vhost_net_compat_ioctl(struct file *f, unsigned int ioctl,
11821198
}
11831199
#endif
11841200

1201+
static ssize_t vhost_net_chr_read_iter(struct kiocb *iocb, struct iov_iter *to)
1202+
{
1203+
struct file *file = iocb->ki_filp;
1204+
struct vhost_net *n = file->private_data;
1205+
struct vhost_dev *dev = &n->dev;
1206+
int noblock = file->f_flags & O_NONBLOCK;
1207+
1208+
return vhost_chr_read_iter(dev, to, noblock);
1209+
}
1210+
1211+
static ssize_t vhost_net_chr_write_iter(struct kiocb *iocb,
1212+
struct iov_iter *from)
1213+
{
1214+
struct file *file = iocb->ki_filp;
1215+
struct vhost_net *n = file->private_data;
1216+
struct vhost_dev *dev = &n->dev;
1217+
1218+
return vhost_chr_write_iter(dev, from);
1219+
}
1220+
1221+
static unsigned int vhost_net_chr_poll(struct file *file, poll_table *wait)
1222+
{
1223+
struct vhost_net *n = file->private_data;
1224+
struct vhost_dev *dev = &n->dev;
1225+
1226+
return vhost_chr_poll(file, dev, wait);
1227+
}
1228+
11851229
static const struct file_operations vhost_net_fops = {
11861230
.owner = THIS_MODULE,
11871231
.release = vhost_net_release,
1232+
.read_iter = vhost_net_chr_read_iter,
1233+
.write_iter = vhost_net_chr_write_iter,
1234+
.poll = vhost_net_chr_poll,
11881235
.unlocked_ioctl = vhost_net_ioctl,
11891236
#ifdef CONFIG_COMPAT
11901237
.compat_ioctl = vhost_net_compat_ioctl,

0 commit comments

Comments
 (0)