Skip to content

Commit 941e3e7

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael Tsirkin: "Fixes all over the place, most notably we are disabling IRQ hardening (again!)" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio_ring: make vring_create_virtqueue_split prettier vhost-vdpa: call vhost_vdpa_cleanup during the release virtio_mmio: Restore guest page size on resume virtio_mmio: Add missing PM calls to freeze/restore caif_virtio: fix race between virtio_device_ready() and ndo_open() virtio-net: fix race between ndo_open() and virtio_device_ready() virtio: disable notification hardening by default virtio: Remove unnecessary variable assignments virtio_ring : keep used_wrap_counter in vq->last_used_idx vduse: Tie vduse mgmtdev and its device vdpa/mlx5: Initialize CVQ vringh only once vdpa/mlx5: Update Control VQ callback information
2 parents 2390095 + c7cc29a commit 941e3e7

File tree

12 files changed

+187
-69
lines changed

12 files changed

+187
-69
lines changed

drivers/net/caif/caif_virtio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,21 @@ static int cfv_probe(struct virtio_device *vdev)
722722
/* Carrier is off until netdevice is opened */
723723
netif_carrier_off(netdev);
724724

725+
/* serialize netdev register + virtio_device_ready() with ndo_open() */
726+
rtnl_lock();
727+
725728
/* register Netdev */
726-
err = register_netdev(netdev);
729+
err = register_netdevice(netdev);
727730
if (err) {
731+
rtnl_unlock();
728732
dev_err(&vdev->dev, "Unable to register netdev (%d)\n", err);
729733
goto err;
730734
}
731735

736+
virtio_device_ready(vdev);
737+
738+
rtnl_unlock();
739+
732740
debugfs_init(cfv);
733741

734742
return 0;

drivers/net/virtio_net.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3642,14 +3642,20 @@ static int virtnet_probe(struct virtio_device *vdev)
36423642
if (vi->has_rss || vi->has_rss_hash_report)
36433643
virtnet_init_default_rss(vi);
36443644

3645-
err = register_netdev(dev);
3645+
/* serialize netdev register + virtio_device_ready() with ndo_open() */
3646+
rtnl_lock();
3647+
3648+
err = register_netdevice(dev);
36463649
if (err) {
36473650
pr_debug("virtio_net: registering device failed\n");
3651+
rtnl_unlock();
36483652
goto free_failover;
36493653
}
36503654

36513655
virtio_device_ready(vdev);
36523656

3657+
rtnl_unlock();
3658+
36533659
err = virtnet_cpu_notif_add(vi);
36543660
if (err) {
36553661
pr_debug("virtio_net: registering cpu notifier failed\n");

drivers/s390/virtio/virtio_ccw.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,13 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev,
11361136
vcdev->err = -EIO;
11371137
}
11381138
virtio_ccw_check_activity(vcdev, activity);
1139-
/* Interrupts are disabled here */
1139+
#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION
1140+
/*
1141+
* Paired with virtio_ccw_synchronize_cbs() and interrupts are
1142+
* disabled here.
1143+
*/
11401144
read_lock(&vcdev->irq_lock);
1145+
#endif
11411146
for_each_set_bit(i, indicators(vcdev),
11421147
sizeof(*indicators(vcdev)) * BITS_PER_BYTE) {
11431148
/* The bit clear must happen before the vring kick. */
@@ -1146,7 +1151,9 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev,
11461151
vq = virtio_ccw_vq_by_ind(vcdev, i);
11471152
vring_interrupt(0, vq);
11481153
}
1154+
#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION
11491155
read_unlock(&vcdev->irq_lock);
1156+
#endif
11501157
if (test_bit(0, indicators2(vcdev))) {
11511158
virtio_config_changed(&vcdev->vdev);
11521159
clear_bit(0, indicators2(vcdev));

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,8 @@ static void mlx5_vdpa_set_vq_cb(struct vdpa_device *vdev, u16 idx, struct vdpa_c
19621962
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
19631963

19641964
ndev->event_cbs[idx] = *cb;
1965+
if (is_ctrl_vq_idx(mvdev, idx))
1966+
mvdev->cvq.event_cb = *cb;
19651967
}
19661968

19671969
static void mlx5_cvq_notify(struct vringh *vring)
@@ -2174,7 +2176,6 @@ static int verify_driver_features(struct mlx5_vdpa_dev *mvdev, u64 features)
21742176
static int setup_virtqueues(struct mlx5_vdpa_dev *mvdev)
21752177
{
21762178
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
2177-
struct mlx5_control_vq *cvq = &mvdev->cvq;
21782179
int err;
21792180
int i;
21802181

@@ -2184,16 +2185,6 @@ static int setup_virtqueues(struct mlx5_vdpa_dev *mvdev)
21842185
goto err_vq;
21852186
}
21862187

2187-
if (mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)) {
2188-
err = vringh_init_iotlb(&cvq->vring, mvdev->actual_features,
2189-
MLX5_CVQ_MAX_ENT, false,
2190-
(struct vring_desc *)(uintptr_t)cvq->desc_addr,
2191-
(struct vring_avail *)(uintptr_t)cvq->driver_addr,
2192-
(struct vring_used *)(uintptr_t)cvq->device_addr);
2193-
if (err)
2194-
goto err_vq;
2195-
}
2196-
21972188
return 0;
21982189

21992190
err_vq:
@@ -2466,6 +2457,21 @@ static void clear_vqs_ready(struct mlx5_vdpa_net *ndev)
24662457
ndev->mvdev.cvq.ready = false;
24672458
}
24682459

2460+
static int setup_cvq_vring(struct mlx5_vdpa_dev *mvdev)
2461+
{
2462+
struct mlx5_control_vq *cvq = &mvdev->cvq;
2463+
int err = 0;
2464+
2465+
if (mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))
2466+
err = vringh_init_iotlb(&cvq->vring, mvdev->actual_features,
2467+
MLX5_CVQ_MAX_ENT, false,
2468+
(struct vring_desc *)(uintptr_t)cvq->desc_addr,
2469+
(struct vring_avail *)(uintptr_t)cvq->driver_addr,
2470+
(struct vring_used *)(uintptr_t)cvq->device_addr);
2471+
2472+
return err;
2473+
}
2474+
24692475
static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
24702476
{
24712477
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -2478,6 +2484,11 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
24782484

24792485
if ((status ^ ndev->mvdev.status) & VIRTIO_CONFIG_S_DRIVER_OK) {
24802486
if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
2487+
err = setup_cvq_vring(mvdev);
2488+
if (err) {
2489+
mlx5_vdpa_warn(mvdev, "failed to setup control VQ vring\n");
2490+
goto err_setup;
2491+
}
24812492
err = setup_driver(mvdev);
24822493
if (err) {
24832494
mlx5_vdpa_warn(mvdev, "failed to setup driver\n");

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,16 +1476,12 @@ static char *vduse_devnode(struct device *dev, umode_t *mode)
14761476
return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev));
14771477
}
14781478

1479-
static void vduse_mgmtdev_release(struct device *dev)
1480-
{
1481-
}
1482-
1483-
static struct device vduse_mgmtdev = {
1484-
.init_name = "vduse",
1485-
.release = vduse_mgmtdev_release,
1479+
struct vduse_mgmt_dev {
1480+
struct vdpa_mgmt_dev mgmt_dev;
1481+
struct device dev;
14861482
};
14871483

1488-
static struct vdpa_mgmt_dev mgmt_dev;
1484+
static struct vduse_mgmt_dev *vduse_mgmt;
14891485

14901486
static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
14911487
{
@@ -1510,7 +1506,7 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
15101506
}
15111507
set_dma_ops(&vdev->vdpa.dev, &vduse_dev_dma_ops);
15121508
vdev->vdpa.dma_dev = &vdev->vdpa.dev;
1513-
vdev->vdpa.mdev = &mgmt_dev;
1509+
vdev->vdpa.mdev = &vduse_mgmt->mgmt_dev;
15141510

15151511
return 0;
15161512
}
@@ -1556,34 +1552,52 @@ static struct virtio_device_id id_table[] = {
15561552
{ 0 },
15571553
};
15581554

1559-
static struct vdpa_mgmt_dev mgmt_dev = {
1560-
.device = &vduse_mgmtdev,
1561-
.id_table = id_table,
1562-
.ops = &vdpa_dev_mgmtdev_ops,
1563-
};
1555+
static void vduse_mgmtdev_release(struct device *dev)
1556+
{
1557+
struct vduse_mgmt_dev *mgmt_dev;
1558+
1559+
mgmt_dev = container_of(dev, struct vduse_mgmt_dev, dev);
1560+
kfree(mgmt_dev);
1561+
}
15641562

15651563
static int vduse_mgmtdev_init(void)
15661564
{
15671565
int ret;
15681566

1569-
ret = device_register(&vduse_mgmtdev);
1570-
if (ret)
1567+
vduse_mgmt = kzalloc(sizeof(*vduse_mgmt), GFP_KERNEL);
1568+
if (!vduse_mgmt)
1569+
return -ENOMEM;
1570+
1571+
ret = dev_set_name(&vduse_mgmt->dev, "vduse");
1572+
if (ret) {
1573+
kfree(vduse_mgmt);
15711574
return ret;
1575+
}
15721576

1573-
ret = vdpa_mgmtdev_register(&mgmt_dev);
1577+
vduse_mgmt->dev.release = vduse_mgmtdev_release;
1578+
1579+
ret = device_register(&vduse_mgmt->dev);
15741580
if (ret)
1575-
goto err;
1581+
goto dev_reg_err;
15761582

1577-
return 0;
1578-
err:
1579-
device_unregister(&vduse_mgmtdev);
1583+
vduse_mgmt->mgmt_dev.id_table = id_table;
1584+
vduse_mgmt->mgmt_dev.ops = &vdpa_dev_mgmtdev_ops;
1585+
vduse_mgmt->mgmt_dev.device = &vduse_mgmt->dev;
1586+
ret = vdpa_mgmtdev_register(&vduse_mgmt->mgmt_dev);
1587+
if (ret)
1588+
device_unregister(&vduse_mgmt->dev);
1589+
1590+
return ret;
1591+
1592+
dev_reg_err:
1593+
put_device(&vduse_mgmt->dev);
15801594
return ret;
15811595
}
15821596

15831597
static void vduse_mgmtdev_exit(void)
15841598
{
1585-
vdpa_mgmtdev_unregister(&mgmt_dev);
1586-
device_unregister(&vduse_mgmtdev);
1599+
vdpa_mgmtdev_unregister(&vduse_mgmt->mgmt_dev);
1600+
device_unregister(&vduse_mgmt->dev);
15871601
}
15881602

15891603
static int vduse_init(void)

drivers/vhost/vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
12091209
vhost_dev_stop(&v->vdev);
12101210
vhost_vdpa_free_domain(v);
12111211
vhost_vdpa_config_put(v);
1212-
vhost_dev_cleanup(&v->vdev);
1212+
vhost_vdpa_cleanup(v);
12131213
mutex_unlock(&d->mutex);
12141214

12151215
atomic_dec(&v->opened);

drivers/virtio/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ menuconfig VIRTIO_MENU
2929

3030
if VIRTIO_MENU
3131

32+
config VIRTIO_HARDEN_NOTIFICATION
33+
bool "Harden virtio notification"
34+
help
35+
Enable this to harden the device notifications and suppress
36+
those that happen at a time where notifications are illegal.
37+
38+
Experimental: Note that several drivers still have bugs that
39+
may cause crashes or hangs when correct handling of
40+
notifications is enforced; depending on the subset of
41+
drivers and devices you use, this may or may not work.
42+
43+
If unsure, say N.
44+
3245
config VIRTIO_PCI
3346
tristate "PCI driver for virtio devices"
3447
depends on PCI

drivers/virtio/virtio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static int virtio_features_ok(struct virtio_device *dev)
219219
* */
220220
void virtio_reset_device(struct virtio_device *dev)
221221
{
222+
#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION
222223
/*
223224
* The below virtio_synchronize_cbs() guarantees that any
224225
* interrupt for this line arriving after
@@ -227,6 +228,7 @@ void virtio_reset_device(struct virtio_device *dev)
227228
*/
228229
virtio_break_device(dev);
229230
virtio_synchronize_cbs(dev);
231+
#endif
230232

231233
dev->config->reset(dev);
232234
}

drivers/virtio/virtio_mmio.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/list.h>
6363
#include <linux/module.h>
6464
#include <linux/platform_device.h>
65+
#include <linux/pm.h>
6566
#include <linux/slab.h>
6667
#include <linux/spinlock.h>
6768
#include <linux/virtio.h>
@@ -556,6 +557,28 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
556557
.synchronize_cbs = vm_synchronize_cbs,
557558
};
558559

560+
#ifdef CONFIG_PM_SLEEP
561+
static int virtio_mmio_freeze(struct device *dev)
562+
{
563+
struct virtio_mmio_device *vm_dev = dev_get_drvdata(dev);
564+
565+
return virtio_device_freeze(&vm_dev->vdev);
566+
}
567+
568+
static int virtio_mmio_restore(struct device *dev)
569+
{
570+
struct virtio_mmio_device *vm_dev = dev_get_drvdata(dev);
571+
572+
if (vm_dev->version == 1)
573+
writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
574+
575+
return virtio_device_restore(&vm_dev->vdev);
576+
}
577+
578+
static const struct dev_pm_ops virtio_mmio_pm_ops = {
579+
SET_SYSTEM_SLEEP_PM_OPS(virtio_mmio_freeze, virtio_mmio_restore)
580+
};
581+
#endif
559582

560583
static void virtio_mmio_release_dev(struct device *_d)
561584
{
@@ -799,6 +822,9 @@ static struct platform_driver virtio_mmio_driver = {
799822
.name = "virtio-mmio",
800823
.of_match_table = virtio_mmio_match,
801824
.acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
825+
#ifdef CONFIG_PM_SLEEP
826+
.pm = &virtio_mmio_pm_ops,
827+
#endif
802828
},
803829
};
804830

drivers/virtio/virtio_pci_modern_dev.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
220220

221221
check_offsets();
222222

223-
mdev->pci_dev = pci_dev;
224-
225223
/* We only own devices >= 0x1000 and <= 0x107f: leave the rest. */
226224
if (pci_dev->device < 0x1000 || pci_dev->device > 0x107f)
227225
return -ENODEV;

0 commit comments

Comments
 (0)