mirror of
https://github.com/torvalds/linux.git
synced 2026-05-27 08:33:17 +02:00
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 <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/6-v3-dbbe6f7e7ae3+124ffe-vtd_prep_jgg@nvidia.com Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Link: https://lore.kernel.org/r/20250714045028.958850-9-baolu.lu@linux.intel.com Signed-off-by: Will Deacon <will@kernel.org>
This commit is contained in:
parent
b33125296b
commit
0fa6f08934
|
|
@ -3643,44 +3643,41 @@ static bool domain_support_force_snooping(struct dmar_domain *domain)
|
|||
return support;
|
||||
}
|
||||
|
||||
static void domain_set_force_snooping(struct dmar_domain *domain)
|
||||
{
|
||||
struct device_domain_info *info;
|
||||
|
||||
assert_spin_locked(&domain->lock);
|
||||
/*
|
||||
* Second level page table supports per-PTE snoop control. The
|
||||
* iommu_map() interface will handle this by setting SNP bit.
|
||||
*/
|
||||
if (!domain->use_first_level) {
|
||||
domain->set_pte_snp = true;
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry(info, &domain->devices, link)
|
||||
intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
|
||||
IOMMU_NO_PASID);
|
||||
}
|
||||
|
||||
static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
|
||||
static bool intel_iommu_enforce_cache_coherency_fs(struct iommu_domain *domain)
|
||||
{
|
||||
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
|
||||
unsigned long flags;
|
||||
struct device_domain_info *info;
|
||||
|
||||
guard(spinlock_irqsave)(&dmar_domain->lock);
|
||||
|
||||
if (dmar_domain->force_snooping)
|
||||
return true;
|
||||
|
||||
spin_lock_irqsave(&dmar_domain->lock, flags);
|
||||
if (!domain_support_force_snooping(dmar_domain) ||
|
||||
(!dmar_domain->use_first_level && dmar_domain->has_mappings)) {
|
||||
spin_unlock_irqrestore(&dmar_domain->lock, flags);
|
||||
if (!domain_support_force_snooping(dmar_domain))
|
||||
return false;
|
||||
}
|
||||
|
||||
domain_set_force_snooping(dmar_domain);
|
||||
dmar_domain->force_snooping = true;
|
||||
spin_unlock_irqrestore(&dmar_domain->lock, flags);
|
||||
list_for_each_entry(info, &dmar_domain->devices, link)
|
||||
intel_pasid_setup_page_snoop_control(info->iommu, info->dev,
|
||||
IOMMU_NO_PASID);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool intel_iommu_enforce_cache_coherency_ss(struct iommu_domain *domain)
|
||||
{
|
||||
struct dmar_domain *dmar_domain = to_dmar_domain(domain);
|
||||
|
||||
guard(spinlock_irqsave)(&dmar_domain->lock);
|
||||
if (!domain_support_force_snooping(dmar_domain) ||
|
||||
dmar_domain->has_mappings)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Second level page table supports per-PTE snoop control. The
|
||||
* iommu_map() interface will handle this by setting SNP bit.
|
||||
*/
|
||||
dmar_domain->set_pte_snp = true;
|
||||
dmar_domain->force_snooping = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -4398,7 +4395,7 @@ const struct iommu_domain_ops intel_fs_paging_domain_ops = {
|
|||
.iotlb_sync = intel_iommu_tlb_sync,
|
||||
.iova_to_phys = intel_iommu_iova_to_phys,
|
||||
.free = intel_iommu_domain_free,
|
||||
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
|
||||
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency_fs,
|
||||
};
|
||||
|
||||
const struct iommu_domain_ops intel_ss_paging_domain_ops = {
|
||||
|
|
@ -4411,7 +4408,7 @@ const struct iommu_domain_ops intel_ss_paging_domain_ops = {
|
|||
.iotlb_sync = intel_iommu_tlb_sync,
|
||||
.iova_to_phys = intel_iommu_iova_to_phys,
|
||||
.free = intel_iommu_domain_free,
|
||||
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency,
|
||||
.enforce_cache_coherency = intel_iommu_enforce_cache_coherency_ss,
|
||||
};
|
||||
|
||||
const struct iommu_ops intel_iommu_ops = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user