On Wed, 2022-05-18 at 16:14 -0300, Jason Gunthorpe wrote:
> On Wed, May 18, 2022 at 02:50:36PM -0400, Eric Farman wrote:
> 
> > I got a heads up from Matt about the s390 KVM vfio- variants
> > failing on
> > linux-next.
> > 
> > For vfio-ap and vfio-ccw, they fail on the above error. Both calls
> > to
> > __iommu_domain_alloc fail because while dev->dev->bus is non-NULL
> > (it
> > points to the mdev bus_type registered in mdev_init()), the bus-
> > > iommu_ops pointer is NULL. Which makes sense; the iommu_group is
> > > vfio-
> > noiommu, via vfio_register_emulated_iommu_dev(), and mdev didn't
> > establish an iommu_ops for its bus.
> 
> Oh, I think this is a VFIO problem, the iommu layer should not have
> to
> deal with these fake non-iommu groups.
> 
> From 9884850a5ceac957e6715beab0888294d4088877 Mon Sep 17 00:00:00
> 2001
> From: Jason Gunthorpe <j...@nvidia.com>
> Date: Wed, 18 May 2022 16:03:34 -0300
> Subject: [PATCH] vfio: Do not manipulate iommu dma_owner for fake
> iommu groups
> 
> Since asserting dma ownership now causes the group to have its DMA
> blocked
> the iommu layer requires a working iommu. This means the dma_owner
> APIs
> cannot be used on the fake groups that VFIO creates. Test for this
> and
> avoid calling them.
> 
> Otherwise asserting dma ownership will fail for VFIO mdev devices as
> a
> BLOCKING iommu_domain cannot be allocated due to the NULL iommu ops.
> 
> Fixes: 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must
> always assign a domain")
> Reported-by: Eric Farman <far...@linux.ibm.com>
> Signed-off-by: Jason Gunthorpe <j...@nvidia.com>

Ah, nice. That takes care of it for me, thank you!

Tested-by: Eric Farman <far...@linux.ibm.com>

> ---
>  drivers/vfio/vfio.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> I think this will have to go through Alex's tree due to all the other
> rework
> in this area.
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index cfcff7764403fc..f5ed03897210c3 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -927,7 +927,8 @@ static void __vfio_group_unset_container(struct
> vfio_group *group)
>               driver->ops->detach_group(container->iommu_data,
>                                         group->iommu_group);
>  
> -     iommu_group_release_dma_owner(group->iommu_group);
> +     if (group->type == VFIO_IOMMU)
> +             iommu_group_release_dma_owner(group->iommu_group);
>  
>       group->container = NULL;
>       group->container_users = 0;
> @@ -1001,9 +1002,11 @@ static int vfio_group_set_container(struct
> vfio_group *group, int container_fd)
>               goto unlock_out;
>       }
>  
> -     ret = iommu_group_claim_dma_owner(group->iommu_group, f.file);
> -     if (ret)
> -             goto unlock_out;
> +     if (group->type == VFIO_IOMMU) {
> +             ret = iommu_group_claim_dma_owner(group->iommu_group,
> f.file);
> +             if (ret)
> +                     goto unlock_out;
> +     }
>  
>       driver = container->iommu_driver;
>       if (driver) {
> @@ -1011,7 +1014,9 @@ static int vfio_group_set_container(struct
> vfio_group *group, int container_fd)
>                                               group->iommu_group,
>                                               group->type);
>               if (ret) {
> -                     iommu_group_release_dma_owner(group-
> >iommu_group);
> +                     if (group->type == VFIO_IOMMU)
> +                             iommu_group_release_dma_owner(
> +                                     group->iommu_group);
>                       goto unlock_out;
>               }
>       }

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to