Skip to content

Commit 8b6c32e

Browse files
committed
Merge branch 'iommu/iommufd/paging-domain-alloc' into iommu/next
* iommu/iommufd/paging-domain-alloc: RDMA/usnic: Use iommu_paging_domain_alloc() wifi: ath11k: Use iommu_paging_domain_alloc() wifi: ath10k: Use iommu_paging_domain_alloc() drm/msm: Use iommu_paging_domain_alloc() vhost-vdpa: Use iommu_paging_domain_alloc() vfio/type1: Use iommu_paging_domain_alloc() iommufd: Use iommu_paging_domain_alloc() iommu: Add iommu_paging_domain_alloc() interface
2 parents 74e54d5 + 3b10f25 commit 8b6c32e

File tree

9 files changed

+54
-25
lines changed

9 files changed

+54
-25
lines changed

drivers/gpu/drm/msm/msm_iommu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,13 @@ struct msm_mmu *msm_iommu_new(struct device *dev, unsigned long quirks)
407407
struct msm_iommu *iommu;
408408
int ret;
409409

410-
domain = iommu_domain_alloc(dev->bus);
411-
if (!domain)
410+
if (!device_iommu_mapped(dev))
412411
return NULL;
413412

413+
domain = iommu_paging_domain_alloc(dev);
414+
if (IS_ERR(domain))
415+
return ERR_CAST(domain);
416+
414417
iommu_set_pgtable_quirks(domain, quirks);
415418

416419
iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);

drivers/infiniband/hw/usnic/usnic_uiom.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ struct usnic_uiom_pd *usnic_uiom_alloc_pd(struct device *dev)
443443
if (!pd)
444444
return ERR_PTR(-ENOMEM);
445445

446-
pd->domain = domain = iommu_domain_alloc(dev->bus);
447-
if (!domain) {
446+
pd->domain = domain = iommu_paging_domain_alloc(dev);
447+
if (IS_ERR(domain)) {
448448
usnic_err("Failed to allocate IOMMU domain");
449449
kfree(pd);
450-
return ERR_PTR(-ENOMEM);
450+
return ERR_CAST(domain);
451451
}
452452

453453
iommu_set_fault_handler(pd->domain, usnic_uiom_dma_fault, NULL);

drivers/iommu/iommu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,10 @@ static int __iommu_domain_alloc_dev(struct device *dev, void *data)
20102010
return 0;
20112011
}
20122012

2013+
/*
2014+
* The iommu ops in bus has been retired. Do not use this interface in
2015+
* new drivers.
2016+
*/
20132017
struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
20142018
{
20152019
const struct iommu_ops *ops = NULL;
@@ -2026,6 +2030,22 @@ struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
20262030
}
20272031
EXPORT_SYMBOL_GPL(iommu_domain_alloc);
20282032

2033+
/**
2034+
* iommu_paging_domain_alloc() - Allocate a paging domain
2035+
* @dev: device for which the domain is allocated
2036+
*
2037+
* Allocate a paging domain which will be managed by a kernel driver. Return
2038+
* allocated domain if successful, or a ERR pointer for failure.
2039+
*/
2040+
struct iommu_domain *iommu_paging_domain_alloc(struct device *dev)
2041+
{
2042+
if (!dev_has_iommu(dev))
2043+
return ERR_PTR(-ENODEV);
2044+
2045+
return __iommu_domain_alloc(dev_iommu_ops(dev), dev, IOMMU_DOMAIN_UNMANAGED);
2046+
}
2047+
EXPORT_SYMBOL_GPL(iommu_paging_domain_alloc);
2048+
20292049
void iommu_domain_free(struct iommu_domain *domain)
20302050
{
20312051
if (domain->type == IOMMU_DOMAIN_SVA)

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
140140
}
141141
hwpt->domain->owner = ops;
142142
} else {
143-
hwpt->domain = iommu_domain_alloc(idev->dev->bus);
144-
if (!hwpt->domain) {
145-
rc = -ENOMEM;
143+
hwpt->domain = iommu_paging_domain_alloc(idev->dev);
144+
if (IS_ERR(hwpt->domain)) {
145+
rc = PTR_ERR(hwpt->domain);
146+
hwpt->domain = NULL;
146147
goto out_abort;
147148
}
148149
}

drivers/net/wireless/ath/ath10k/snoc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,10 @@ static int ath10k_fw_init(struct ath10k *ar)
16351635

16361636
ar_snoc->fw.dev = &pdev->dev;
16371637

1638-
iommu_dom = iommu_domain_alloc(&platform_bus_type);
1639-
if (!iommu_dom) {
1638+
iommu_dom = iommu_paging_domain_alloc(ar_snoc->fw.dev);
1639+
if (IS_ERR(iommu_dom)) {
16401640
ath10k_err(ar, "failed to allocate iommu domain\n");
1641-
ret = -ENOMEM;
1641+
ret = PTR_ERR(iommu_dom);
16421642
goto err_unregister;
16431643
}
16441644

drivers/net/wireless/ath/ath11k/ahb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,10 +1001,10 @@ static int ath11k_ahb_fw_resources_init(struct ath11k_base *ab)
10011001

10021002
ab_ahb->fw.dev = &pdev->dev;
10031003

1004-
iommu_dom = iommu_domain_alloc(&platform_bus_type);
1005-
if (!iommu_dom) {
1004+
iommu_dom = iommu_paging_domain_alloc(ab_ahb->fw.dev);
1005+
if (IS_ERR(iommu_dom)) {
10061006
ath11k_err(ab, "failed to allocate iommu domain\n");
1007-
ret = -ENOMEM;
1007+
ret = PTR_ERR(iommu_dom);
10081008
goto err_unregister;
10091009
}
10101010

drivers/vfio/vfio_iommu_type1.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ static int vfio_iommu_domain_alloc(struct device *dev, void *data)
21352135
{
21362136
struct iommu_domain **domain = data;
21372137

2138-
*domain = iommu_domain_alloc(dev->bus);
2138+
*domain = iommu_paging_domain_alloc(dev);
21392139
return 1; /* Don't iterate */
21402140
}
21412141

@@ -2192,11 +2192,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
21922192
* us a representative device for the IOMMU API call. We don't actually
21932193
* want to iterate beyond the first device (if any).
21942194
*/
2195-
ret = -EIO;
21962195
iommu_group_for_each_dev(iommu_group, &domain->domain,
21972196
vfio_iommu_domain_alloc);
2198-
if (!domain->domain)
2197+
if (IS_ERR(domain->domain)) {
2198+
ret = PTR_ERR(domain->domain);
21992199
goto out_free_domain;
2200+
}
22002201

22012202
if (iommu->nesting) {
22022203
ret = iommu_enable_nesting(domain->domain);

drivers/vhost/vdpa.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,26 +1312,24 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
13121312
struct vdpa_device *vdpa = v->vdpa;
13131313
const struct vdpa_config_ops *ops = vdpa->config;
13141314
struct device *dma_dev = vdpa_get_dma_dev(vdpa);
1315-
const struct bus_type *bus;
13161315
int ret;
13171316

13181317
/* Device want to do DMA by itself */
13191318
if (ops->set_map || ops->dma_map)
13201319
return 0;
13211320

1322-
bus = dma_dev->bus;
1323-
if (!bus)
1324-
return -EFAULT;
1325-
13261321
if (!device_iommu_capable(dma_dev, IOMMU_CAP_CACHE_COHERENCY)) {
13271322
dev_warn_once(&v->dev,
13281323
"Failed to allocate domain, device is not IOMMU cache coherent capable\n");
13291324
return -ENOTSUPP;
13301325
}
13311326

1332-
v->domain = iommu_domain_alloc(bus);
1333-
if (!v->domain)
1334-
return -EIO;
1327+
v->domain = iommu_paging_domain_alloc(dma_dev);
1328+
if (IS_ERR(v->domain)) {
1329+
ret = PTR_ERR(v->domain);
1330+
v->domain = NULL;
1331+
return ret;
1332+
}
13351333

13361334
ret = iommu_attach_device(v->domain, dma_dev);
13371335
if (ret)

include/linux/iommu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ extern bool iommu_present(const struct bus_type *bus);
785785
extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap);
786786
extern bool iommu_group_has_isolated_msi(struct iommu_group *group);
787787
extern struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus);
788+
struct iommu_domain *iommu_paging_domain_alloc(struct device *dev);
788789
extern void iommu_domain_free(struct iommu_domain *domain);
789790
extern int iommu_attach_device(struct iommu_domain *domain,
790791
struct device *dev);
@@ -1093,6 +1094,11 @@ static inline struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus
10931094
return NULL;
10941095
}
10951096

1097+
static inline struct iommu_domain *iommu_paging_domain_alloc(struct device *dev)
1098+
{
1099+
return ERR_PTR(-ENODEV);
1100+
}
1101+
10961102
static inline void iommu_domain_free(struct iommu_domain *domain)
10971103
{
10981104
}

0 commit comments

Comments
 (0)