[PATCH v1 8/9] iommu: Introduce iotlb_sync_map callback

From: Dmitry Osipenko
Date: Fri May 11 2018 - 16:09:50 EST


On 11.05.2018 16:02, Robin Murphy wrote:
> On 08/05/18 19:16, Dmitry Osipenko wrote:
>> Introduce iotlb_sync_map() callback that is invoked in the end of
>> iommu_map(). This new callback allows IOMMU drivers to avoid syncing
>> on mapping of each contiguous chunk and sync only when whole mapping
>> is completed, optimizing performance of the mapping operation.
>
> This looks like a reasonable compromise - for users of
> IO_PGTABLE_QUIRK_TLBI_ON_MAP we can leave the implicit add_flush() in place for
> each individual map call, but at least move the sync() out to this callback,
> which should still be beneficial overall.
>
> Modulo one possible nit below,
>
> Reviewed-by: Robin Murphy <robin.murphy@xxxxxxx>
>
>> Signed-off-by: Dmitry Osipenko <digetx@xxxxxxxxx>
>> ---
>> Â drivers/iommu/iommu.c | 8 ++++++--
>> Â include/linux/iommu.h | 1 +
>> Â 2 files changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index d2aa23202bb9..39b2ee66aa96 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -1508,13 +1508,14 @@ static size_t iommu_pgsize(struct iommu_domain *domain,
>> Â int iommu_map(struct iommu_domain *domain, unsigned long iova,
>> ÂÂÂÂÂÂÂÂÂÂÂ phys_addr_t paddr, size_t size, int prot)
>> Â {
>> +ÂÂÂ const struct iommu_ops *ops = domain->ops;
>> ÂÂÂÂÂ unsigned long orig_iova = iova;
>> ÂÂÂÂÂ unsigned int min_pagesz;
>> ÂÂÂÂÂ size_t orig_size = size;
>> ÂÂÂÂÂ phys_addr_t orig_paddr = paddr;
>> ÂÂÂÂÂ int ret = 0;
>> Â -ÂÂÂ if (unlikely(domain->ops->map == NULL ||
>> +ÂÂÂ if (unlikely(ops->map == NULL ||
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ domain->pgsize_bitmap == 0UL))
>> ÂÂÂÂÂÂÂÂÂ return -ENODEV;
>> Â @@ -1543,7 +1544,7 @@ int iommu_map(struct iommu_domain *domain, unsigned
>> long iova,
>> ÂÂÂÂÂÂÂÂÂ pr_debug("mapping: iova 0x%lx pa %pa pgsize 0x%zx\n",
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ iova, &paddr, pgsize);
>> Â -ÂÂÂÂÂÂÂ ret = domain->ops->map(domain, iova, paddr, pgsize, prot);
>> +ÂÂÂÂÂÂÂ ret = ops->map(domain, iova, paddr, pgsize, prot);
>> ÂÂÂÂÂÂÂÂÂ if (ret)
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ break;
>> Â @@ -1552,6 +1553,9 @@ int iommu_map(struct iommu_domain *domain, unsigned
>> long iova,
>> ÂÂÂÂÂÂÂÂÂ size -= pgsize;
>> ÂÂÂÂÂ }
>> Â +ÂÂÂ if (ops->iotlb_sync_map)
>> +ÂÂÂÂÂÂÂ ops->iotlb_sync_map(domain);
>
> Is it worth trying to skip this in the error case when we're just going to undo
> it immediately?

I can imagine an IOMMU driver that could handle syncing of mapping differently
from the unmapping, in this case it may not worth skipping sync_map in the error
case.