Skip to content

Commit

Permalink
vfio: Avoid disabling and enabling vectors repeatedly in VFIO migration
Browse files Browse the repository at this point in the history
In VFIO migration resume phase and some guest startups, there are
already unmasked vectors in the vector table when calling
vfio_msix_enable(). So in order to avoid inefficiently disabling
and enabling vectors repeatedly, let's allocate all needed vectors
first and then enable these unmasked vectors one by one without
disabling.

Signed-off-by: Shenming Lu <lushenming@huawei.com>
Message-Id: <20210310030233.1133-4-lushenming@huawei.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
Shenming Lu authored and awilliam committed Mar 16, 2021
1 parent 8ce1ff9 commit ecebe53
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions hw/vfio/pci.c
Expand Up @@ -569,6 +569,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)

static void vfio_msix_enable(VFIOPCIDevice *vdev)
{
PCIDevice *pdev = &vdev->pdev;
unsigned int nr, max_vec = 0;

vfio_disable_interrupts(vdev);

vdev->msi_vectors = g_new0(VFIOMSIVector, vdev->msix->entries);
Expand All @@ -587,11 +590,22 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev)
* triggering to userspace, then immediately release the vector, leaving
* the physical device with no vectors enabled, but MSI-X enabled, just
* like the guest view.
* If there are already unmasked vectors (in migration resume phase and
* some guest startups) which will be enabled soon, we can allocate all
* of them here to avoid inefficiently disabling and enabling vectors
* repeatedly later.
*/
vfio_msix_vector_do_use(&vdev->pdev, 0, NULL, NULL);
vfio_msix_vector_release(&vdev->pdev, 0);
if (!pdev->msix_function_masked) {
for (nr = 0; nr < msix_nr_vectors_allocated(pdev); nr++) {
if (!msix_is_masked(pdev, nr)) {
max_vec = nr;
}
}
}
vfio_msix_vector_do_use(pdev, max_vec, NULL, NULL);
vfio_msix_vector_release(pdev, max_vec);

if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use,
if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use,
vfio_msix_vector_release, NULL)) {
error_report("vfio: msix_set_vector_notifiers failed");
}
Expand Down

0 comments on commit ecebe53

Please sign in to comment.