From patchwork Wed Feb 7 17:40:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 770778 Received: from mail-yw1-f170.google.com (mail-yw1-f170.google.com [209.85.128.170]) (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 9385F81ACE for ; Wed, 7 Feb 2024 17:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707327668; cv=none; b=rYRs3fgdhA4LQcmvVQpdFY0qrBpKlH9A35qlaFXHgsv0kTsXBh3VJCopOtuPHLmzOLFYFwCr1PaxdiCH6y2pWxXY6+v+naZYRFc2wVuR3lIk/0OaBpmDKyKH/jNflNbmXf2NZSLvbAtl+4cuQcWebVJCmVN7gctOQJhFk4EeTOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707327668; c=relaxed/simple; bh=Pts1Ollg+kHIJn7gcBTh60hwuP/+5EbYctTIjn8gNGo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PZQSti1FEqCMeqKxFV3Wm3kf1N/VINlQjyUWDva6zAopSis2m/IxYBr2GUedK0iOHVnQTziQIW/tJNNKSweXNpDgM5b/MnqLVc4QJ/hNJKjEPuFC7k5m56IHsr65U1KjhxNvnKd8UvtmdddhUfup7f+L2iltJVfARWOVTu07bFg= 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.170 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 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: by mail-yw1-f170.google.com with SMTP id 00721157ae682-6002317a427so8739567b3.2 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=ayWyLMKv9qjAFLgRrwJY/0Yw1mwI5Zhs/WPBoOxJRa8JY91IkyEAX+FXVAQhhXfV6M dkW5nUzI9DzOImz2+ZCmFeQTIRrO1L4o2NVr0HBeHjzYYJQzAHVIXqXUrRWHi8MXgLCJ MfYHHLS3UGfoK+GpqCVI7JM70DwJBvg1lFVvFmFsBR4ONbrBFRjV2bh2bDpCZsZMGRjY oLo65gkvp2ehoRKwyHzgzK50LbeZNZ7oGkFffH/CIwa5BV1LvHRFrphImHvJQA1b6Dki c0Ph2NoNeOeD79bzWrBJ6qisNd6mLx6miamw6EKWlWUfyEj9/wA3qaMTTeFLm5QVak/h 2qiw== X-Forwarded-Encrypted: i=1; AJvYcCV5oxlQBm7lli18OMONmVQQADGKr/XQ+tZ6Wrd2G03+Lbo/SbMNhQWDVV8kF6H62JuIMdo/CTIPFvNVuJLdncOrDIplWzKakMigLWLe5OkZDDU= X-Gm-Message-State: AOJu0YxarwjjGeHtqG+g0q3jIwwjZG1ygyhMvYex69p4cMipReRv2gB8 w3MdAf05edw4ilx7/2SyQXh4HbQXY3mYyzzHocm8VmmqwGQ03EDMI1v9upX5EUA= X-Google-Smtp-Source: AGHT+IEEHU0Zq486UjgccXih/doHmjMJ7ii4hv+46i8KhFxxFLmJqhnzWQ3qz8k37AV1xp4vGAJu6A== 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/WA9DCIOYKmjzvnmxeBED3dOwxSJ7FMF3P7X+3ERyu7sWGAfJMo4dSW5siD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q/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-samsung-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ---------------------------------------------------------------------- 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 Acked-by: Jernej Skrabec Acked-by: Marek Szyprowski