[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 14/20] vfio/common: Extract vIOMMU code from vfio_sync_dirty_b
From: |
Avihai Horon |
Subject: |
[PATCH v2 14/20] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap() |
Date: |
Wed, 22 Feb 2023 19:49:09 +0200 |
Extract vIOMMU code from vfio_sync_dirty_bitmap() to a new function and
restructure the code.
This is done as preparation for the following patches which will add
vIOMMU support to device dirty page tracking. No functional changes
intended.
Signed-off-by: Avihai Horon <avihaih@nvidia.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 797eb2c26e..4a7fff6eeb 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1866,37 +1866,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.26.3
- Re: [PATCH v2 11/20] vfio/common: Add device dirty page tracking start/stop, (continued)
- [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Avihai Horon, 2023/02/22
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Alex Williamson, 2023/02/22
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Joao Martins, 2023/02/23
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Alex Williamson, 2023/02/23
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Joao Martins, 2023/02/23
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Alex Williamson, 2023/02/23
- Re: [PATCH v2 10/20] vfio/common: Record DMA mapped IOVA ranges, Joao Martins, 2023/02/23
[PATCH v2 12/20] vfio/common: Extract code from vfio_get_dirty_bitmap() to new function, Avihai Horon, 2023/02/22
[PATCH v2 14/20] vfio/common: Extract vIOMMU code from vfio_sync_dirty_bitmap(),
Avihai Horon <=
[PATCH v2 13/20] vfio/common: Add device dirty page bitmap sync, Avihai Horon, 2023/02/22
[PATCH v2 15/20] memory/iommu: Add IOMMU_ATTR_MAX_IOVA attribute, Avihai Horon, 2023/02/22
[PATCH v2 16/20] intel-iommu: Implement get_attr() method, Avihai Horon, 2023/02/22
[PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Avihai Horon, 2023/02/22
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Alex Williamson, 2023/02/22
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Jason Gunthorpe, 2023/02/22
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Alex Williamson, 2023/02/23
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Jason Gunthorpe, 2023/02/23
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Joao Martins, 2023/02/23
- Re: [PATCH v2 17/20] vfio/common: Support device dirty page tracking with vIOMMU, Alex Williamson, 2023/02/23