Skip to content

Commit 9872f9b

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Consolidate duplicate cache invaliation code
The pasid based IOTLB and devTLB invalidation code is duplicate in several places. Consolidate them by using the common helpers. Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 6ee1d74 commit 9872f9b

File tree

2 files changed

+11
-62
lines changed

2 files changed

+11
-62
lines changed

drivers/iommu/intel/pasid.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,6 @@ pasid_cache_invalidation_with_pasid(struct intel_iommu *iommu,
456456
qi_submit_sync(iommu, &desc, 1, 0);
457457
}
458458

459-
static void
460-
iotlb_invalidation_with_pasid(struct intel_iommu *iommu, u16 did, u32 pasid)
461-
{
462-
struct qi_desc desc;
463-
464-
desc.qw0 = QI_EIOTLB_PASID(pasid) | QI_EIOTLB_DID(did) |
465-
QI_EIOTLB_GRAN(QI_GRAN_NONG_PASID) | QI_EIOTLB_TYPE;
466-
desc.qw1 = 0;
467-
desc.qw2 = 0;
468-
desc.qw3 = 0;
469-
470-
qi_submit_sync(iommu, &desc, 1, 0);
471-
}
472-
473459
static void
474460
devtlb_invalidation_with_pasid(struct intel_iommu *iommu,
475461
struct device *dev, u32 pasid)
@@ -514,7 +500,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev,
514500
clflush_cache_range(pte, sizeof(*pte));
515501

516502
pasid_cache_invalidation_with_pasid(iommu, did, pasid);
517-
iotlb_invalidation_with_pasid(iommu, did, pasid);
503+
qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
518504

519505
/* Device IOTLB doesn't need to be flushed in caching mode. */
520506
if (!cap_caching_mode(iommu->cap))
@@ -530,7 +516,7 @@ static void pasid_flush_caches(struct intel_iommu *iommu,
530516

531517
if (cap_caching_mode(iommu->cap)) {
532518
pasid_cache_invalidation_with_pasid(iommu, did, pasid);
533-
iotlb_invalidation_with_pasid(iommu, did, pasid);
519+
qi_flush_piotlb(iommu, did, pasid, 0, -1, 0);
534520
} else {
535521
iommu_flush_write_buffer(iommu);
536522
}

drivers/iommu/intel/svm.c

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -123,53 +123,16 @@ static void __flush_svm_range_dev(struct intel_svm *svm,
123123
unsigned long address,
124124
unsigned long pages, int ih)
125125
{
126-
struct qi_desc desc;
126+
struct device_domain_info *info = get_domain_info(sdev->dev);
127127

128-
if (pages == -1) {
129-
desc.qw0 = QI_EIOTLB_PASID(svm->pasid) |
130-
QI_EIOTLB_DID(sdev->did) |
131-
QI_EIOTLB_GRAN(QI_GRAN_NONG_PASID) |
132-
QI_EIOTLB_TYPE;
133-
desc.qw1 = 0;
134-
} else {
135-
int mask = ilog2(__roundup_pow_of_two(pages));
136-
137-
desc.qw0 = QI_EIOTLB_PASID(svm->pasid) |
138-
QI_EIOTLB_DID(sdev->did) |
139-
QI_EIOTLB_GRAN(QI_GRAN_PSI_PASID) |
140-
QI_EIOTLB_TYPE;
141-
desc.qw1 = QI_EIOTLB_ADDR(address) |
142-
QI_EIOTLB_IH(ih) |
143-
QI_EIOTLB_AM(mask);
144-
}
145-
desc.qw2 = 0;
146-
desc.qw3 = 0;
147-
qi_submit_sync(sdev->iommu, &desc, 1, 0);
148-
149-
if (sdev->dev_iotlb) {
150-
desc.qw0 = QI_DEV_EIOTLB_PASID(svm->pasid) |
151-
QI_DEV_EIOTLB_SID(sdev->sid) |
152-
QI_DEV_EIOTLB_QDEP(sdev->qdep) |
153-
QI_DEIOTLB_TYPE;
154-
if (pages == -1) {
155-
desc.qw1 = QI_DEV_EIOTLB_ADDR(-1ULL >> 1) |
156-
QI_DEV_EIOTLB_SIZE;
157-
} else if (pages > 1) {
158-
/* The least significant zero bit indicates the size. So,
159-
* for example, an "address" value of 0x12345f000 will
160-
* flush from 0x123440000 to 0x12347ffff (256KiB). */
161-
unsigned long last = address + ((unsigned long)(pages - 1) << VTD_PAGE_SHIFT);
162-
unsigned long mask = __rounddown_pow_of_two(address ^ last);
163-
164-
desc.qw1 = QI_DEV_EIOTLB_ADDR((address & ~mask) |
165-
(mask - 1)) | QI_DEV_EIOTLB_SIZE;
166-
} else {
167-
desc.qw1 = QI_DEV_EIOTLB_ADDR(address);
168-
}
169-
desc.qw2 = 0;
170-
desc.qw3 = 0;
171-
qi_submit_sync(sdev->iommu, &desc, 1, 0);
172-
}
128+
if (WARN_ON(!pages))
129+
return;
130+
131+
qi_flush_piotlb(sdev->iommu, sdev->did, svm->pasid, address, pages, ih);
132+
if (info->ats_enabled)
133+
qi_flush_dev_iotlb_pasid(sdev->iommu, sdev->sid, info->pfsid,
134+
svm->pasid, sdev->qdep, address,
135+
order_base_2(pages));
173136
}
174137

175138
static void intel_flush_svm_range_dev(struct intel_svm *svm,

0 commit comments

Comments
 (0)