Message ID | 384f7b4333a1f75da09e390902b8f82be21a0dd3.1729897278.git.nicolinc@nvidia.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE) | expand |
On Sat, 26 Oct 2024 at 07:51, Nicolin Chen <nicolinc@nvidia.com> wrote: > > This avoids a bigger trouble of exposing struct iommufd_device and struct > iommufd_vdevice in the public header. > > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> > --- > include/linux/iommufd.h | 8 ++++++++ > drivers/iommu/iommufd/driver.c | 13 +++++++++++++ > 2 files changed, 21 insertions(+) > > diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h > index 0287a6d00192..dc174d02132b 100644 > --- a/include/linux/iommufd.h > +++ b/include/linux/iommufd.h > @@ -184,6 +184,8 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) > struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, > size_t size, > enum iommufd_object_type type); > +struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, > + unsigned long vdev_id); > #else /* !CONFIG_IOMMUFD_DRIVER */ > static inline struct iommufd_object * > _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, > @@ -191,6 +193,12 @@ _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, > { > return ERR_PTR(-EOPNOTSUPP); > } > + > +static inline struct device * > +iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id) > +{ > + return NULL; > +} > #endif /* CONFIG_IOMMUFD_DRIVER */ > > /* > diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c > index c0876d3f91c7..3604443f82a1 100644 > --- a/drivers/iommu/iommufd/driver.c > +++ b/drivers/iommu/iommufd/driver.c > @@ -36,3 +36,16 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, > return ERR_PTR(rc); > } > EXPORT_SYMBOL_NS_GPL(_iommufd_object_alloc, IOMMUFD); > + > +/* 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; > +} Got this error? ld: Unexpected GOT/PLT entries detected! ld: Unexpected run-time procedure linkages detected! ld: drivers/iommu/iommufd/driver.o: in function `iommufd_viommu_find_dev': linux/drivers/iommu/iommufd/driver.c:47: undefined reference to `lockdep_is_held' make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 make[1]: *** [/home/linaro/iommufd/linux/Makefile:1166: vmlinux] Error 2 make: *** [Makefile:224: __sub-make] Error 2
On Sun, Oct 27, 2024 at 11:02:31PM +0800, Zhangfei Gao wrote: > On Sat, 26 Oct 2024 at 07:51, Nicolin Chen <nicolinc@nvidia.com> wrote: > > +/* 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; > > +} > > Got this error? > > ld: Unexpected GOT/PLT entries detected! > ld: Unexpected run-time procedure linkages detected! > ld: drivers/iommu/iommufd/driver.o: in function `iommufd_viommu_find_dev': > linux/drivers/iommu/iommufd/driver.c:47: undefined reference to > `lockdep_is_held' > make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 > make[1]: *** [/home/linaro/iommufd/linux/Makefile:1166: vmlinux] Error 2 > make: *** [Makefile:224: __sub-make] Error 2 Should fix it with: - lockdep_is_held(&viommu->vdevs.xa_lock); + lockdep_assert_held(&viommu->vdevs.xa_lock); Thanks Nicolin
> From: Nicolin Chen <nicolinc@nvidia.com> > Sent: Monday, October 28, 2024 6:49 AM > > On Sun, Oct 27, 2024 at 11:02:31PM +0800, Zhangfei Gao wrote: > > On Sat, 26 Oct 2024 at 07:51, Nicolin Chen <nicolinc@nvidia.com> wrote: > > > +/* 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; > > > +} > > > > Got this error? > > > > ld: Unexpected GOT/PLT entries detected! > > ld: Unexpected run-time procedure linkages detected! > > ld: drivers/iommu/iommufd/driver.o: in function > `iommufd_viommu_find_dev': > > linux/drivers/iommu/iommufd/driver.c:47: undefined reference to > > `lockdep_is_held' > > make[2]: *** [scripts/Makefile.vmlinux:34: vmlinux] Error 1 > > make[1]: *** [/home/linaro/iommufd/linux/Makefile:1166: vmlinux] Error > 2 > > make: *** [Makefile:224: __sub-make] Error 2 > > Should fix it with: > - lockdep_is_held(&viommu->vdevs.xa_lock); > + lockdep_assert_held(&viommu->vdevs.xa_lock); > with that, Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 0287a6d00192..dc174d02132b 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -184,6 +184,8 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx) struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, enum iommufd_object_type type); +struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu, + unsigned long vdev_id); #else /* !CONFIG_IOMMUFD_DRIVER */ static inline struct iommufd_object * _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, @@ -191,6 +193,12 @@ _iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device * +iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id) +{ + return NULL; +} #endif /* CONFIG_IOMMUFD_DRIVER */ /* diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c index c0876d3f91c7..3604443f82a1 100644 --- a/drivers/iommu/iommufd/driver.c +++ b/drivers/iommu/iommufd/driver.c @@ -36,3 +36,16 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, return ERR_PTR(rc); } EXPORT_SYMBOL_NS_GPL(_iommufd_object_alloc, IOMMUFD); + +/* 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);
This avoids a bigger trouble of exposing struct iommufd_device and struct iommufd_vdevice in the public header. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> --- include/linux/iommufd.h | 8 ++++++++ drivers/iommu/iommufd/driver.c | 13 +++++++++++++ 2 files changed, 21 insertions(+)