Re: [PATCH 5/6] iommu: init pasid array while doing domain_replace and iopf is active

From: Joel Granados
Date: Fri Sep 13 2024 - 04:10:57 EST


On Thu, Sep 12, 2024 at 07:22:30PM +0800, Baolu Lu wrote:
> On 2024/9/12 16:25, Joel Granados wrote:
> > /**
> > * iommu_attach_group_handle - Attach an IOMMU domain to an IOMMU group
> > * @domain: IOMMU domain to attach
> > diff --git i/drivers/iommu/iommufd/fault.c w/drivers/iommu/iommufd/fault.c
> > index ea7f1bf64892..51cb70465b87 100644
> > --- i/drivers/iommu/iommufd/fault.c
> > +++ w/drivers/iommu/iommufd/fault.c
> > @@ -189,8 +189,15 @@ static int iommufd_init_pasid_array(struct iommu_domain *domain,
> > if (!handle)
> > return -ENOMEM;
> > handle->idev = idev;
> > + handle->handle.domain = domain;
> > +
> > + mutex_lock(&group->mutex);
> > + ret = xa_insert(&group->pasid_array, IOMMU_NO_PASID, handle, GFP_KERNEL);
> > + mutex_unlock(&group->mutex);
> > +
> > + if (ret == -EBUSY)
> > + ret = 0;
> >
> > - ret = iommu_init_pasid_array(domain, group, &handle->handle);
> > if (ret)
> > kfree(handle);
>
> This is supposed to be done automatically when an iopf capable domain is
> attached to or replaced with a device. Please refer to
> iommufd_fault_domain_attach_dev() and
> iommufd_fault_domain_replace_dev().
>
> Is there anything preventing this from happening?
Nope, You are correct. This does indeed happen through
iommufd_fault_domain_replace_dev
-> __fault_domain_replace_dev
-> iommu_replace_group_handle.

This was probably left from trying to do this outside the replace path.
Sorry for the noise; will remove it in V2.

Thx for the review

Best

--

Joel Granados