RE: [RFC 2/8] iommufd: replace attach_fn with a structure

Tian, Kevin
2023-09-27T04:22:04Z

> From: Baolu Lu <baolu.lu@linux.intel.com>
> Sent: Wednesday, September 27, 2023 10:18 AM
>
> On 9/26/23 5:26 PM, Yi Liu wrote:
> >
> > -typedef struct iommufd_hw_pagetable *(*attach_fn)(
> > - struct iommufd_device *idev, struct iommufd_hw_pagetable *hwpt);
> > +static struct iommufd_hw_pagetable *do_attach(struct iommufd_device
> *idev,
> > + struct iommufd_hw_pagetable *hwpt, struct attach_data
> *data)
> > +{
> > + return data->attach_fn(idev, hwpt);
> > +}
>
> I assume that this change was made because we need to pass the pasid
> value to the attach_fn() callback.
>
> If so, how about passing it directly to attach_fn() function?
>
> typedef struct iommufd_hw_pagetable *(*attach_fn)(
> struct iommufd_device *idev,
> struct iommufd_hw_pagetable *hwpt,
> ioasid_t pasid);
>
> In no pasid case, use IOMMU_NO_PASID.
>

that is one option, but also means the existing device attach_fn() needs
to accept an unused pasid parameter which doesn't read good.

So this patch chooses to handle the pasid necessity in an outer wrapper
and contain the pasid awareness only in pasid related attach_fn.