Fix vfio_find_dma_valid to return WAITED on success if it was necessary to wait which mean iommu lock was dropped and reacquired. This allows vfio_iommu_type1_pin_pages to recheck vaddr_invalid_count and possibly avoid the checking the validity of every vaddr in its list. Signed-off-by: Anthony Yznaga <anthony.yznaga@xxxxxxxxxx> --- drivers/vfio/vfio_iommu_type1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index a3e925a41b0d..7ca8c4e95da4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -612,6 +612,7 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start, size_t size, struct vfio_dma **dma_p) { int ret; + int waited = 0; do { *dma_p = vfio_find_dma(iommu, start, size); @@ -620,10 +621,10 @@ static int vfio_find_dma_valid(struct vfio_iommu *iommu, dma_addr_t start, else if (!(*dma_p)->vaddr_invalid) ret = 0; else - ret = vfio_wait(iommu); + ret = waited = vfio_wait(iommu); } while (ret > 0); - return ret; + return ret ? ret : waited; } /* -- 1.8.3.1