Skip to content

Commit 7a41dcb

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Set the pgsize_bitmap correctly
When using io_pgtable the correct pgsize_bitmap is stored in the cfg, both v1_alloc_pgtable() and v2_alloc_pgtable() set it correctly. This fixes a bug where the v2 pgtable had the wrong pgsize as protection_domain_init_v2() would set it and then do_iommu_domain_alloc() immediately resets it. Remove the confusing ops.pgsize_bitmap since that is not used if the driver sets domain.pgsize_bitmap. Fixes: 1342881 ("iommu/amd: Add domain_alloc_user based domain allocation") Reviewed-by: Vasant Hegde <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent b0a6c88 commit 7a41dcb

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,26 +2264,11 @@ void protection_domain_free(struct protection_domain *domain)
22642264
kfree(domain);
22652265
}
22662266

2267-
static int protection_domain_init_v1(struct protection_domain *domain)
2268-
{
2269-
domain->pd_mode = PD_MODE_V1;
2270-
return 0;
2271-
}
2272-
2273-
static int protection_domain_init_v2(struct protection_domain *pdom)
2274-
{
2275-
pdom->pd_mode = PD_MODE_V2;
2276-
pdom->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
2277-
2278-
return 0;
2279-
}
2280-
22812267
struct protection_domain *protection_domain_alloc(unsigned int type)
22822268
{
22832269
struct io_pgtable_ops *pgtbl_ops;
22842270
struct protection_domain *domain;
22852271
int pgtable;
2286-
int ret;
22872272

22882273
domain = kzalloc(sizeof(*domain), GFP_KERNEL);
22892274
if (!domain)
@@ -2319,18 +2304,14 @@ struct protection_domain *protection_domain_alloc(unsigned int type)
23192304

23202305
switch (pgtable) {
23212306
case AMD_IOMMU_V1:
2322-
ret = protection_domain_init_v1(domain);
2307+
domain->pd_mode = PD_MODE_V1;
23232308
break;
23242309
case AMD_IOMMU_V2:
2325-
ret = protection_domain_init_v2(domain);
2310+
domain->pd_mode = PD_MODE_V2;
23262311
break;
23272312
default:
2328-
ret = -EINVAL;
2329-
break;
2330-
}
2331-
2332-
if (ret)
23332313
goto out_err;
2314+
}
23342315

23352316
pgtbl_ops = alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl_cfg, domain);
23362317
if (!pgtbl_ops)
@@ -2383,10 +2364,10 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
23832364
domain->domain.geometry.aperture_start = 0;
23842365
domain->domain.geometry.aperture_end = dma_max_address();
23852366
domain->domain.geometry.force_aperture = true;
2367+
domain->domain.pgsize_bitmap = domain->iop.iop.cfg.pgsize_bitmap;
23862368

23872369
if (iommu) {
23882370
domain->domain.type = type;
2389-
domain->domain.pgsize_bitmap = iommu->iommu.ops->pgsize_bitmap;
23902371
domain->domain.ops = iommu->iommu.ops->default_domain_ops;
23912372

23922373
if (dirty_tracking)
@@ -2869,7 +2850,6 @@ const struct iommu_ops amd_iommu_ops = {
28692850
.device_group = amd_iommu_device_group,
28702851
.get_resv_regions = amd_iommu_get_resv_regions,
28712852
.is_attach_deferred = amd_iommu_is_attach_deferred,
2872-
.pgsize_bitmap = AMD_IOMMU_PGSIZES,
28732853
.def_domain_type = amd_iommu_def_domain_type,
28742854
.dev_enable_feat = amd_iommu_dev_enable_feature,
28752855
.dev_disable_feat = amd_iommu_dev_disable_feature,

0 commit comments

Comments
 (0)