Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp464720rdh; Wed, 7 Feb 2024 09:41:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXU71eCtNhj7licSPIeE962TYosfY0ILMHnEBdkq/6rCOCl/z085yqsK63nytGutlr29kh0Hh+TypFP+GcPhaNWBLZ2rM+cW1XiKOMTYA== X-Google-Smtp-Source: AGHT+IEMu9+pize83DSwdI2ep2ldbEIH82gw6cYwPdT+vYvbeZESlguuyBAuQNrcL0pLJb5HwRgv X-Received: by 2002:a05:6512:79:b0:511:49e1:6a2b with SMTP id i25-20020a056512007900b0051149e16a2bmr4088295lfo.46.1707327712058; Wed, 07 Feb 2024 09:41:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707327712; cv=pass; d=google.com; s=arc-20160816; b=V/s6sqW8NjplEqi0K1wl5uFIoZg/ljX1s9pM3xkt0L1SFiZyeVgev/bF461Dkw2jrW 4X4YC/9kmuXR7C+XvUQG1s8kFK33yrPBMyk9olqjTnSwBuD3HdxzWBVa1Rnjw1ZM8gVr VjAnnnwnu69x0PsqDEf9Iu0AQiOMeWRBQ3kHALBobBseyRCxA8mtSE972Oi77dp5F3Zj 0qwjoOksedlniP9sICB1vCXS0xBO0vTo4/DUJkyCEBALVxsQfgQWWIo/Fn8SjTRcGgQw fV1Pfc7F4duWK757I7RZJbMN+isuhesVhaCc5yry3q+v1OriKjszwpwLXOkflB0UkWCU +ovA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=si3iSYQzW/wS10JKxA6PCTvsO4f4p9drxSnRwVUScZU=; fh=eERruUYxI3g8sYWMd3V+B7P2FIclli1+xNWgD8DWci4=; b=eqtaS8G4pKAb2gReOKSL0AVp9Et4CkHgg6OzygMyydXb6vRnyq6CVEmpcBZ+JdSTu9 iyO3RRW2gTUMEjPSuh+ZKw4sT394VNGUgYQ9mz2cbm/Z/Wj7jRjrVr91EZ6VDW4FNdFq n0BQMfWj3JSqaJz06oMQV2idjzMOWxN9wF+LyGvIgf7QJKb+KMNSnxehNGiD7+VEkXH2 lFWm2V5mXvMY9n+wa7buCCulFVvZ8eMDZYeDIQiC4HX4YwdPevJYm9uuYfiENYKyjgkc iwHoF7d6hRlTcugS9YTqN3P338YjgqZA2ifGCO0zXAMCj6BD75SSkQ6V07djD+5PukkJ cvWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=temperror (no key for signature) header.i=@soleen.com header.s=google header.b=Er00PaUp; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-56832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56832-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUQGjmxG23sRc0qn8zYLYIj4prVCfjDg0O27CqJE2DPQjTDI9GPl5qNRpYOn5yjTnudgzr/vEHACNjyAdqJ3XOGsnCpVDRJvnGCJEg4Iw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g2-20020a170906394200b00a31914f552esi1174201eje.710.2024.02.07.09.41.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@soleen.com header.s=google header.b=Er00PaUp; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-56832-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56832-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 67A1B1F28404 for ; Wed, 7 Feb 2024 17:41:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6055483CCE; Wed, 7 Feb 2024 17:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=soleen.com header.i=@soleen.com header.b="Er00PaUp" Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD38482C64 for ; Wed, 7 Feb 2024 17:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707327669; cv=none; b=UyN4vDXq6+Z5y4X3emK+0lxIytAPhwKQuMtqxTJMdl+h8KwyD4zFA7faaF/iSUdxFBSg+c9+tupluXgEiofYi2cCRORmLO7InltyMjl0zpKVH/F4niO9NMo7vqZfC0uVwj0bPvrcfkurU8tETiAmU+bqJW1sni9mnf3NKLB47jw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707327669; c=relaxed/simple; bh=Pts1Ollg+kHIJn7gcBTh60hwuP/+5EbYctTIjn8gNGo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=W7wBDLLSlCgvjwOdzy+HxXRk4u73rmr4FTaVXSTrwQwyjkVZ6kPvs04zihMp3VxJQDjB8/uuI1YXLMnt5FAVrppJO3dJRYNkvoETea2Ri+yzZEFKFeCp5OZab5F5n2uf85aUA/AhI5CefP8oZUJjetQmcBKOEemV+QiRH3VQHC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com; spf=none smtp.mailfrom=soleen.com; dkim=fail (0-bit key) header.d=soleen.com header.i=@soleen.com header.b=Er00PaUp reason="key not found in DNS"; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=soleen.com Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-60492003050so8625657b3.0 for ; Wed, 07 Feb 2024 09:41:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327665; x=1707932465; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=si3iSYQzW/wS10JKxA6PCTvsO4f4p9drxSnRwVUScZU=; b=Er00PaUpSH/5jhHWznyDOQ1DfmcMQSAL15LHJFisVQQTL/nGgEfw+XgJx5X6dgsQ4q RU9qdlHpmxcCfGn7HI1DyVo31+NSJKzE/Or8OrD1m3mcDlYYAagUWBnNbO/btxSw5XOH Lqz3GWZCgo435t4YvZ3qhm1i+hy0IbnfaqdGS1mbvpXD5sdasMvQVyHJ3czkuSXYXJmk gsMiK+/+9YC6Vo/68DLNFPezjHxHHBb33m9BAEimpFiLS/+7VNZKN+127ZIfPRxgH+QD wOIxgMi2K2onpDYo2mBpHLB/t8iRvJ2BplzJhnoq0WLNJ0+uMKueyXMLDwdD+Hl1ad/U 2UyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327665; x=1707932465; 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=si3iSYQzW/wS10JKxA6PCTvsO4f4p9drxSnRwVUScZU=; b=KhMZqsRhRWK/hUfm65ae8vqUjwWnLN3ZvrZuFi8f4jvyMG+0wd7D3Bc02J8g/QODYb K2c3jmTVchdrMB9YHv7KolXWVnwhrjoSkN7dxNbbibi5/TVQhR3yQJ4o38jGUR5/VGNg feqn7wxMTRmmSzpGPJE070Rvit6v/ThTuOsEW6p0Xa5nkV/E7yE+6ysWZmnVBSBBo+g3 VQMuWsDUvACwXJ6jDefd7gBqcvuf3CAdKVwP9hdSgE4cNfznYX1EF4mk9Hp2hyanQVIx aHveUXj089JGAsksfwXPgkkHKq/EQ8u4LEAQ+mV/nfX8kEqaUd0pC/LOKf/vI/zRcqTq XzZA== X-Forwarded-Encrypted: i=1; AJvYcCUybzF07HezVgXCslhfKuzXgHxvfs7YSDOTfjdyMz8kwECUtAxKZ2ZAbCzGaIhJK5+UANQL15PgPZjD9rZCQz7fGmOpnuSVkz7lA54I X-Gm-Message-State: AOJu0YyQTk+JLyr3oUkV7Lw38I5a9cbC2dIcIiInjwjm3WMB3ahcKzZS J6t7JBTexb6ty4AGRpCtRynMKfw66ZFFa7/RSVcM+EC6VJQ78CR6vkBsq8St4jo= X-Received: by 2002:a0d:d641:0:b0:604:9fd4:a0ec with SMTP id y62-20020a0dd641000000b006049fd4a0ecmr668771ywd.5.1707327665531; Wed, 07 Feb 2024 09:41:05 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUkpA1e8or7NcUr/WsWjrzjdXlKnYP7Brox9OXywH4gDbvfn48o3nQvHRI3pVbQX4O+aXkOe6P1Hn3x8IUM5XVB16c5XA7JXuzZH5fDUuhC3U9N1bfEbkfjgV7/xqboIkaeaOm372F/MkZZVEq0wEc2DJuJkyXvpBTbqVylv+rD5YWo0/G+Kg3OD5182kxWb9kzCZ+UE/n0vaD+CRG2C1kuzz4SmrQ6NdqQbHPuKYn6WxVgQS1Scls5HHdhjkF410H1Jnetb2wUH9Vej4DTNp8scc0RM4g+s3dGiuedxcYwU/O4lWzNLDnUo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Tc5D9/kmWyxIE8uXkDBqWdSKuVjeQqEFojdrrbHmALXwMRaHOqgrUm+TD21Sq/eQwjWSfH+Z Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:05 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, 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, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.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, m.szyprowski@samsung.com, 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, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 00/10] IOMMU memory observability Date: Wed, 7 Feb 2024 17:40:52 +0000 Message-ID: <20240207174102.1486130-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ---------------------------------------------------------------------- Changelog ---------------------------------------------------------------------- v4: - Synced with v6.8-rc3 - Updated commit log for "iommu: account IOMMU allocated memory" as suggested by Michal Koutný - Added more Acked-bys David Rientjes and Thierry Reding - Added Tested-by Bagas Sanjaya. v3: - Sync with v6.7-rc7 - Addressed comments from David Rientjes: s/pages/page/, added unlikely() into the branches, expanded comment for iommu_free_pages_list(). - Added Acked-bys: David Rientjes v2: - Added Reviewed-by Janne Grunau - Sync with 6.7.0-rc3 - Separated form the series patches: vhost-vdpa: account iommu allocations https://lore.kernel.org/all/20231130200447.2319543-1-pasha.tatashin@soleen.com vfio: account iommu allocations https://lore.kernel.org/all/20231130200900.2320829-1-pasha.tatashin@soleen.com as suggested by Jason Gunthorpe - Fixed SPARC build issue detected by kernel test robot - Drop the following patches as they do account iommu page tables: iommu/dma: use page allocation function provided by iommu-pages.h iommu/fsl: use page allocation function provided by iommu-pages.h iommu/iommufd: use page allocation function provided by iommu-pages.h as suggested by Robin Murphy. These patches are not related to IOMMU page tables. We might need to do a separate work to support DMA observability. - Remove support iommu/io-pgtable-arm-v7s as the 2nd level pages are under a page size, thanks Robin Murphy for pointing this out. ---------------------------------------------------------------------- Description ---------------------------------------------------------------------- IOMMU subsystem may contain state that is in gigabytes. Majority of that state is iommu page tables. Yet, there is currently, no way to observe how much memory is actually used by the iommu subsystem. This patch series solves this problem by adding both observability to all pages that are allocated by IOMMU, and also accountability, so admins can limit the amount if via cgroups. The system-wide observability is using /proc/meminfo: SecPageTables: 438176 kB Contains IOMMU and KVM memory. Per-node observability: /sys/devices/system/node/nodeN/meminfo Node N SecPageTables: 422204 kB Contains IOMMU and KVM memory in the given NUMA node. Per-node IOMMU only observability: /sys/devices/system/node/nodeN/vmstat nr_iommu_pages 105555 Contains number of pages IOMMU allocated in the given node. Accountability: using sec_pagetables cgroup-v2 memory.stat entry. With the change, iova_stress[1] stops as limit is reached: $ ./iova_stress iova space: 0T free memory: 497G iova space: 1T free memory: 495G iova space: 2T free memory: 493G iova space: 3T free memory: 491G stops as limit is reached. This series encorporates suggestions that came from the discussion at LPC [2]. ---------------------------------------------------------------------- [1] https://github.com/soleen/iova_stress [2] https://lpc.events/event/17/contributions/1466 ---------------------------------------------------------------------- Previous versions v1: https://lore.kernel.org/all/20231128204938.1453583-1-pasha.tatashin@soleen.com v2: https://lore.kernel.org/linux-mm/20231130201504.2322355-1-pasha.tatashin@soleen.com v3: https://lore.kernel.org/all/20231226200205.562565-1-pasha.tatashin@soleen.com ---------------------------------------------------------------------- Pasha Tatashin (10): iommu/vt-d: add wrapper functions for page allocations iommu/amd: use page allocation function provided by iommu-pages.h iommu/io-pgtable-arm: use page allocation function provided by iommu-pages.h iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h iommu/exynos: use page allocation function provided by iommu-pages.h iommu/rockchip: use page allocation function provided by iommu-pages.h iommu/sun50i: use page allocation function provided by iommu-pages.h iommu/tegra-smmu: use page allocation function provided by iommu-pages.h iommu: observability of the IOMMU allocations iommu: account IOMMU allocated memory Documentation/admin-guide/cgroup-v2.rst | 2 +- Documentation/filesystems/proc.rst | 4 +- drivers/iommu/amd/amd_iommu.h | 8 - drivers/iommu/amd/init.c | 91 +++++---- drivers/iommu/amd/io_pgtable.c | 13 +- drivers/iommu/amd/io_pgtable_v2.c | 20 +- drivers/iommu/amd/iommu.c | 13 +- drivers/iommu/exynos-iommu.c | 14 +- drivers/iommu/intel/dmar.c | 10 +- drivers/iommu/intel/iommu.c | 47 ++--- drivers/iommu/intel/iommu.h | 2 - drivers/iommu/intel/irq_remapping.c | 10 +- drivers/iommu/intel/pasid.c | 12 +- drivers/iommu/intel/svm.c | 7 +- drivers/iommu/io-pgtable-arm.c | 15 +- drivers/iommu/io-pgtable-dart.c | 37 ++-- drivers/iommu/iommu-pages.h | 236 ++++++++++++++++++++++++ drivers/iommu/rockchip-iommu.c | 14 +- drivers/iommu/sun50i-iommu.c | 7 +- drivers/iommu/tegra-smmu.c | 18 +- include/linux/mmzone.h | 5 +- mm/vmstat.c | 3 + 22 files changed, 397 insertions(+), 191 deletions(-) create mode 100644 drivers/iommu/iommu-pages.h -- 2.43.0.594.gd9cf4e227d-goog