[PATCH v4 08/14] iommufd/viommu: Add vdev_to_dev helper

Nicolin Chen nicolinc at nvidia.com
Thu Oct 24 20:39:44 PDT 2024


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



More information about the linux-arm-kernel mailing list