[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 18/27] hw/vfio/common: Introduce hostwin_from_range
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC v3 18/27] hw/vfio/common: Introduce hostwin_from_range helper |
Date: |
Fri, 12 Apr 2019 12:03:45 +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 | 37 ++++++++++++++++++-------------------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index cf876d5264..785d9c191c 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -494,6 +494,19 @@ static VFIOGuestIOMMU
*vfio_alloc_guest_iommu(VFIOContainer *container,
return giommu;
}
+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)
{
@@ -503,7 +516,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(
@@ -580,15 +592,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);
@@ -759,16 +764,10 @@ 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 v3 08/27] hw/vfio/common: Force nested if iommu requires it, (continued)
- [Qemu-devel] [RFC v3 08/27] hw/vfio/common: Force nested if iommu requires it, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 09/27] memory: Prepare for different kinds of IOMMU MR notifiers, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 10/27] memory: Add IOMMUConfigNotifier, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 12/27] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 11/27] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 13/27] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 14/27] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 15/27] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 16/27] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 17/27] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 18/27] hw/vfio/common: Introduce hostwin_from_range helper,
Eric Auger <=
- [Qemu-devel] [RFC v3 19/27] hw/vfio/common: Introduce helpers to DMA map/unap a RAM section, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 20/27] hw/vfio/common: Setup nested stage mappings, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 21/27] hw/vfio/common: Register a MAP notifier for MSI binding, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 22/27] vfio-pci: Expose MSI stage 1 bindings to the host, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 23/27] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 24/27] hw/arm/smmuv3: Implement fault injection, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 25/27] vfio-pci: register handler for iommu fault, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 26/27] vfio-pci: Set up fault regions, Eric Auger, 2019/04/12
- [Qemu-devel] [RFC v3 27/27] vfio-pci: Implement the DMA fault handler, Eric Auger, 2019/04/12
- Re: [Qemu-devel] [RFC v3 00/27] vSMMUv3/pSMMUv3 2 stage VFIO integration, no-reply, 2019/04/12