[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230905194849.v1.2.Id3ab7cf665bcead097654937233a645722a4cce3@changeid>
Date: Tue, 5 Sep 2023 19:49:13 +0800
From: Michael Shavit <mshavit@...gle.com>
To: iommu@...ts.linux.dev, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org
Cc: will@...nel.org, robin.murphy@....com, nicolinc@...dia.com,
jean-philippe@...aro.org, jgg@...dia.com, tina.zhang@...el.com,
Michael Shavit <mshavit@...gle.com>,
Jason Gunthorpe <jgg@...pe.ca>, Joerg Roedel <joro@...tes.org>,
Kevin Tian <kevin.tian@...el.com>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Lu Baolu <baolu.lu@...ux.intel.com>,
Mark Brown <broonie@...nel.org>,
Tomas Krcka <krckatom@...zon.de>,
Yicong Yang <yangyicong@...ilicon.com>
Subject: [PATCH v1 2/3] 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@...gle.com>
---
Note that this is true today because iommu_sva_bind_device calls
iommu_get_domain_for_dev_pasid to elude the iommu_attach_device_pasid if
a domain is already attached.
But even with Tina's patch series where iommu_get_domain_for_dev_pasid
is no longer used, iommu_attach_device_pasid also checks whether a
domain is already attached in the group's pasid_array.
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
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 32784758ccce6..9fb6907c5e7d4 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
@@ -28,7 +28,6 @@ struct arm_smmu_bond {
struct mm_struct *mm;
struct arm_smmu_mmu_notifier *smmu_mn;
struct list_head list;
- refcount_t refs;
};
#define sva_to_bond(handle) \
@@ -330,20 +329,11 @@ static int __arm_smmu_sva_bind(struct device *dev, struct mm_struct *mm)
if (!master || !master->sva_enabled)
return -ENODEV;
- /* If bind() was already called for this {dev, mm} pair, reuse it. */
- list_for_each_entry(bond, &master->bonds, list) {
- if (bond->mm == mm) {
- refcount_inc(&bond->refs);
- return &bond->sva;
- }
- }
-
bond = kzalloc(sizeof(*bond), GFP_KERNEL);
if (!bond)
return -ENOMEM;
bond->mm = mm;
- refcount_set(&bond->refs, 1);
bond->smmu_mn = arm_smmu_mmu_notifier_get(smmu_domain, mm);
if (IS_ERR(bond->smmu_mn)) {
@@ -522,7 +512,7 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain,
}
}
- if (!WARN_ON(!bond) && refcount_dec_and_test(&bond->refs)) {
+ if (!WARN_ON(!bond)) {
list_del(&bond->list);
arm_smmu_mmu_notifier_put(bond->smmu_mn);
kfree(bond);
--
2.42.0.283.g2d96d420d3-goog
Powered by blists - more mailing lists