Re: [PATCH v4 2/7] iommu: Allow .iotlb_sync_map to fail and handle s390's -ENOMEM return

From: Niklas Schnelle
Date: Thu Jan 19 2023 - 06:32:14 EST


On Wed, 2023-01-04 at 13:05 +0100, Niklas Schnelle wrote:
> On s390 when using a paging hypervisor, .iotlb_sync_map is used to sync
> mappings by letting the hypervisor inspect the synced IOVA range and
> updating a shadow table. This however means that .iotlb_sync_map can
> fail as the hypervisor may run out of resources while doing the sync.
> This can be due to the hypervisor being unable to pin guest pages, due
> to a limit on mapped addresses such as vfio_iommu_type1.dma_entry_limit
> or lack of other resources. Either way such a failure to sync a mapping
> should result in a DMA_MAPPING_ERROR.
>
> Now especially when running with batched IOTLB flushes for unmap it may
> be that some IOVAs have already been invalidated but not yet synced via
> .iotlb_sync_map. Thus if the hypervisor indicates running out of
> resources, first do a global flush allowing the hypervisor to free
> resources associated with these mappings as well a retry creating the
> new mappings and only if that also fails report this error to callers.
>
> Signed-off-by: Niklas Schnelle <schnelle@xxxxxxxxxxxxx>
> ---
> v3 -> v4:
> - Adapted signature of .iommu_tlb_sync mapo for sun50i IOMMU driver added in
> v6.2-rc1 (kernel test robot)
>
>

@Joerg, this patch, while being a prerequisite to the DMA API
conversion, is independent and in fact would also be needed for IOMMU
use in a nested KVM guest. With Baolu's and Matt's R-b's I think it
would make sense to pick this up for v6.3 even if the DMA API
conversion takes longer while we figure out details and the flush queue
changes. What do you think?

Thanks,
Niklas