Skip to content

Commit 0d609a1

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Add domain_alloc_identity()
virtio-iommu has a mode where the IDENTITY domain is actually a paging domain with an identity mapping covering some of the system address space manually created. To support this add a new domain_alloc_identity() op that accepts the struct device so that virtio can allocate and fully finalize a paging domain to return. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/2-v4-ff5fb6b03bd1+288-iommu_virtio_domains_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 0d76a6e commit 0d609a1

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

drivers/iommu/iommu.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,15 +1631,19 @@ static struct iommu_domain *__iommu_alloc_identity_domain(struct device *dev)
16311631
if (ops->identity_domain)
16321632
return ops->identity_domain;
16331633

1634-
/* Older drivers create the identity domain via ops->domain_alloc() */
1635-
if (!ops->domain_alloc)
1634+
if (ops->domain_alloc_identity) {
1635+
domain = ops->domain_alloc_identity(dev);
1636+
if (IS_ERR(domain))
1637+
return domain;
1638+
} else if (ops->domain_alloc) {
1639+
domain = ops->domain_alloc(IOMMU_DOMAIN_IDENTITY);
1640+
if (!domain)
1641+
return ERR_PTR(-ENOMEM);
1642+
if (IS_ERR(domain))
1643+
return domain;
1644+
} else {
16361645
return ERR_PTR(-EOPNOTSUPP);
1637-
1638-
domain = ops->domain_alloc(IOMMU_DOMAIN_IDENTITY);
1639-
if (IS_ERR(domain))
1640-
return domain;
1641-
if (!domain)
1642-
return ERR_PTR(-ENOMEM);
1646+
}
16431647

16441648
iommu_domain_init(domain, IOMMU_DOMAIN_IDENTITY, ops);
16451649
return domain;

include/linux/iommu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
567567
* @domain_alloc: allocate and return an iommu domain if success. Otherwise
568568
* NULL is returned. The domain is not fully initialized until
569569
* the caller iommu_domain_alloc() returns.
570+
* @domain_alloc_identity: allocate an IDENTITY domain. Drivers should prefer to
571+
* use identity_domain instead. This should only be used
572+
* if dynamic logic is necessary.
570573
* @domain_alloc_paging_flags: Allocate an iommu domain corresponding to the
571574
* input parameters as defined in
572575
* include/uapi/linux/iommufd.h. The @user_data can be
@@ -625,6 +628,7 @@ struct iommu_ops {
625628

626629
/* Domain allocation and freeing by the iommu driver */
627630
struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type);
631+
struct iommu_domain *(*domain_alloc_identity)(struct device *dev);
628632
struct iommu_domain *(*domain_alloc_paging_flags)(
629633
struct device *dev, u32 flags,
630634
const struct iommu_user_data *user_data);

0 commit comments

Comments
 (0)