Skip to content

Commit 2c3262f

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Acquiring lock in domain ID allocation helpers
The iommu->lock is used to protect the per-IOMMU domain ID resource. Moving the lock into the ID alloc/free helpers makes the code more compact. At the same time, the device_domain_lock is irrelevant to the domain ID resource, remove its assertion as well. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/20220706025524.2904370-7-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent ffd5869 commit 2c3262f

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

drivers/iommu/intel/iommu.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,16 +1779,13 @@ static struct dmar_domain *alloc_domain(unsigned int type)
17791779
return domain;
17801780
}
17811781

1782-
/* Must be called with iommu->lock */
17831782
static int domain_attach_iommu(struct dmar_domain *domain,
17841783
struct intel_iommu *iommu)
17851784
{
17861785
unsigned long ndomains;
1787-
int num;
1788-
1789-
assert_spin_locked(&device_domain_lock);
1790-
assert_spin_locked(&iommu->lock);
1786+
int num, ret = 0;
17911787

1788+
spin_lock(&iommu->lock);
17921789
domain->iommu_refcnt[iommu->seq_id] += 1;
17931790
if (domain->iommu_refcnt[iommu->seq_id] == 1) {
17941791
ndomains = cap_ndoms(iommu->cap);
@@ -1797,7 +1794,8 @@ static int domain_attach_iommu(struct dmar_domain *domain,
17971794
if (num >= ndomains) {
17981795
pr_err("%s: No free domain ids\n", iommu->name);
17991796
domain->iommu_refcnt[iommu->seq_id] -= 1;
1800-
return -ENOSPC;
1797+
ret = -ENOSPC;
1798+
goto out_unlock;
18011799
}
18021800

18031801
set_bit(num, iommu->domain_ids);
@@ -1806,24 +1804,25 @@ static int domain_attach_iommu(struct dmar_domain *domain,
18061804
domain_update_iommu_cap(domain);
18071805
}
18081806

1809-
return 0;
1807+
out_unlock:
1808+
spin_unlock(&iommu->lock);
1809+
return ret;
18101810
}
18111811

18121812
static void domain_detach_iommu(struct dmar_domain *domain,
18131813
struct intel_iommu *iommu)
18141814
{
18151815
int num;
18161816

1817-
assert_spin_locked(&device_domain_lock);
1818-
assert_spin_locked(&iommu->lock);
1819-
1817+
spin_lock(&iommu->lock);
18201818
domain->iommu_refcnt[iommu->seq_id] -= 1;
18211819
if (domain->iommu_refcnt[iommu->seq_id] == 0) {
18221820
num = domain->iommu_did[iommu->seq_id];
18231821
clear_bit(num, iommu->domain_ids);
18241822
domain_update_iommu_cap(domain);
18251823
domain->iommu_did[iommu->seq_id] = 0;
18261824
}
1825+
spin_unlock(&iommu->lock);
18271826
}
18281827

18291828
static inline int guestwidth_to_adjustwidth(int gaw)
@@ -2472,9 +2471,7 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
24722471

24732472
spin_lock(&device_domain_lock);
24742473
info->domain = domain;
2475-
spin_lock(&iommu->lock);
24762474
ret = domain_attach_iommu(domain, iommu);
2477-
spin_unlock(&iommu->lock);
24782475
if (ret) {
24792476
spin_unlock(&device_domain_lock);
24802477
return ret;
@@ -4178,10 +4175,7 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info)
41784175
}
41794176

41804177
list_del(&info->link);
4181-
4182-
spin_lock(&iommu->lock);
41834178
domain_detach_iommu(domain, iommu);
4184-
spin_unlock(&iommu->lock);
41854179
}
41864180

41874181
static void dmar_remove_one_dev_info(struct device *dev)

0 commit comments

Comments
 (0)