Skip to content

Commit 909f4ab

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommu: Add new iommu op to create domains owned by userspace
Introduce a new iommu_domain op to create domains owned by userspace, e.g. through IOMMUFD. These domains have a few different properties compares to kernel owned domains: - They may be PAGING domains, but created with special parameters. For instance aperture size changes/number of levels, different IOPTE formats, or other things necessary to make a vIOMMU work - We have to track all the memory allocations with GFP_KERNEL_ACCOUNT to make the cgroup sandbox stronger - Device-specialty domains, such as NESTED domains can be created by IOMMUFD. The new op clearly says the domain is being created by IOMMUFD, that the domain is intended for userspace use, and it provides a way to pass user flags or a driver specific uAPI structure to customize the created domain to exactly what the vIOMMU userspace driver requires. iommu drivers that cannot support VFIO/IOMMUFD should not support this op. This includes any driver that cannot provide a fully functional PAGING domain. This new op for now is only supposed to be used by IOMMUFD, hence no wrapper for it. IOMMUFD would call the callback directly. As for domain free, IOMMUFD would use iommu_domain_free(). Link: https://lore.kernel.org/r/20230928071528.26258-2-yi.l.liu@intel.com Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Co-developed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent bb812e0 commit 909f4ab

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

include/linux/iommu.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,15 @@ struct iommu_iotlb_gather {
234234
* op is allocated in the iommu driver and freed by the caller after
235235
* use. The information type is one of enum iommu_hw_info_type defined
236236
* in include/uapi/linux/iommufd.h.
237-
* @domain_alloc: allocate iommu domain
237+
* @domain_alloc: allocate and return an iommu domain if success. Otherwise
238+
* NULL is returned. The domain is not fully initialized until
239+
* the caller iommu_domain_alloc() returns.
240+
* @domain_alloc_user: Allocate an iommu domain corresponding to the input
241+
* parameters as defined in include/uapi/linux/iommufd.h.
242+
* Unlike @domain_alloc, it is called only by IOMMUFD and
243+
* must fully initialize the new domain before return.
244+
* Upon success, a domain is returned. Upon failure,
245+
* ERR_PTR must be returned.
238246
* @probe_device: Add device to iommu driver handling
239247
* @release_device: Remove device from iommu driver handling
240248
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -267,6 +275,7 @@ struct iommu_ops {
267275

268276
/* Domain allocation and freeing by the iommu driver */
269277
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
278+
struct iommu_domain *(*domain_alloc_user)(struct device *dev, u32 flags);
270279

271280
struct iommu_device *(*probe_device)(struct device *dev);
272281
void (*release_device)(struct device *dev);

0 commit comments

Comments
 (0)