Attempt to reduce indirect call overhead when mapping a substantial
scatter-gather list.

Signed-off-by: Chuck Lever <chuck.le...@oracle.com>
---
 drivers/iommu/intel/iommu.c |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 013097b6d55f..deae39f1477a 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -4952,6 +4952,42 @@ static int intel_iommu_map(struct iommu_domain *domain,
                                hpa >> VTD_PAGE_SHIFT, size, prot);
 }
 
+static int intel_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
+                             struct scatterlist *sg, unsigned int nents,
+                             int prot, gfp_t gfp, size_t *mapped)
+{
+       unsigned int i = 0;
+       phys_addr_t start;
+       size_t len = 0;
+       int ret;
+
+       while (i <= nents) {
+               phys_addr_t s_phys = sg_phys(sg);
+
+               if (len && s_phys != start + len) {
+                       ret = intel_iommu_map(domain, iova + *mapped, start,
+                                             len, prot, gfp);
+                       if (ret)
+                               return ret;
+
+                       *mapped += len;
+                       len = 0;
+               }
+
+               if (len) {
+                       len += sg->length;
+               } else {
+                       len = sg->length;
+                       start = s_phys;
+               }
+
+               if (++i < nents)
+                       sg = sg_next(sg);
+       }
+
+       return 0;
+}
+
 static size_t intel_iommu_unmap(struct iommu_domain *domain,
                                unsigned long iova, size_t size,
                                struct iommu_iotlb_gather *gather)
@@ -5519,6 +5555,7 @@ const struct iommu_ops intel_iommu_ops = {
        .aux_detach_dev         = intel_iommu_aux_detach_device,
        .aux_get_pasid          = intel_iommu_aux_get_pasid,
        .map                    = intel_iommu_map,
+       .map_sg                 = intel_iommu_map_sg,
        .iotlb_sync_map         = intel_iommu_iotlb_sync_map,
        .unmap                  = intel_iommu_unmap,
        .flush_iotlb_all        = intel_flush_iotlb_all,


_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to