Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20210114085021.717041-1-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Lu Baolu and committed by
Joerg Roedel
9872f9bd 6ee1d745

+10 -61
+2 -16
drivers/iommu/intel/pasid.c
··· 457 457 } 458 458 459 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 - 473 - static void 474 460 devtlb_invalidation_with_pasid(struct intel_iommu *iommu, 475 461 struct device *dev, u32 pasid) 476 462 { ··· 500 514 clflush_cache_range(pte, sizeof(*pte)); 501 515 502 516 pasid_cache_invalidation_with_pasid(iommu, did, pasid); 503 - iotlb_invalidation_with_pasid(iommu, did, pasid); 517 + qi_flush_piotlb(iommu, did, pasid, 0, -1, 0); 504 518 505 519 /* Device IOTLB doesn't need to be flushed in caching mode. */ 506 520 if (!cap_caching_mode(iommu->cap)) ··· 516 530 517 531 if (cap_caching_mode(iommu->cap)) { 518 532 pasid_cache_invalidation_with_pasid(iommu, did, pasid); 519 - iotlb_invalidation_with_pasid(iommu, did, pasid); 533 + qi_flush_piotlb(iommu, did, pasid, 0, -1, 0); 520 534 } else { 521 535 iommu_flush_write_buffer(iommu); 522 536 }
+8 -45
drivers/iommu/intel/svm.c
··· 123 123 unsigned long address, 124 124 unsigned long pages, int ih) 125 125 { 126 - struct qi_desc desc; 126 + struct device_domain_info *info = get_domain_info(sdev->dev); 127 127 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)); 128 + if (WARN_ON(!pages)) 129 + return; 136 130 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 - } 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)); 173 136 } 174 137 175 138 static void intel_flush_svm_range_dev(struct intel_svm *svm,