The interrupt might be triggered after a reset since there is
no synchronization between resetting and irq injecting. And it
might break something if the interrupt is delayed until a new
round of device initialization.
Fixes:
c8a6153b6c59 ("vduse: Introduce VDUSE - vDPA Device in Userspace")
Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
Link: https://lore.kernel.org/r/20210929083050.88-1-xieyongji@bytedance.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
struct vdpa_callback config_cb;
struct work_struct inject;
spinlock_t irq_lock;
struct vdpa_callback config_cb;
struct work_struct inject;
spinlock_t irq_lock;
+ struct rw_semaphore rwsem;
int minor;
bool broken;
bool connected;
int minor;
bool broken;
bool connected;
if (domain->bounce_map)
vduse_domain_reset_bounce_map(domain);
if (domain->bounce_map)
vduse_domain_reset_bounce_map(domain);
+ down_write(&dev->rwsem);
+
dev->status = 0;
dev->driver_features = 0;
dev->generation++;
dev->status = 0;
dev->driver_features = 0;
dev->generation++;
flush_work(&vq->inject);
flush_work(&vq->kick);
}
flush_work(&vq->inject);
flush_work(&vq->kick);
}
+
+ up_write(&dev->rwsem);
}
static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
}
static int vduse_vdpa_set_vq_address(struct vdpa_device *vdpa, u16 idx,
spin_unlock_irq(&vq->irq_lock);
}
spin_unlock_irq(&vq->irq_lock);
}
+static int vduse_dev_queue_irq_work(struct vduse_dev *dev,
+ struct work_struct *irq_work)
+{
+ int ret = -EINVAL;
+
+ down_read(&dev->rwsem);
+ if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
+ goto unlock;
+
+ ret = 0;
+ queue_work(vduse_irq_wq, irq_work);
+unlock:
+ up_read(&dev->rwsem);
+
+ return ret;
+}
+
static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
static long vduse_dev_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
break;
}
case VDUSE_DEV_INJECT_CONFIG_IRQ:
break;
}
case VDUSE_DEV_INJECT_CONFIG_IRQ:
- ret = -EINVAL;
- if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
- break;
-
- ret = 0;
- queue_work(vduse_irq_wq, &dev->inject);
+ ret = vduse_dev_queue_irq_work(dev, &dev->inject);
break;
case VDUSE_VQ_SETUP: {
struct vduse_vq_config config;
break;
case VDUSE_VQ_SETUP: {
struct vduse_vq_config config;
case VDUSE_VQ_INJECT_IRQ: {
u32 index;
case VDUSE_VQ_INJECT_IRQ: {
u32 index;
- ret = -EINVAL;
- if (!(dev->status & VIRTIO_CONFIG_S_DRIVER_OK))
- break;
-
ret = -EFAULT;
if (get_user(index, (u32 __user *)argp))
break;
ret = -EFAULT;
if (get_user(index, (u32 __user *)argp))
break;
if (index >= dev->vq_num)
break;
if (index >= dev->vq_num)
break;
index = array_index_nospec(index, dev->vq_num);
index = array_index_nospec(index, dev->vq_num);
- queue_work(vduse_irq_wq, &dev->vqs[index].inject);
+ ret = vduse_dev_queue_irq_work(dev, &dev->vqs[index].inject);
INIT_LIST_HEAD(&dev->send_list);
INIT_LIST_HEAD(&dev->recv_list);
spin_lock_init(&dev->irq_lock);
INIT_LIST_HEAD(&dev->send_list);
INIT_LIST_HEAD(&dev->recv_list);
spin_lock_init(&dev->irq_lock);
+ init_rwsem(&dev->rwsem);
INIT_WORK(&dev->inject, vduse_dev_irq_inject);
init_waitqueue_head(&dev->waitq);
INIT_WORK(&dev->inject, vduse_dev_irq_inject);
init_waitqueue_head(&dev->waitq);