aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vfio/vfio_iommu_spapr_tce.c')
-rw-r--r--drivers/vfio/vfio_iommu_spapr_tce.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 0582b72ef377..34e4b3ad8b92 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -511,6 +511,12 @@ static long tce_iommu_build_v2(struct tce_container *container,
511 unsigned long hpa; 511 unsigned long hpa;
512 enum dma_data_direction dirtmp; 512 enum dma_data_direction dirtmp;
513 513
514 if (!tbl->it_userspace) {
515 ret = tce_iommu_userspace_view_alloc(tbl);
516 if (ret)
517 return ret;
518 }
519
514 for (i = 0; i < pages; ++i) { 520 for (i = 0; i < pages; ++i) {
515 struct mm_iommu_table_group_mem_t *mem = NULL; 521 struct mm_iommu_table_group_mem_t *mem = NULL;
516 unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, 522 unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl,
@@ -584,15 +590,6 @@ static long tce_iommu_create_table(struct tce_container *container,
584 WARN_ON(!ret && !(*ptbl)->it_ops->free); 590 WARN_ON(!ret && !(*ptbl)->it_ops->free);
585 WARN_ON(!ret && ((*ptbl)->it_allocated_size != table_size)); 591 WARN_ON(!ret && ((*ptbl)->it_allocated_size != table_size));
586 592
587 if (!ret && container->v2) {
588 ret = tce_iommu_userspace_view_alloc(*ptbl);
589 if (ret)
590 (*ptbl)->it_ops->free(*ptbl);
591 }
592
593 if (ret)
594 decrement_locked_vm(table_size >> PAGE_SHIFT);
595
596 return ret; 593 return ret;
597} 594}
598 595
@@ -1064,10 +1061,7 @@ static int tce_iommu_take_ownership(struct tce_container *container,
1064 if (!tbl || !tbl->it_map) 1061 if (!tbl || !tbl->it_map)
1065 continue; 1062 continue;
1066 1063
1067 rc = tce_iommu_userspace_view_alloc(tbl); 1064 rc = iommu_take_ownership(tbl);
1068 if (!rc)
1069 rc = iommu_take_ownership(tbl);
1070
1071 if (rc) { 1065 if (rc) {
1072 for (j = 0; j < i; ++j) 1066 for (j = 0; j < i; ++j)
1073 iommu_release_ownership( 1067 iommu_release_ownership(
@@ -1169,6 +1163,10 @@ static int tce_iommu_attach_group(void *iommu_data,
1169 /* pr_debug("tce_vfio: Attaching group #%u to iommu %p\n", 1163 /* pr_debug("tce_vfio: Attaching group #%u to iommu %p\n",
1170 iommu_group_id(iommu_group), iommu_group); */ 1164 iommu_group_id(iommu_group), iommu_group); */
1171 table_group = iommu_group_get_iommudata(iommu_group); 1165 table_group = iommu_group_get_iommudata(iommu_group);
1166 if (!table_group) {
1167 ret = -ENODEV;
1168 goto unlock_exit;
1169 }
1172 1170
1173 if (tce_groups_attached(container) && (!table_group->ops || 1171 if (tce_groups_attached(container) && (!table_group->ops ||
1174 !table_group->ops->take_ownership || 1172 !table_group->ops->take_ownership ||