Skip to content

Commit 9313f80

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: "vhost, vdpa, and virtio cleanups and fixes A very quiet cycle, no new features" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: MAINTAINERS: add URL for virtio-mem vhost_vdpa: remove unnecessary spin_lock in vhost_vring_call vringh: fix __vringh_iov() when riov and wiov are different vdpa/mlx5: Setup driver only if VIRTIO_CONFIG_S_DRIVER_OK s390: virtio: PV needs VIRTIO I/O device protection virtio: let arch advertise guest's memory access restrictions vhost_vdpa: Fix duplicate included kernel.h vhost: reduce stack usage in log_used virtio-mem: Constify mem_id_table virtio_input: Constify id_table virtio-balloon: Constify id_table vdpa/mlx5: Fix failure to bring link up vdpa/mlx5: Make use of a specific 16 bit endianness API
2 parents 090a7d0 + 88a0d60 commit 9313f80

14 files changed

Lines changed: 65 additions & 22 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18629,6 +18629,7 @@ VIRTIO MEM DRIVER
1862918629
M: David Hildenbrand <david@redhat.com>
1863018630
L: virtualization@lists.linux-foundation.org
1863118631
S: Maintained
18632+
W: https://virtio-mem.gitlab.io/
1863218633
F: drivers/virtio/virtio_mem.c
1863318634
F: include/uapi/linux/virtio_mem.h
1863418635

arch/s390/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ menu "Virtualization"
810810
config PROTECTED_VIRTUALIZATION_GUEST
811811
def_bool n
812812
prompt "Protected virtualization guest support"
813+
select ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
813814
help
814815
Select this option, if you want to be able to run this
815816
kernel as a protected virtualization KVM guest.

arch/s390/mm/init.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <asm/kasan.h>
4747
#include <asm/dma-mapping.h>
4848
#include <asm/uv.h>
49+
#include <linux/virtio_config.h>
4950

5051
pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);
5152

@@ -162,6 +163,16 @@ bool force_dma_unencrypted(struct device *dev)
162163
return is_prot_virt_guest();
163164
}
164165

166+
#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
167+
168+
int arch_has_restricted_virtio_memory_access(void)
169+
{
170+
return is_prot_virt_guest();
171+
}
172+
EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
173+
174+
#endif
175+
165176
/* protected virtualization */
166177
static void pv_init(void)
167178
{

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,11 @@ static inline bool mlx5_vdpa_is_little_endian(struct mlx5_vdpa_dev *mvdev)
15221522
(mvdev->actual_features & (1ULL << VIRTIO_F_VERSION_1));
15231523
}
15241524

1525+
static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
1526+
{
1527+
return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
1528+
}
1529+
15251530
static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
15261531
{
15271532
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -1535,8 +1540,8 @@ static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
15351540
return err;
15361541

15371542
ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features;
1538-
ndev->config.mtu = __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev),
1539-
ndev->mtu);
1543+
ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, ndev->mtu);
1544+
ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP);
15401545
return err;
15411546
}
15421547

@@ -1653,6 +1658,9 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_net *ndev, struct vhost_iotlb *
16531658
if (err)
16541659
goto err_mr;
16551660

1661+
if (!(ndev->mvdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
1662+
return 0;
1663+
16561664
restore_channels_info(ndev);
16571665
err = setup_driver(ndev);
16581666
if (err)

drivers/vhost/vdpa.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/nospec.h>
2323
#include <linux/vhost.h>
2424
#include <linux/virtio_net.h>
25-
#include <linux/kernel.h>
2625

2726
#include "vhost.h"
2827

@@ -97,26 +96,20 @@ static void vhost_vdpa_setup_vq_irq(struct vhost_vdpa *v, u16 qid)
9796
return;
9897

9998
irq = ops->get_vq_irq(vdpa, qid);
100-
spin_lock(&vq->call_ctx.ctx_lock);
10199
irq_bypass_unregister_producer(&vq->call_ctx.producer);
102-
if (!vq->call_ctx.ctx || irq < 0) {
103-
spin_unlock(&vq->call_ctx.ctx_lock);
100+
if (!vq->call_ctx.ctx || irq < 0)
104101
return;
105-
}
106102

107103
vq->call_ctx.producer.token = vq->call_ctx.ctx;
108104
vq->call_ctx.producer.irq = irq;
109105
ret = irq_bypass_register_producer(&vq->call_ctx.producer);
110-
spin_unlock(&vq->call_ctx.ctx_lock);
111106
}
112107

113108
static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)
114109
{
115110
struct vhost_virtqueue *vq = &v->vqs[qid];
116111

117-
spin_lock(&vq->call_ctx.ctx_lock);
118112
irq_bypass_unregister_producer(&vq->call_ctx.producer);
119-
spin_unlock(&vq->call_ctx.ctx_lock);
120113
}
121114

122115
static void vhost_vdpa_reset(struct vhost_vdpa *v)

drivers/vhost/vhost.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ static void vhost_vring_call_reset(struct vhost_vring_call *call_ctx)
302302
{
303303
call_ctx->ctx = NULL;
304304
memset(&call_ctx->producer, 0x0, sizeof(struct irq_bypass_producer));
305-
spin_lock_init(&call_ctx->ctx_lock);
306305
}
307306

308307
static void vhost_vq_reset(struct vhost_dev *dev,
@@ -1650,9 +1649,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
16501649
break;
16511650
}
16521651

1653-
spin_lock(&vq->call_ctx.ctx_lock);
16541652
swap(ctx, vq->call_ctx.ctx);
1655-
spin_unlock(&vq->call_ctx.ctx_lock);
16561653
break;
16571654
case VHOST_SET_VRING_ERR:
16581655
if (copy_from_user(&f, argp, sizeof f)) {
@@ -1897,7 +1894,7 @@ static int log_write_hva(struct vhost_virtqueue *vq, u64 hva, u64 len)
18971894

18981895
static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
18991896
{
1900-
struct iovec iov[64];
1897+
struct iovec *iov = vq->log_iov;
19011898
int i, ret;
19021899

19031900
if (!vq->iotlb)

drivers/vhost/vhost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ enum vhost_uaddr_type {
6464
struct vhost_vring_call {
6565
struct eventfd_ctx *ctx;
6666
struct irq_bypass_producer producer;
67-
spinlock_t ctx_lock;
6867
};
6968

7069
/* The virtqueue structure describes a queue attached to a device. */
@@ -123,6 +122,7 @@ struct vhost_virtqueue {
123122
/* Log write descriptors */
124123
void __user *log_base;
125124
struct vhost_log *log;
125+
struct iovec log_iov[64];
126126

127127
/* Ring endianness. Defaults to legacy native endianness.
128128
* Set to true when starting a modern virtio device. */

drivers/vhost/vringh.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,14 @@ __vringh_iov(struct vringh *vrh, u16 i,
284284
desc_max = vrh->vring.num;
285285
up_next = -1;
286286

287+
/* You must want something! */
288+
if (WARN_ON(!riov && !wiov))
289+
return -EINVAL;
290+
287291
if (riov)
288292
riov->i = riov->used = 0;
289-
else if (wiov)
293+
if (wiov)
290294
wiov->i = wiov->used = 0;
291-
else
292-
/* You must want something! */
293-
BUG();
294295

295296
for (;;) {
296297
void *addr;

drivers/virtio/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ config VIRTIO
66
bus, such as CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_MMIO, CONFIG_RPMSG
77
or CONFIG_S390_GUEST.
88

9+
config ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
10+
bool
11+
help
12+
This option is selected if the architecture may need to enforce
13+
VIRTIO_F_ACCESS_PLATFORM
14+
915
menuconfig VIRTIO_MENU
1016
bool "Virtio drivers"
1117
default y

drivers/virtio/virtio.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ int virtio_finalize_features(struct virtio_device *dev)
176176
if (ret)
177177
return ret;
178178

179+
ret = arch_has_restricted_virtio_memory_access();
180+
if (ret) {
181+
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
182+
dev_warn(&dev->dev,
183+
"device must provide VIRTIO_F_VERSION_1\n");
184+
return -ENODEV;
185+
}
186+
187+
if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
188+
dev_warn(&dev->dev,
189+
"device must provide VIRTIO_F_ACCESS_PLATFORM\n");
190+
return -ENODEV;
191+
}
192+
}
193+
179194
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1))
180195
return 0;
181196

0 commit comments

Comments
 (0)