Skip to content

Commit 9fd9e14

Browse files
sumitsemwalgregkh
authored andcommitted
vfio/spapr: Postpone allocation of userspace version of TCE table
From: Alexey Kardashevskiy <aik@ozlabs.ru> [ Upstream commit 39701e56f5f16ea0cf8fc9e8472e645f8de91d23 ] The iommu_table struct manages a hardware TCE table and a vmalloc'd table with corresponding userspace addresses. Both are allocated when the default DMA window is created and this happens when the very first group is attached to a container. As we are going to allow the userspace to configure container in one memory context and pas container fd to another, we have to postpones such allocations till a container fd is passed to the destination user process so we would account locked memory limit against the actual container user constrainsts. This postpones the it_userspace array allocation till it is used first time for mapping. The unmapping patch already checks if the array is allocated. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4110080 commit 9fd9e14

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

drivers/vfio/vfio_iommu_spapr_tce.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ static long tce_iommu_build_v2(struct tce_container *container,
511511
unsigned long hpa;
512512
enum dma_data_direction dirtmp;
513513

514+
if (!tbl->it_userspace) {
515+
ret = tce_iommu_userspace_view_alloc(tbl);
516+
if (ret)
517+
return ret;
518+
}
519+
514520
for (i = 0; i < pages; ++i) {
515521
struct mm_iommu_table_group_mem_t *mem = NULL;
516522
unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl,
@@ -584,15 +590,6 @@ static long tce_iommu_create_table(struct tce_container *container,
584590
WARN_ON(!ret && !(*ptbl)->it_ops->free);
585591
WARN_ON(!ret && ((*ptbl)->it_allocated_size != table_size));
586592

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-
596593
return ret;
597594
}
598595

@@ -1064,10 +1061,7 @@ static int tce_iommu_take_ownership(struct tce_container *container,
10641061
if (!tbl || !tbl->it_map)
10651062
continue;
10661063

1067-
rc = tce_iommu_userspace_view_alloc(tbl);
1068-
if (!rc)
1069-
rc = iommu_take_ownership(tbl);
1070-
1064+
rc = iommu_take_ownership(tbl);
10711065
if (rc) {
10721066
for (j = 0; j < i; ++j)
10731067
iommu_release_ownership(

0 commit comments

Comments
 (0)