Commit 63972f63 authored by Reinette Chatre's avatar Reinette Chatre Committed by Alex Williamson

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: default avatarReinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/lkml/20230316155646.07ae266f.alex.williamson@redhat.com/Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/e27d350f02a65b8cbacd409b4321f5ce35b3186d.1683740667.git.reinette.chatre@intel.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent b156e48f
...@@ -245,8 +245,6 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev) ...@@ -245,8 +245,6 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev)
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
vdev->num_ctx = 1;
/* /*
* If the virtual interrupt is masked, restore it. Devices * If the virtual interrupt is masked, restore it. Devices
* supporting DisINTx can be masked at the hardware level * supporting DisINTx can be masked at the hardware level
...@@ -334,7 +332,6 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev) ...@@ -334,7 +332,6 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
} }
vfio_intx_set_signal(vdev, -1); vfio_intx_set_signal(vdev, -1);
vdev->irq_type = VFIO_PCI_NUM_IRQS; vdev->irq_type = VFIO_PCI_NUM_IRQS;
vdev->num_ctx = 0;
vfio_irq_ctx_free(vdev, ctx, 0); vfio_irq_ctx_free(vdev, ctx, 0);
} }
...@@ -370,7 +367,6 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi ...@@ -370,7 +367,6 @@ static int vfio_msi_enable(struct vfio_pci_core_device *vdev, int nvec, bool msi
} }
vfio_pci_memory_unlock_and_restore(vdev, cmd); vfio_pci_memory_unlock_and_restore(vdev, cmd);
vdev->num_ctx = nvec;
vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX : vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
VFIO_PCI_MSI_IRQ_INDEX; VFIO_PCI_MSI_IRQ_INDEX;
...@@ -394,9 +390,6 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev, ...@@ -394,9 +390,6 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_core_device *vdev,
int irq, ret; int irq, ret;
u16 cmd; u16 cmd;
if (vector >= vdev->num_ctx)
return -EINVAL;
irq = pci_irq_vector(pdev, vector); irq = pci_irq_vector(pdev, vector);
if (irq < 0) if (irq < 0)
return -EINVAL; return -EINVAL;
...@@ -483,9 +476,6 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start, ...@@ -483,9 +476,6 @@ static int vfio_msi_set_block(struct vfio_pci_core_device *vdev, unsigned start,
unsigned int i, j; unsigned int i, j;
int ret = 0; int ret = 0;
if (start >= vdev->num_ctx || start + count > vdev->num_ctx)
return -EINVAL;
for (i = 0, j = start; i < count && !ret; i++, j++) { for (i = 0, j = start; i < count && !ret; i++, j++) {
int fd = fds ? fds[i] : -1; int fd = fds ? fds[i] : -1;
ret = vfio_msi_set_vector_signal(vdev, j, fd, msix); 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) ...@@ -524,7 +514,6 @@ static void vfio_msi_disable(struct vfio_pci_core_device *vdev, bool msix)
pci_intx(pdev, 0); pci_intx(pdev, 0);
vdev->irq_type = VFIO_PCI_NUM_IRQS; vdev->irq_type = VFIO_PCI_NUM_IRQS;
vdev->num_ctx = 0;
} }
/* /*
...@@ -659,7 +648,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev, ...@@ -659,7 +648,7 @@ static int vfio_pci_set_msi_trigger(struct vfio_pci_core_device *vdev,
return ret; return ret;
} }
if (!irq_is(vdev, index) || start + count > vdev->num_ctx) if (!irq_is(vdev, index))
return -EINVAL; return -EINVAL;
for (i = start; i < start + count; i++) { for (i = start; i < start + count; i++) {
......
...@@ -60,7 +60,6 @@ struct vfio_pci_core_device { ...@@ -60,7 +60,6 @@ struct vfio_pci_core_device {
spinlock_t irqlock; spinlock_t irqlock;
struct mutex igate; struct mutex igate;
struct xarray ctx; struct xarray ctx;
int num_ctx;
int irq_type; int irq_type;
int num_regions; int num_regions;
struct vfio_pci_region *region; struct vfio_pci_region *region;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment