[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v9 13/29] vfio: Introduce hostwin_from_range helper
From: |
Eric Auger |
Subject: |
[RFC v9 13/29] vfio: Introduce hostwin_from_range helper |
Date: |
Sun, 11 Apr 2021 14:08:56 +0200 |
Let's introduce a hostwin_from_range() helper that returns the
hostwin encapsulating an IOVA range or NULL if none is found.
This improves the readibility of callers and removes the usage
of hostwin_found.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
hw/vfio/common.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 30dc45df90..a8f835328e 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -649,6 +649,19 @@ out:
rcu_read_unlock();
}
+static VFIOHostDMAWindow *
+hostwin_from_range(VFIOContainer *container, hwaddr iova, hwaddr end)
+{
+ VFIOHostDMAWindow *hostwin;
+
+ QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next) {
+ if (hostwin->min_iova <= iova && end <= hostwin->max_iova) {
+ return hostwin;
+ }
+ }
+ return NULL;
+}
+
static void vfio_listener_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@@ -658,7 +671,6 @@ static void vfio_listener_region_add(MemoryListener
*listener,
void *vaddr;
int ret;
VFIOHostDMAWindow *hostwin;
- bool hostwin_found;
Error *err = NULL;
if (vfio_listener_skipped_section(section)) {
@@ -744,15 +756,8 @@ static void vfio_listener_region_add(MemoryListener
*listener,
#endif
}
- hostwin_found = false;
- QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next) {
- if (hostwin->min_iova <= iova && end <= hostwin->max_iova) {
- hostwin_found = true;
- break;
- }
- }
-
- if (!hostwin_found) {
+ hostwin = hostwin_from_range(container, iova, end);
+ if (!hostwin) {
error_setg(&err, "Container %p can't map guest IOVA region"
" 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx, container, iova, end);
goto fail;
@@ -934,16 +939,9 @@ static void vfio_listener_region_del(MemoryListener
*listener,
if (memory_region_is_ram_device(section->mr)) {
hwaddr pgmask;
- VFIOHostDMAWindow *hostwin;
- bool hostwin_found = false;
+ VFIOHostDMAWindow *hostwin = hostwin_from_range(container, iova, end);
- QLIST_FOREACH(hostwin, &container->hostwin_list, hostwin_next) {
- if (hostwin->min_iova <= iova && end <= hostwin->max_iova) {
- hostwin_found = true;
- break;
- }
- }
- assert(hostwin_found); /* or region_add() would have failed */
+ assert(hostwin); /* or region_add() would have failed */
pgmask = (1ULL << ctz64(hostwin->iova_pgsizes)) - 1;
try_unmap = !((iova & pgmask) || (int128_get64(llsize) & pgmask));
--
2.26.3
- [RFC v9 03/29] header update against 5.12-rc6 and IOMMU/VFIO nested stage APIs, (continued)
- [RFC v9 03/29] header update against 5.12-rc6 and IOMMU/VFIO nested stage APIs, Eric Auger, 2021/04/11
- [RFC v9 04/29] memory: Add new fields in IOTLBEntry, Eric Auger, 2021/04/11
- [RFC v9 05/29] hw/arm/smmuv3: Improve stage1 ASID invalidation, Eric Auger, 2021/04/11
- [RFC v9 06/29] hw/arm/smmu-common: Allow domain invalidation for NH_ALL/NSNH_ALL, Eric Auger, 2021/04/11
- [RFC v9 07/29] memory: Add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2021/04/11
- [RFC v9 09/29] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2021/04/11
- [RFC v9 08/29] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2021/04/11
- [RFC v9 10/29] iommu: Introduce generic header, Eric Auger, 2021/04/11
- [RFC v9 11/29] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2021/04/11
- [RFC v9 12/29] vfio: Force nested if iommu requires it, Eric Auger, 2021/04/11
- [RFC v9 13/29] vfio: Introduce hostwin_from_range helper,
Eric Auger <=
- [RFC v9 14/29] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2021/04/11
- [RFC v9 15/29] vfio: Set up nested stage mappings, Eric Auger, 2021/04/11
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Kunkun Jiang, 2021/04/13
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Auger Eric, 2021/04/13
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Kunkun Jiang, 2021/04/13
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Auger Eric, 2021/04/14
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Kunkun Jiang, 2021/04/14
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Auger Eric, 2021/04/26
- Re: [RFC v9 15/29] vfio: Set up nested stage mappings, Kunkun Jiang, 2021/04/28