On Thu, Oct 17, 2024 at 02:15:00PM -0300, Jason Gunthorpe wrote: > On Wed, Oct 09, 2024 at 09:38:08AM -0700, Nicolin Chen wrote: > > > +static struct iommufd_viommu * > > +mock_viommu_alloc(struct iommu_device *iommu_dev, struct iommu_domain *domain, > > + struct iommufd_ctx *ictx, unsigned int viommu_type) > > +{ > > + struct mock_iommu_device *mock_iommu = > > + container_of(iommu_dev, struct mock_iommu_device, iommu_dev); > > + struct mock_viommu *mock_viommu; > > + > > + if (viommu_type != IOMMU_VIOMMU_TYPE_SELFTEST) > > + return ERR_PTR(-EOPNOTSUPP); > > What about the default viommu? What happens then? IOMMU_VIOMMU_TYPE_DEFAULT is allocated by the core, it won't go down to iommu_ops->viommu_alloc (this function). > > + mock_viommu = iommufd_viommu_alloc(ictx, mock_viommu, core, > > + &mock_viommu_ops); > > + if (IS_ERR(mock_viommu)) > > + return ERR_CAST(mock_viommu); > > + > > + if (!refcount_inc_not_zero(&mock_iommu->users)) { > > It would be a bug if the iommu_dev being passed in was somehow > released while iommufd had hold of it through vfio. So just use > refcount_inc() OK. Thanks Nicolin