On Wed, Jan 03, 2024 at 08:02:04PM -0400, Jason Gunthorpe wrote:
On Wed, Jan 03, 2024 at 12:18:35PM -0800, Nicolin Chen wrote:
The driver would have to create it and there would be some driver specific enclosing struct to go with it
Perhaps device_ids goes in the driver specific struct, I don't know.
+struct iommufd_viommu {
- struct iommufd_object obj;
- struct iommufd_ctx *ictx;
- struct iommu_device *iommu_dev;
- struct iommufd_hwpt_paging *hwpt; /* maybe unneeded */
- int vmid;
- union iommu_driver_user_data {
struct iommu_driver_user_vtd;
struct iommu_driver_user_arm_smmuv3;
struct iommu_driver_user_amd_viommu;
- };
Not like that, in the usual container_of way
How about this:
// iommu.h @@ -490,6 +490,16 @@ struct iommu_ops { + /* User space instance allocation and freeing by the iommu driver */ + struct iommu_device_user *(*iommu_alloc_user)(struct iommu_device *iommu); + void (*iommu_free_user)(struct iommu_device_user *iommu_user); + int (*iommu_user_set_dev_id)(struct iommu_device_user *iommu_user, + struct device *dev, u64 dev_id); + int (*iommu_user_unset_dev_id)(struct iommu_device_user *iommu_user, + struct device *dev); + int (*iommu_cache_invalidate_usewr)(struct iommu_device_user *iommu_user, + struct iommu_user_data_array *array); ... +/** + * struct iommu_device_user - IOMMU core representation of one IOMMU virtual + * instance + * @iommu_dev: Underlying IOMMU hardware instance + * @id: Virtual instance ID, e.g. a vmid + */ +struct iommu_device_user { + struct iommu_device *iommu_dev; + struct xarray virtual_ids; + u32 id; +};
// iommufd_private.h +struct iommufd_viommu { + struct iommufd_object obj; + struct iommufd_ctx *ictx; + struct iommu_device *iommu_dev; + struct iommu_device_user *iommu_user; + struct iommufd_hwpt_paging *hwpt; +}; + +int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd); +void iommufd_viommu_destroy(struct iommufd_object *obj);
So iommu_alloc_user op allocates a driver private structure that contains an iommu_device_user and returns &priv->iommu_user.
The set/unset_dev_id ops probably need a type argument if there can be a multi-xarray case, then the virtual_ids xarray should be moved to the driver private structure too?
Also, a 64-bit virtual id in the uAPI was suggested previously. But xarray is limited to a 32-bit index? Should we compromise the uAPI to 32-bit or is there an alternative for a 64-bit id lookup?
Thanks Nicolin