stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: alexander.levin@verizon.com
To: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH for-4.9 21/40] vfio/spapr: Postpone allocation of userspace version of TCE table
Date: Thu, 16 Mar 2017 18:46:14 +0000	[thread overview]
Message-ID: <20170316184545.14455-22-alexander.levin@verizon.com> (raw)
In-Reply-To: <20170316184545.14455-1-alexander.levin@verizon.com>

From: Alexey Kardashevskiy <aik@ozlabs.ru>

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>
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c
index 80378dd..2a6e138 100644
--- a/drivers/vfio/vfio_iommu_spapr_tce.c
+++ b/drivers/vfio/vfio_iommu_spapr_tce.c
@@ -509,6 +509,12 @@ static long tce_iommu_build_v2(struct tce_container *container,
 	unsigned long hpa;
 	enum dma_data_direction dirtmp;
 
+	if (!tbl->it_userspace) {
+		ret = tce_iommu_userspace_view_alloc(tbl);
+		if (ret)
+			return ret;
+	}
+
 	for (i = 0; i < pages; ++i) {
 		struct mm_iommu_table_group_mem_t *mem = NULL;
 		unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl,
@@ -582,15 +588,6 @@ static long tce_iommu_create_table(struct tce_container *container,
 	WARN_ON(!ret && !(*ptbl)->it_ops->free);
 	WARN_ON(!ret && ((*ptbl)->it_allocated_size != table_size));
 
-	if (!ret && container->v2) {
-		ret = tce_iommu_userspace_view_alloc(*ptbl);
-		if (ret)
-			(*ptbl)->it_ops->free(*ptbl);
-	}
-
-	if (ret)
-		decrement_locked_vm(table_size >> PAGE_SHIFT);
-
 	return ret;
 }
 
@@ -1062,10 +1059,7 @@ static int tce_iommu_take_ownership(struct tce_container *container,
 		if (!tbl || !tbl->it_map)
 			continue;
 
-		rc = tce_iommu_userspace_view_alloc(tbl);
-		if (!rc)
-			rc = iommu_take_ownership(tbl);
-
+		rc = iommu_take_ownership(tbl);
 		if (rc) {
 			for (j = 0; j < i; ++j)
 				iommu_release_ownership(
-- 
2.9.3

  parent reply	other threads:[~2017-03-16 19:03 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 18:46 [PATCH for-4.9 00/40] Stable commits taken from Ubuntu Yakkety alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 03/40] igb: add i211 to i210 PHY workaround alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 01/40] xen: do not re-use pirq number cached in pci device msi msg data alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 02/40] igb: Workaround for igb i210 firmware issue alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 05/40] scsi: ibmvscsis: Return correct partition name/# to client alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 04/40] scsi: ibmvscsis: Issues from Dan Carpenter/Smatch alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 06/40] scsi: ibmvscsis: Clean up properly if target_submit_cmd/tmr fails alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 08/40] scsi: ibmvscsis: Synchronize cmds at tpg_enable_store time alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 09/40] scsi: ibmvscsis: Synchronize cmds at remove time alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 07/40] scsi: ibmvscsis: Rearrange functions for future patches alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 10/40] x86/hyperv: Handle unknown NMIs on one CPU when unknown_nmi_panic alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 12/40] PCI: Remove pci_resource_bar() and pci_iov_resource_bar() alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 11/40] PCI: Separate VF BAR updates from standard BAR updates alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 13/40] PCI: Add comments about ROM BAR updating alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 15/40] PCI: Don't update VF BARs while VF memory space is enabled alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 14/40] PCI: Decouple IORESOURCE_ROM_ENABLE and PCI_ROM_ADDRESS_ENABLE alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 16/40] PCI: Update BARs using property bits appropriate for type alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 18/40] PCI: Do any VF BAR updates before enabling the BARs alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 17/40] PCI: Ignore BAR updates on virtual functions alexander.levin
2017-03-16 18:46 ` alexander.levin [this message]
2017-03-16 18:46 ` [PATCH for-4.9 19/40] ibmveth: calculate gso_segs for large packets alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 20/40] Drivers: hv: ring_buffer: count on wrap around mappings in get_next_pkt_raw() (v2) alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 23/40] powerpc/iommu: Stop using @current in mm_iommu_xxx alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 22/40] powerpc/iommu: Pass mm_struct to init/cleanup helpers alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 24/40] vfio/spapr: Reference mm in tce_container alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 25/40] powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 26/40] vfio/spapr: Add a helper to create default DMA window alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 27/40] vfio/spapr: Postpone default window creation alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 28/40] drm/nouveau/disp/gp102: fix cursor/overlay immediate channel indices alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 29/40] drm/nouveau/disp/nv50-: split chid into chid.ctrl and chid.user alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 32/40] s390/zcrypt: Introduce CEX6 toleration alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 31/40] block: allow WRITE_SAME commands with the SG_IO ioctl alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 30/40] drm/nouveau/disp/nv50-: specify ctrl/user separately when constructing classes alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 34/40] slub: move synchronize_sched out of slab_mutex on shrink alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 33/40] [media] uvcvideo: uvc_scan_fallback() for webcams with broken chain alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 35/40] ACPI / blacklist: add _REV quirks for Dell Precision 5520 and 3520 alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 38/40] net: phy: Avoid deadlock during phy_error() alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 36/40] ACPI / blacklist: Make Dell Latitude 3350 ethernet work alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 37/40] serial: 8250_pci: Detach low-level driver during PCI error recovery alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 39/40] usb: gadget: udc: atmel: remove memory leak alexander.levin
2017-03-16 18:46 ` [PATCH for-4.9 40/40] powerpc/mm: Fix build break when CMA=n && SPAPR_TCE_IOMMU=y alexander.levin
2017-03-17  0:08 ` [PATCH for-4.9 00/40] Stable commits taken from Ubuntu Yakkety gregkh
2017-03-17  0:43   ` alexander.levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170316184545.14455-22-alexander.levin@verizon.com \
    --to=alexander.levin@verizon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).