Skip to content

Commit 9c54567

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: "A couple of fixes that seem important enough to pick at the last moment" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio-ring: fix DMA metadata flags vduse: Fix race condition between resetting and irq injecting vduse: Disallow injecting interrupt before DRIVER_OK is set
2 parents 1fc596a + 890d335 commit 9c54567

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct vduse_dev {
8080
struct vdpa_callback config_cb;
8181
struct work_struct inject;
8282
spinlock_t irq_lock;
83+
struct rw_semaphore rwsem;
8384
int minor;
8485
bool broken;
8586
bool connected;
@@ -410,6 +411,8 @@ static void vduse_dev_reset(struct vduse_dev *dev)
410411
if (domain->bounce_map)
411412
vduse_domain_reset_bounce_map(domain);
412413

414+
down_write(&dev->rwsem);
415+
413416
dev->status = 0;
414417
dev->driver_features = 0;
415418
dev->generation++;
@@ -443,6 +446,8 @@ static void vduse_dev_reset(struct vduse_dev *dev)
443446
flush_work(&vq->inject);
444447
flush_work(&vq->kick);
445448
}
449+
450+
up_write(&dev->rwsem);
446451
}
447452

448453
static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
@@ -885,6 +890,23 @@ static void vduse_vq_irq_inject(struct work_struct *work)
885890
spin_unlock_irq(&vq->irq_lock);
886891
}
887892

893+
static int vduse_dev_queue_irq_work(struct vduse_dev *dev,
894+
struct work_struct *irq_work)
895+
{
896+
int ret = -EINVAL;
897+
898+
down_read(&dev->rwsem);
899+
if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
900+
goto unlock;
901+
902+
ret = 0;
903+
queue_work(vduse_irq_wq, irq_work);
904+
unlock:
905+
up_read(&dev->rwsem);
906+
907+
return ret;
908+
}
909+
888910
static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
889911
unsigned long arg)
890912
{
@@ -966,8 +988,7 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
966988
break;
967989
}
968990
case VDUSE_DEV_INJECT_CONFIG_IRQ:
969-
ret = 0;
970-
queue_work(vduse_irq_wq, &dev->inject);
991+
ret = vduse_dev_queue_irq_work(dev, &dev->inject);
971992
break;
972993
case VDUSE_VQ_SETUP: {
973994
struct vduse_vq_config config;
@@ -1053,9 +1074,8 @@ static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
10531074
if (index >= dev->vq_num)
10541075
break;
10551076

1056-
ret = 0;
10571077
index = array_index_nospec(index, dev->vq_num);
1058-
queue_work(vduse_irq_wq, &dev->vqs[index].inject);
1078+
ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index].inject);
10591079
break;
10601080
}
10611081
default:
@@ -1136,6 +1156,7 @@ static struct vduse_dev *vduse_dev_create(void)
11361156
INIT_LIST_HEAD(&dev->send_list);
11371157
INIT_LIST_HEAD(&dev->recv_list);
11381158
spin_lock_init(&dev->irq_lock);
1159+
init_rwsem(&dev->rwsem);
11391160

11401161
INIT_WORK(&dev->inject, vduse_dev_irq_inject);
11411162
init_waitqueue_head(&dev->waitq);

drivers/virtio/virtio_ring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq,
576576
/* Last one doesn't continue. */
577577
desc[prev].flags &= cpu_to_virtio16(_vq->vdev, ~VRING_DESC_F_NEXT);
578578
if (!indirect && vq->use_dma_api)
579-
vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags =
579+
vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags &=
580580
~VRING_DESC_F_NEXT;
581581

582582
if (indirect) {

0 commit comments

Comments
 (0)