Skip to content

Commit 37ed364

Browse files
shavitmichaelwilldeacon
authored andcommitted
iommu/arm-smmu-v3-sva: Remove bond refcount
Always allocate a new arm_smmu_bond in __arm_smmu_sva_bind and remove the bond refcount since arm_smmu_bond can never be shared across calls to __arm_smmu_sva_bind. The iommu framework will not allocate multiple SVA domains for the same (device/mm) pair, nor will it call set_dev_pasid for a device if a domain is already attached on the given pasid. There's also a one-to-one mapping between MM and PASID. __arm_smmu_sva_bind is therefore never called with the same (device/mm) pair, and so there's no reason to try and normalize allocations of the arm_smmu_bond struct for a (device/mm) pair across set_dev_pasid. Signed-off-by: Michael Shavit <mshavit@google.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/20230905194849.v1.2.Id3ab7cf665bcead097654937233a645722a4cce3@changeid Signed-off-by: Will Deacon <will@kernel.org>
1 parent d912aed commit 37ed364

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct arm_smmu_bond {
2828
struct mm_struct *mm;
2929
struct arm_smmu_mmu_notifier *smmu_mn;
3030
struct list_head list;
31-
refcount_t refs;
3231
};
3332

3433
#define sva_to_bond(handle) \
@@ -386,20 +385,11 @@ static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm)
386385
if (!master || !master->sva_enabled)
387386
return -ENODEV;
388387

389-
/* If bind() was already called for this {dev, mm} pair, reuse it. */
390-
list_for_each_entry(bond, &master->bonds, list) {
391-
if (bond->mm == mm) {
392-
refcount_inc(&bond->refs);
393-
return &bond->sva;
394-
}
395-
}
396-
397388
bond = kzalloc(sizeof(*bond), GFP_KERNEL);
398389
if (!bond)
399390
return -ENOMEM;
400391

401392
bond->mm = mm;
402-
refcount_set(&bond->refs, 1);
403393

404394
bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm);
405395
if (IS_ERR(bond->smmu_mn)) {
@@ -578,7 +568,7 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain,
578568
}
579569
}
580570

581-
if (!WARN_ON(!bond) && refcount_dec_and_test(&bond->refs)) {
571+
if (!WARN_ON(!bond)) {
582572
list_del(&bond->list);
583573
arm_smmu_mmu_notifier_put(bond->smmu_mn);
584574
kfree(bond);

0 commit comments

Comments
 (0)