[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 13/15] vfio/common: Extract vIOMMU code from vfio_sync_dirty_b
From: |
Joao Martins |
Subject: |
[PATCH v4 13/15] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap() |
Date: |
Thu, 22 Jun 2023 22:48:43 +0100 |
From: Avihai Horon <avihaih@nvidia.com>
Extract vIOMMU code from vfio_sync_dirty_bitmap() to a new function and
restructure the code.
This is done in preparation for optimizing vIOMMU deviice dirty page
tracking. No functional changes intended.
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
hw/vfio/common.c | 63 +++++++++++++++++++++++++++++-------------------
1 file changed, 38 insertions(+), 25 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 85fddef24026..c530e9d87f21 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1914,37 +1914,50 @@ static int
vfio_sync_ram_discard_listener_dirty_bitmap(VFIOContainer *container,
&vrdl);
}
+static int vfio_sync_iommu_dirty_bitmap(VFIOContainer *container,
+ MemoryRegionSection *section)
+{
+ VFIOGuestIOMMU *giommu;
+ bool found = false;
+ Int128 llend;
+ vfio_giommu_dirty_notifier gdn;
+ int idx;
+
+ QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) {
+ if (MEMORY_REGION(giommu->iommu_mr) == section->mr &&
+ giommu->n.start == section->offset_within_region) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ return 0;
+ }
+
+ gdn.giommu = giommu;
+ idx = memory_region_iommu_attrs_to_index(giommu->iommu_mr,
+ MEMTXATTRS_UNSPECIFIED);
+
+ llend = int128_add(int128_make64(section->offset_within_region),
+ section->size);
+ llend = int128_sub(llend, int128_one());
+
+ iommu_notifier_init(&gdn.n, vfio_iommu_map_dirty_notify,
IOMMU_NOTIFIER_MAP,
+ section->offset_within_region, int128_get64(llend),
+ idx);
+ memory_region_iommu_replay(giommu->iommu_mr, &gdn.n);
+
+ return 0;
+}
+
static int vfio_sync_dirty_bitmap(VFIOContainer *container,
MemoryRegionSection *section)
{
ram_addr_t ram_addr;
if (memory_region_is_iommu(section->mr)) {
- VFIOGuestIOMMU *giommu;
-
- QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) {
- if (MEMORY_REGION(giommu->iommu_mr) == section->mr &&
- giommu->n.start == section->offset_within_region) {
- Int128 llend;
- vfio_giommu_dirty_notifier gdn = { .giommu = giommu };
- int idx = memory_region_iommu_attrs_to_index(giommu->iommu_mr,
- MEMTXATTRS_UNSPECIFIED);
-
- llend =
int128_add(int128_make64(section->offset_within_region),
- section->size);
- llend = int128_sub(llend, int128_one());
-
- iommu_notifier_init(&gdn.n,
- vfio_iommu_map_dirty_notify,
- IOMMU_NOTIFIER_MAP,
- section->offset_within_region,
- int128_get64(llend),
- idx);
- memory_region_iommu_replay(giommu->iommu_mr, &gdn.n);
- break;
- }
- }
- return 0;
+ return vfio_sync_iommu_dirty_bitmap(container, section);
} else if (memory_region_has_ram_discard_manager(section->mr)) {
return vfio_sync_ram_discard_listener_dirty_bitmap(container, section);
}
--
2.17.2
- [PATCH v4 03/15] hw/pci: Introduce pci_device_iommu_get_attr(), (continued)
- [PATCH v4 03/15] hw/pci: Introduce pci_device_iommu_get_attr(), Joao Martins, 2023/06/22
- [PATCH v4 04/15] intel-iommu: Switch to pci_setup_iommu_ops(), Joao Martins, 2023/06/22
- [PATCH v4 05/15] memory/iommu: Add IOMMU_ATTR_DMA_TRANSLATION attribute, Joao Martins, 2023/06/22
- [PATCH v4 06/15] intel-iommu: Implement get_attr() method, Joao Martins, 2023/06/22
- [PATCH v4 07/15] vfio/common: Track whether DMA Translation is enabled on the vIOMMU, Joao Martins, 2023/06/22
- [PATCH v4 08/15] vfio/common: Relax vIOMMU detection when DMA translation is off, Joao Martins, 2023/06/22
- [PATCH v4 09/15] memory/iommu: Add IOMMU_ATTR_MAX_IOVA attribute, Joao Martins, 2023/06/22
- [PATCH v4 10/15] intel-iommu: Implement IOMMU_ATTR_MAX_IOVA get_attr() attribute, Joao Martins, 2023/06/22
- [PATCH v4 11/15] vfio/common: Move dirty tracking ranges update to helper, Joao Martins, 2023/06/22
- [PATCH v4 14/15] vfio/common: Optimize device dirty page tracking with vIOMMU, Joao Martins, 2023/06/22
- [PATCH v4 13/15] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap(),
Joao Martins <=
- [PATCH v4 15/15] vfio/common: Block migration with vIOMMUs without address width limits, Joao Martins, 2023/06/22
- [PATCH v4 12/15] vfio/common: Support device dirty page tracking with vIOMMU, Joao Martins, 2023/06/22
- Re: [PATCH v4 00/15] vfio: VFIO migration support with vIOMMU, Joao Martins, 2023/06/22