On Mon, Oct 21, 2024 at 05:20:17PM -0700, Nicolin Chen wrote: > +/* Caller should xa_lock(&viommu->vdevs) to protect the return value */ > +struct device *vdev_to_dev(struct iommufd_vdevice *vdev) > +{ > + return vdev ? vdev->idev->dev : NULL; > +} > +EXPORT_SYMBOL_NS_GPL(vdev_to_dev, IOMMUFD); Changing to not exposing the iommufd_vdevice structure, I reworked this helper to a vIOMMU-based one: +/* Caller should xa_lock(&viommu->vdevs) to protect the return value */ +struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, + unsigned long vdev_id) +{ + struct iommufd_vdevice *vdev; + + lockdep_is_held(&viommu->vdevs.xa_lock); + + vdev = xa_load(&viommu->vdevs, vdev_id); + return vdev ? vdev->idev->dev : NULL; +} +EXPORT_SYMBOL_NS_GPL(iommufd_viommu_find_dev, IOMMUFD); Nicolin