Re: [RFC PATCH v6 08/11] iommufd: Add vIOMMU provider support

From: Jason Gunthorpe

Date: Fri Sep 25 2026 - 08:39:46 EST


On Fri, Sep 25, 2026 at 11:38:15AM +0530, Aneesh Kumar K.V wrote:
> Jason Gunthorpe <jgg@xxxxxxxxxx> writes:
>
> >> vIOMMU creation currently dispatches directly through the physical IOMMU
> >> driver. Some vIOMMU types need an implementation supplied by another
> >> subsystem, together with private data whose lifetime extends across all
> >> vIOMMUs using that implementation.
> >>
> >> Introduce a vIOMMU provider that associates implementation operations,
> >> their module owner and private data. Allow one external provider to
> >> register for each non-default vIOMMU type.
> >
> > This seems much more extensive than I imagined when I proposed this.
> >
> > I imagined you'd just have iommufd see there is a TSM attached the pci
> > device with a function call, and check if that TSM handled the
> > requested iommu ID.
> >
> > No need for a registration system because we already know the only
> > possible TSM driver that can handle it,
> >
>
> Agreed, there will be only one vIOMMU provider. But, without a
> registration mechanism, what would the module dependency look like?
>
> I currently have the TSM driver depending on IOMMUFD. Therefore, the TSM
> driver needs to tell iommufd which vIOMMU type it provides and register
> the corresponding provider. IOMMUFD does not call into TSM directly.

Just put the two new ops in:

struct pci_tsm_ops {
size_t (*viommu_get_size)(struct device *dev, enum iommu_viommu_type type);
int (*viommu_init)(struct iommufd_viommu *viommu, struct device *dev,
struct iommu_domain *parent,
const struct iommu_user_data *user_data);
}

And bounce them with a static inline

static inline
ssize_t pci_tsm_viommu_get_size(struct device *dev, enum iommu_viommu_type type)
{
const struct pci_tsm_ops *ops;
struct pci_dev *pdev;

if (!dev_is_pci(dev))
return -EINVAL;

pdev = to_pci_dev(dev);
if (!pdev->tsm)
return -ENODEV;

ops = to_pci_tsm_ops(pdev->tsm);
if (!ops->viommu_get_size)
return 0;
return ops->viommu_get_size(dev, type);
}

No module dependency.

The iommufd side is simple, it just calls this before calling the
iommu driver. First one to return a size wins and creates the viommu.

We'd want to have a reasonable lifetime model where the the pdev->tsm
is guarenteed stable while a driver is bound.

Jason