Skip to content
  • Antonios Motakis's avatar
    VFIO: vfio_iommu_type1: fix bug caused by break in nested loop · d93b3ac0
    Antonios Motakis authored
    
    
    In vfio_iommu_type1.c there is a bug in vfio_dma_do_map, when checking
    that pages are not already mapped. Since the check is being done in a
    for loop nested within the main loop, breaking out of it does not create
    the intended behavior. If the underlying IOMMU driver returns a non-NULL
    value, this will be ignored and mapping the DMA range will be attempted
    anyway, leading to unpredictable behavior.
    
    This interracts badly with the ARM SMMU driver issue fixed in the patch
    that was submitted with the title:
    "[PATCH 2/2] ARM: SMMU: return NULL on error in arm_smmu_iova_to_phys"
    Both fixes are required in order to use the vfio_iommu_type1 driver
    with an ARM SMMU.
    
    This patch refactors the function slightly, in order to also make this
    kind of bug less likely.
    
    Signed-off-by: default avatarAntonios Motakis <a.motakis@virtualopensystems.com>
    Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
    d93b3ac0