Skip to content

Commit d7b2d2b

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Make SVA allocate a normal arm_smmu_domain
Currently the SVA domain is a naked struct iommu_domain, allocate a struct arm_smmu_domain instead. This is necessary to be able to use the struct arm_master_domain mechanism. Tested-by: Nicolin Chen <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Reviewed-by: Michael Shavit <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Jerry Snitselaar <[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 1d5f34f commit d7b2d2b

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain,
639639
}
640640

641641
arm_smmu_make_sva_cd(&target, master, mm, bond->smmu_mn->cd->asid);
642-
ret = arm_smmu_set_pasid(master, NULL, id, &target);
642+
ret = arm_smmu_set_pasid(master, to_smmu_domain(domain), id, &target);
643643
if (ret) {
644644
list_del(&bond->list);
645645
arm_smmu_mmu_notifier_put(bond->smmu_mn);
@@ -653,7 +653,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain,
653653

654654
static void arm_smmu_sva_domain_free(struct iommu_domain *domain)
655655
{
656-
kfree(domain);
656+
kfree(to_smmu_domain(domain));
657657
}
658658

659659
static const struct iommu_domain_ops arm_smmu_sva_domain_ops = {
@@ -664,13 +664,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = {
664664
struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev,
665665
struct mm_struct *mm)
666666
{
667-
struct iommu_domain *domain;
667+
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
668+
struct arm_smmu_device *smmu = master->smmu;
669+
struct arm_smmu_domain *smmu_domain;
668670

669-
domain = kzalloc(sizeof(*domain), GFP_KERNEL);
670-
if (!domain)
671-
return ERR_PTR(-ENOMEM);
672-
domain->type = IOMMU_DOMAIN_SVA;
673-
domain->ops = &arm_smmu_sva_domain_ops;
671+
smmu_domain = arm_smmu_domain_alloc();
672+
if (IS_ERR(smmu_domain))
673+
return ERR_CAST(smmu_domain);
674+
smmu_domain->domain.type = IOMMU_DOMAIN_SVA;
675+
smmu_domain->domain.ops = &arm_smmu_sva_domain_ops;
676+
smmu_domain->smmu = smmu;
674677

675-
return domain;
678+
return &smmu_domain->domain;
676679
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,15 +2272,10 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)
22722272
}
22732273
}
22742274

2275-
static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
2275+
struct arm_smmu_domain *arm_smmu_domain_alloc(void)
22762276
{
22772277
struct arm_smmu_domain *smmu_domain;
22782278

2279-
/*
2280-
* Allocate the domain and initialise some of its data structures.
2281-
* We can't really do anything meaningful until we've added a
2282-
* master.
2283-
*/
22842279
smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL);
22852280
if (!smmu_domain)
22862281
return ERR_PTR(-ENOMEM);
@@ -2290,6 +2285,22 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
22902285
spin_lock_init(&smmu_domain->devices_lock);
22912286
INIT_LIST_HEAD(&smmu_domain->mmu_notifiers);
22922287

2288+
return smmu_domain;
2289+
}
2290+
2291+
static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
2292+
{
2293+
struct arm_smmu_domain *smmu_domain;
2294+
2295+
/*
2296+
* Allocate the domain and initialise some of its data structures.
2297+
* We can't really do anything meaningful until we've added a
2298+
* master.
2299+
*/
2300+
smmu_domain = arm_smmu_domain_alloc();
2301+
if (IS_ERR(smmu_domain))
2302+
return ERR_CAST(smmu_domain);
2303+
22932304
if (dev) {
22942305
struct arm_smmu_master *master = dev_iommu_priv_get(dev);
22952306
int ret;
@@ -2303,7 +2314,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev)
23032314
return &smmu_domain->domain;
23042315
}
23052316

2306-
static void arm_smmu_domain_free(struct iommu_domain *domain)
2317+
static void arm_smmu_domain_free_paging(struct iommu_domain *domain)
23072318
{
23082319
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
23092320
struct arm_smmu_device *smmu = smmu_domain->smmu;
@@ -3305,7 +3316,7 @@ static struct iommu_ops arm_smmu_ops = {
33053316
.iotlb_sync = arm_smmu_iotlb_sync,
33063317
.iova_to_phys = arm_smmu_iova_to_phys,
33073318
.enable_nesting = arm_smmu_enable_nesting,
3308-
.free = arm_smmu_domain_free,
3319+
.free = arm_smmu_domain_free_paging,
33093320
}
33103321
};
33113322

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom)
790790
extern struct xarray arm_smmu_asid_xa;
791791
extern struct mutex arm_smmu_asid_lock;
792792

793+
struct arm_smmu_domain *arm_smmu_domain_alloc(void);
794+
793795
void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid);
794796
struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master,
795797
u32 ssid);

0 commit comments

Comments
 (0)