vfio/type1: implement unmap all
Implement VFIO_DMA_UNMAP_FLAG_ALL. Signed-off-by: Steve Sistare <steven.sistare@oracle.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
0f53afa12b
commit
c196509953
@ -1078,6 +1078,7 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
|
|||||||
unsigned long pgshift;
|
unsigned long pgshift;
|
||||||
dma_addr_t iova = unmap->iova;
|
dma_addr_t iova = unmap->iova;
|
||||||
unsigned long size = unmap->size;
|
unsigned long size = unmap->size;
|
||||||
|
bool unmap_all = unmap->flags & VFIO_DMA_UNMAP_FLAG_ALL;
|
||||||
|
|
||||||
mutex_lock(&iommu->lock);
|
mutex_lock(&iommu->lock);
|
||||||
|
|
||||||
@ -1087,8 +1088,13 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
|
|||||||
if (iova & (pgsize - 1))
|
if (iova & (pgsize - 1))
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
|
||||||
if (!size || size & (pgsize - 1))
|
if (unmap_all) {
|
||||||
|
if (iova || size)
|
||||||
|
goto unlock;
|
||||||
|
size = SIZE_MAX;
|
||||||
|
} else if (!size || size & (pgsize - 1)) {
|
||||||
goto unlock;
|
goto unlock;
|
||||||
|
}
|
||||||
|
|
||||||
if (iova + size - 1 < iova || size > SIZE_MAX)
|
if (iova + size - 1 < iova || size > SIZE_MAX)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
@ -1132,7 +1138,7 @@ again:
|
|||||||
* will only return success and a size of zero if there were no
|
* will only return success and a size of zero if there were no
|
||||||
* mappings within the range.
|
* mappings within the range.
|
||||||
*/
|
*/
|
||||||
if (iommu->v2) {
|
if (iommu->v2 && !unmap_all) {
|
||||||
dma = vfio_find_dma(iommu, iova, 1);
|
dma = vfio_find_dma(iommu, iova, 1);
|
||||||
if (dma && dma->iova != iova)
|
if (dma && dma->iova != iova)
|
||||||
goto unlock;
|
goto unlock;
|
||||||
@ -2509,6 +2515,7 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu,
|
|||||||
case VFIO_TYPE1_IOMMU:
|
case VFIO_TYPE1_IOMMU:
|
||||||
case VFIO_TYPE1v2_IOMMU:
|
case VFIO_TYPE1v2_IOMMU:
|
||||||
case VFIO_TYPE1_NESTING_IOMMU:
|
case VFIO_TYPE1_NESTING_IOMMU:
|
||||||
|
case VFIO_UNMAP_ALL:
|
||||||
return 1;
|
return 1;
|
||||||
case VFIO_DMA_CC_IOMMU:
|
case VFIO_DMA_CC_IOMMU:
|
||||||
if (!iommu)
|
if (!iommu)
|
||||||
@ -2698,6 +2705,8 @@ static int vfio_iommu_type1_unmap_dma(struct vfio_iommu *iommu,
|
|||||||
{
|
{
|
||||||
struct vfio_iommu_type1_dma_unmap unmap;
|
struct vfio_iommu_type1_dma_unmap unmap;
|
||||||
struct vfio_bitmap bitmap = { 0 };
|
struct vfio_bitmap bitmap = { 0 };
|
||||||
|
uint32_t mask = VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP |
|
||||||
|
VFIO_DMA_UNMAP_FLAG_ALL;
|
||||||
unsigned long minsz;
|
unsigned long minsz;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -2706,8 +2715,11 @@ static int vfio_iommu_type1_unmap_dma(struct vfio_iommu *iommu,
|
|||||||
if (copy_from_user(&unmap, (void __user *)arg, minsz))
|
if (copy_from_user(&unmap, (void __user *)arg, minsz))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
if (unmap.argsz < minsz ||
|
if (unmap.argsz < minsz || unmap.flags & ~mask)
|
||||||
unmap.flags & ~VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP)
|
return -EINVAL;
|
||||||
|
|
||||||
|
if ((unmap.flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) &&
|
||||||
|
(unmap.flags & VFIO_DMA_UNMAP_FLAG_ALL))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (unmap.flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) {
|
if (unmap.flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user