Message ID | cover.1730313494.git.nicolinc@nvidia.com |
---|---|
Headers | show |
Series | iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE) | expand |
On Thu, 31 Oct 2024 at 05:36, Nicolin Chen <nicolinc@nvidia.com> wrote: > > Following the previous vIOMMU series, this adds another vDEVICE structure, > representing the association from an iommufd_device to an iommufd_viommu. > This gives the whole architecture a new "v" layer: > _______________________________________________________________________ > | iommufd (with vIOMMU/vDEVICE) | > | _____________ _____________ | > | | | | | | > | |----------------| vIOMMU |<---| vDEVICE |<------| | > | | | | |_____________| | | > | | ______ | | _____________ ___|____ | > | | | | | | | | | | | > | | | IOAS |<---|(HWPT_PAGING)|<---| HWPT_NESTED |<--| DEVICE | | > | | |______| |_____________| |_____________| |________| | > |______|________|______________|__________________|_______________|_____| > | | | | | > ______v_____ | ______v_____ ______v_____ ___v__ > | struct | | PFN | (paging) | | (nested) | |struct| > |iommu_device| |------>|iommu_domain|<----|iommu_domain|<----|device| > |____________| storage|____________| |____________| |______| > > This vDEVICE object is used to collect and store all vIOMMU-related device > information/attributes in a VM. As an initial series for vDEVICE, add only > the virt_id to the vDEVICE, which is a vIOMMU specific device ID in a VM: > e.g. vSID of ARM SMMUv3, vDeviceID of AMD IOMMU, and vRID of Intel VT-d to > a Context Table. This virt_id helps IOMMU drivers to link the vID to a pID > of the device against the physical IOMMU instance. This is essential for a > vIOMMU-based invalidation, where the request contains a device's vID for a > device cache flush, e.g. ATC invalidation. > > Therefore, with this vDEVICE object, support a vIOMMU-based invalidation, > by reusing IOMMUFD_CMD_HWPT_INVALIDATE for a vIOMMU object to flush cache > with a given driver data. > > As for the implementation of the series, add driver support in ARM SMMUv3 > for a real world use case. > > This series is on Github: > https://github.com/nicolinc/iommufd/commits/iommufd_viommu_p2-v6 > (QEMU branch for testing will be provided in Jason's nesting series) Thanks Nico I tested on aarch64, functions are OK. But with some hacks https://github.com/Linaro/linux-kernel-uadk/commit/22f47d6f3a34a0867a187473bd5ba0e0ee3395d4 Thanks
On Thu, Oct 31, 2024 at 02:28:12PM +0800, Zhangfei Gao wrote: > > As for the implementation of the series, add driver support in ARM SMMUv3 > > for a real world use case. > > > > This series is on Github: > > https://github.com/nicolinc/iommufd/commits/iommufd_viommu_p2-v6 > > (QEMU branch for testing will be provided in Jason's nesting series) > > Thanks Nico > > I tested on aarch64, functions are OK. > > But with some hacks > https://github.com/Linaro/linux-kernel-uadk/commit/22f47d6f3a34a0867a187473bd5ba0e0ee3395d4 Hmm, it seems like we should permit IOMMU_HWPT_FAULT_ID_VALID domain creation on ARM? Jason
On Wed, Oct 30, 2024 at 02:35:32PM -0700, Nicolin Chen wrote: > This avoids a bigger trouble of exposing struct iommufd_device and struct > iommufd_vdevice in the public header. > > Reviewed-by: Kevin Tian <kevin.tian@intel.com> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> > --- > include/linux/iommufd.h | 8 ++++++++ > drivers/iommu/iommufd/driver.c | 13 +++++++++++++ > 2 files changed, 21 insertions(+) Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Jason
On Wed, Oct 30, 2024 at 02:35:31PM -0700, Nicolin Chen wrote: > From: Jason Gunthorpe <jgg@nvidia.com> > > The iommu_copy_struct_from_user_array helper can be used to copy a single > entry from a user array which might not be efficient if the array is big. > > Add a new iommu_copy_struct_from_full_user_array to copy the entire user > array at once. Update the existing iommu_copy_struct_from_user_array kdoc > accordingly. > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > Reviewed-by: Kevin Tian <kevin.tian@intel.com> > Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> > --- > include/linux/iommu.h | 48 ++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 47 insertions(+), 1 deletion(-) Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Jason
On Thu, Oct 31, 2024 at 02:28:12PM +0800, Zhangfei Gao wrote: > On Thu, 31 Oct 2024 at 05:36, Nicolin Chen <nicolinc@nvidia.com> wrote: > > > > Following the previous vIOMMU series, this adds another vDEVICE structure, > > representing the association from an iommufd_device to an iommufd_viommu. > > This gives the whole architecture a new "v" layer: > > _______________________________________________________________________ > > | iommufd (with vIOMMU/vDEVICE) | > > | _____________ _____________ | > > | | | | | | > > | |----------------| vIOMMU |<---| vDEVICE |<------| | > > | | | | |_____________| | | > > | | ______ | | _____________ ___|____ | > > | | | | | | | | | | | > > | | | IOAS |<---|(HWPT_PAGING)|<---| HWPT_NESTED |<--| DEVICE | | > > | | |______| |_____________| |_____________| |________| | > > |______|________|______________|__________________|_______________|_____| > > | | | | | > > ______v_____ | ______v_____ ______v_____ ___v__ > > | struct | | PFN | (paging) | | (nested) | |struct| > > |iommu_device| |------>|iommu_domain|<----|iommu_domain|<----|device| > > |____________| storage|____________| |____________| |______| > > > > This vDEVICE object is used to collect and store all vIOMMU-related device > > information/attributes in a VM. As an initial series for vDEVICE, add only > > the virt_id to the vDEVICE, which is a vIOMMU specific device ID in a VM: > > e.g. vSID of ARM SMMUv3, vDeviceID of AMD IOMMU, and vRID of Intel VT-d to > > a Context Table. This virt_id helps IOMMU drivers to link the vID to a pID > > of the device against the physical IOMMU instance. This is essential for a > > vIOMMU-based invalidation, where the request contains a device's vID for a > > device cache flush, e.g. ATC invalidation. > > > > Therefore, with this vDEVICE object, support a vIOMMU-based invalidation, > > by reusing IOMMUFD_CMD_HWPT_INVALIDATE for a vIOMMU object to flush cache > > with a given driver data. > > > > As for the implementation of the series, add driver support in ARM SMMUv3 > > for a real world use case. > > > > This series is on Github: > > https://github.com/nicolinc/iommufd/commits/iommufd_viommu_p2-v6 > > (QEMU branch for testing will be provided in Jason's nesting series) > > Thanks Nico > > I tested on aarch64, functions are OK. > > But with some hacks > https://github.com/Linaro/linux-kernel-uadk/commit/22f47d6f3a34a0867a187473bd5ba0e0ee3395d4 Though we will have some small changes to this two series (and possibly a small change to SMMUv3 driver too for that flags in the hacks), would you mind giving this two series a Tested-by? Thanks! Nicolin
On Thu, Oct 31, 2024 at 08:59:37AM -0300, Jason Gunthorpe wrote: > On Thu, Oct 31, 2024 at 02:28:12PM +0800, Zhangfei Gao wrote: > > > > As for the implementation of the series, add driver support in ARM SMMUv3 > > > for a real world use case. > > > > > > This series is on Github: > > > https://github.com/nicolinc/iommufd/commits/iommufd_viommu_p2-v6 > > > (QEMU branch for testing will be provided in Jason's nesting series) > > > > Thanks Nico > > > > I tested on aarch64, functions are OK. > > > > But with some hacks > > https://github.com/Linaro/linux-kernel-uadk/commit/22f47d6f3a34a0867a187473bd5ba0e0ee3395d4 > > Hmm, it seems like we should permit IOMMU_HWPT_FAULT_ID_VALID domain > creation on ARM? +1, since we proved PRI could work :) Thanks Nicolin
On Thu, Oct 31, 2024 at 09:56:37AM -0700, Nicolin Chen wrote: > On Thu, Oct 31, 2024 at 10:29:41AM -0300, Jason Gunthorpe wrote: > > On Wed, Oct 30, 2024 at 02:35:27PM -0700, Nicolin Chen wrote: > > > +void iommufd_vdevice_destroy(struct iommufd_object *obj) > > > +{ > > > + struct iommufd_vdevice *vdev = > > > + container_of(obj, struct iommufd_vdevice, obj); > > > + struct iommufd_viommu *viommu = vdev->viommu; > > > + > > > + /* xa_cmpxchg is okay to fail if alloc returned -EEXIST previously */ > > > + xa_cmpxchg(&viommu->vdevs, vdev->id, vdev, NULL, GFP_KERNEL); > > > > There are crazy races that would cause this not to work. Another > > thread could have successfully destroyed whatever caused EEXIST and > > the successfully registered this same vdev to the same id. Then this > > will wrongly erase the other threads entry. > > > > It would be better to skip the erase directly if the EEXIST unwind is > > being taken. > > Hmm, is the "another thread" an alloc() or a destroy()? I was thinking both > It doesn't seem to me that there could be another destroy() on the > same object since this current destroy() is the abort to an > unfinalized object. And it doesn't seem that another alloc() will > get the same vdev ptr since every vdev allocation in the alloc() > will be different? Ah so you are saying that since the vdev 'old' is local to this thread it can't possibly by aliased by another? I was worried the id could be aliased, but yes, that seems right that the vdev cmpxchg would reject that. So lets leave it Jason
On Thu, Oct 31, 2024 at 02:04:46PM -0300, Jason Gunthorpe wrote: > On Thu, Oct 31, 2024 at 09:56:37AM -0700, Nicolin Chen wrote: > > On Thu, Oct 31, 2024 at 10:29:41AM -0300, Jason Gunthorpe wrote: > > > On Wed, Oct 30, 2024 at 02:35:27PM -0700, Nicolin Chen wrote: > > > > +void iommufd_vdevice_destroy(struct iommufd_object *obj) > > > > +{ > > > > + struct iommufd_vdevice *vdev = > > > > + container_of(obj, struct iommufd_vdevice, obj); > > > > + struct iommufd_viommu *viommu = vdev->viommu; > > > > + > > > > + /* xa_cmpxchg is okay to fail if alloc returned -EEXIST previously */ > > > > + xa_cmpxchg(&viommu->vdevs, vdev->id, vdev, NULL, GFP_KERNEL); > > > > > > There are crazy races that would cause this not to work. Another > > > thread could have successfully destroyed whatever caused EEXIST and > > > the successfully registered this same vdev to the same id. Then this > > > will wrongly erase the other threads entry. > > > > > > It would be better to skip the erase directly if the EEXIST unwind is > > > being taken. > > > > Hmm, is the "another thread" an alloc() or a destroy()? > > I was thinking both > > > It doesn't seem to me that there could be another destroy() on the > > same object since this current destroy() is the abort to an > > unfinalized object. And it doesn't seem that another alloc() will > > get the same vdev ptr since every vdev allocation in the alloc() > > will be different? > > Ah so you are saying that since the vdev 'old' is local to this thread > it can't possibly by aliased by another? > > I was worried the id could be aliased, but yes, that seems right that > the vdev cmpxchg would reject that. > > So lets leave it Ack. I'll still update this since xa_cmpxchg can give other errno: + /* xa_cmpxchg is okay to fail if alloc returned -EEXIST previously */ - /* xa_cmpxchg is okay to fail if alloc failed xa_cmpxchg previously */ Thanks Nicolin