Skip to content

Commit d8cd200

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Pass arm_smmu_domain and arm_smmu_device to finalize
Instead of putting container_of() casts in the internals, use the proper type in this call chain. This makes it easier to check that the two global static domains are not leaking into call chains they should not. Passing the smmu avoids the only caller from having to set it and unset it in the error path. Reviewed-by: Michael Shavit <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Moritz Fischer <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent d36464f commit d8cd200

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static struct arm_smmu_option_prop arm_smmu_options[] = {
8989
{ 0, NULL},
9090
};
9191

92+
static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
93+
struct arm_smmu_device *smmu);
94+
9295
static void parse_driver_options(struct arm_smmu_device *smmu)
9396
{
9497
int i = 0;
@@ -2242,12 +2245,12 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
22422245
kfree(smmu_domain);
22432246
}
22442247

2245-
static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
2248+
static int arm_smmu_domain_finalise_s1(struct arm_smmu_device *smmu,
2249+
struct arm_smmu_domain *smmu_domain,
22462250
struct io_pgtable_cfg *pgtbl_cfg)
22472251
{
22482252
int ret;
22492253
u32 asid;
2250-
struct arm_smmu_device *smmu = smmu_domain->smmu;
22512254
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
22522255
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
22532256

@@ -2279,11 +2282,11 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
22792282
return ret;
22802283
}
22812284

2282-
static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain,
2285+
static int arm_smmu_domain_finalise_s2(struct arm_smmu_device *smmu,
2286+
struct arm_smmu_domain *smmu_domain,
22832287
struct io_pgtable_cfg *pgtbl_cfg)
22842288
{
22852289
int vmid;
2286-
struct arm_smmu_device *smmu = smmu_domain->smmu;
22872290
struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
22882291

22892292
/* Reserve VMID 0 for stage-2 bypass STEs */
@@ -2296,17 +2299,17 @@ static int arm_smmu_domain_finalise_s2(struct arm_smmu_domain *smmu_domain,
22962299
return 0;
22972300
}
22982301

2299-
static int arm_smmu_domain_finalise(struct iommu_domain *domain)
2302+
static int arm_smmu_domain_finalise(struct arm_smmu_domain *smmu_domain,
2303+
struct arm_smmu_device *smmu)
23002304
{
23012305
int ret;
23022306
unsigned long ias, oas;
23032307
enum io_pgtable_fmt fmt;
23042308
struct io_pgtable_cfg pgtbl_cfg;
23052309
struct io_pgtable_ops *pgtbl_ops;
2306-
int (*finalise_stage_fn)(struct arm_smmu_domain *,
2307-
struct io_pgtable_cfg *);
2308-
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
2309-
struct arm_smmu_device *smmu = smmu_domain->smmu;
2310+
int (*finalise_stage_fn)(struct arm_smmu_device *smmu,
2311+
struct arm_smmu_domain *smmu_domain,
2312+
struct io_pgtable_cfg *pgtbl_cfg);
23102313

23112314
/* Restrict the stage to what we can actually support */
23122315
if (!(smmu->features & ARM_SMMU_FEAT_TRANS_S1))
@@ -2345,17 +2348,18 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain)
23452348
if (!pgtbl_ops)
23462349
return -ENOMEM;
23472350

2348-
domain->pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
2349-
domain->geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1;
2350-
domain->geometry.force_aperture = true;
2351+
smmu_domain->domain.pgsize_bitmap = pgtbl_cfg.pgsize_bitmap;
2352+
smmu_domain->domain.geometry.aperture_end = (1UL << pgtbl_cfg.ias) - 1;
2353+
smmu_domain->domain.geometry.force_aperture = true;
23512354

2352-
ret = finalise_stage_fn(smmu_domain, &pgtbl_cfg);
2355+
ret = finalise_stage_fn(smmu, smmu_domain, &pgtbl_cfg);
23532356
if (ret < 0) {
23542357
free_io_pgtable_ops(pgtbl_ops);
23552358
return ret;
23562359
}
23572360

23582361
smmu_domain->pgtbl_ops = pgtbl_ops;
2362+
smmu_domain->smmu = smmu;
23592363
return 0;
23602364
}
23612365

@@ -2547,10 +2551,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
25472551
mutex_lock(&smmu_domain->init_mutex);
25482552

25492553
if (!smmu_domain->smmu) {
2550-
smmu_domain->smmu = smmu;
2551-
ret = arm_smmu_domain_finalise(domain);
2552-
if (ret)
2553-
smmu_domain->smmu = NULL;
2554+
ret = arm_smmu_domain_finalise(smmu_domain, smmu);
25542555
} else if (smmu_domain->smmu != smmu)
25552556
ret = -EINVAL;
25562557

0 commit comments

Comments
 (0)