From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75F24C021A0 for ; Sat, 15 Feb 2025 08:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qMdWKD0kdtOq+yJVNXU2XZOFzLtu3uXSMprlQpoMEJg=; b=mNG0bB2Ol4kK6PbWbUT1RCv1xx C7fxckH7m6ES7mFWlo/MpbBxTjIDvrKaXbmwGdy1wO5QXSYnVxXGLcboNL3l7Z23J+ohv3pnUIdWB scAvr3oHjJdgUW3KmjgDTRZ5ZRVDUWeUyf5FkxkbiDj99vQlgLU7dWeVqQlFUuYO9rX10lUXqqQaR ptBewgFxpxRLEOHwQ80AtRgu14WwoSmq5upKrNxKROlzXOwjDtHXs3uniOBRBXZU3/TyOGaYp2YWZ tJ5Jx2RYwKFn/W0I6JlNcD9Qtox1AAJHUce42z7zFJTtEhPEXue/SFIscvPnyVlEwmXIr3Z3QC30h wy/WS29g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tjDul-0000000HHBe-1liF; Sat, 15 Feb 2025 08:52:43 +0000 Received: from mgamail.intel.com ([198.175.65.10]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tjDtJ-0000000HH5x-2tAI; Sat, 15 Feb 2025 08:51:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739609473; x=1771145473; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=bOL7hyxwdyA5NZF7YWFX1w7MgDLf45Pn8T+oWqiAy80=; b=j/luwkOSeWKokaacvlHoaKSz3XIbxKaT6KNpBc5knprsH0FtP37rKKL1 XFWJvygAVK6VUJ2te4RxpxNsNc6G1WWDld4wInPhbiKa1COPqs18F8FvX LRV9suf+ry+Zr8HrGUJgckqbO9m9T7i1zVEUVnNTLC3yRedkW2SR52zs9 X2MQQg6hfIQKllFzNbWOAuz8wd8Cog7vzgqOLYCjn5DkNYUBZ5D0jh6UI N0U/T9gOBRgqcoQQqv/5M/Sd2kh5fL8ZcW7H0cilsUsBoJBkBay9VuyJ7 JPu0zJjZ28oWX0pW5mLmV1eR2cGwmUy/gEY8wDlibnSEsQS8+yiV8dK9Q g==; X-CSE-ConnectionGUID: 4Z9cYiemRleSBs/1C1Y5Iw== X-CSE-MsgGUID: JIWgr1uWT/yg7ZvMHKBiXQ== X-IronPort-AV: E=McAfee;i="6700,10204,11345"; a="57764814" X-IronPort-AV: E=Sophos;i="6.13,288,1732608000"; d="scan'208";a="57764814" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2025 00:51:12 -0800 X-CSE-ConnectionGUID: /r+F0jx4RVKMBSVF09lU6w== X-CSE-MsgGUID: r0L1deRvR9Cz9JN551mbGw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,288,1732608000"; d="scan'208";a="114287640" Received: from allen-sbox.sh.intel.com (HELO [10.239.159.30]) ([10.239.159.30]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2025 00:51:04 -0800 Message-ID: <84fd4500-a12c-40d6-a532-e2956ed1c35e@linux.intel.com> Date: Sat, 15 Feb 2025 16:48:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 07/23] iommu/pages: De-inline the substantial functions To: Jason Gunthorpe , Alim Akhtar , Alyssa Rosenzweig , Albert Ou , asahi@lists.linux.dev, David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Marek Szyprowski , Hector Martin , Palmer Dabbelt , Paul Walmsley , Robin Murphy , Samuel Holland , Suravee Suthikulpanit , Sven Peter , Thierry Reding , Tomasz Jeznach , Krishna Reddy , Chen-Yu Tsai , Will Deacon Cc: Bagas Sanjaya , Joerg Roedel , Pasha Tatashin , patches@lists.linux.dev, David Rientjes , Matthew Wilcox References: <7-v2-545d29711869+a76b5-iommu_pages_jgg@nvidia.com> Content-Language: en-US From: Baolu Lu In-Reply-To: <7-v2-545d29711869+a76b5-iommu_pages_jgg@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250215_005113_811553_D8D38E4F X-CRM114-Status: GOOD ( 23.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2/15/25 01:07, Jason Gunthorpe wrote: > These are called in a lot of places and are not trivial. Move them to the > core module. > > Tidy some of the comments and function arguments, fold > __iommu_alloc_account() into its only caller, change > __iommu_free_account() into __iommu_free_page() to remove some > duplication. > > Signed-off-by: Jason Gunthorpe > --- > drivers/iommu/Makefile | 1 + > drivers/iommu/iommu-pages.c | 84 +++++++++++++++++++++++++++++ > drivers/iommu/iommu-pages.h | 103 ++---------------------------------- > 3 files changed, 90 insertions(+), 98 deletions(-) > create mode 100644 drivers/iommu/iommu-pages.c > > diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile > index 5e5a83c6c2aae2..fe91d770abe16c 100644 > --- a/drivers/iommu/Makefile > +++ b/drivers/iommu/Makefile > @@ -1,6 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0 > obj-y += amd/ intel/ arm/ iommufd/ riscv/ > obj-$(CONFIG_IOMMU_API) += iommu.o > +obj-$(CONFIG_IOMMU_SUPPORT) += iommu-pages.o > obj-$(CONFIG_IOMMU_API) += iommu-traces.o > obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o > obj-$(CONFIG_IOMMU_DEBUGFS) += iommu-debugfs.o > diff --git a/drivers/iommu/iommu-pages.c b/drivers/iommu/iommu-pages.c > new file mode 100644 > index 00000000000000..dbf7205bb23dcc > --- /dev/null > +++ b/drivers/iommu/iommu-pages.c > @@ -0,0 +1,84 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Copyright (c) 2024, Google LLC. > + * Pasha Tatashin > + */ > +#include "iommu-pages.h" > +#include > +#include > + > +/** > + * iommu_alloc_pages_node - Allocate a zeroed page of a given order from > + * specific NUMA node > + * @nid: memory NUMA node id > + * @gfp: buddy allocator flags > + * @order: page order > + * > + * Returns the virtual address of the allocated page. The page must be > + * freed either by calling iommu_free_page() or via iommu_put_pages_list(). nit: ... by calling iommu_free_pages() ... and s/page/pages/g in above comments? > + */ > +void *iommu_alloc_pages_node(int nid, gfp_t gfp, unsigned int order) > +{ > + const unsigned long pgcnt = 1UL << order; > + struct page *page; > + > + page = alloc_pages_node(nid, gfp | __GFP_ZERO | __GFP_COMP, order); > + if (unlikely(!page)) > + return NULL; > + > + /* > + * All page allocations that should be reported to as "iommu-pagetables" > + * to userspace must use one of the functions below. This includes > + * allocations of page-tables and other per-iommu_domain configuration > + * structures. > + * > + * This is necessary for the proper accounting as IOMMU state can be > + * rather large, i.e. multiple gigabytes in size. > + */ > + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt); > + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, pgcnt); > + > + return page_address(page); > +} > +EXPORT_SYMBOL_GPL(iommu_alloc_pages_node); > + > +static void __iommu_free_page(struct page *page) It's more readable if renaming it to __iommu_free_pages()? > +{ > + unsigned int order = folio_order(page_folio(page)); > + const unsigned long pgcnt = 1UL << order; > + > + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt); > + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, -pgcnt); > + put_page(page); > +} Thanks, baolu