Re: [Intel-gfx] [PATCH v9 16/25] iommufd/device: Add iommufd_access_detach() API
> From: Jason Gunthorpe > Sent: Wednesday, April 5, 2023 10:29 PM > > > > > > > > Does this need to go in via iommufd first? There seems to be quite a > > > > bit of churn in iommufd/device.c vs the vfio_mdev_ops branch (ie. it > > > > doesn't apply). Thanks, > > > > > > I think it is best to stay with this series, Yi has to rebase it > > > > The rebased version is here. Shall I resend a version which is rebased on > > top of vfio_mdev_ops? > > > > > https://github.com/yiliu1765/iommufd/commit/d3d8f65c82fe2ca2a7b1a635f4b40b2a > 0971daa9 > > When you post the v10 it should be based on top of the vfio_mdev_ops > and the hot reset series. yes. At least, I see the hot reset series needs to be refreshed w.r.t. the comments from Alex and Eric. Regards, Yi Liu
Re: [Intel-gfx] [PATCH v9 16/25] iommufd/device: Add iommufd_access_detach() API
On Wed, Apr 05, 2023 at 02:10:19PM +, Liu, Yi L wrote: > > From: Jason Gunthorpe > > Sent: Wednesday, April 5, 2023 7:56 PM > > > > On Tue, Apr 04, 2023 at 04:45:12PM -0600, Alex Williamson wrote: > > > On Sat, 1 Apr 2023 08:18:24 -0700 > > > Yi Liu wrote: > > > > > > > From: Nicolin Chen > > > > > > > > Previously, the detach routine is only done by the destroy(). And it was > > > > called by vfio_iommufd_emulated_unbind() when the device runs close(), > > > > so > > > > all the mappings in iopt were cleaned in that setup, when the call trace > > > > reaches this detach() routine. > > > > > > > > Now, there's a need of a detach uAPI, meaning that it does not only need > > > > a new iommufd_access_detach() API, but also requires > > > > access->ops->unmap() > > > > call as a cleanup. So add one. > > > > > > > > However, leaving that unprotected can introduce some potential of a race > > > > condition during the pin_/unpin_pages() call, where access->ioas->iopt > > > > is > > > > getting referenced. So, add an ioas_lock to protect the context of iopt > > > > referencings. > > > > > > > > Also, to allow the iommufd_access_unpin_pages() callback to happen via > > > > this unmap() call, add an ioas_unpin pointer, so the unpin routine won't > > > > be affected by the "access->ioas = NULL" trick. > > > > > > > > Reviewed-by: Kevin Tian > > > > Tested-by: Terrence Xu > > > > Tested-by: Yanting Jiang > > > > Signed-off-by: Nicolin Chen > > > > Signed-off-by: Yi Liu > > > > --- > > > > drivers/iommu/iommufd/device.c | 76 +++-- > > > > drivers/iommu/iommufd/iommufd_private.h | 2 + > > > > include/linux/iommufd.h | 1 + > > > > 3 files changed, 74 insertions(+), 5 deletions(-) > > > > > > Does this need to go in via iommufd first? There seems to be quite a > > > bit of churn in iommufd/device.c vs the vfio_mdev_ops branch (ie. it > > > doesn't apply). Thanks, > > > > I think it is best to stay with this series, Yi has to rebase it > > The rebased version is here. Shall I resend a version which is rebased on > top of vfio_mdev_ops? > > https://github.com/yiliu1765/iommufd/commit/d3d8f65c82fe2ca2a7b1a635f4b40b2a0971daa9 When you post the v10 it should be based on top of the vfio_mdev_ops and the hot reset series. Jason
Re: [Intel-gfx] [PATCH v9 16/25] iommufd/device: Add iommufd_access_detach() API
> From: Jason Gunthorpe > Sent: Wednesday, April 5, 2023 7:56 PM > > On Tue, Apr 04, 2023 at 04:45:12PM -0600, Alex Williamson wrote: > > On Sat, 1 Apr 2023 08:18:24 -0700 > > Yi Liu wrote: > > > > > From: Nicolin Chen > > > > > > Previously, the detach routine is only done by the destroy(). And it was > > > called by vfio_iommufd_emulated_unbind() when the device runs close(), so > > > all the mappings in iopt were cleaned in that setup, when the call trace > > > reaches this detach() routine. > > > > > > Now, there's a need of a detach uAPI, meaning that it does not only need > > > a new iommufd_access_detach() API, but also requires access->ops->unmap() > > > call as a cleanup. So add one. > > > > > > However, leaving that unprotected can introduce some potential of a race > > > condition during the pin_/unpin_pages() call, where access->ioas->iopt is > > > getting referenced. So, add an ioas_lock to protect the context of iopt > > > referencings. > > > > > > Also, to allow the iommufd_access_unpin_pages() callback to happen via > > > this unmap() call, add an ioas_unpin pointer, so the unpin routine won't > > > be affected by the "access->ioas = NULL" trick. > > > > > > Reviewed-by: Kevin Tian > > > Tested-by: Terrence Xu > > > Tested-by: Yanting Jiang > > > Signed-off-by: Nicolin Chen > > > Signed-off-by: Yi Liu > > > --- > > > drivers/iommu/iommufd/device.c | 76 +++-- > > > drivers/iommu/iommufd/iommufd_private.h | 2 + > > > include/linux/iommufd.h | 1 + > > > 3 files changed, 74 insertions(+), 5 deletions(-) > > > > Does this need to go in via iommufd first? There seems to be quite a > > bit of churn in iommufd/device.c vs the vfio_mdev_ops branch (ie. it > > doesn't apply). Thanks, > > I think it is best to stay with this series, Yi has to rebase it The rebased version is here. Shall I resend a version which is rebased on top of vfio_mdev_ops? https://github.com/yiliu1765/iommufd/commit/d3d8f65c82fe2ca2a7b1a635f4b40b2a0971daa9 Regards, Yi Liu
Re: [Intel-gfx] [PATCH v9 16/25] iommufd/device: Add iommufd_access_detach() API
On Tue, Apr 04, 2023 at 04:45:12PM -0600, Alex Williamson wrote: > On Sat, 1 Apr 2023 08:18:24 -0700 > Yi Liu wrote: > > > From: Nicolin Chen > > > > Previously, the detach routine is only done by the destroy(). And it was > > called by vfio_iommufd_emulated_unbind() when the device runs close(), so > > all the mappings in iopt were cleaned in that setup, when the call trace > > reaches this detach() routine. > > > > Now, there's a need of a detach uAPI, meaning that it does not only need > > a new iommufd_access_detach() API, but also requires access->ops->unmap() > > call as a cleanup. So add one. > > > > However, leaving that unprotected can introduce some potential of a race > > condition during the pin_/unpin_pages() call, where access->ioas->iopt is > > getting referenced. So, add an ioas_lock to protect the context of iopt > > referencings. > > > > Also, to allow the iommufd_access_unpin_pages() callback to happen via > > this unmap() call, add an ioas_unpin pointer, so the unpin routine won't > > be affected by the "access->ioas = NULL" trick. > > > > Reviewed-by: Kevin Tian > > Tested-by: Terrence Xu > > Tested-by: Yanting Jiang > > Signed-off-by: Nicolin Chen > > Signed-off-by: Yi Liu > > --- > > drivers/iommu/iommufd/device.c | 76 +++-- > > drivers/iommu/iommufd/iommufd_private.h | 2 + > > include/linux/iommufd.h | 1 + > > 3 files changed, 74 insertions(+), 5 deletions(-) > > Does this need to go in via iommufd first? There seems to be quite a > bit of churn in iommufd/device.c vs the vfio_mdev_ops branch (ie. it > doesn't apply). Thanks, I think it is best to stay with this series, Yi has to rebase it Jason
Re: [Intel-gfx] [PATCH v9 16/25] iommufd/device: Add iommufd_access_detach() API
On Sat, 1 Apr 2023 08:18:24 -0700 Yi Liu wrote: > From: Nicolin Chen > > Previously, the detach routine is only done by the destroy(). And it was > called by vfio_iommufd_emulated_unbind() when the device runs close(), so > all the mappings in iopt were cleaned in that setup, when the call trace > reaches this detach() routine. > > Now, there's a need of a detach uAPI, meaning that it does not only need > a new iommufd_access_detach() API, but also requires access->ops->unmap() > call as a cleanup. So add one. > > However, leaving that unprotected can introduce some potential of a race > condition during the pin_/unpin_pages() call, where access->ioas->iopt is > getting referenced. So, add an ioas_lock to protect the context of iopt > referencings. > > Also, to allow the iommufd_access_unpin_pages() callback to happen via > this unmap() call, add an ioas_unpin pointer, so the unpin routine won't > be affected by the "access->ioas = NULL" trick. > > Reviewed-by: Kevin Tian > Tested-by: Terrence Xu > Tested-by: Yanting Jiang > Signed-off-by: Nicolin Chen > Signed-off-by: Yi Liu > --- > drivers/iommu/iommufd/device.c | 76 +++-- > drivers/iommu/iommufd/iommufd_private.h | 2 + > include/linux/iommufd.h | 1 + > 3 files changed, 74 insertions(+), 5 deletions(-) Does this need to go in via iommufd first? There seems to be quite a bit of churn in iommufd/device.c vs the vfio_mdev_ops branch (ie. it doesn't apply). Thanks, Alex