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 A1ACEC4332F for ; Thu, 14 Dec 2023 19:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AA916B02BC; Thu, 14 Dec 2023 14:17:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 334B86B02BD; Thu, 14 Dec 2023 14:17:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1ACF06B02BF; Thu, 14 Dec 2023 14:17:24 -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 03C426B02BC for ; Thu, 14 Dec 2023 14:17:24 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C2CEE80463 for ; Thu, 14 Dec 2023 19:17:23 +0000 (UTC) X-FDA: 81566382366.14.B409462 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by imf23.hostedemail.com (Postfix) with ESMTP id 07636140017 for ; Thu, 14 Dec 2023 19:17:21 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=lpQA7qLC; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.171 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=1702581442; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=O2wAVapsX3d4Wu5zcLkO1Y9GXGGh0W89rcgF3jgTa1I=; b=y0jviDJDemOn8y57mDhjU7VY55HEJWutzAEAF2e+kiQ5yFv765cFO9pkRU20VUU6iWKbSq SZgG1qY2X1WhtLJ2aFf9y4Ocx0epUcoNUTcMnYRRWxOhYrK0gXRuDrV8owWcaZ0z2Z60Xv e0+Sfh3xQcaaUIs1XNTVvFZtJUMad2U= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=lpQA7qLC; dmarc=none; spf=pass (imf23.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702581442; a=rsa-sha256; cv=none; b=eKE8Wf9fEa0CDeYf/9i7WIbhZIXP3MpCK6NQuQtnAFpom0sMXf2bpUUCqYkAV+JmLWazCX 6kb7VP77w9oYXlYTJ9o+sA11a4STxQbl1mVWbBPOOKQN+Ey2vjRYs+ZVtubmCCCtzyioHi Q0duMoRwTC+yspLmpXGB7jPnajbzQaU= Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-425e63955f6so22129361cf.3 for ; Thu, 14 Dec 2023 11:17:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1702581441; x=1703186241; darn=kvack.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=O2wAVapsX3d4Wu5zcLkO1Y9GXGGh0W89rcgF3jgTa1I=; b=lpQA7qLCSmYmD1Zq5m0VeMBB78bHHX6hVzd/fdXgW7k0l80xahqIr4UIZfe3iLEkSn FSi8KBMwADSEUUJzqIwF1TcEwEGJsgzsxOO8OO1Td+bFEjISmAAjRqV2ZahrFZ2su7oR n7R1BGSGrjzPXc5OeZCs1Np6ie9XgFOeIxOBv3lsgtr938FHC/g74MkdCvbBMUl2eXcu J38WBpcqpe1BjGrjxj6i25syiTQsoi9z1t0CqoiYIWzeIgHC+34jLkVBk4NZcyYvsWHM DVjKqKNKJYm1KKN32YbNWrX0V/hV/OzUuD1+RlRMSCqYI1R2MO/LrvHf1VXNgeWMxrm6 uWmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702581441; x=1703186241; 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=O2wAVapsX3d4Wu5zcLkO1Y9GXGGh0W89rcgF3jgTa1I=; b=o5etS3QVpjBA6AnLlT9b/jNKrC8uriWy5YhDlc9BkojSBQELG+O+3/oN3IDpAsXwu7 AuMHo/Fnz6IHtS4Cw4G7GjmM1ICbouKzFTI3EMhrgQ38RWNL1qbsGk2uYahDneZTSQQq /J6iwy5GCnTm8D7w8cPknB8ffRB4x8QPZP4Z9LhbHn/28K5UYscvKtjPVxwkjBP91bVE 8KYObJsft2dX/es2EvdWnvXsGQ66+7VeUyAgDwcGFyxoWx5J+DYiRa+uDGZQyF4PJpDb T025atoSJzHWWmikELt9N8P3Imbjbemp8l499wOcsVG3qJ0r+cEOhj0tcS6hYSYUAGNo 45vw== X-Gm-Message-State: AOJu0YwxmbZl43I+NxVj9260u8L3k2z+T0Gk/hsjZTOGsXnCOzGuKYO3 Er0y4Awrh8gYLubZtpyVfE2SVOVlTphK2v4i5yjNmg== X-Google-Smtp-Source: AGHT+IFzRCB9Md6JcXtZ2Es25f4UOuYMeLP9Itx6hDPrn436g7L6e3bJmetcIjga0ApETmdpPvmDW7XHrih7qp2afIE= X-Received: by 2002:a05:622a:452:b0:423:a4f6:9aa2 with SMTP id o18-20020a05622a045200b00423a4f69aa2mr12441941qtx.6.1702581441062; Thu, 14 Dec 2023 11:17:21 -0800 (PST) MIME-Version: 1.0 References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> <20231130201504.2322355-2-pasha.tatashin@soleen.com> <776e17af-ae25-16a0-f443-66f3972b00c0@google.com> In-Reply-To: <776e17af-ae25-16a0-f443-66f3972b00c0@google.com> From: Pasha Tatashin Date: Thu, 14 Dec 2023 14:16:44 -0500 Message-ID: Subject: Re: [PATCH v2 01/10] iommu/vt-d: add wrapper functions for page allocations To: David Rientjes 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 07636140017 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: prbwuaqzugy9mntf7gj9uieyietjwed7 X-HE-Tag: 1702581441-430518 X-HE-Meta: U2FsdGVkX19yBJjev6HTeZlme9dZz3PNBzLpdlZFh63JpCCrwcvZBi2SyCN3cZySvqUIZHil6XHXzIydog0C2RX+DxShb/ERkW8WAPST5k63pNE4BW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Vpi9g/FI3lO4zqQTXJ6shZqrCSvWJzHO5Z0N+ynheYBntWvhAqGFrpH73mzTHkeETbzHY9PHAwBniLVxo40FwBjGJ+GFU0ysj6dDLUWQj+Zbpg/2eQ4ElgkxfmrlVVFWLB6XXk3cjEXck7C0GMT2UV7DX2FWeq4cGXnvF89QFEq6tZ8Ck= 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, Dec 14, 2023 at 12:58=E2=80=AFPM David Rientjes wrote: > > 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 a= s 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? If no locality is required, there is a better interface: __iommu_alloc_pages(). That one will also take a look at the calling process policies to determine the proper NUMA node when nothing is specified. However, when policies should be ignored, and no locality required, NUMA_NO_NODE can be passed. > > > + * @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. In this file, where there a page with an "order", I reference it with "pages", when no order (i.e. order =3D 0), I reference it with "page" I.e.: __iommu_alloc_page vs. __iommu_alloc_pages > > > + > > + pages =3D alloc_pages_node(nid, gfp | __GFP_ZERO, order); > > + if (!pages) > > unlikely()? Will add it. > > > + 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 =3D alloc_pages(gfp | __GFP_ZERO, order); > > + if (!pages) > > + return NULL; > > + > > + return pages; > > +} > > + > > +/** > > + * __iommu_alloc_page_node - allocate a zeroed page at specific NUMA n= ode. > > + * @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? Yes, more than one page, basically, when order may be > 0. > > +/** > > + * 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? Thank you for the review. I will add info about locking requirements, in fact they are very relaxed. These pages are added to the list by unmaps or remaps operation in Intel IOMMU implementation. These calls assume that whoever is doing those operations has exclusive access to the VA range in the page table of that operation. The pages in this freelist only belong to the former page-tables from the IOVA range for those operations. > > + */ > > +static inline void iommu_free_pages_list(struct list_head *pages) > > +{ > > + while (!list_empty(pages)) { > > + struct page *p =3D list_entry(pages->prev, struct page, l= ru); > > + > > + list_del(&p->lru); > > + put_page(p); > > + } > > +}