From patchwork Tue Nov 28 20:49:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13471798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3D77C07E97 for ; Tue, 28 Nov 2023 20:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6360F6B0366; Tue, 28 Nov 2023 15:49:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E6436B0367; Tue, 28 Nov 2023 15:49:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 438FC6B0368; Tue, 28 Nov 2023 15:49:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 304866B0366 for ; Tue, 28 Nov 2023 15:49:59 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0B171403B9 for ; Tue, 28 Nov 2023 20:49:59 +0000 (UTC) X-FDA: 81508554918.02.9BDCBEC Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf13.hostedemail.com (Postfix) with ESMTP id 4917920024 for ; Tue, 28 Nov 2023 20:49:57 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=MIEkkt7x; spf=pass (imf13.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701204597; a=rsa-sha256; cv=none; b=Kmwk44AMP0dZBO9K7/NDkLAiQBAdBaBm1SyL3rnTr9BoWYxW67rhAThZOC8wCURZRbmTyn EhCdtOcyfgNdA56JRVNTRXrwvE0f8mKseVEtOTKA8hc4CJdgJL8eeHHz4ylk42ag8cZ3nV N9clAhrWPeEEnbNfOAU4Ww7616LmZ6Y= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=MIEkkt7x; spf=pass (imf13.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.53 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701204597; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YSGX0jW3To7/xuABL7QXXsr1KCFhu7Z9tThr0mLMrMc=; b=RPtO7ND7//Qgay71+4T24Vnwirl4uA87QPK8iGElWCf3huhJrQJHo/P5kttpCHoNPmO+Jl uLpQ/XBrAG+X0Ssc/8uRyGyF4wCYQOHx+0fX8igpP+Ro3LUfPR7Tr3JFS/sf5qZR/5a1zS pR7Ga2pgqrSxzr8M5SbDtJGB5Zd8cM4= Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-67a35b68c34so18752466d6.3 for ; Tue, 28 Nov 2023 12:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701204596; x=1701809396; darn=kvack.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=YSGX0jW3To7/xuABL7QXXsr1KCFhu7Z9tThr0mLMrMc=; b=MIEkkt7xOjvBDE4lorEGMG6oicUw34E+BSY+NrpZX57VgatEHEDLehItwBu101ZqX3 QCsG8r6z7DuP3RIsCHrXblxdqzde4GUZJL2FRiCimoIwhmXZJDmtnM4L00vUleEHIXCi Z9YT9bb2KkV7LYrYnJdagV634WFLEXDEdX1sKf5ghQmn0uBqhb1chtsIz6UNxv9GLI5Z arvxYLVhWEvYEVH83ePu/roZaOg1uooTggipGJrBgPZPTUQSL/rhoykTywY6x8BfXwzj F7Fv4oVL7n5Nzf8FV5C5tQa/WtiKIUkUyM+tGQD/tly0hyq4T/rA7XUMrYHK6yX2Dd2z OsSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701204596; x=1701809396; 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=YSGX0jW3To7/xuABL7QXXsr1KCFhu7Z9tThr0mLMrMc=; b=daAj6vYrPfE7A+gFy1j5Wlsrv2phKtidnPeQv0GE5h6oZ3sXCtjeTbZwyBMaHqe3x/ DhsmihzaLWl0XoJhCsvLZuYxcbGRlqixFbhSafMvHf36dqym2r7IJokipumFyDHsYwka dENR1Xnz7duw3AN7+MNSyApwRjVweEr+f3b0OxGjADriMnl6bnEdukQ+b+vJdDCyL6Bt xRZCZKTb5Pf5240CAfgMY7g2PA0Nd8OvSoMI063E64/M7+3MI57Fig0KBTdDAoMJkxq0 D7ivbfVb166jN8KiZO5B1XjsiFOA4GZje1mfILnEAa8VuQm9X2QtiYXkII3vGjDiRNyq tX9A== X-Gm-Message-State: AOJu0YzCMHRAa1nSywAtMNzSdUzC5MAcezwuWtzbgKcFrlRSdUJdLRV4 UGfW+1zUyXvFvB8y6Z+nTbIPOA== X-Google-Smtp-Source: AGHT+IH3XyzLx3HqaxxWdryJd33MqMJHkx6z6Xt3swBEGkMdx9JQSLka9GW0WH1FkTVqo27TzFUimQ== X-Received: by 2002:a05:6214:246f:b0:67a:4ba1:84d5 with SMTP id im15-20020a056214246f00b0067a4ba184d5mr7928400qvb.16.1701204596396; Tue, 28 Nov 2023 12:49:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:49:56 -0800 (PST) From: Pasha Tatashin 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 16/16] vfio: account iommu allocations Date: Tue, 28 Nov 2023 20:49:38 +0000 Message-ID: <20231128204938.1453583-17-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4917920024 X-Stat-Signature: rs3bqait9f53o5i8gh6supyameocq67n X-Rspam-User: X-HE-Tag: 1701204597-489471 X-HE-Meta: U2FsdGVkX18qjhfPLYewTaxuQ1Vq0t3ko0TssOxTOF6rzSfL6K1GkXBITHrDNfehOoH4nAO4X3CzbP7TFY0VCQx8/ub9NzjxOyK5GyQW37jXSXqJGwXZhgmsXp9l4W4xTGm6Yu05w4R5sueFKa02E7fNceVAdDCcBFW/flWYSe/ynfaN4jGWHTHSOCPnsIJ5f0t+hhLbQkufTkDXuraZANP+aAbnC4p8hkm5msV/oGKhzSY5UMnaV9UJ7IY0iKgutTQgRyfP0BCn1TOAgSlu2gyN9W10Djixuvl2AwfQiYVX/pVKBSLWNuGtKSPHdmRm/ZnCxMeKCcm87Y2lrugl5ttnnnzU1THYS28vADGCl/x7LTxMXrYONdPvCeHSx0u8TvKTwwHRbcBAjv2iLJpBVpMdglyCpXhCUI7PlYGz+akHL8hOe05IGTf8MqeqlFeuEC6WpL/dV4S78OT0S/0s0kVA3dYe68cu3WcdwQ88P3tjmwBN4Wd93cV9poKcacZkkKBilQ4abJYLWR9H271MyTSKjWAX0/4SKCoPGNIBFKK1gcOGH/Fc76ImB2p7kDYJfMdwrSABthXWj5tGbhGoazdAu27Vu1ZXR14CgPgaAMfJWW3x08xU1A4W826ittOjDqZ1/xqhAqOND8gQ/NGC5PQk8RGsqn2GYZrf7KLV8FuW5DA2VVg54Xh6uOWKR4qtaycjJbab5SJ8/HFAGjHR7UguB5W8z+Jmf99+65j9DBJYxCHcADjA5C1mvGRzV5RKG5F35wBKxoZ1/wtk+GRPUnhGSh3PMLxgGjAEEiIMqgxj2yAeE3CxBpaZEBThI0tVqaLfs2e68dY5Lg2Ua6AUKHH+RQb5M7pGxYR7GQvZTx2Mrd2lqhdOPRRCKxr8HN2waw6QfuxIco8VEme/uek0dcJ2I/ESk8Orv0zxT5H9fyMDT+wZ/AUVvpSpjn0Hlc3aVk70G49r2MLveUU0lvE Bx78GbY5 HsJiyeznPYQdg0tT0jmmsAGRDJa5k/CL23nQJ5vvJgjc5bI5dqbLJpMgeB1jkjexmFbTOxxSj/e4CTUdn2MwY32pkYYl0KC/Rwy1jnsPVw4An92LThpAOXQb3xkMOSLWlJ/arYjcSEGqtHIaZVUO+1rbHUXd8YAKJy4NSuJjPOFYiHYxMm7whnVGYWL5lJC7bKzvyJyAPJBpp5uFn3a7bZtKkmnQOGoBol8NICjstANV/feKL1oBT5XGfDJdmmUCQvj9YKS6Z6T4q02hTbMPAZL+2WTBmJ7dDjaOjMNVqWNB8pkxz5TwqjNBr8mtEAteL2FWpBeIOGEruTWPmr6PxIbBKKMcS9Yjam9L7APeKbXORT72n3Bnyv/ObEY2lyNjUh0WPVQEjpa9yklr6X423LN4VGYU3lr4qhMB0N5msLr8BXPJ6EAWOp2m2Er8pgQL/FdZ+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: iommu allocations should be accounted in order to allow admins to monitor and limit the amount of iommu memory. Signed-off-by: Pasha Tatashin --- drivers/vfio/vfio_iommu_type1.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index eacd6ec04de5..b2854d7939ce 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1436,7 +1436,7 @@ static int vfio_iommu_map(struct vfio_iommu *iommu, dma_addr_t iova, list_for_each_entry(d, &iommu->domain_list, next) { ret = iommu_map(d->domain, iova, (phys_addr_t)pfn << PAGE_SHIFT, npage << PAGE_SHIFT, prot | IOMMU_CACHE, - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (ret) goto unwind; @@ -1750,7 +1750,8 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu, } ret = iommu_map(domain->domain, iova, phys, size, - dma->prot | IOMMU_CACHE, GFP_KERNEL); + dma->prot | IOMMU_CACHE, + GFP_KERNEL_ACCOUNT); if (ret) { if (!dma->iommu_mapped) { vfio_unpin_pages_remote(dma, iova, @@ -1845,7 +1846,8 @@ static void vfio_test_domain_fgsp(struct vfio_domain *domain, struct list_head * continue; ret = iommu_map(domain->domain, start, page_to_phys(pages), PAGE_SIZE * 2, - IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE, GFP_KERNEL); + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE, + GFP_KERNEL_ACCOUNT); if (!ret) { size_t unmapped = iommu_unmap(domain->domain, start, PAGE_SIZE);