[Devel] [PATCH hci-8.1 4/5] Revert "vfio/type1: exclude mdevs from VFIO_UPDATE_VADDR"

Andrey Drobyshev andrey.drobyshev at virtuozzo.com
Fri Oct 23 19:53:42 MSK 2026


From: Anthony Yznaga <anthony.yznaga at oracle.com>

This reverts commit ef3a3f6a294ba65fd906a291553935881796f8a5.

This re-enables support for using VFIO_UPDATE_VADDR with vfio
mediated devices which is needed to fully support Live Update.

Orabug: 35370252
Signed-off-by: Anthony Yznaga <anthony.yznaga at oracle.com>
Reviewed-by: Steve Sistare <steven.sistare at oracle.com>

https://virtuozzo.atlassian.net/browse/VSTOR-150595
(cherry picked from commit 24e5a96e6a4ac34b09d45687c38e9d2aa8cea4ac)
---
 drivers/vfio/vfio_iommu_type1.c | 44 ++-------------------------------
 include/uapi/linux/vfio.h       | 15 +++++------
 2 files changed, 8 insertions(+), 51 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 6193ff966667..89132d3c037e 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -979,12 +979,6 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data,
 
 	mutex_lock(&iommu->lock);
 
-	if (WARN_ONCE(iommu->vaddr_invalid_count,
-		      "vfio_pin_pages not allowed with VFIO_UPDATE_VADDR\n")) {
-		ret = -EBUSY;
-		goto pin_done;
-	}
-
 	/*
 	 * Wait for all necessary vaddr's to be valid so they can be used in
 	 * the main loop without dropping the lock, to avoid racing vs unmap.
@@ -1483,12 +1477,6 @@ static int vfio_dma_do_unmap(struct vfio_iommu *iommu,
 
 	mutex_lock(&iommu->lock);
 
-	/* Cannot update vaddr if mdev is present. */
-	if (invalidate_vaddr && !list_empty(&iommu->emulated_iommu_groups)) {
-		ret = -EBUSY;
-		goto unlock;
-	}
-
 	if (iova != unmap->iova || size != unmap->size) {
 		ret = -EOVERFLOW;
 		goto unlock;
@@ -2327,16 +2315,11 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
 	struct iommu_domain_geometry *geo;
 	LIST_HEAD(iova_copy);
 	LIST_HEAD(group_resv_regions);
-	int ret = -EBUSY;
+	int ret = -EINVAL;
 
 	mutex_lock(&iommu->lock);
 
-	/* Attach could require pinning, so disallow while vaddr is invalid. */
-	if (iommu->vaddr_invalid_count)
-		goto out_unlock;
-
 	/* Check for duplicates */
-	ret = -EINVAL;
 	if (vfio_iommu_find_iommu_group(iommu, iommu_group))
 		goto out_unlock;
 
@@ -2795,16 +2778,6 @@ static int vfio_domains_have_enforce_cache_coherency(struct vfio_iommu *iommu)
 	return ret;
 }
 
-static bool vfio_iommu_has_emulated(struct vfio_iommu *iommu)
-{
-	bool ret;
-
-	mutex_lock(&iommu->lock);
-	ret = !list_empty(&iommu->emulated_iommu_groups);
-	mutex_unlock(&iommu->lock);
-	return ret;
-}
-
 static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu,
 					    unsigned long arg)
 {
@@ -2812,13 +2785,8 @@ static int vfio_iommu_type1_check_extension(struct vfio_iommu *iommu,
 	case VFIO_TYPE1_IOMMU:
 	case VFIO_TYPE1v2_IOMMU:
 	case VFIO_UNMAP_ALL:
-		return 1;
 	case VFIO_UPDATE_VADDR:
-		/*
-		 * Disable this feature if mdevs are present.  They cannot
-		 * safely pin/unpin/rw while vaddrs are being updated.
-		 */
-		return iommu && !vfio_iommu_has_emulated(iommu);
+		return 1;
 	case VFIO_DMA_CC_IOMMU:
 		if (!iommu)
 			return 0;
@@ -3289,13 +3257,6 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova,
 	size_t done;
 
 	mutex_lock(&iommu->lock);
-
-	if (WARN_ONCE(iommu->vaddr_invalid_count,
-		      "vfio_dma_rw not allowed with VFIO_UPDATE_VADDR\n")) {
-		ret = -EBUSY;
-		goto out;
-	}
-
 	while (count > 0) {
 		ret = vfio_iommu_type1_dma_rw_chunk(iommu, user_iova, data,
 						    count, write, &done);
@@ -3307,7 +3268,6 @@ static int vfio_iommu_type1_dma_rw(void *iommu_data, dma_addr_t user_iova,
 		user_iova += done;
 	}
 
-out:
 	mutex_unlock(&iommu->lock);
 	return ret;
 }
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index ac2329f24141..de95371c179a 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -50,11 +50,7 @@
 /* Supports VFIO_DMA_UNMAP_FLAG_ALL */
 #define VFIO_UNMAP_ALL			9
 
-/*
- * Supports the vaddr flag for DMA map and unmap.  Not supported for mediated
- * devices, so this capability is subject to change as groups are added or
- * removed.
- */
+/* Supports the vaddr flag for DMA map and unmap */
 #define VFIO_UPDATE_VADDR		10
 
 /*
@@ -1594,7 +1590,8 @@ struct vfio_iommu_type1_info_dma_avail {
  * Map process virtual addresses to IO virtual addresses using the
  * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required.
  *
- * If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova. The vaddr
+ * If flags & VFIO_DMA_MAP_FLAG_VADDR, update the base vaddr for iova, and
+ * unblock translation of host virtual addresses in the iova range.  The vaddr
  * must have previously been invalidated with VFIO_DMA_UNMAP_FLAG_VADDR.  To
  * maintain memory consistency within the user application, the updated vaddr
  * must address the same memory object as originally mapped.  Failure to do so
@@ -1645,9 +1642,9 @@ struct vfio_bitmap {
  * must be 0.  This cannot be combined with the get-dirty-bitmap flag.
  *
  * If flags & VFIO_DMA_UNMAP_FLAG_VADDR, do not unmap, but invalidate host
- * virtual addresses in the iova range.  DMA to already-mapped pages continues.
- * Groups may not be added to the container while any addresses are invalid.
- * This cannot be combined with the get-dirty-bitmap flag.
+ * virtual addresses in the iova range.  Tasks that attempt to translate an
+ * iova's vaddr will block.  DMA to already-mapped pages continues.  This
+ * cannot be combined with the get-dirty-bitmap flag.
  */
 struct vfio_iommu_type1_dma_unmap {
 	__u32	argsz;
-- 
2.47.1



More information about the Devel mailing list