[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231202092630.14764-1-yan.y.zhao@intel.com>
Date: Sat, 2 Dec 2023 17:26:30 +0800
From: Yan Zhao <yan.y.zhao@...el.com>
To: iommu@...ts.linux.dev, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: alex.williamson@...hat.com, jgg@...dia.com, pbonzini@...hat.com,
seanjc@...gle.com, joro@...tes.org, will@...nel.org,
robin.murphy@....com, kevin.tian@...el.com,
baolu.lu@...ux.intel.com, dwmw2@...radead.org, yi.l.liu@...el.com,
Yan Zhao <yan.y.zhao@...el.com>
Subject: [RFC PATCH 22/42] iommu/vt-d: Support cache invalidate of IOMMU_DOMAIN_KVM domain
Support invalidation of hardware TLBs on KVM invalidates mappings on
domain of type IOMMU_DOMAIN_KVM.
Signed-off-by: Yan Zhao <yan.y.zhao@...el.com>
---
drivers/iommu/intel/kvm.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/iommu/intel/kvm.c b/drivers/iommu/intel/kvm.c
index 998d6daaf7ea1..56cb8f9bf1da0 100644
--- a/drivers/iommu/intel/kvm.c
+++ b/drivers/iommu/intel/kvm.c
@@ -62,10 +62,41 @@ static bool kvm_domain_enforce_cache_coherency(struct iommu_domain *domain)
return true;
}
+static void domain_flush_iotlb_psi(struct dmar_domain *domain,
+ unsigned long iova, unsigned long size)
+{
+ struct iommu_domain_info *info;
+ unsigned long i;
+
+ if (!IS_ALIGNED(size, VTD_PAGE_SIZE) ||
+ !IS_ALIGNED(iova, VTD_PAGE_SIZE)) {
+ pr_err("Invalid KVM domain invalidation: iova=0x%lx, size=0x%lx\n",
+ iova, size);
+ return;
+ }
+
+ xa_for_each(&domain->iommu_array, i, info)
+ iommu_flush_iotlb_psi(info->iommu, domain,
+ iova >> VTD_PAGE_SHIFT,
+ size >> VTD_PAGE_SHIFT, 1, 0);
+}
+
+static void kvm_domain_cache_invalidate(struct iommu_domain *domain,
+ unsigned long iova, unsigned long size)
+{
+ struct dmar_domain *dmar_domain = to_dmar_domain(domain);
+
+ if (iova == 0 && size == -1UL)
+ intel_flush_iotlb_all(domain);
+ else
+ domain_flush_iotlb_psi(dmar_domain, iova, size);
+}
+
static const struct iommu_domain_ops intel_kvm_domain_ops = {
.attach_dev = intel_iommu_attach_device,
.free = intel_iommu_domain_free,
.enforce_cache_coherency = kvm_domain_enforce_cache_coherency,
+ .cache_invalidate_kvm = kvm_domain_cache_invalidate,
};
struct iommu_domain *
--
2.17.1
Powered by blists - more mailing lists