From patchwork Thu Nov 30 20:09:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13474984 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 103C3C4167B for ; Thu, 30 Nov 2023 20:09:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88BFD6B0495; Thu, 30 Nov 2023 15:09:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83BB66B0496; Thu, 30 Nov 2023 15:09:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 705006B0497; Thu, 30 Nov 2023 15:09:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5EFBF6B0495 for ; Thu, 30 Nov 2023 15:09:06 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 321DDC02D8 for ; Thu, 30 Nov 2023 20:09:06 +0000 (UTC) X-FDA: 81515709492.25.ED31B50 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 7A0D3A001C for ; Thu, 30 Nov 2023 20:09:04 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=CrN3mXQ3; dmarc=none; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701374944; 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: references:dkim-signature; bh=Be1KAg53A/Objdu3EOp617iDWrhswh7WogUdBagnrZg=; b=hCqwoL0QYIubJAi1NOtxpqxZk+1lxQXoxGhF2Q+MhbMY+DNR4UIlPXFDMvcYiARW+2F0uE tEZZiOpD0h5e4eoCYEgBZuYccrhod30nLXYYl7Iyqy4kkzqo1NunefUORdzZa3smQrwxMx NkWQTgTit+Q500Jzl5lb6e9ReVOkfBg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=CrN3mXQ3; dmarc=none; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701374944; a=rsa-sha256; cv=none; b=Uxj2fV6mOu2dTrWdLGIQCh4h+HySuU83Jc4QsbiT8d00/96he5UPormpTGvWCJMMyHFFbS Iuub+NjDG0KTN29YCNJbTQYcaH8gl36KnCUYVf556E/G94tV7UuDyeulTw+I/8ORSBBP7F DQ2E7qKFQgh1d8FX63eyzlXw+RCEcVg= Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-41cd8bd5727so7784331cf.3 for ; Thu, 30 Nov 2023 12:09:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701374943; x=1701979743; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Be1KAg53A/Objdu3EOp617iDWrhswh7WogUdBagnrZg=; b=CrN3mXQ39Pj+jEYysFONp5YExfH5k9XX/KVD8z6XeBboIIQ3npAHHbc+8+AvVnAuqB 6lN1jteL5x4WSUqj1DoZwk03zCZ6N9O/IQjnXQYXWv8a4fCi/rYSobrtEJaL5xNBMxyI /UWA4PGqax3d1dGG8VAsZoLMRYy+1/H7Wsz/Q9qENhwLdjjmRGVVQpScBAJdiulSPj/e aDNsrat14Rko4u9wPMZpq95cVSVl5wsAqsfML1CXF7wcmklfhherFB1ovPEct5tkuwc8 JtwVzh3zYEaGRXuKEWJk6hxAwl8ciOckcinuLEpUqe9+m08ovBgW1BlbA66iwrI6Q6g0 heHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701374943; x=1701979743; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Be1KAg53A/Objdu3EOp617iDWrhswh7WogUdBagnrZg=; b=YzJm+1oGetNyRnqaa2l9Jy239VCLWNq1KDCsQ/q1sw8gLOkgiu2fmFWAo939VxSjWa d1Vu8MAFAJuoYv8NhptGY6so5gF+xb9RFoFwafYQNuGtQ6kPPq5DcjVq/IWCpwXmc68W MMPH2vmc8Ol28kNc07E2g9e8C1L1WY3yXs9ufgffEccp0/U7jPeRS/WHP3XN7CNvuh2o elCnp3TqVWtxyANTmlpceM4lRczx0WhfSKFfuNG9Qq5Yk8Rl5DX2YbsqeZYEdjcrT5n0 7DMhrV6mhMII9hHORNXFTbxrDSZsBFnJxoJw2EMsGLIkmbZ+i6RCjoM9Vnjo/K9rVi5o JAeQ== X-Gm-Message-State: AOJu0YwGuiiTupiHsgTor3quy4+W89PYYvmgA1IzOzCLOqMD9wVICLxq tLVnpEK/AoqwSlaSjJWW35YEpA== X-Google-Smtp-Source: AGHT+IGyZ1MVJbpF5QMDxLNeNlkaL79u3htakyAB6E9jsA5aoQ8faIPkDh3Pm0do6EH90LCTcQ3f/g== X-Received: by 2002:a05:622a:1389:b0:41e:1d15:69a6 with SMTP id o9-20020a05622a138900b0041e1d1569a6mr28803241qtk.31.1701374943507; Thu, 30 Nov 2023 12:09:03 -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 c7-20020ac86e87000000b0041cb8947ed2sm786258qtv.26.2023.11.30.12.09.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:09:03 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, linux-mm@kvack.org, pasha.tatashin@soleen.com, alex.williamson@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] vfio: account iommu allocations Date: Thu, 30 Nov 2023 20:09:00 +0000 Message-ID: <20231130200900.2320829-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog MIME-Version: 1.0 X-Rspamd-Queue-Id: 7A0D3A001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: y5qoziu7jp14hgx7yd5opkpesn36jqp5 X-HE-Tag: 1701374944-777127 X-HE-Meta: U2FsdGVkX18wmcVR0neROUwg96T5d0oBLHhpujWEDlso0NZQGtQZRK6U4hO2ZNjMCiGq5+K/42/Bylgrib2YSg4UqjNM4v1HyZODCETGk+f9+GZlQDNOBCNouArRZ2RsPIldpHG8DGBFMy1h1Ifn4TsQ982Oy9MzyHE2o44OOhRiWotATIUemtVhEinpV5HWzLzIDgQwLw6KVoQEASpe9En+FA8tqnW2rqesDk45DWCGBJusAak9bvdkp1b/E3T1Ft4x2Iu+K9IdZT034RSpNZYSjBmRBBrvurPHQ118Ex1GXewOivH4dIyNGTU/E0GtiulWGrmuyIyS23hDOuG0hn6ohalNuO9T3XwKvfHU2ams8ss0GayqZJXMa4/poQZoct2/Y45hCJ2jkbhPTCsMAl3c9fcDZRNrAeKHsjvoLkejJPS8wzMN6MfZRsa/zuRFhVPhkk2W/y9tl9s3qzk4W1yMYqeos+LkY00igO0PjAu4Xb0Mc2RYH5Piy56/hctI0z1kJPPXa3LAUlVQxzlcqyVOrrvvGb4U29PQWfhK9df8T1ZmmPpllEkB1wgZkINy7IA87gxpqhLanWJBlIB8GDecL5TxlLDY1c/5seL1KNEV997ep1Rk3ZFzhWB/pLRy38ScvkiukZvcC2PNj8yQbD+BCEf6DH6uVWQqRDxd5pZnTQBo+eCVNmmC6I+deyeSrZwDyKv4hJ5GInOWG4YMbreJHWuvCwObCAipWEL+daY61pq+twJoqkb/ACwZCQItRxVt8k9pynRTye2P336yPkKKYiZldPsgqpuevA7NuInTg3EVYyNps2imHmbXg1U8E7JSNB7DpF/ScB7si1ivGOTLQroc1V9skQimtxVgPj+hPDKA3iiTqGgTW7D4cQ9+HoKcFHotMb4W7bnZ2Z/1OICDa9/coF32c9JE8glAOJViB5EeLfErj7EITxi1rxI8x6quYL2tYuuYVRKt2fO qfwdT7uw xWMI2AEESJ3W6Wz0fS2TL/uTkl9Nl8f2R4A2On1iHkA5vh8g5t8utzltRUyiSfZk73s3sdCPEx6NIYfBDGTwOkito66Iynvzt/9LqDjLzJVXUrrIu4Usk9VimAdAS7XQnJRqgk8VCT9qnQGuxChdNbOAKztdu7zzYj2tXlFtfj7lRRrfHN/TCkPUIAqLMgv5Csq4Or3s13LWaqrTYWI6B6r2EwdmJmnh7uRNJzdMSwGmbfguRBfKxivAD8ngo49H0LHfbN0bq6GEvSY75AJbHFoi0vkRDyeF+m4KtaOQx2y9mMCNxhD3u1FjRP2VBi0D7E1XsYnLruzt7JdFxMBx5PYxm4CHeSrbk0hur43LZhctN2KEtEL2z2d8ZH2i5pkl/UkhdOiULhQdD1eTjvA+Q0OvORmnl4y/7yzoWAsdEjctCSFty5sOiVSVUKw== 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 Reviewed-by: Jason Gunthorpe --- drivers/vfio/vfio_iommu_type1.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) This patch is spinned of from the series: https://lore.kernel.org/all/20231128204938.1453583-1-pasha.tatashin@soleen.com 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);