From patchwork Sat Apr 13 00:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628388 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 1C832C4345F for ; Sat, 13 Apr 2024 00:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAA5D6B008A; Fri, 12 Apr 2024 20:25:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A808A6B008C; Fri, 12 Apr 2024 20:25:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9210C6B0092; Fri, 12 Apr 2024 20:25:28 -0400 (EDT) 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 74DE56B008A for ; Fri, 12 Apr 2024 20:25:28 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0CA44120FEE for ; Sat, 13 Apr 2024 00:25:28 +0000 (UTC) X-FDA: 82002614736.28.703FD0A Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 3EF9EA0002 for ; Sat, 13 Apr 2024 00:25:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=FDuxFY+r; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.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=1712967926; 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=dxPD9e5Q1st8MCbV2NGQC2VF5/nUXXzMpKHuTELQ6SM=; b=QQTRz+M2dqkpyGqO5utj5UkZS6sr6bXJVnNiPhAMhsU3xSH0P6L7L7Had0RxQ2XbqDhA66 Nqqpzu6jaNdiwkM5hx+sX4ZdaHaje+B0rBkCI2lnUIQCIj8Jb+5EwTc5/d1tlCgKEXfM+g M9NcU148qSDH6txNYAvEFBtXd9JStPs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=FDuxFY+r; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967926; a=rsa-sha256; cv=none; b=4QzCI9zi4dxQbZkquSmovRS1xD+Ruy6ypzVVL4Ga6lLjDe4YcThMlrBXVOqIDaWryTU01V kMPc6I/mJS39noJHJQvel0butSNi2qBRka5WwLDxObfYu+6FU9tNZJgDUMgBFB2nggeMRe 8yqk5mJiQ/amBmhrYmqcGZMYNOtQYnA= Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-78d57b9f3caso83087885a.3 for ; Fri, 12 Apr 2024 17:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967925; x=1713572725; 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=dxPD9e5Q1st8MCbV2NGQC2VF5/nUXXzMpKHuTELQ6SM=; b=FDuxFY+rrvyTHF6Vu5wQBf1pBMxhztvpClh5A4JNzRbVzdSp29cPKLQDkIUtDPo4C9 oQDeT1yudL2CyGB79+uHE5q5in03cuXSvLNK2fnss/txIYsVbeBNpwxLcqQ6KS6kR+cn 9dzZ4L0fqd8vxvZtKPj2isyzBTMisDbtnqBVkAzE6CgIUrslPYMDCZ9csDKttVrkup87 b2ee0zk0cqajgQAmHFpqFDFQuIF0Lfdsjv2V7PtKyA7SHHVDac6P2ejUb7/e+DIdDU8Q ky55q9gLCvIr2PrhrNijbdKpAHxWJmQA1ecuU8XNTfH5qVP7BIqYxhkElIpOS02HT//n Wrvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967925; x=1713572725; 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=dxPD9e5Q1st8MCbV2NGQC2VF5/nUXXzMpKHuTELQ6SM=; b=VOPDFM7c72cV7CAus2qHbeU4SPhNdghnKFjlLI9DW4Q5z+kvhhP6GlG0exvZF+si2A 6yMrustYPy6fItn1jLvn1bUJJz0ugkCDPa2VBrjSm//nIivJjJYBf6F7AukGDSSbOBM1 3XwRWhXV9RYgjnbsIOHc1R0yzfiurwJJJb7KgKWmhpG4x/vycgV6edTPTpMPz5zDPLtl u/Pr3zWy78IL/uLn2dF5u1K62PaSm3C1xrOdebs8ao7rHOJxEzIQpS1tRXI9qUhit7b1 gYBVb9/rLeBcsqKrlIpyCO7BDwnwFgwjoKttDpHeLvEZq0Zlb+DTEkH7qo3QM2skE4HH Ciog== X-Forwarded-Encrypted: i=1; AJvYcCU1y2s9z009E2d3t0Jm3LWL0NwJ+mYBROluM1Qy9+fwk1synqD9vwLeFaxFkWEckBqegLjUiU8jjdCf9kpIhkOBfV8= X-Gm-Message-State: AOJu0YxoK2X3YIDUynf0Z/5xFHFxQIy2it4JSL4zyw4j72gzcefUbV7g UmK08WMp4uYMld6qvCNUNaBIt6ktSgmMKXXAfFzcMgurMs6oXik9XC5pV5yz5b4= X-Google-Smtp-Source: AGHT+IF7Vr8g4aGey5MWA+q3W7MDwSCWGzrkZkaE7zDxFxXJB774VSRb4A04gmHX15xeQKDoOQC1aA== X-Received: by 2002:a05:620a:c90:b0:78d:39ef:c1e4 with SMTP id q16-20020a05620a0c9000b0078d39efc1e4mr4239836qki.24.1712967925336; Fri, 12 Apr 2024 17:25:25 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:25 -0700 (PDT) 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 v6 00/11] IOMMU memory observability Date: Sat, 13 Apr 2024 00:25:11 +0000 Message-ID: <20240413002522.1101315-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3EF9EA0002 X-Stat-Signature: wwwuib7dknjihboixwsaqbxjiskw3z6f X-HE-Tag: 1712967926-729633 X-HE-Meta: U2FsdGVkX18nNCE/DtlEbjL5d9bAWANiN/IXroufl2XAI1q2RBU4v2DKFtSSVmggrPyue89XOtpTXkopeTy7zzh93F3HK3/Vu82VXgym+/+bz43tvrrzS9SMFJD6jIrMs6pvG6gQ+q8xoljpeTFK+7u+qkV9F0r8AahP9e67EqGDuCGjnsPIp7HTgK78RgxMQxdRPUNf9LDSfvMszAnNfjwhtxiz3hfvpLpHC/UFWlFV1Ob2iysUS6xMtvvJDheJtqpIkqYcUz3R5jO4sGmxRyhzqNp6CXO2raXrAqEo+NZlOL2qvMsnJBY23P4+SbgCVBX06hOjm7/hhCo10wjFXvPPcqkGOyI+HyyA098LPLofU48lfHUFBADcpRhAIpCIwR+1FNrMtpEPXiFEXwBR1atf95Z/Hdk/imndsusZQJsKDuiiSwQnRGf9P3IRrTE9onn3wuwA2Xh64q3GKA0MRtAVKAZZ97/tvKSmG56IRyaBVaC6Ck5o8845alzccSLImcli9GEqVHvSU5DYTWrGjqlNvP6pGWSbzzfJhfJr6svugHaQrknf9hxP2ygXi71h8dtB+FnzeOrtt9hhw9P1OlXuYaVRSFgqoT9RKii+lWWHkQd4Oageahp0NOmvJjXf1h/CxAitJHm/ewdVd8tlYFp9SJ/lDrYvYEPOaXw6mkLL3U0tZ+ar2EuzbEEO8aT99dusHqXH0l4Y9zv2x8caicoIOZh+ub2xChgd2jvv2LNOJOrJ/AssU3BIiHZUtCPZABblG9WxTK1P4+IpjN23m5NwPWkrnk0anOZvga8KTYd6/exS8Euin1zyfNMxmv6Oxhnu1wL0pIpoipohhoKDQRUNGa4jLXPEvjirnpzK8RLIJkHdYzJMBKRvgxhn+pGS7t20WTxnuAH3cU0Jhg2bE+MRx+5iAbpbQh5G0rnw/1Pxtk/kJiDfbmMYZQVGSHorLhK5ygUrdYkufu1L8il yZ42Fc9J vel4d+0mBwLNH3UJ/AkrLgvmp1NYC2aHKhqRtUxF7pME/SXBTwfZDfSC0wxNvc8CNf0M8revRE/fRPqx8a62tz6clbz8bjfEbFWCOGGYSMDt+WEcJCNhpiPwi3U5Dlrl+UuLXvQuTtZ2w54Yv6LqVZRDgKo3ipxnrNsFImYpvnGtfQKyhtXGqAVM3ZW+1qRWqX4xA353LCk3JpLh8hxCRdDB7PuchbrVn5oBKKxaePJbJbLiDo63NMZIdhi3/laX/iHExp/IicnPPLgPHwADuLDQQDIt15+U0hVOFIs9+tGmXEaTlWsiOfC4r1DXUXFDysxeYCqKGUCvq8QAl4Kawmu2yo34XS3v3VyJw3qzaRwAPtI2HgYqqiCw+XtVQ3MO1+4pkHAKki1PWQ6MR76ttg9zHheI9Jmmm+hoIrrCtggstyAsOivTq2E8vJypXf/gqIkPkz5BnHqkOlUpy8U01FFOifEezOvjFmFZxmqgpjA99IFjLQ73ldhcBH9RAKyqq3GoQsV0fhxmubzqn7zWHjcHs5xG8M9NPEI14TE70gXA4YBtAxLmVzqfOMPM4XPti0D3ytlEZGdT16/qtOYJkX6XthYMvKc//n4GT0faiD+PvIObSpiGngpFF68hKy+xsmsHAWUSBE3J/tnWwHV4xDl1KJTuRFs/DUfmMt1ilPDK81h8NRAJydjxM05Jh87C0PFtL 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: ---------------------------------------------------------------------- Changelog ---------------------------------------------------------------------- v6: - Added Acked-bys - fixed minor spelling error - Synced with Linus master branch (8f2c057754b25075aa3da132cd4fd4478cdab854) ---------------------------------------------------------------------- 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 v4: https://lore.kernel.org/all/20240207174102.1486130-1-pasha.tatashin@soleen.com v5: https://lore.kernel.org/all/20240222173942.1481394-1-pasha.tatashin@soleen.com ---------------------------------------------------------------------- Pasha Tatashin (11): iommu/vt-d: add wrapper functions for page allocations iommu/dma: use iommu_put_pages_list() to releae freelist 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 | 18 +-- drivers/iommu/amd/iommu.c | 11 +- drivers/iommu/dma-iommu.c | 7 +- drivers/iommu/exynos-iommu.c | 14 +- drivers/iommu/intel/dmar.c | 16 +- drivers/iommu/intel/iommu.c | 47 ++---- drivers/iommu/intel/iommu.h | 2 - drivers/iommu/intel/irq_remapping.c | 16 +- drivers/iommu/intel/pasid.c | 18 +-- drivers/iommu/intel/svm.c | 11 +- drivers/iommu/io-pgtable-arm.c | 15 +- drivers/iommu/io-pgtable-dart.c | 37 ++--- drivers/iommu/iommu-pages.h | 186 ++++++++++++++++++++++++ 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 + 23 files changed, 359 insertions(+), 204 deletions(-) create mode 100644 drivers/iommu/iommu-pages.h