Skip to content

Commit 63972f6

Browse files
rchatreawilliam
authored andcommitted
vfio/pci: Remove interrupt context counter
struct vfio_pci_core_device::num_ctx counts how many interrupt contexts have been allocated. When all interrupt contexts are allocated simultaneously num_ctx provides the upper bound of all vectors that can be used as indices into the interrupt context array. With the upcoming support for dynamic MSI-X the number of interrupt contexts does not necessarily span the range of allocated interrupts. Consequently, num_ctx is no longer a trusted upper bound for valid indices. Stop using num_ctx to determine if a provided vector is valid. Use the existence of allocated interrupt. This changes behavior on the error path when user space provides an invalid vector range. Behavior changes from early exit without any modifications to possible modifications to valid vectors within the invalid range. This is acceptable considering that an invalid range is not a valid scenario, see link to discussion. The checks that ensure that user space provides a range of vectors that is valid for the device are untouched. Signed-off-by: Reinette Chatre <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Reviewed-by: Kevin Tian <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/e27d350f02a65b8cbacd409b4321f5ce35b3186d.1683740667.git.reinette.chatre@intel.com Signed-off-by: Alex Williamson <[email protected]>
1 parent b156e48 commit 63972f6

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

drivers/vfio/pci/vfio_pci_intrs.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev)
245245
if (!ctx)
246246
return -ENOMEM;
247247

248-
vdev->num_ctx = 1;
249-
250248
/*
251249
* If the virtual interrupt is masked, restore it. Devices
252250
* supporting DisINTx can be masked at the hardware level
@@ -334,7 +332,6 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
334332
}
335333
vfio_intx_set_signal(vdev, -1);
336334
vdev->irq_type = VFIO_PCI_NUM_IRQS;
337-
vdev->num_ctx = 0;
338335
vfio_irq_ctx_free(vdev, ctx, 0);
339336
}
340337

@@ -370,7 +367,6 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi
370367
}
371368
vfio_pci_memory_unlock_and_restore(vdev, cmd);
372369

373-
vdev->num_ctx = nvec;
374370
vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
375371
VFIO_PCI_MSI_IRQ_INDEX;
376372

@@ -394,9 +390,6 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,
394390
int irq, ret;
395391
u16 cmd;
396392

397-
if (vector >= vdev->num_ctx)
398-
return -EINVAL;
399-
400393
irq = pci_irq_vector(pdev, vector);
401394
if (irq < 0)
402395
return -EINVAL;
@@ -483,9 +476,6 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
483476
unsigned int i, j;
484477
int ret = 0;
485478

486-
if (start >= vdev->num_ctx || start + count > vdev->num_ctx)
487-
return -EINVAL;
488-
489479
for (i = 0, j = start; i < count && !ret; i++, j++) {
490480
int fd = fds ? fds[i] : -1;
491481
ret = vfio_msi_set_vector_signal(vdev, j, fd, msix);
@@ -524,7 +514,6 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix)
524514
pci_intx(pdev, 0);
525515

526516
vdev->irq_type = VFIO_PCI_NUM_IRQS;
527-
vdev->num_ctx = 0;
528517
}
529518

530519
/*
@@ -659,7 +648,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
659648
return ret;
660649
}
661650

662-
if (!irq_is(vdev, index) || start + count > vdev->num_ctx)
651+
if (!irq_is(vdev, index))
663652
return -EINVAL;
664653

665654
for (i = start; i < start + count; i++) {

include/linux/vfio_pci_core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ struct vfio_pci_core_device {
6060
spinlock_t irqlock;
6161
struct mutex igate;
6262
struct xarray ctx;
63-
int num_ctx;
6463
int irq_type;
6564
int num_regions;
6665
struct vfio_pci_region *region;

0 commit comments

Comments
 (0)