[PATCH v10 12/13] iommu/arm-smmu-v3: Implement iommu_sva_bind/unbind()

Jean-Philippe Brucker jean-philippe at linaro.org
Wed Nov 25 04:27:49 EST 2020


On Tue, Nov 24, 2020 at 07:58:00PM -0400, Jason Gunthorpe wrote:
> On Fri, Sep 18, 2020 at 12:18:52PM +0200, Jean-Philippe Brucker wrote:
> 
> > +/* Allocate or get existing MMU notifier for this {domain, mm} pair */
> > +static struct arm_smmu_mmu_notifier *
> > +arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
> > +			  struct mm_struct *mm)
> > +{
> > +	int ret;
> > +	struct arm_smmu_ctx_desc *cd;
> > +	struct arm_smmu_mmu_notifier *smmu_mn;
> > +
> > +	list_for_each_entry(smmu_mn, &smmu_domain->mmu_notifiers, list) {
> > +		if (smmu_mn->mn.mm == mm) {
> > +			refcount_inc(&smmu_mn->refs);
> > +			return smmu_mn;
> > +		}
> > +	}
> > +
> > +	cd = arm_smmu_alloc_shared_cd(mm);
> > +	if (IS_ERR(cd))
> > +		return ERR_CAST(cd);
> > +
> > +	smmu_mn = kzalloc(sizeof(*smmu_mn), GFP_KERNEL);
> > +	if (!smmu_mn) {
> > +		ret = -ENOMEM;
> > +		goto err_free_cd;
> > +	}
> > +
> > +	refcount_set(&smmu_mn->refs, 1);
> > +	smmu_mn->cd = cd;
> > +	smmu_mn->domain = smmu_domain;
> > +	smmu_mn->mn.ops = &arm_smmu_mmu_notifier_ops;
> > +
> > +	ret = mmu_notifier_register(&smmu_mn->mn, mm);
> > +	if (ret) {
> > +		kfree(smmu_mn);
> > +		goto err_free_cd;
> > +	}
> 
> I suppose this hasn't been applied yet, but someone asked me to look
> at this series..

It's queued for v5.11, but I could submit improvements for 5.12

> Why did you drop the change to mmu_notifier_get here?

Dropped at v6 when I got rid of the io_mm cruft:
https://lore.kernel.org/linux-iommu/20200430143424.2787566-1-jean-philippe@linaro.org/

> I'm strongly
> trying to discourage static lists matching mm's like smmu_mn is
> doing. This is handled by the core code, don't open code it..

We discussed this at v6, which wonkily stored the mn ops in the domain to
obtain a unique notifier per {mm, domain}. A clean solution requires
changing mm_notifier_get() to use an opaque token. Rather than testing
{mm, ops} uniqueness it would compare {mm, ops, token}. I figured it
wasn't worth the effort for a single driver, especially since the SMMU
driver would still have one list matching because it needs to deal with
both {mm, domain} and {mm, device} uniqueness.
https://lore.kernel.org/linux-iommu/20200501121552.GA6012@infradead.org/

Thanks,
Jean




More information about the linux-arm-kernel mailing list