Inter-revision diff: patch 12

Comparing v2 (message) to v12 (message)

--- v2
+++ v12
@@ -1,118 +1,81 @@
-This makes use of the it_page_size from the iommu_table struct
-as page size can differ.
+This is to make extended ownership and multiple groups support patches
+simpler for review.
 
-This replaces missing IOMMU_PAGE_SHIFT macro in commented debug code
-as recently introduced IOMMU_PAGE_XXX macros do not include
-IOMMU_PAGE_SHIFT.
+This should cause no behavioural change.
 
 Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
+[aw: for the vfio related changes]
+Acked-by: Alex Williamson <alex.williamson@redhat.com>
+Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
+Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
 ---
- drivers/vfio/vfio_iommu_spapr_tce.c | 36 ++++++++++++++++++------------------
- 1 file changed, 18 insertions(+), 18 deletions(-)
+ drivers/vfio/vfio_iommu_spapr_tce.c | 40 ++++++++++++++++++++++---------------
+ 1 file changed, 24 insertions(+), 16 deletions(-)
 
 diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
-index c9fac97..0dccbc4 100644
+index cf5d4a1..e65bc73 100644
 --- a/drivers/vfio/vfio_iommu_spapr_tce.c
 +++ b/drivers/vfio/vfio_iommu_spapr_tce.c
-@@ -36,7 +36,7 @@ static long try_increment_locked_vm(struct iommu_table *tbl)
- 	if (!current || !current->mm)
- 		return -ESRCH; /* process exited */
+@@ -460,16 +460,21 @@ static int tce_iommu_attach_group(void *iommu_data,
+ 				iommu_group_id(container->tbl->it_group),
+ 				iommu_group_id(iommu_group));
+ 		ret = -EBUSY;
+-	} else if (container->enabled) {
++		goto unlock_exit;
++	}
++
++	if (container->enabled) {
+ 		pr_err("tce_vfio: attaching group #%u to enabled container\n",
+ 				iommu_group_id(iommu_group));
+ 		ret = -EBUSY;
+-	} else {
+-		ret = iommu_take_ownership(tbl);
+-		if (!ret)
+-			container->tbl = tbl;
++		goto unlock_exit;
+ 	}
  
--	npages = (tbl->it_size << IOMMU_PAGE_SHIFT_4K) >> PAGE_SHIFT;
-+	npages = (tbl->it_size << tbl->it_page_shift) >> PAGE_SHIFT;
++	ret = iommu_take_ownership(tbl);
++	if (!ret)
++		container->tbl = tbl;
++
++unlock_exit:
+ 	mutex_unlock(&container->lock);
  
- 	down_write(&current->mm->mmap_sem);
- 	locked = current->mm->locked_vm + npages;
-@@ -60,7 +60,7 @@ static void decrement_locked_vm(struct iommu_table *tbl)
- 	if (!current || !current->mm)
- 		return; /* process exited */
+ 	return ret;
+@@ -487,19 +492,22 @@ static void tce_iommu_detach_group(void *iommu_data,
+ 		pr_warn("tce_vfio: detaching group #%u, expected group is #%u\n",
+ 				iommu_group_id(iommu_group),
+ 				iommu_group_id(tbl->it_group));
+-	} else {
+-		if (container->enabled) {
+-			pr_warn("tce_vfio: detaching group #%u from enabled container, forcing disable\n",
+-					iommu_group_id(tbl->it_group));
+-			tce_iommu_disable(container);
+-		}
++		goto unlock_exit;
++	}
  
--	npages = (tbl->it_size << IOMMU_PAGE_SHIFT_4K) >> PAGE_SHIFT;
-+	npages = (tbl->it_size << tbl->it_page_shift) >> PAGE_SHIFT;
+-		/* pr_debug("tce_vfio: detaching group #%u from iommu %p\n",
+-				iommu_group_id(iommu_group), iommu_group); */
+-		container->tbl = NULL;
+-		tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
+-		iommu_release_ownership(tbl);
++	if (container->enabled) {
++		pr_warn("tce_vfio: detaching group #%u from enabled container, forcing disable\n",
++				iommu_group_id(tbl->it_group));
++		tce_iommu_disable(container);
+ 	}
++
++	/* pr_debug("tce_vfio: detaching group #%u from iommu %p\n",
++	   iommu_group_id(iommu_group), iommu_group); */
++	container->tbl = NULL;
++	tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
++	iommu_release_ownership(tbl);
++
++unlock_exit:
+ 	mutex_unlock(&container->lock);
+ }
  
- 	down_write(&current->mm->mmap_sem);
- 	if (npages > current->mm->locked_vm)
-@@ -284,8 +284,8 @@ static long tce_iommu_ioctl(void *iommu_data,
- 		if (info.argsz < minsz)
- 			return -EINVAL;
- 
--		info.dma32_window_start = tbl->it_offset << IOMMU_PAGE_SHIFT_4K;
--		info.dma32_window_size = tbl->it_size << IOMMU_PAGE_SHIFT_4K;
-+		info.dma32_window_start = tbl->it_offset << tbl->it_page_shift;
-+		info.dma32_window_size = tbl->it_size << tbl->it_page_shift;
- 		info.flags = 0;
- 
- 		if (copy_to_user((void __user *)arg, &info, minsz))
-@@ -318,10 +318,6 @@ static long tce_iommu_ioctl(void *iommu_data,
- 				VFIO_DMA_MAP_FLAG_WRITE))
- 			return -EINVAL;
- 
--		if ((param.size & ~IOMMU_PAGE_MASK_4K) ||
--				(param.vaddr & ~IOMMU_PAGE_MASK_4K))
--			return -EINVAL;
--
- 		/* iova is checked by the IOMMU API */
- 		tce = param.vaddr;
- 		if (param.flags & VFIO_DMA_MAP_FLAG_READ)
-@@ -334,21 +330,25 @@ static long tce_iommu_ioctl(void *iommu_data,
- 			return -ENXIO;
- 		BUG_ON(!tbl->it_group);
- 
-+		if ((param.size & ~IOMMU_PAGE_MASK(tbl)) ||
-+				(param.vaddr & ~IOMMU_PAGE_MASK(tbl)))
-+			return -EINVAL;
-+
- 		ret = iommu_tce_put_param_check(tbl, param.iova, tce);
- 		if (ret)
- 			return ret;
- 
--		for (i = 0; i < (param.size >> IOMMU_PAGE_SHIFT_4K); ++i) {
-+		for (i = 0; i < (param.size >> tbl->it_page_shift); ++i) {
- 			ret = iommu_put_tce_user_mode(tbl,
--					(param.iova >> IOMMU_PAGE_SHIFT_4K) + i,
-+					(param.iova >> tbl->it_page_shift) + i,
- 					tce);
- 			if (ret)
- 				break;
--			tce += IOMMU_PAGE_SIZE_4K;
-+			tce += IOMMU_PAGE_SIZE(tbl);
- 		}
- 		if (ret)
- 			iommu_clear_tces_and_put_pages(tbl,
--					param.iova >> IOMMU_PAGE_SHIFT_4K, i);
-+					param.iova >> tbl->it_page_shift, i);
- 
- 		iommu_flush_tce(tbl);
- 
-@@ -379,23 +379,23 @@ static long tce_iommu_ioctl(void *iommu_data,
- 		if (param.flags)
- 			return -EINVAL;
- 
--		if (param.size & ~IOMMU_PAGE_MASK_4K)
--			return -EINVAL;
--
- 		tbl = spapr_tce_find_table(container, data, param.iova);
- 		if (!tbl)
- 			return -ENXIO;
- 
-+		if (param.size & ~IOMMU_PAGE_MASK(tbl))
-+			return -EINVAL;
-+
- 		BUG_ON(!tbl->it_group);
- 
- 		ret = iommu_tce_clear_param_check(tbl, param.iova, 0,
--				param.size >> IOMMU_PAGE_SHIFT_4K);
-+				param.size >> tbl->it_page_shift);
- 		if (ret)
- 			return ret;
- 
- 		ret = iommu_clear_tces_and_put_pages(tbl,
--				param.iova >> IOMMU_PAGE_SHIFT_4K,
--				param.size >> IOMMU_PAGE_SHIFT_4K);
-+				param.iova >> tbl->it_page_shift,
-+				param.size >> tbl->it_page_shift);
- 		iommu_flush_tce(tbl);
- 
- 		return ret;
 -- 
-2.0.0
+2.4.0.rc3.8.gfb3e7d5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help