[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v2 08/28] hw/vfio/common: Force nested if iommu requir
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC v2 08/28] hw/vfio/common: Force nested if iommu requires it |
Date: |
Fri, 21 Sep 2018 10:17:59 +0200 |
In case we detect the address space is translated by
a virtual IOMMU which requires nested stages, let's set up
the container with the VFIO_TYPE1_NESTING_IOMMU iommu_type.
Signed-off-by: Eric Auger <address@hidden>
---
hw/vfio/common.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 53b8f773cc..1416892f1c 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1041,11 +1041,15 @@ static void vfio_put_address_space(VFIOAddressSpace
*space)
* nested only is selected if requested by @force_nested
*/
static int vfio_iommu_get_type(VFIOContainer *container,
- Error **errp)
+ bool force_nested, Error **errp)
{
int fd = container->fd;
- if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) {
+ if (force_nested &&
+ ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_NESTING_IOMMU)) {
+ /* NESTED implies v2 */
+ return VFIO_TYPE1_NESTING_IOMMU;
+ } else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) {
return VFIO_TYPE1v2_IOMMU;
} else if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU)) {
return VFIO_TYPE1_IOMMU;
@@ -1085,9 +1089,16 @@ static int vfio_connect_container(VFIOGroup *group,
AddressSpace *as,
VFIOContainer *container;
int ret, fd;
VFIOAddressSpace *space;
+ IOMMUMemoryRegion *iommu_mr;
int iommu_type;
+ bool force_nested = false;
bool v2 = false;
+ if (as != &address_space_memory && memory_region_is_iommu(as->root)) {
+ iommu_mr = IOMMU_MEMORY_REGION(as->root);
+ memory_region_iommu_get_attr(iommu_mr, IOMMU_ATTR_VFIO_NESTED,
+ (void *)&force_nested);
+ }
space = vfio_get_address_space(as);
@@ -1148,12 +1159,18 @@ static int vfio_connect_container(VFIOGroup *group,
AddressSpace *as,
QLIST_INIT(&container->giommu_list);
QLIST_INIT(&container->hostwin_list);
- iommu_type = vfio_iommu_get_type(container, errp);
+ iommu_type = vfio_iommu_get_type(container, force_nested, errp);
if (iommu_type < 0) {
goto free_container_exit;
}
+ if (force_nested && iommu_type != VFIO_TYPE1_NESTING_IOMMU) {
+ error_setg(errp, "nested mode requested by the virtual IOMMU "
+ "but not supported by the vfio iommu");
+ }
+
switch (iommu_type) {
+ case VFIO_TYPE1_NESTING_IOMMU:
case VFIO_TYPE1v2_IOMMU:
case VFIO_TYPE1_IOMMU:
{
--
2.17.1
- [Qemu-devel] [RFC v2 00/28] vSMMUv3/pSMMUv3 2 stage VFIO integration, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 01/28] hw/arm/smmu-common: Fix the name of the iommu memory regions, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 02/28] hw/arm/smmuv3: fix eventq recording and IRQ triggerring, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 05/28] memory: add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 04/28] linux-headers: Partial header update, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 03/28] update-linux-headers: Import iommu.h, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 06/28] hw/arm/smmuv3: Implement get_attr API to report IOMMU_ATTR_VFIO_NESTED, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 07/28] hw/vfio/common: Refactor container initialization, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 08/28] hw/vfio/common: Force nested if iommu requires it,
Eric Auger <=
- [Qemu-devel] [RFC v2 09/28] memory: Introduce IOMMUIOLTBNotifier, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 10/28] memory: rename memory_region notify_iommu, notify_one, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 11/28] memory: Add IOMMUConfigNotifier, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 13/28] hw/arm/smmuv3: Store s1ctrptr in translation config data, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 12/28] memory: Add arch_id in IOTLBEntry, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 14/28] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 16/28] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 15/28] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 17/28] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper, Eric Auger, 2018/09/21
- [Qemu-devel] [RFC v2 18/28] hw/vfio/common: Introduce vfio_dma_(un)map_ram_section helpers, Eric Auger, 2018/09/21