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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1DA1C4167B for ; Thu, 14 Dec 2023 17:58:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F9DE8D00D6; Thu, 14 Dec 2023 12:58:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 00CDC8D00C7; Thu, 14 Dec 2023 12:58:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7A928D00D6; Thu, 14 Dec 2023 12:58:28 -0500 (EST) 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 BA5F98D00C7 for ; Thu, 14 Dec 2023 12:58:28 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8E93A1C16BA for ; Thu, 14 Dec 2023 17:58:28 +0000 (UTC) X-FDA: 81566183496.16.88D3FC8 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) by imf06.hostedemail.com (Postfix) with ESMTP id B7141180023 for ; Thu, 14 Dec 2023 17:58:26 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uptOJ5ga; spf=pass (imf06.hostedemail.com: domain of rientjes@google.com designates 209.85.166.179 as permitted sender) smtp.mailfrom=rientjes@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702576706; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=o8hhXPzgTkSbGrZlVoxMVSGKEuHWo76SGrFtR2YZpAU=; b=3R815lnyShldfQ9C/2DAy2y6QQi5NZPKARzGqZrlR6quUht8cc5MJwOAGDIMWvzluQxPRB Cwfe3rpaFATjOsimIXAFUK/fIoFvAFVl1dk+5LKtacHTUYJycNtiHAWeisYsLNYCH9Xvia MXxeprqZo4zZPiujGw7KHtpuiyZWwtY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702576706; a=rsa-sha256; cv=none; b=QWbM3pcmp087yJw35RWv1dtyUz1M+oLOJ4OINtrAn8QImv3L2i1rTqcjNHNQGseD3YaK3A Ubcvg0/akbCxh/CAlrtIdfbaPSnOmBatLzZroezsbGSNG5z9hdWvNpq6Fy1sqUc+2HWfsw 8Mj7SO3d3Jwyd0GxOfXz7w3gZZt/b0k= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uptOJ5ga; spf=pass (imf06.hostedemail.com: domain of rientjes@google.com designates 209.85.166.179 as permitted sender) smtp.mailfrom=rientjes@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-35f8865cc32so2315ab.0 for ; Thu, 14 Dec 2023 09:58:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702576706; x=1703181506; darn=kvack.org; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=o8hhXPzgTkSbGrZlVoxMVSGKEuHWo76SGrFtR2YZpAU=; b=uptOJ5ga5Fn8v0HV2t0uTL9C7GFcgXj2VM05AedzKIUkCGXNBQLwp1SZPuAEze5oor GqoGReYFR1hDFKpsmvykINgDm3KpvGKKnPyHFqsHl+lUFV3szoUzw0TnFWSbICx9i9px VPj1wumdu57GvnQG+WxTK7uT2cbPWsvk/TX5jM5LMwLYvSaVjG6chXPtzC3a18f+FP0j 4nw3nnfnqjT/5y3fi9DqihexBidaDJOJOvxSgqgc0B7SkuVZAPP/yn0/nXpA7g+5vTS0 uVNdEtfuSbbIyTKgHpFpAobMlYcA0ShOAwj2ejKHSYWjxVm5WlDK+qbUKBTGHjINkxfm hnSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702576706; x=1703181506; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o8hhXPzgTkSbGrZlVoxMVSGKEuHWo76SGrFtR2YZpAU=; b=Fs/XlGItnrEkFE00i7f28CDhDFecEJ/Gy4VBvjOt6ijX7bZaLeQ6+1dsFWZKuS4B4b AkQynlc25tLRu/52WN5d4eseiCbKUBU093hIpkL+dEjaFX0GaTZ21POEhLhuZxEcJxrc KS2aHx39VS6NNEeG9I0gyj+aYoBDaWKjOZveJTKIgUtUkH7R9if3r0tnLMaMgyUDPjmW Rqnsm7Ff8tSuU93I57yDDEGTSpsNIFREAk7ZJDofD/ORhWnYRqXoIdY5089PtOEWlUqK qiU42zBK5PPx39XwUqH/kQmwTnjxLTY+1MBFLjXhy+FrGcPAAkzQyZyD/k062B+byirn izbw== X-Gm-Message-State: AOJu0YzSBS+FKgCTZm6ROuJiPeg7D91656PUK9ekfRuYLkp1KC04Uy2p szWP55AQGRouwJHWKgjs91u9Rg== X-Google-Smtp-Source: AGHT+IHmJZOc6yIjryc1hqs+mSoywAgy/Kw7JX+y+PxO7dXRpBhV7x9zJfpibywCzeGN/8UCDSSJcQ== X-Received: by 2002:a05:6e02:4a3:b0:35f:7497:181a with SMTP id e3-20020a056e0204a300b0035f7497181amr419773ils.2.1702576705658; Thu, 14 Dec 2023 09:58:25 -0800 (PST) Received: from [2620:0:1008:15:740b:4c24:bdb6:a42a] ([2620:0:1008:15:740b:4c24:bdb6:a42a]) by smtp.gmail.com with ESMTPSA id ba1-20020a170902720100b001d09c539c95sm12769653plb.90.2023.12.14.09.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 09:58:25 -0800 (PST) Date: Thu, 14 Dec 2023 09:58:23 -0800 (PST) From: David Rientjes To: Pasha Tatashin cc: Andrew Morton , 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, will@kernel.org, yu-cheng.yu@intel.com Subject: Re: [PATCH v2 01/10] iommu/vt-d: add wrapper functions for page allocations In-Reply-To: <20231130201504.2322355-2-pasha.tatashin@soleen.com> Message-ID: <776e17af-ae25-16a0-f443-66f3972b00c0@google.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> <20231130201504.2322355-2-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: B7141180023 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: x4anhceoxr87p6xgbzdcfuczehwn6bha X-HE-Tag: 1702576706-938740 X-HE-Meta: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ke6o8AvvuuxNWMhIYCLEVb9G/HMIeBn42xqjDcD6ka0Wn3yG3KPPaq1Mb2jdJtxz96f5PTNetk+t3LvuRsThpHGC+3/N8z7mgtub/qzIKxuKrexuiC6gl7gh+8zaeYX4KVnme932XyPm7JKRSZCf+p9Qv392VUQX5c4N+XhrmM4EYpHwTRYCycyclhpPeclOp1QNtuqvMjTXyLHC2z09kWvf5QQY8F9eEJg1LqEW0rQSR01ToS8gJpPL0XDg0uGeyOWSPa6hsWEzmHD5a6HmlNZmCiM9uGMwcf1MC69OcCPNSgSMDXV6VjGvwyqB+f+JSp+SFn0obw27NzzSOTJ+pE3YZbiBjVfCsNGbo7crb/1b27K08kvvvtGJuM4i0jRgIzEJvsY+FoUsCE2lAPO55i+M= 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: On Thu, 30 Nov 2023, Pasha Tatashin wrote: > diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h > new file mode 100644 > index 000000000000..2332f807d514 > --- /dev/null > +++ b/drivers/iommu/iommu-pages.h > @@ -0,0 +1,199 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (c) 2023, Google LLC. > + * Pasha Tatashin > + */ > + > +#ifndef __IOMMU_PAGES_H > +#define __IOMMU_PAGES_H > + > +#include > +#include > +#include > + > +/* > + * All page allocation that are performed in the IOMMU subsystem must use one of > + * the functions below. This is necessary for the proper accounting as IOMMU > + * state can be rather large, i.e. multiple gigabytes in size. > + */ > + > +/** > + * __iommu_alloc_pages_node - allocate a zeroed page of a given order from > + * specific NUMA node. > + * @nid: memory NUMA node id NUMA_NO_NODE if no locality requirements? > + * @gfp: buddy allocator flags > + * @order: page order > + * > + * returns the head struct page of the allocated page. > + */ > +static inline struct page *__iommu_alloc_pages_node(int nid, gfp_t gfp, > + int order) > +{ > + struct page *pages; s/pages/page/ here and later in this file. > + > + pages = alloc_pages_node(nid, gfp | __GFP_ZERO, order); > + if (!pages) unlikely()? > + return NULL; > + > + return pages; > +} > + > +/** > + * __iommu_alloc_pages - allocate a zeroed page of a given order. > + * @gfp: buddy allocator flags > + * @order: page order > + * > + * returns the head struct page of the allocated page. > + */ > +static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order) > +{ > + struct page *pages; > + > + pages = alloc_pages(gfp | __GFP_ZERO, order); > + if (!pages) > + return NULL; > + > + return pages; > +} > + > +/** > + * __iommu_alloc_page_node - allocate a zeroed page at specific NUMA node. > + * @nid: memory NUMA node id > + * @gfp: buddy allocator flags > + * > + * returns the struct page of the allocated page. > + */ > +static inline struct page *__iommu_alloc_page_node(int nid, gfp_t gfp) > +{ > + return __iommu_alloc_pages_node(nid, gfp, 0); > +} > + > +/** > + * __iommu_alloc_page - allocate a zeroed page > + * @gfp: buddy allocator flags > + * > + * returns the struct page of the allocated page. > + */ > +static inline struct page *__iommu_alloc_page(gfp_t gfp) > +{ > + return __iommu_alloc_pages(gfp, 0); > +} > + > +/** > + * __iommu_free_pages - free page of a given order > + * @pages: head struct page of the page I think "pages" implies more than one page, this is just a (potentially compound) page? > + * @order: page order > + */ > +static inline void __iommu_free_pages(struct page *pages, int order) > +{ > + if (!pages) > + return; > + > + __free_pages(pages, order); > +} > + > +/** > + * __iommu_free_page - free page > + * @page: struct page of the page > + */ > +static inline void __iommu_free_page(struct page *page) > +{ > + __iommu_free_pages(page, 0); > +} > + > +/** > + * 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 > + */ > +static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) > +{ > + struct page *pages = __iommu_alloc_pages_node(nid, gfp, order); > + > + if (!pages) > + return NULL; > + > + return page_address(pages); > +} > + > +/** > + * iommu_alloc_pages - allocate a zeroed page of a given order > + * @gfp: buddy allocator flags > + * @order: page order > + * > + * returns the virtual address of the allocated page > + */ > +static inline void *iommu_alloc_pages(gfp_t gfp, int order) > +{ > + struct page *pages = __iommu_alloc_pages(gfp, order); > + > + if (!pages) > + return NULL; > + > + return page_address(pages); > +} > + > +/** > + * iommu_alloc_page_node - allocate a zeroed page at specific NUMA node. > + * @nid: memory NUMA node id > + * @gfp: buddy allocator flags > + * > + * returns the virtual address of the allocated page > + */ > +static inline void *iommu_alloc_page_node(int nid, gfp_t gfp) > +{ > + return iommu_alloc_pages_node(nid, gfp, 0); > +} > + > +/** > + * iommu_alloc_page - allocate a zeroed page > + * @gfp: buddy allocator flags > + * > + * returns the virtual address of the allocated page > + */ > +static inline void *iommu_alloc_page(gfp_t gfp) > +{ > + return iommu_alloc_pages(gfp, 0); > +} > + > +/** > + * iommu_free_pages - free page of a given order > + * @virt: virtual address of the page to be freed. > + * @order: page order > + */ > +static inline void iommu_free_pages(void *virt, int order) > +{ > + if (!virt) > + return; > + > + __iommu_free_pages(virt_to_page(virt), order); > +} > + > +/** > + * iommu_free_page - free page > + * @virt: virtual address of the page to be freed. > + */ > +static inline void iommu_free_page(void *virt) > +{ > + iommu_free_pages(virt, 0); > +} > + > +/** > + * iommu_free_pages_list - free a list of pages. > + * @pages: the head of the lru list to be freed. Document the locking requirements for this? > + */ > +static inline void iommu_free_pages_list(struct list_head *pages) > +{ > + while (!list_empty(pages)) { > + struct page *p = list_entry(pages->prev, struct page, lru); > + > + list_del(&p->lru); > + put_page(p); > + } > +} > + > +#endif /* __IOMMU_PAGES_H */ > -- > 2.43.0.rc2.451.g8631bc7472-goog > > >