@@ -1214,12 +1214,10 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
return PTR_ERR(data);
}
- mutex_lock(&vdev->intr_ctx.igate);
ret = vfio_pci_set_irqs_ioctl(&vdev->intr_ctx, hdr.flags, hdr.index,
hdr.start, hdr.count, data);
- mutex_unlock(&vdev->intr_ctx.igate);
kfree(data);
return ret;
@@ -826,7 +826,9 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_intr_ctx *intr_ctx, uint32_t flags,
int (*func)(struct vfio_pci_intr_ctx *intr_ctx, unsigned int index,
unsigned int start, unsigned int count, uint32_t flags,
void *data) = NULL;
+ int ret = -ENOTTY;
+ mutex_lock(&intr_ctx->igate);
switch (index) {
case VFIO_PCI_INTX_IRQ_INDEX:
switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
@@ -887,7 +889,11 @@ int vfio_pci_set_irqs_ioctl(struct vfio_pci_intr_ctx *intr_ctx, uint32_t flags,
}
if (!func)
- return -ENOTTY;
+ goto out_unlock;
+
+ ret = func(intr_ctx, index, start, count, flags, data);
- return func(intr_ctx, index, start, count, flags, data);
+out_unlock:
+ mutex_unlock(&intr_ctx->igate);
+ return ret;
}
vfio_pci_set_irqs_ioctl() is the entrypoint for interrupt management via the VFIO_DEVICE_SET_IRQS ioctl(). vfio_pci_set_irqs_ioctl() can be called from a virtual device driver after its callbacks have been configured to support the needed interrupt management. The igate mutex is obtained before vfio_pci_set_irqs_ioctl() to protect against concurrent changes to interrupt context. It should not be necessary for all users of vfio_pci_set_irqs_ioctl() to remember to take the mutex. Acquire and release the mutex within vfio_pci_set_irqs_ioctl(). Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> --- Changes since RFC V2: - Improve changelog. drivers/vfio/pci/vfio_pci_core.c | 2 -- drivers/vfio/pci/vfio_pci_intrs.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-)