[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v8 11/28] vfio: Force nested if iommu requires it
From: |
Eric Auger |
Subject: |
[RFC v8 11/28] vfio: Force nested if iommu requires it |
Date: |
Thu, 25 Feb 2021 11:52:16 +0100 |
In case we detect the address space is translated by
a virtual IOMMU which requires HW nested paging to
integrate with VFIO, let's set up the container with
the VFIO_TYPE1_NESTING_IOMMU iommu_type.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v7 -> v8
- remove as != &address_space_memory as
memory_region_is_iommu(as->root) is sufficient [Kunkun]
v4 -> v5:
- fail immediatly if nested is wanted but not supported
v2 -> v3:
- add "nested only is selected if requested by @force_nested"
comment in this patch
---
hw/vfio/common.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index fcf2c5049f..04e5699ccf 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1546,27 +1546,38 @@ static void vfio_put_address_space(VFIOAddressSpace
*space)
* vfio_get_iommu_type - selects the richest iommu_type (v2 first)
*/
static int vfio_get_iommu_type(VFIOContainer *container,
+ bool want_nested,
Error **errp)
{
- int iommu_types[] = { VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU,
+ int iommu_types[] = { VFIO_TYPE1_NESTING_IOMMU,
+ VFIO_TYPE1v2_IOMMU, VFIO_TYPE1_IOMMU,
VFIO_SPAPR_TCE_v2_IOMMU, VFIO_SPAPR_TCE_IOMMU };
- int i;
+ int i, ret = -EINVAL;
for (i = 0; i < ARRAY_SIZE(iommu_types); i++) {
if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) {
- return iommu_types[i];
+ if (iommu_types[i] == VFIO_TYPE1_NESTING_IOMMU && !want_nested) {
+ continue;
+ }
+ ret = iommu_types[i];
+ break;
}
}
- error_setg(errp, "No available IOMMU models");
- return -EINVAL;
+ if (ret < 0) {
+ error_setg(errp, "No available IOMMU models");
+ } else if (want_nested && ret != VFIO_TYPE1_NESTING_IOMMU) {
+ error_setg(errp, "Nested mode requested but not supported");
+ ret = -EINVAL;
+ }
+ return ret;
}
static int vfio_init_container(VFIOContainer *container, int group_fd,
- Error **errp)
+ bool want_nested, Error **errp)
{
int iommu_type, ret;
- iommu_type = vfio_get_iommu_type(container, errp);
+ iommu_type = vfio_get_iommu_type(container, want_nested, errp);
if (iommu_type < 0) {
return iommu_type;
}
@@ -1671,6 +1682,14 @@ static int vfio_connect_container(VFIOGroup *group,
AddressSpace *as,
VFIOContainer *container;
int ret, fd;
VFIOAddressSpace *space;
+ IOMMUMemoryRegion *iommu_mr;
+ bool nested = false;
+
+ if (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 *)&nested);
+ }
space = vfio_get_address_space(as);
@@ -1740,13 +1759,14 @@ static int vfio_connect_container(VFIOGroup *group,
AddressSpace *as,
QLIST_INIT(&container->giommu_list);
QLIST_INIT(&container->hostwin_list);
- ret = vfio_init_container(container, group->fd, errp);
+ ret = vfio_init_container(container, group->fd, nested, errp);
if (ret) {
goto free_container_exit;
}
trace_vfio_connect_new_container(group->groupid, container->fd);
switch (container->iommu_type) {
+ case VFIO_TYPE1_NESTING_IOMMU:
case VFIO_TYPE1v2_IOMMU:
case VFIO_TYPE1_IOMMU:
{
--
2.26.2
- [RFC v8 01/28] hw/vfio/common: trace vfio_connect_container operations, (continued)
- [RFC v8 01/28] hw/vfio/common: trace vfio_connect_container operations, Eric Auger, 2021/02/25
- [RFC v8 02/28] update-linux-headers: Import iommu.h, Eric Auger, 2021/02/25
- [RFC v8 03/28] header update against 5.11-rc2 and IOMMU/VFIO nested stage APIs, Eric Auger, 2021/02/25
- [RFC v8 05/28] hw/arm/smmuv3: Properly propagate S1 asid invalidation, Eric Auger, 2021/02/25
- [RFC v8 04/28] memory: Add new fields in IOTLBEntry, Eric Auger, 2021/02/25
- [RFC v8 06/28] memory: Add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2021/02/25
- [RFC v8 07/28] memory: Add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2021/02/25
- [RFC v8 08/28] memory: Introduce IOMMU Memory Region inject_faults API, Eric Auger, 2021/02/25
- [RFC v8 09/28] iommu: Introduce generic header, Eric Auger, 2021/02/25
- [RFC v8 10/28] pci: introduce PCIPASIDOps to PCIDevice, Eric Auger, 2021/02/25
- [RFC v8 11/28] vfio: Force nested if iommu requires it,
Eric Auger <=
- [RFC v8 12/28] vfio: Introduce hostwin_from_range helper, Eric Auger, 2021/02/25
- [RFC v8 13/28] vfio: Introduce helpers to DMA map/unmap a RAM section, Eric Auger, 2021/02/25
- [RFC v8 14/28] vfio: Set up nested stage mappings, Eric Auger, 2021/02/25
- [RFC v8 15/28] vfio: Pass stage 1 MSI bindings to the host, Eric Auger, 2021/02/25
- [RFC v8 16/28] vfio: Helper to get IRQ info including capabilities, Eric Auger, 2021/02/25
- [RFC v8 17/28] vfio/pci: Register handler for iommu fault, Eric Auger, 2021/02/25
- [RFC v8 18/28] vfio/pci: Set up the DMA FAULT region, Eric Auger, 2021/02/25
- [RFC v8 19/28] vfio/pci: Implement the DMA fault handler, Eric Auger, 2021/02/25
- [RFC v8 20/28] hw/arm/smmuv3: Advertise MSI_TRANSLATE attribute, Eric Auger, 2021/02/25
- [RFC v8 21/28] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2021/02/25