Message ID | 20240528071831.17560-3-shameerali.kolothum.thodi@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | iommu/smmuv3: Add IOMMUFD dirty tracking support for SMMUv3 | expand |
On Tue, May 28, 2024 at 08:18:26AM +0100, Shameer Kolothum wrote: > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > @@ -648,7 +648,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, > > static void arm_smmu_sva_domain_free(struct iommu_domain *domain) > { > - kfree(domain); > + kfree(to_smmu_domain(domain)); > } > @@ -659,13 +659,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { > struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, > struct mm_struct *mm) > { > - struct iommu_domain *domain; > + struct arm_smmu_master *master = dev_iommu_priv_get(dev); > + struct arm_smmu_device *smmu = master->smmu; > + struct arm_smmu_domain *smmu_domain; > > - domain = kzalloc(sizeof(*domain), GFP_KERNEL); > - if (!domain) > - return ERR_PTR(-ENOMEM); > - domain->type = IOMMU_DOMAIN_SVA; > - domain->ops = &arm_smmu_sva_domain_ops; > + smmu_domain = arm_smmu_domain_alloc(); > + if (IS_ERR(smmu_domain)) > + return ERR_CAST(smmu_domain); > + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; > + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; > + smmu_domain->smmu = smmu; > > - return domain; > + return &smmu_domain->domain; > } If you drop these two hunks you can drop the first patch as well. There is no need to touch SVA in this series Jason
> -----Original Message----- > From: Jason Gunthorpe <jgg@nvidia.com> > Sent: Saturday, June 1, 2024 10:07 PM > To: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com> > Cc: iommu@lists.linux.dev; linux-arm-kernel@lists.infradead.org; > robin.murphy@arm.com; will@kernel.org; joro@8bytes.org; > ryan.roberts@arm.com; kevin.tian@intel.com; nicolinc@nvidia.com; > mshavit@google.com; eric.auger@redhat.com; joao.m.martins@oracle.com; > jiangkunkun <jiangkunkun@huawei.com>; zhukeqian > <zhukeqian1@huawei.com>; Linuxarm <linuxarm@huawei.com> > Subject: Re: [PATCH v4 2/7] iommu/arm-smmu-v3: Factor out a common > arm_smmu_domain_alloc() > > On Tue, May 28, 2024 at 08:18:26AM +0100, Shameer Kolothum wrote: > > > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > > @@ -648,7 +648,7 @@ static int arm_smmu_sva_set_dev_pasid(struct > iommu_domain *domain, > > > > static void arm_smmu_sva_domain_free(struct iommu_domain *domain) > > { > > - kfree(domain); > > + kfree(to_smmu_domain(domain)); > > } > > > > @@ -659,13 +659,16 @@ static const struct iommu_domain_ops > arm_smmu_sva_domain_ops = { > > struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, > > struct mm_struct *mm) > > { > > - struct iommu_domain *domain; > > + struct arm_smmu_master *master = dev_iommu_priv_get(dev); > > + struct arm_smmu_device *smmu = master->smmu; > > + struct arm_smmu_domain *smmu_domain; > > > > - domain = kzalloc(sizeof(*domain), GFP_KERNEL); > > - if (!domain) > > - return ERR_PTR(-ENOMEM); > > - domain->type = IOMMU_DOMAIN_SVA; > > - domain->ops = &arm_smmu_sva_domain_ops; > > + smmu_domain = arm_smmu_domain_alloc(); > > + if (IS_ERR(smmu_domain)) > > + return ERR_CAST(smmu_domain); > > + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; > > + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; > > + smmu_domain->smmu = smmu; > > > > - return domain; > > + return &smmu_domain->domain; > > } > > If you drop these two hunks you can drop the first patch as well. There > is no need to touch SVA in this series That is right. I will make those changes and re-spin soon. Thanks, SHameer
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 28f8bf4327f6..70c95887757f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -648,7 +648,7 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_domain *domain, static void arm_smmu_sva_domain_free(struct iommu_domain *domain) { - kfree(domain); + kfree(to_smmu_domain(domain)); } static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { @@ -659,13 +659,16 @@ static const struct iommu_domain_ops arm_smmu_sva_domain_ops = { struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm) { - struct iommu_domain *domain; + struct arm_smmu_master *master = dev_iommu_priv_get(dev); + struct arm_smmu_device *smmu = master->smmu; + struct arm_smmu_domain *smmu_domain; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return ERR_PTR(-ENOMEM); - domain->type = IOMMU_DOMAIN_SVA; - domain->ops = &arm_smmu_sva_domain_ops; + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + smmu_domain->domain.type = IOMMU_DOMAIN_SVA; + smmu_domain->domain.ops = &arm_smmu_sva_domain_ops; + smmu_domain->smmu = smmu; - return domain; + return &smmu_domain->domain; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index bd79422f7b6f..b574a36a7b95 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2237,15 +2237,10 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap) } } -static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +struct arm_smmu_domain *arm_smmu_domain_alloc(void) { struct arm_smmu_domain *smmu_domain; - /* - * Allocate the domain and initialise some of its data structures. - * We can't really do anything meaningful until we've added a - * master. - */ smmu_domain = kzalloc(sizeof(*smmu_domain), GFP_KERNEL); if (!smmu_domain) return ERR_PTR(-ENOMEM); @@ -2255,6 +2250,22 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) spin_lock_init(&smmu_domain->devices_lock); INIT_LIST_HEAD(&smmu_domain->mmu_notifiers); + return smmu_domain; +} + +static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) +{ + struct arm_smmu_domain *smmu_domain; + + /* + * Allocate the domain and initialise some of its data structures. + * We can't really do anything meaningful until we've added a + * master. + */ + smmu_domain = arm_smmu_domain_alloc(); + if (IS_ERR(smmu_domain)) + return ERR_CAST(smmu_domain); + if (dev) { struct arm_smmu_master *master = dev_iommu_priv_get(dev); int ret; @@ -2268,7 +2279,7 @@ static struct iommu_domain *arm_smmu_domain_alloc_paging(struct device *dev) return &smmu_domain->domain; } -static void arm_smmu_domain_free(struct iommu_domain *domain) +static void arm_smmu_domain_free_paging(struct iommu_domain *domain) { struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_device *smmu = smmu_domain->smmu; @@ -3111,7 +3122,7 @@ static struct iommu_ops arm_smmu_ops = { .iotlb_sync = arm_smmu_iotlb_sync, .iova_to_phys = arm_smmu_iova_to_phys, .enable_nesting = arm_smmu_enable_nesting, - .free = arm_smmu_domain_free, + .free = arm_smmu_domain_free_paging, } }; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 4c6c843669aa..e67ce0f8867f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -774,6 +774,8 @@ static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) extern struct xarray arm_smmu_asid_xa; extern struct mutex arm_smmu_asid_lock; +struct arm_smmu_domain *arm_smmu_domain_alloc(void); + void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid); struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid);