Skip to content

Commit 0fa6f08

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/vt-d: Split intel_iommu_enforce_cache_coherency()
First Stage and Second Stage have very different ways to deny no-snoop. The first stage uses the PGSNP bit which is global per-PASID so enabling requires loading new PASID entries for all the attached devices. Second stage uses a bit per PTE, so enabling just requires telling future maps to set the bit. Since we now have two domain ops we can have two functions that can directly code their required actions instead of a bunch of logic dancing around use_first_level. Combine domain_set_force_snooping() into the new functions since they are the only caller. Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent b331252 commit 0fa6f08

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,44 +3643,41 @@ static bool domain_support_force_snooping(struct dmar_domain *domain)
36433643
return support;
36443644
}
36453645

3646-
static void domain_set_force_snooping(struct dmar_domain *domain)
3646+
static bool intel_iommu_enforce_cache_coherency_fs(struct iommu_domain *domain)
36473647
{
3648+
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
36483649
struct device_domain_info *info;
36493650

3650-
assert_spin_locked(&domain->lock);
3651-
/*
3652-
* Second level page table supports per-PTE snoop control. The
3653-
* iommu_map() interface will handle this by setting SNP bit.
3654-
*/
3655-
if (!domain->use_first_level) {
3656-
domain->set_pte_snp = true;
3657-
return;
3658-
}
3651+
guard(spinlock_irqsave)(&dmar_domain->lock);
3652+
3653+
if (dmar_domain->force_snooping)
3654+
return true;
36593655

3660-
list_for_each_entry(info, &domain->devices, link)
3656+
if (!domain_support_force_snooping(dmar_domain))
3657+
return false;
3658+
3659+
dmar_domain->force_snooping = true;
3660+
list_for_each_entry(info, &dmar_domain->devices, link)
36613661
intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
36623662
IOMMU_NO_PASID);
3663+
return true;
36633664
}
36643665

3665-
static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
3666+
static bool intel_iommu_enforce_cache_coherency_ss(struct iommu_domain *domain)
36663667
{
36673668
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
3668-
unsigned long flags;
36693669

3670-
if (dmar_domain->force_snooping)
3671-
return true;
3672-
3673-
spin_lock_irqsave(&dmar_domain->lock, flags);
3670+
guard(spinlock_irqsave)(&dmar_domain->lock);
36743671
if (!domain_support_force_snooping(dmar_domain) ||
3675-
(!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
3676-
spin_unlock_irqrestore(&dmar_domain->lock, flags);
3672+
dmar_domain->has_mappings)
36773673
return false;
3678-
}
36793674

3680-
domain_set_force_snooping(dmar_domain);
3675+
/*
3676+
* Second level page table supports per-PTE snoop control. The
3677+
* iommu_map() interface will handle this by setting SNP bit.
3678+
*/
3679+
dmar_domain->set_pte_snp = true;
36813680
dmar_domain->force_snooping = true;
3682-
spin_unlock_irqrestore(&dmar_domain->lock, flags);
3683-
36843681
return true;
36853682
}
36863683

@@ -4398,7 +4395,7 @@ const struct iommu_domain_ops intel_fs_paging_domain_ops = {
43984395
.iotlb_sync = intel_iommu_tlb_sync,
43994396
.iova_to_phys = intel_iommu_iova_to_phys,
44004397
.free = intel_iommu_domain_free,
4401-
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
4398+
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency_fs,
44024399
};
44034400

44044401
const struct iommu_domain_ops intel_ss_paging_domain_ops = {
@@ -4411,7 +4408,7 @@ const struct iommu_domain_ops intel_ss_paging_domain_ops = {
44114408
.iotlb_sync = intel_iommu_tlb_sync,
44124409
.iova_to_phys = intel_iommu_iova_to_phys,
44134410
.free = intel_iommu_domain_free,
4414-
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
4411+
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency_ss,
44154412
};
44164413

44174414
const struct iommu_ops intel_iommu_ops = {

0 commit comments

Comments
 (0)