Message ID | 20231128204938.1453583-7-pasha.tatashin@soleen.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp4217575vqx; Tue, 28 Nov 2023 12:50:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqVRt4x3QYQkgG/R/bmWfom3mx4mOIWQMMC6WExJj1+6GtUd2MWwmNhTvmIha4Z/oEpjLx X-Received: by 2002:a05:6808:1486:b0:3af:9848:1590 with SMTP id e6-20020a056808148600b003af98481590mr21620973oiw.6.1701204618331; Tue, 28 Nov 2023 12:50:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701204618; cv=none; d=google.com; s=arc-20160816; b=mzIjF+piLG4PMRrDtqXbqtBZqVq7AhnVQ0BZprsLKQ0psUbBeHUFUjhudzLKbNhxvo mPcSkXmBYKmH76bm5AeGyRAxebd/a19xvqUDy9Za46ef9kL6ZX8eMcw6D0xuxIEKJ3nG GB9cboDZk7CacllDKdv/QUd1i61D2t+QHtTXPOX6rv64OtYejBaz5Vt+OT6+Q+npPU43 /4K4FqvIY+ZnUzbkZodlOcUekdHczyR9DjFnoPdqmpiT57Vx+6yS9+D2fA4a7MFLHnD1 xTGUVJOeXG+SSsA1c4f36cYToSwLNWInV/xDKN0ODoF4REti/+nAfjqdKIXmrOiJvycu t60A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=9pzjq4U1m3Jk3/Q2EGDhq/3TlS/Ht1C4D8j4bsFObkQ=; fh=z7CihAYYs+frw4g3uL4utEDJXxOOJDcFFsLsywo+fzs=; b=d+DpMlkcQLoVzc+YsAXFncuY39VUJSEyX9gMz0GXmwDzmGZGBzDFAIwbMDuESK+pt1 hWcjzqRQmJ0kqAN2pgl+vosN2W01MLC9yruREx+LFpcAWysu3WbiCmZVbibhAHrp6CJd Qzl8qOxq/FV/rXLkz4d3qFEJ4zZpRB4t9+WbhkflQZJHygtDeNanm1S/1xIauIWfXatm Yx4mZJPBXAPfXE8NJDHe2dozzkVw2kl/DArGkJL3ChZQePsWtsMJmsiD1y//0lyvvXNN b5TgMTGOm9aWRBttqr74YF3o2XHQAm+TkEiQoaxWxecCeE/pTTV1SF2UMLNZj1JvSuWS l37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=eESCoOjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bn17-20020a056a02031100b005bdff97f97bsi14679939pgb.92.2023.11.28.12.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:50:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=eESCoOjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EC04380AF3D0; Tue, 28 Nov 2023 12:50:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346404AbjK1UuA (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 28 Nov 2023 15:50:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345733AbjK1Utp (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 28 Nov 2023 15:49:45 -0500 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C56801BE3 for <linux-kernel@vger.kernel.org>; Tue, 28 Nov 2023 12:49:47 -0800 (PST) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5cc7966e731so50209037b3.0 for <linux-kernel@vger.kernel.org>; Tue, 28 Nov 2023 12:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701204587; x=1701809387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9pzjq4U1m3Jk3/Q2EGDhq/3TlS/Ht1C4D8j4bsFObkQ=; b=eESCoOjNDxfrFLQ7MyEVad+SgTNdaWIKY9zAC6chNUh+LzlsqIJTp7jW3FM3XiEgaW escNzH8gnKUuAH+N2uVP3GlavOp587ZYyyZc0bGbcs+VSbr/A7LsO2DVA61WUOyPK9rf 8e5E3h8ul2nHgN679Qnhe/KQhFXUJ/g7Jq/fjnVDYU93uEwFt41+ra92QkHgo2UExzkU vgVScuS4d9ZzuwO2f0leQULME174Q/f1n0++ExHntJ8dlgeakTntW2nmigsMfZVGKHlf EuddNsGT/OfXbUZ2M9BtTRAdjAuRKiYZ15Xsfar09fvB0T1tDHNmqU8HIsSc15muKbNY ++wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701204587; x=1701809387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9pzjq4U1m3Jk3/Q2EGDhq/3TlS/Ht1C4D8j4bsFObkQ=; b=ZREHkEhZ0Bd4N3oWcd6LEP1Iwov/sKUjqiYPG5KalFhLWOB70UUhQdlPvrZXr9lFqy DHp4d+XGpaQFi3fqbR+1PGq5l0QSc/n1C2j44llDQeawXhtaKlQMURSGid3SV8LRWBOM lT1geDd9XzT1Z6vVLXbl6lb0+cjBDuvhT4whbFNh2Ig06S4Cn2EFohiDDJZw3u/83jEm sd1zToXDzqoQHF5qgywD+M46tqRpzEUvEL7PQMTiwLq6daUMzeSYH4o6/pa1kUj5b40X shXsY2kjgcuzwwRTgZec55R8qSoqRuGRXMidwQ8KqsaCqYymyfSsoVj1UouYucAm38qM C0PQ== X-Gm-Message-State: AOJu0YysUCdVUvnweb2YgT9eoBfMjJCLAtT7vpoeNtU2TZ/OOa15Fj4d eaAFYzohLqyM0m9wQ5KnY8XBig== X-Received: by 2002:a81:87c2:0:b0:5c0:fc45:a249 with SMTP id x185-20020a8187c2000000b005c0fc45a249mr12000775ywf.40.1701204586847; Tue, 28 Nov 2023 12:49:46 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id d11-20020a0cfe8b000000b0067a56b6adfesm1056863qvs.71.2023.11.28.12.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:49:46 -0800 (PST) From: Pasha Tatashin <pasha.tatashin@soleen.com> To: akpm@linux-foundation.org, alex.williamson@redhat.com, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jasowang@redhat.com, jernej.skrabec@gmail.com, jgg@ziepe.ca, jonathanh@nvidia.com, joro@8bytes.org, kevin.tian@intel.com, krzysztof.kozlowski@linaro.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, mst@redhat.com, m.szyprowski@samsung.com, netdev@vger.kernel.org, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, virtualization@lists.linux.dev, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com Subject: [PATCH 06/16] iommu/dma: use page allocation function provided by iommu-pages.h Date: Tue, 28 Nov 2023 20:49:28 +0000 Message-ID: <20231128204938.1453583-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231128204938.1453583-1-pasha.tatashin@soleen.com> References: <20231128204938.1453583-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 28 Nov 2023 12:50:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783842333971137377 X-GMAIL-MSGID: 1783842333971137377 |
Series |
IOMMU memory observability
|
|
Commit Message
Pasha Tatashin
Nov. 28, 2023, 8:49 p.m. UTC
Convert iommu/dma-iommu.c to use the new page allocation functions
provided in iommu-pages.h.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
drivers/iommu/dma-iommu.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Comments
On 2023-11-28 8:49 pm, Pasha Tatashin wrote: > Convert iommu/dma-iommu.c to use the new page allocation functions > provided in iommu-pages.h. These have nothing to do with IOMMU pagetables, they are DMA buffers and they belong to whoever called the corresponding dma_alloc_* function. Thanks, Robin. > Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> > --- > drivers/iommu/dma-iommu.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 85163a83df2f..822adad464c2 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -31,6 +31,7 @@ > #include <linux/vmalloc.h> > > #include "dma-iommu.h" > +#include "iommu-pages.h" > > struct iommu_dma_msi_page { > struct list_head list; > @@ -874,7 +875,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, > static void __iommu_dma_free_pages(struct page **pages, int count) > { > while (count--) > - __free_page(pages[count]); > + __iommu_free_page(pages[count]); > kvfree(pages); > } > > @@ -912,7 +913,8 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, > order_size = 1U << order; > if (order_mask > order_size) > alloc_flags |= __GFP_NORETRY; > - page = alloc_pages_node(nid, alloc_flags, order); > + page = __iommu_alloc_pages_node(nid, alloc_flags, > + order); > if (!page) > continue; > if (order) > @@ -1572,7 +1574,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size, > > page = dma_alloc_contiguous(dev, alloc_size, gfp); > if (!page) > - page = alloc_pages_node(node, gfp, get_order(alloc_size)); > + page = __iommu_alloc_pages_node(node, gfp, get_order(alloc_size)); > if (!page) > return NULL; >
On Tue, Nov 28, 2023 at 5:34 PM Robin Murphy <robin.murphy@arm.com> wrote: > > On 2023-11-28 8:49 pm, Pasha Tatashin wrote: > > Convert iommu/dma-iommu.c to use the new page allocation functions > > provided in iommu-pages.h. > > These have nothing to do with IOMMU pagetables, they are DMA buffers and > they belong to whoever called the corresponding dma_alloc_* function. Hi Robin, This is true, however, we want to account and observe the pages allocated by IOMMU subsystem for DMA buffers, as they are essentially unmovable locked pages. Should we separate IOMMU memory from KVM memory all together and add another field to /proc/meminfo, something like "iommu -> iommu pagetable and dma memory", or do we want to export DMA memory separately from IOMMU page tables? Since, I included DMA memory, I specifically removed mentioning of IOMMU page tables in the most of places, and only report it as IOMMU memory. However, since it is still bundled together with SecPageTables it can be confusing. Pasha
On 2023-11-28 10:50 pm, Pasha Tatashin wrote: > On Tue, Nov 28, 2023 at 5:34 PM Robin Murphy <robin.murphy@arm.com> wrote: >> >> On 2023-11-28 8:49 pm, Pasha Tatashin wrote: >>> Convert iommu/dma-iommu.c to use the new page allocation functions >>> provided in iommu-pages.h. >> >> These have nothing to do with IOMMU pagetables, they are DMA buffers and >> they belong to whoever called the corresponding dma_alloc_* function. > > Hi Robin, > > This is true, however, we want to account and observe the pages > allocated by IOMMU subsystem for DMA buffers, as they are essentially > unmovable locked pages. Should we separate IOMMU memory from KVM > memory all together and add another field to /proc/meminfo, something > like "iommu -> iommu pagetable and dma memory", or do we want to > export DMA memory separately from IOMMU page tables? These are not allocated by "the IOMMU subsystem", they are allocated by the DMA API. Even if you want to claim that a driver pinning memory via iommu_dma_ops is somehow different from the same driver pinning the same amount of memory via dma-direct when iommu.passthrough=1, it's still nonsense because you're failing to account the pages which iommu_dma_ops gets from CMA, dma_common_alloc_pages(), dynamic SWIOTLB, the various pools, and so on. Thanks, Robin. > Since, I included DMA memory, I specifically removed mentioning of > IOMMU page tables in the most of places, and only report it as IOMMU > memory. However, since it is still bundled together with SecPageTables > it can be confusing. > > Pasha
On Tue, Nov 28, 2023 at 5:59 PM Robin Murphy <robin.murphy@arm.com> wrote: > > On 2023-11-28 10:50 pm, Pasha Tatashin wrote: > > On Tue, Nov 28, 2023 at 5:34 PM Robin Murphy <robin.murphy@arm.com> wrote: > >> > >> On 2023-11-28 8:49 pm, Pasha Tatashin wrote: > >>> Convert iommu/dma-iommu.c to use the new page allocation functions > >>> provided in iommu-pages.h. > >> > >> These have nothing to do with IOMMU pagetables, they are DMA buffers and > >> they belong to whoever called the corresponding dma_alloc_* function. > > > > Hi Robin, > > > > This is true, however, we want to account and observe the pages > > allocated by IOMMU subsystem for DMA buffers, as they are essentially > > unmovable locked pages. Should we separate IOMMU memory from KVM > > memory all together and add another field to /proc/meminfo, something > > like "iommu -> iommu pagetable and dma memory", or do we want to > > export DMA memory separately from IOMMU page tables? > > These are not allocated by "the IOMMU subsystem", they are allocated by > the DMA API. Even if you want to claim that a driver pinning memory via > iommu_dma_ops is somehow different from the same driver pinning the same > amount of memory via dma-direct when iommu.passthrough=1, it's still > nonsense because you're failing to account the pages which iommu_dma_ops > gets from CMA, dma_common_alloc_pages(), dynamic SWIOTLB, the various > pools, and so on. > > Thanks, > Robin. > > > Since, I included DMA memory, I specifically removed mentioning of > > IOMMU page tables in the most of places, and only report it as IOMMU > > memory. However, since it is still bundled together with SecPageTables > > it can be confusing. > > > > Pasha
> > This is true, however, we want to account and observe the pages > > allocated by IOMMU subsystem for DMA buffers, as they are essentially > > unmovable locked pages. Should we separate IOMMU memory from KVM > > memory all together and add another field to /proc/meminfo, something > > like "iommu -> iommu pagetable and dma memory", or do we want to > > export DMA memory separately from IOMMU page tables? > > These are not allocated by "the IOMMU subsystem", they are allocated by > the DMA API. Even if you want to claim that a driver pinning memory via > iommu_dma_ops is somehow different from the same driver pinning the same > amount of memory via dma-direct when iommu.passthrough=1, it's still > nonsense because you're failing to account the pages which iommu_dma_ops > gets from CMA, dma_common_alloc_pages(), dynamic SWIOTLB, the various > pools, and so on. I see, IOMMU variants are used only for discontiguous allocations, and the common ones are defined outside of driver/iommu. Alright, I can remove all the changes for all no-page table related IOMMU allocations. Pasha
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 85163a83df2f..822adad464c2 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -31,6 +31,7 @@ #include <linux/vmalloc.h> #include "dma-iommu.h" +#include "iommu-pages.h" struct iommu_dma_msi_page { struct list_head list; @@ -874,7 +875,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, static void __iommu_dma_free_pages(struct page **pages, int count) { while (count--) - __free_page(pages[count]); + __iommu_free_page(pages[count]); kvfree(pages); } @@ -912,7 +913,8 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, order_size = 1U << order; if (order_mask > order_size) alloc_flags |= __GFP_NORETRY; - page = alloc_pages_node(nid, alloc_flags, order); + page = __iommu_alloc_pages_node(nid, alloc_flags, + order); if (!page) continue; if (order) @@ -1572,7 +1574,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size, page = dma_alloc_contiguous(dev, alloc_size, gfp); if (!page) - page = alloc_pages_node(node, gfp, get_order(alloc_size)); + page = __iommu_alloc_pages_node(node, gfp, get_order(alloc_size)); if (!page) return NULL;