Skip to content

Commit 6544250

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Add ops->domain_alloc_sva()
Make a new op that receives the device and the mm_struct that the SVA domain should be created for. Unlike domain_alloc_paging() the dev argument is never NULL here. This allows drivers to fully initialize the SVA domain and allocate the mmu_notifier during allocation. It allows the notifier lifetime to follow the lifetime of the iommu_domain. Since we have only one call site, upgrade the new op to return ERR_PTR instead of NULL. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Tina Zhang <tina.zhang@intel.com> Link: https://lore.kernel.org/r/20240311090843.133455-15-vasant.hegde@amd.com Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20240416080656.60968-12-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent deda9a7 commit 6544250

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

drivers/iommu/iommu-sva.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm
108108

109109
/* Allocate a new domain and set it on device pasid. */
110110
domain = iommu_sva_domain_alloc(dev, mm);
111-
if (!domain) {
112-
ret = -ENOMEM;
111+
if (IS_ERR(domain)) {
112+
ret = PTR_ERR(domain);
113113
goto out_free_handle;
114114
}
115115

@@ -283,9 +283,15 @@ struct iommu_domain *iommu_sva_domain_alloc(struct device *dev,
283283
const struct iommu_ops *ops = dev_iommu_ops(dev);
284284
struct iommu_domain *domain;
285285

286-
domain = ops->domain_alloc(IOMMU_DOMAIN_SVA);
287-
if (!domain)
288-
return NULL;
286+
if (ops->domain_alloc_sva) {
287+
domain = ops->domain_alloc_sva(dev, mm);
288+
if (IS_ERR(domain))
289+
return domain;
290+
} else {
291+
domain = ops->domain_alloc(IOMMU_DOMAIN_SVA);
292+
if (!domain)
293+
return ERR_PTR(-ENOMEM);
294+
}
289295

290296
domain->type = IOMMU_DOMAIN_SVA;
291297
mmgrab(mm);

include/linux/iommu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static inline int __iommu_copy_struct_from_user_array(
517517
* Upon failure, ERR_PTR must be returned.
518518
* @domain_alloc_paging: Allocate an iommu_domain that can be used for
519519
* UNMANAGED, DMA, and DMA_FQ domain types.
520+
* @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressing.
520521
* @probe_device: Add device to iommu driver handling
521522
* @release_device: Remove device from iommu driver handling
522523
* @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -557,6 +558,8 @@ struct iommu_ops {
557558
struct device *dev, u32 flags, struct iommu_domain *parent,
558559
const struct iommu_user_data *user_data);
559560
struct iommu_domain *(*domain_alloc_paging)(struct device *dev);
561+
struct iommu_domain *(*domain_alloc_sva)(struct device *dev,
562+
struct mm_struct *mm);
560563

561564
struct iommu_device *(*probe_device)(struct device *dev);
562565
void (*release_device)(struct device *dev);

0 commit comments

Comments
 (0)