Skip to content

Commit a1ddcbe

Browse files
committed
iommu/vt-d: Pass dmar_domain directly into iommu_flush_iotlb_psi
This function can figure out the domain-id to use itself from the iommu_did array. This is more reliable over different domain types and brings us one step further to remove the domain->id field. Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent de24e55 commit a1ddcbe

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

drivers/iommu/intel-iommu.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,11 +1471,14 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain,
14711471
spin_unlock_irqrestore(&device_domain_lock, flags);
14721472
}
14731473

1474-
static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did,
1475-
unsigned long pfn, unsigned int pages, int ih, int map)
1474+
static void iommu_flush_iotlb_psi(struct intel_iommu *iommu,
1475+
struct dmar_domain *domain,
1476+
unsigned long pfn, unsigned int pages,
1477+
int ih, int map)
14761478
{
14771479
unsigned int mask = ilog2(__roundup_pow_of_two(pages));
14781480
uint64_t addr = (uint64_t)pfn << VTD_PAGE_SHIFT;
1481+
u16 did = domain->iommu_did[iommu->seq_id];
14791482

14801483
BUG_ON(pages == 0);
14811484

@@ -3422,7 +3425,9 @@ static dma_addr_t __intel_map_single(struct device *dev, phys_addr_t paddr,
34223425

34233426
/* it's a non-present to present mapping. Only flush if caching mode */
34243427
if (cap_caching_mode(iommu->cap))
3425-
iommu_flush_iotlb_psi(iommu, domain->id, mm_to_dma_pfn(iova->pfn_lo), size, 0, 1);
3428+
iommu_flush_iotlb_psi(iommu, domain,
3429+
mm_to_dma_pfn(iova->pfn_lo),
3430+
size, 0, 1);
34263431
else
34273432
iommu_flush_write_buffer(iommu);
34283433

@@ -3473,7 +3478,7 @@ static void flush_unmaps(void)
34733478

34743479
/* On real hardware multiple invalidations are expensive */
34753480
if (cap_caching_mode(iommu->cap))
3476-
iommu_flush_iotlb_psi(iommu, domain->id,
3481+
iommu_flush_iotlb_psi(iommu, domain,
34773482
iova->pfn_lo, iova_size(iova),
34783483
!deferred_flush[i].freelist[j], 0);
34793484
else {
@@ -3557,7 +3562,7 @@ static void intel_unmap(struct device *dev, dma_addr_t dev_addr)
35573562
freelist = domain_unmap(domain, start_pfn, last_pfn);
35583563

35593564
if (intel_iommu_strict) {
3560-
iommu_flush_iotlb_psi(iommu, domain->id, start_pfn,
3565+
iommu_flush_iotlb_psi(iommu, domain, start_pfn,
35613566
last_pfn - start_pfn + 1, !freelist, 0);
35623567
/* free iova */
35633568
__free_iova(&domain->iovad, iova);
@@ -3715,7 +3720,7 @@ static int intel_map_sg(struct device *dev, struct scatterlist *sglist, int nele
37153720

37163721
/* it's a non-present to present mapping. Only flush if caching mode */
37173722
if (cap_caching_mode(iommu->cap))
3718-
iommu_flush_iotlb_psi(iommu, domain->id, start_vpfn, size, 0, 1);
3723+
iommu_flush_iotlb_psi(iommu, domain, start_vpfn, size, 0, 1);
37193724
else
37203725
iommu_flush_write_buffer(iommu);
37213726

@@ -4421,7 +4426,7 @@ static int intel_iommu_memory_notifier(struct notifier_block *nb,
44214426

44224427
rcu_read_lock();
44234428
for_each_active_iommu(iommu, drhd)
4424-
iommu_flush_iotlb_psi(iommu, si_domain->id,
4429+
iommu_flush_iotlb_psi(iommu, si_domain,
44254430
iova->pfn_lo, iova_size(iova),
44264431
!freelist, 0);
44274432
rcu_read_unlock();
@@ -4872,17 +4877,18 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain,
48724877
npages = last_pfn - start_pfn + 1;
48734878

48744879
for_each_set_bit(iommu_id, dmar_domain->iommu_bmp, g_num_of_iommus) {
4875-
iommu = g_iommus[iommu_id];
4876-
4877-
/*
4878-
* find bit position of dmar_domain
4879-
*/
4880-
ndomains = cap_ndoms(iommu->cap);
4881-
for_each_set_bit(num, iommu->domain_ids, ndomains) {
4882-
if (get_iommu_domain(iommu, num) == dmar_domain)
4883-
iommu_flush_iotlb_psi(iommu, num, start_pfn,
4884-
npages, !freelist, 0);
4885-
}
4880+
iommu = g_iommus[iommu_id];
4881+
4882+
/*
4883+
* find bit position of dmar_domain
4884+
*/
4885+
ndomains = cap_ndoms(iommu->cap);
4886+
for_each_set_bit(num, iommu->domain_ids, ndomains) {
4887+
if (get_iommu_domain(iommu, num) == dmar_domain)
4888+
iommu_flush_iotlb_psi(iommu, dmar_domain,
4889+
start_pfn, npages,
4890+
!freelist, 0);
4891+
}
48864892

48874893
}
48884894

0 commit comments

Comments
 (0)