mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
vfio/pci: enable vector on dynamic MSI-X allocation
The vector_use callback is used to enable vector that is unmasked in guest. The kernel used to only support static MSI-X allocation. When allocating a new interrupt using "static MSI-X allocation" kernels, QEMU first disables all previously allocated vectors and then re-allocates all including the new one. The nr_vectors of VFIOPCIDevice indicates that all vectors from 0 to nr_vectors are allocated (and may be enabled), which is used to loop all the possibly used vectors when e.g., disabling MSI-X interrupts. Extend the vector_use function to support dynamic MSI-X allocation when host supports the capability. QEMU therefore can individually allocate and enable a new interrupt without affecting others or causing interrupts lost during runtime. Utilize nr_vectors to calculate the upper bound of enabled vectors in dynamic MSI-X allocation mode since looping all msix_entries_nr is not efficient and unnecessary. Signed-off-by: Jing Liu <jing2.liu@intel.com> Tested-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
45d85f6228
commit
d9e6710d7d
1 changed files with 28 additions and 18 deletions
|
@ -470,6 +470,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
||||||
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
||||||
VFIOMSIVector *vector;
|
VFIOMSIVector *vector;
|
||||||
int ret;
|
int ret;
|
||||||
|
bool resizing = !!(vdev->nr_vectors < nr + 1);
|
||||||
|
|
||||||
trace_vfio_msix_vector_do_use(vdev->vbasedev.name, nr);
|
trace_vfio_msix_vector_do_use(vdev->vbasedev.name, nr);
|
||||||
|
|
||||||
|
@ -512,19 +513,27 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don't want to have the host allocate all possible MSI vectors
|
* When dynamic allocation is not supported, we don't want to have the
|
||||||
* for a device if they're not in use, so we shutdown and incrementally
|
* host allocate all possible MSI vectors for a device if they're not
|
||||||
* increase them as needed.
|
* in use, so we shutdown and incrementally increase them as needed.
|
||||||
|
* nr_vectors represents the total number of vectors allocated.
|
||||||
|
*
|
||||||
|
* When dynamic allocation is supported, let the host only allocate
|
||||||
|
* and enable a vector when it is in use in guest. nr_vectors represents
|
||||||
|
* the upper bound of vectors being enabled (but not all of the ranges
|
||||||
|
* is allocated or enabled).
|
||||||
*/
|
*/
|
||||||
if (vdev->nr_vectors < nr + 1) {
|
if (resizing) {
|
||||||
vdev->nr_vectors = nr + 1;
|
vdev->nr_vectors = nr + 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!vdev->defer_kvm_irq_routing) {
|
if (!vdev->defer_kvm_irq_routing) {
|
||||||
|
if (vdev->msix->noresize && resizing) {
|
||||||
vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
|
vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
|
||||||
ret = vfio_enable_vectors(vdev, true);
|
ret = vfio_enable_vectors(vdev, true);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_report("vfio: failed to enable vectors, %d", ret);
|
error_report("vfio: failed to enable vectors, %d", ret);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
int32_t fd;
|
int32_t fd;
|
||||||
|
@ -541,6 +550,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
||||||
error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
|
error_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable PBA emulation when nothing more is pending. */
|
/* Disable PBA emulation when nothing more is pending. */
|
||||||
clear_bit(nr, vdev->msix->pending);
|
clear_bit(nr, vdev->msix->pending);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue