Skip to content

Commit ce2cd17

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd: Enhance amd_iommu_domain_alloc_user()
Previous patch enhanced core layer to check device PASID capability and pass right flags to ops->domain_alloc_user(). Enhance amd_iommu_domain_alloc_user() to allocate domain with appropriate page table based on flags parameter. - If flags is empty then allocate domain with default page table type. This will eventually replace ops->domain_alloc(). For UNMANAGED domain, core will call this interface with flags=0. So AMD driver will continue to allocate V1 page table. - If IOMMU_HWPT_ALLOC_PASID flags is passed then allocate domain with v2 page table. Signed-off-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20241028093810.5901-10-vasant.hegde@amd.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent a005ef6 commit ce2cd17

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,9 +2346,6 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
23462346
if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY))
23472347
return ERR_PTR(-EINVAL);
23482348

2349-
if (dirty_tracking && !amd_iommu_hd_support(iommu))
2350-
return ERR_PTR(-EOPNOTSUPP);
2351-
23522349
domain = protection_domain_alloc(type,
23532350
dev ? dev_to_node(dev) : NUMA_NO_NODE);
23542351
if (!domain)
@@ -2403,11 +2400,36 @@ amd_iommu_domain_alloc_user(struct device *dev, u32 flags,
24032400

24042401
{
24052402
unsigned int type = IOMMU_DOMAIN_UNMANAGED;
2403+
struct amd_iommu *iommu = NULL;
2404+
const u32 supported_flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
2405+
IOMMU_HWPT_ALLOC_PASID;
2406+
2407+
if (dev)
2408+
iommu = get_amd_iommu_from_dev(dev);
2409+
2410+
if ((flags & ~supported_flags) || parent || user_data)
2411+
return ERR_PTR(-EOPNOTSUPP);
2412+
2413+
/* Allocate domain with v2 page table if IOMMU supports PASID. */
2414+
if (flags & IOMMU_HWPT_ALLOC_PASID) {
2415+
if (!amd_iommu_pasid_supported())
2416+
return ERR_PTR(-EOPNOTSUPP);
2417+
2418+
return do_iommu_domain_alloc(type, dev, flags, AMD_IOMMU_V2);
2419+
}
2420+
2421+
/* Allocate domain with v1 page table for dirty tracking */
2422+
if (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) {
2423+
if (iommu && amd_iommu_hd_support(iommu)) {
2424+
return do_iommu_domain_alloc(type, dev,
2425+
flags, AMD_IOMMU_V1);
2426+
}
24062427

2407-
if ((flags & ~IOMMU_HWPT_ALLOC_DIRTY_TRACKING) || parent || user_data)
24082428
return ERR_PTR(-EOPNOTSUPP);
2429+
}
24092430

2410-
return do_iommu_domain_alloc(type, dev, flags, AMD_IOMMU_V1);
2431+
/* If nothing specific is required use the kernel commandline default */
2432+
return do_iommu_domain_alloc(type, dev, 0, amd_iommu_pgtable);
24112433
}
24122434

24132435
void amd_iommu_domain_free(struct iommu_domain *dom)

0 commit comments

Comments
 (0)