[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v4 17/27] hw/vfio/common: Introduce vfio_alloc_guest_i
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC v4 17/27] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper |
Date: |
Mon, 27 May 2019 13:41:53 +0200 |
Soon this code will be called several times. So let's introduce
an helper.
Signed-off-by: Eric Auger <address@hidden>
---
hw/vfio/common.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 75fb568f95..7df8b92563 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -24,6 +24,7 @@
#include <linux/kvm.h>
#endif
#include <linux/vfio.h>
+#include <linux/iommu.h>
#include "hw/vfio/vfio-common.h"
#include "hw/vfio/vfio.h"
@@ -497,6 +498,19 @@ out:
rcu_read_unlock();
}
+static VFIOGuestIOMMU *vfio_alloc_guest_iommu(VFIOContainer *container,
+ IOMMUMemoryRegion *iommu,
+ hwaddr offset)
+{
+ VFIOGuestIOMMU *giommu = g_new0(VFIOGuestIOMMU, 1);
+
+ giommu->container = container;
+ giommu->iommu = iommu;
+ giommu->iommu_offset = offset;
+ /* notifier will be registered separately */
+ return giommu;
+}
+
static void vfio_listener_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@@ -604,6 +618,7 @@ static void vfio_listener_region_add(MemoryListener
*listener,
if (memory_region_is_iommu(section->mr)) {
VFIOGuestIOMMU *giommu;
IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
+ hwaddr offset;
int iommu_idx;
trace_vfio_listener_region_add_iommu(iova, end);
@@ -613,11 +628,11 @@ static void vfio_listener_region_add(MemoryListener
*listener,
* would be the right place to wire that up (tell the KVM
* device emulation the VFIO iommu handles to use).
*/
- giommu = g_malloc0(sizeof(*giommu));
- giommu->iommu = iommu_mr;
- giommu->iommu_offset = section->offset_within_address_space -
- section->offset_within_region;
- giommu->container = container;
+
+ offset = section->offset_within_address_space -
+ section->offset_within_region;
+ giommu = vfio_alloc_guest_iommu(container, iommu_mr, offset);
+
llend = int128_add(int128_make64(section->offset_within_region),
section->size);
llend = int128_sub(llend, int128_one());
--
2.20.1
- [Qemu-devel] [RFC v4 07/27] hw/arm/smmuv3: Advertise VFIO_NESTED and MSI_TRANSLATE attributes, (continued)
- [Qemu-devel] [RFC v4 07/27] hw/arm/smmuv3: Advertise VFIO_NESTED and MSI_TRANSLATE attributes, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 08/27] hw/vfio/common: Force nested if iommu requires it, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 09/27] memory: Prepare for different kinds of IOMMU MR notifiers, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 10/27] memory: Add IOMMUConfigNotifier, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 11/27] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 12/27] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 13/27] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 14/27] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 15/27] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 16/27] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 17/27] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper,
Eric Auger <=
- [Qemu-devel] [RFC v4 18/27] hw/vfio/common: Introduce hostwin_from_range helper, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 19/27] hw/vfio/common: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 20/27] hw/vfio/common: Setup nested stage mappings, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 21/27] hw/vfio/common: Register a MAP notifier for MSI binding, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 22/27] vfio-pci: Expose MSI stage 1 bindings to the host, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 23/27] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 26/27] vfio-pci: Set up fault regions, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 27/27] vfio-pci: Implement the DMA fault handler, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 25/27] vfio-pci: register handler for iommu fault, Eric Auger, 2019/05/27
- [Qemu-devel] [RFC v4 24/27] hw/arm/smmuv3: Implement fault injection, Eric Auger, 2019/05/27