From patchwork Sat Mar 25 16:18:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 95990 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp532210qgd; Sat, 25 Mar 2017 09:19:36 -0700 (PDT) X-Received: by 10.98.201.77 with SMTP id k74mr16185694pfg.74.1490458776055; Sat, 25 Mar 2017 09:19:36 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3si6723034pli.62.2017.03.25.09.19.35; Sat, 25 Mar 2017 09:19:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751359AbdCYQTg (ORCPT + 5 others); Sat, 25 Mar 2017 12:19:36 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:33829 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751309AbdCYQTf (ORCPT ); Sat, 25 Mar 2017 12:19:35 -0400 Received: by mail-pg0-f50.google.com with SMTP id 21so9214851pgg.1 for ; Sat, 25 Mar 2017 09:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n5OwpQ+t8u1+jZ0qTOzFWC0MdRvtnECTRownmQq0/CU=; b=ULjLBAhn3dC2jgiWB2bbi2vWFZu0/M6RYcYn3O0SIVsApkoRKUB9vUZXx9zrpTcCFH LT+THI2+VEL9ib48+yfUusaKZpJPh3y0RJn4sWAy8mqyQG5jNiy88cYHYLTQOcCdd0Kj UdWUfxHUS/Cd6ylvkOWbKwzeyd9nOXnRgJozI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n5OwpQ+t8u1+jZ0qTOzFWC0MdRvtnECTRownmQq0/CU=; b=oNOMI+Huq+ceX7csHm2Y8ILTULwpzKxLFg/3zR20ILuMm+FZld6GBLbqKUOfG6zXMd RpBvs9lXu/4H/lS88ZQ3tCuWZlwVmp7rACqbOTaZa3wqhB+W2gWXE09PsY6gPJyEOvOQ /BHVPAzLCsuLSIhFWkvBeX/Gf8D/vMXI0a1rCr6LeZIKZ29aJjx7FXzxos9ljENgy0Mw +siGyooU7pub9kn7+iuI1lWinIDCIAXzUEGt48XJEnpv7D6lKmFIvUuP6O21Ar6MozMH YT8yICjXs+dY7LGktw7gclY80dknq1r0+93D007EHzfN4gUlrltcuLzyeQFMmgpX3zNq oZSQ== X-Gm-Message-State: AFeK/H3S8cOxHcUHQTnwv0vJLQHqbWc+PiZaJBLeR+B6Eyc/a89d9G5ZTD1+RqPoMzJ9yY3S X-Received: by 10.84.236.76 with SMTP id h12mr11356907pln.110.1490458773976; Sat, 25 Mar 2017 09:19:33 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id q194sm11469541pfq.43.2017.03.25.09.19.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Mar 2017 09:19:32 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Alexey Kardashevskiy , Michael Ellerman , Sasha Levin , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 13/19] vfio/spapr: Postpone allocation of userspace version of TCE table Date: Sat, 25 Mar 2017 21:48:13 +0530 Message-Id: <1490458699-24484-14-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> References: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Alexey Kardashevskiy [ 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 Reviewed-by: David Gibson Acked-by: Alex Williamson Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/vfio/vfio_iommu_spapr_tce.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/vfio/vfio_iommu_spapr_tce.c b/drivers/vfio/vfio_iommu_spapr_tce.c index 0582b72..1a9f18b 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, 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, @@ -584,15 +590,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; } @@ -1064,10 +1061,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(