[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-arm] [RFC v4 08/27] hw/vfio/common: Force nested if iommu requ
From: |
Peter Xu |
Subject: |
Re: [Qemu-arm] [RFC v4 08/27] hw/vfio/common: Force nested if iommu requires it |
Date: |
Tue, 28 May 2019 10:47:47 +0800 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Mon, May 27, 2019 at 01:41:44PM +0200, Eric Auger wrote:
> 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>
>
> ---
>
> v2 -> v3:
> - add "nested only is selected if requested by @force_nested"
> comment in this patch
> ---
> hw/vfio/common.c | 27 +++++++++++++++++++++++----
> 1 file changed, 23 insertions(+), 4 deletions(-)
>
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 1f1deff360..99ade21056 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -1136,14 +1136,19 @@ 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 force_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;
>
> for (i = 0; i < ARRAY_SIZE(iommu_types); i++) {
> if (ioctl(container->fd, VFIO_CHECK_EXTENSION, iommu_types[i])) {
> + if (iommu_types[i] == VFIO_TYPE1_NESTING_IOMMU && !force_nested)
> {
If force_nested==true and if the kernel does not support
VFIO_TYPE1_NESTING_IOMMU, we will still return other iommu types?
That seems to not match with what "force" mean here.
What I feel like is that we want an "iommu_nest_types[]" which only
contains VFIO_TYPE1_NESTING_IOMMU. Then:
if (nested) {
target_types = iommu_nest_types;
} else {
target_types = iommu_types;
}
foreach (target_types)
...
return -EINVAL;
Might be clearer? Then we can drop [2] below since we'll fail earlier
at [1].
> + continue;
> + }
> return iommu_types[i];
> }
> }
> @@ -1152,11 +1157,11 @@ static int vfio_get_iommu_type(VFIOContainer
> *container,
> }
>
> static int vfio_init_container(VFIOContainer *container, int group_fd,
> - Error **errp)
> + bool force_nested, Error **errp)
> {
> int iommu_type, ret;
>
> - iommu_type = vfio_get_iommu_type(container, errp);
> + iommu_type = vfio_get_iommu_type(container, force_nested, errp);
> if (iommu_type < 0) {
> return iommu_type;
[1]
> }
> @@ -1192,6 +1197,14 @@ static int vfio_connect_container(VFIOGroup *group,
> AddressSpace *as,
> VFIOContainer *container;
> int ret, fd;
> VFIOAddressSpace *space;
> + IOMMUMemoryRegion *iommu_mr;
> + bool force_nested = 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);
>
> @@ -1252,12 +1265,18 @@ 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, force_nested, errp);
> if (ret) {
> goto free_container_exit;
> }
>
> + if (force_nested && container->iommu_type != VFIO_TYPE1_NESTING_IOMMU) {
> + error_setg(errp, "nested mode requested by the virtual IOMMU "
> + "but not supported by the vfio iommu");
> + }
[2]
> +
> switch (container->iommu_type) {
> + case VFIO_TYPE1_NESTING_IOMMU:
> case VFIO_TYPE1v2_IOMMU:
> case VFIO_TYPE1_IOMMU:
> {
> --
> 2.20.1
>
Regards,
--
Peter Xu
- [Qemu-arm] [RFC v4 00/27] vSMMUv3/pSMMUv3 2 stage VFIO integration, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 01/27] vfio/common: Introduce vfio_set_irq_signaling helper, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 02/27] update-linux-headers: Import iommu.h, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 03/27] update-linux-headers: Add sve_context.h to asm-arm64, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 04/27] header update against 5.2.0-rc1 and IOMMU/VFIO nested stage APIs, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 05/27] memory: add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 06/27] memory: add IOMMU_ATTR_MSI_TRANSLATE IOMMU memory region attribute, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 07/27] hw/arm/smmuv3: Advertise VFIO_NESTED and MSI_TRANSLATE attributes, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 08/27] hw/vfio/common: Force nested if iommu requires it, Eric Auger, 2019/05/27
- Re: [Qemu-arm] [RFC v4 08/27] hw/vfio/common: Force nested if iommu requires it,
Peter Xu <=
- [Qemu-arm] [RFC v4 09/27] memory: Prepare for different kinds of IOMMU MR notifiers, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 10/27] memory: Add IOMMUConfigNotifier, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 11/27] memory: Add arch_id and leaf fields in IOTLBEntry, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 12/27] hw/arm/smmuv3: Store the PASID table GPA in the translation config, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 13/27] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 14/27] hw/arm/smmuv3: Fill the IOTLBEntry arch_id on NH_VA invalidation, Eric Auger, 2019/05/27
- [Qemu-arm] [RFC v4 15/27] hw/arm/smmuv3: Fill the IOTLBEntry leaf field on NH_VA invalidation, Eric Auger, 2019/05/27