[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v4 15/29] vfio: Introduce hostwin_from_range helper
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC v4 15/29] vfio: Introduce hostwin_from_range helper |
Date: |
Thu, 11 Jul 2019 19:28:31 +0200 |
Let's introduce a hostwin_from_range() helper that returns the
hostwin encapsulating an IOVA range or NULL if non is found.
This improves the readibility of callers and removes the usage
of hostwin_found.
Signed-off-by: Eric Auger <address@hidden>
---
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 46a1a089a4..81d29ce908 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -497,6 +497,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)
{
@@ -506,7 +519,6 @@ static void vfio_listener_region_add(MemoryListener
*listener,
void *vaddr;
int ret;
VFIOHostDMAWindow *hostwin;
- bool hostwin_found;
if (vfio_listener_skipped_section(section)) {
trace_vfio_listener_region_add_skip(
@@ -583,15 +595,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_report("vfio: IOMMU container %p can't map guest IOVA region"
" 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx,
container, iova, end);
@@ -763,16 +768,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.20.1
- [Qemu-devel] [RFC v4 04/29] hw/arm/smmuv3: Log a guest error when decoding an invalid STE, (continued)
- [Qemu-devel] [RFC v4 04/29] hw/arm/smmuv3: Log a guest error when decoding an invalid STE, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 06/29] update-linux-headers: Import iommu.h, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 07/29] update-linux-headers: Add sve_context.h to asm-arm64, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 08/29] header update against 5.3.0-rc0 and IOMMU/VFIO nested stage APIs, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 09/29] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 10/29] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 11/29] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 12/29] iommu: Introduce generic header, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 13/29] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 14/29] vfio: Force nested if iommu requires it, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 15/29] vfio: Introduce hostwin_from_range helper,
Eric Auger <=
- [Qemu-devel] [RFC v4 16/29] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 17/29] vfio: Set up nested stage mappings, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 18/29] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 19/29] vfio: Helper to get IRQ info including capabilities, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 20/29] vfio/pci: Register handler for iommu fault, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 21/29] vfio/pci: Set up the DMA FAULT region, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 22/29] vfio/pci: Implement the DMA fault handler, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 23/29] hw/arm/smmuv3: Advertise MSI_TRANSLATE attribute, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 24/29] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2019/07/11
- [Qemu-devel] [RFC v4 25/29] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2019/07/11