Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1322837rdb; Fri, 16 Feb 2024 11:52:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWI6WVP38VAXU3atVk+/31f+ItAeXCbvMNTqp1kgf/mRAIy0/3AcmUWAjcw8ifOAFmyL8vBEWMw5+akKOYIt424R5FG0ZaatgTXfrO86A== X-Google-Smtp-Source: AGHT+IGtyjJQRpCzTPsZxk2ciIa6ZCCdLRJLIQNo9ziWYlHpmKGEqu0QeTrLS54W4rq3hukDxoMN X-Received: by 2002:a05:6358:e497:b0:176:d2dc:5115 with SMTP id by23-20020a056358e49700b00176d2dc5115mr6491003rwb.20.1708113129924; Fri, 16 Feb 2024 11:52:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708113129; cv=pass; d=google.com; s=arc-20160816; b=EHJ8nMur/Sx1lyRimGVKwRoNnzqFrqcPDdYmGxkdxdOOQUX9o24p1fYNP9Nlg3UUJU DOSh8TZpOLOIp5tYqTerb+FfCQ9GW2sbEF2MuNBQlQFXtKxxGgZKI1nPtW2gshsTnLXV vjCe4cQ6G/AjyJIX5t3z+PvuNewr5r7Xl/7T7+s7bcFZpQm5541tlFzCZl0QJjfVRIps FD9PVkCcOZpKyJNS7K60B1db6FiaeA8BejRe8aUaqztO+MYEV7daALpM7S336i4mXLu9 XENynaDDzer8NWgRePqwpZtsUei0TjUzP1gmD6WuBZfbcnimHGYIQxbIidAKUweioi1Q Q6uA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=XMO1uzBf5Ipo+B8nJFhezHnHhPZI6cIYH4qqZglP7mw=; fh=6Soe1o27zK//Prjl1+9Af+ExMhAEV2OCRWf5p5lWg4A=; b=n68Te+SyoVWUmxcg/OvKQMlRu1XzD6qUM1c/pPdrDe1bImdSrTRSIEhbCjhNjfONne T31+zjpEsYB+vE/jusrPZid+5vlSDg8JD2FEz37EroXa2pHiu6A8iOI6xeMQk32tBoO1 GojpYVXfYDedC6ssB+qgvgHAp20M46yM609gY0od81jCLVrBWBXl3wewXX9GeEFsP3y4 p7+PQiqmjpO+zoj1odYKaaq6JgWHSiZjjgT513MihxhZ4laRgsoNo/x7fQ5P8v8dmxCg vn7jHkmcqoB2BPpIUgFbBz81Vn12fKh7ZCZL2QTuqCtRRdrAh7EuZ5XIv29mAVzIn80P K5Qw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="YX/jXwaF"; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-69266-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bq7-20020a056a02044700b005dc4219ac31si369966pgb.139.2024.02.16.11.52.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 11:52:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69266-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b="YX/jXwaF"; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-69266-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69266-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B11E6B22889 for ; Fri, 16 Feb 2024 19:49:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96C2B13A253; Fri, 16 Feb 2024 19:48:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="YX/jXwaF" Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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 AB1F2137C52 for ; Fri, 16 Feb 2024 19:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708112921; cv=none; b=bBv97PZKutw2kHG9v+IpZ6yiaYA2TsKp1qIzmz9byAzp+bSU8ZJNsjgvW3H/HAo/scZ/wie+IOhtr3ITTtWqqVnJduVlZtZjSKvTxHDxg2ahrVgtnidjvQJDD6N9uuk5vr4R+BPPuz7k/4qj9u5VFtsu8knQbrkGhwLQCg5rsm0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708112921; c=relaxed/simple; bh=m2Wvv0O31LwrnCQdUKYEs3sNTTEexlxilQS/jlCfnew=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nVtbJCMX7loztu8DlJaZvsMDSNoSOgNAEkjnFyt5BoEI71Q/mqHeHab6vfHcbA9jkXiVGvKLqmVkTsHv1vOMi7Mgyg8NqmWhyjrgnbe0yTUsJ6xh6JktMFbJq53TvmJ4N8IrfXJ6Ipmx+KGPtbnX264fLVOlhvkwRaDRIBvR63Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=YX/jXwaF; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d0a4e1789cso28534601fa.3 for ; Fri, 16 Feb 2024 11:48:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1708112917; x=1708717717; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XMO1uzBf5Ipo+B8nJFhezHnHhPZI6cIYH4qqZglP7mw=; b=YX/jXwaFS/hB9HhbzEkfX8cSH4LyyWANTm6daW/jaTDSixVYXYJ8kZXl3XHjLa3Rq5 iUU7aAFL94+s6iHS0CLve1DvbxMa9hUYM1/71ifPsUJaQtqPisbfE2CAyc63oAFT5TYc basuhP0hUoEqMIyhM6lAWzzOrGne74JlZevCrQ6aEqmeEOZOLPD92I6Q1VECKXoj7181 cJsP3MdtZsEMuJnK5kLDEp6U40o4AFqha5hdIx6sII//n8rmeQswx6ppCWitx/d/slrB JV0e12TJmGqbB/jOQHav8Aj3G/UvLeAdBikf7bajKfSKPmyGdPqrTYRIVQcx46M0HIHQ E2lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708112917; x=1708717717; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XMO1uzBf5Ipo+B8nJFhezHnHhPZI6cIYH4qqZglP7mw=; b=NY0tUkpw2hKqAwy9P4vH8acV6sdXALZm3RgNvfdu78jn/9XzESjBcFY7YKYoA7Hg0a MiD89N/Vb9qGBulM8yxvERvyRb+hLKWQUuoT5XWCh095kiNMeqs6exb9TL4dbHsUV3vx rOiQ5XtVlWnLx5R/QeWGKzVE/1aMmVW3tIiYj634Qp3HsXZmQpaSCK7U5jf/qtVGZ5fs LMOlvrSwqzPkjyA0MHSpN4SMldWh4MZZcKyUpVB6bHcND9Y/4bTDGwGoSYoNPZkRcFwL wrxu1EyVdyKDI0G7LOPW3EjQzxMBs49QXRE9OYFKlyAwBu+7Syx52Uq2aOaJzlNzDNFE H2Zw== X-Forwarded-Encrypted: i=1; AJvYcCWp3kU/s3T5b8/3lkYQI208BGIjqlB8aMitY5Q6LToqv7SmHJs6Lgtt/nRCCUiZWiyg4k/QskBYklpIPO+E2YumcnAikyhii8ZilEU5 X-Gm-Message-State: AOJu0YyuRIjcIZIaRqEFvUiFAveEy281P0JJJYIULtcfZNE3uKfPV+Os iIZ1l4H4jOI1nvPvMIaXJAnbPjSB7ceCjIizhNvb8AVcB+Tsx6OJHbyEvyFnEkRJPYIArlQaiD1 wgQ6m7q5eMFo329pLWac/ZDIe5EyGyjKBMT9DEQ== X-Received: by 2002:ac2:5bd1:0:b0:511:a021:220a with SMTP id u17-20020ac25bd1000000b00511a021220amr4183994lfn.21.1708112917508; Fri, 16 Feb 2024 11:48:37 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231226200205.562565-1-pasha.tatashin@soleen.com> <20231226200205.562565-11-pasha.tatashin@soleen.com> <20240213131210.GA28926@willie-the-truck> <20240216175752.GB2374@willie-the-truck> In-Reply-To: <20240216175752.GB2374@willie-the-truck> From: Pasha Tatashin Date: Fri, 16 Feb 2024 14:48:00 -0500 Message-ID: Subject: Re: [PATCH v3 10/10] iommu: account IOMMU allocated memory To: Will Deacon Cc: 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, 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, yu-cheng.yu@intel.com, rientjes@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 16, 2024 at 12:58=E2=80=AFPM Will Deacon wrot= e: > > On Tue, Feb 13, 2024 at 10:44:53AM -0500, Pasha Tatashin wrote: > > > > SecPageTables > > > > - Memory consumed by secondary page tables, this curre= ntly > > > > - currently includes KVM mmu allocations on x86 and ar= m64. > > > > + Memory consumed by secondary page tables, this curre= ntly includes > > > > + KVM mmu and IOMMU allocations on x86 and arm64. > > > > Hi Will, > > > > > While I can see the value in this for IOMMU mappings managed by VFIO, > > > doesn't this end up conflating that with the normal case of DMA domai= ns? > > > For systems that e.g. rely on an IOMMU for functional host DMA, it se= ems > > > wrong to subject that to accounting constraints. > > > > The accounting constraints are only applicable when GFP_KERNEL_ACCOUNT > > is passed to the iommu mapping functions. We do that from the vfio, > > iommufd, and vhost. Without this flag, the memory useage is reported > > in /proc/meminfo as part of SecPageTables field, but not constrained > > in cgroup. > > Thanks, Pasha, that explanation makes sense. I still find it bizarre to > include IOMMU allocations from the DMA API in SecPageTables though, and > I worry that it will confuse people who are using that metric as a way > to get a feeling for how much memory is being used by KVM's secondary > page-tables. As an extreme example, having a non-zero SecPageTables count > without KVM even compiled in is pretty bizarre. I agree; I also prefer a new field in /proc/meminfo named 'IOMMUPageTables'. This is what I proposed at LPC, but I was asked to reuse the existing 'SecPageTables' field instead. The rationale was that 'secondary' implies not only KVM page tables, but any other non-regular page tables. I would appreciate the opinion of IOMMU maintainers on this: is it preferable to bundle the information with 'SecPageTables' or maintain a separate field? Pasha