[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/10] vfio: Avoid disabling and enabling vectors repeatedly in VF
From: |
Alex Williamson |
Subject: |
[PULL 08/10] vfio: Avoid disabling and enabling vectors repeatedly in VFIO migration |
Date: |
Tue, 16 Mar 2021 11:07:29 -0600 |
User-agent: |
StGit/0.23 |
From: Shenming Lu <lushenming@huawei.com>
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>
---
hw/vfio/pci.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 759a3b1abf4b..5c65aa0a98e2 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -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);
@@ -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");
}
- [PULL 00/10] VFIO updates for QEMU 6.0, Alex Williamson, 2021/03/16
- [PULL 01/10] vfio: Fix vfio_listener_log_sync function name typo, Alex Williamson, 2021/03/16
- [PULL 02/10] hw/vfio/pci-quirks: Replace the word 'blacklist', Alex Williamson, 2021/03/16
- [PULL 03/10] MAINTAINERS: Cover docs/igd-assign.txt in VFIO section, Alex Williamson, 2021/03/16
- [PULL 04/10] vfio: Do not register any IOMMU_NOTIFIER_DEVIOTLB_UNMAP notifier, Alex Williamson, 2021/03/16
- [PULL 05/10] spapr_iommu: Fix vhost integration regression, Alex Williamson, 2021/03/16
- [PULL 06/10] vfio: Move the saving of the config space to the right place in VFIO migration, Alex Williamson, 2021/03/16
- [PULL 07/10] vfio: Set the priority of the VFIO VM state change handler explicitly, Alex Williamson, 2021/03/16
- [PULL 08/10] vfio: Avoid disabling and enabling vectors repeatedly in VFIO migration,
Alex Williamson <=
- [PULL 09/10] vfio: Support host translation granule size, Alex Williamson, 2021/03/16
- [PULL 10/10] vfio/migrate: Move switch of dirty tracking into vfio_memory_listener, Alex Williamson, 2021/03/16
- Re: [PULL 00/10] VFIO updates for QEMU 6.0, Peter Maydell, 2021/03/17