From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E018CC4167B for ; Thu, 30 Nov 2023 20:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376690AbjK3UPK (ORCPT ); Thu, 30 Nov 2023 15:15:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376621AbjK3UPF (ORCPT ); Thu, 30 Nov 2023 15:15:05 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0409170F for ; Thu, 30 Nov 2023 12:15:09 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id af79cd13be357-77d8c38ea78so69054685a.0 for ; Thu, 30 Nov 2023 12:15:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375309; x=1701980109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5Yy4hUPviTRiK7d1jgshQ8ZyWUkBDBJBzqyGrbBWtJ8=; b=NJnel5dBXUmr59kMoWIfsx/tef0bo8XVwm9Yzosn2o3TJt429AX8VmNj2PrbH8y81e MqqszbgjyAhGob/oL5nHCgtkimcMjWQW9Nvpv4u2TxY0iuyT9rZZsFBmpe5xoWD4EKWf IMHJfnClrA/XPvV1NIHMCsmf4RxsaUYiGkAhibWqcMUOuc9WyzexTf9MuxInP2gDmQsv CMaGweLctNrmmBwtomKgxije6t9KNw0MSu7WuXp+eRJiL5vCIOiNz/5eMFlnqYzxePlt jxp4vyuC6+zLmPzoDOGTaa1XGhwgn1m8WNpIS5JVjEe08epeh6CzW6o1BBRuRfrB5udD QVeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375309; x=1701980109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Yy4hUPviTRiK7d1jgshQ8ZyWUkBDBJBzqyGrbBWtJ8=; b=cbzwiQARZpx2MzjwnZ8m260ctB6SBeLHDtT8wXR8qwmlSsET3MG0ghhHRbspUG4Qqc m1IFuPI/Y134JMqf/wMwuHj/XAqa+l9Od+2/zGo7yF1ENcuKQkOZV7mhBCAwyf7fGE6j 31JKmMXFn0mXnAWwaFGyecWlpUbDWhZYmt1vQAnd0mq+HNFyUshIqNJmTseioHCQ92kf XROW2xZ5qqdOO97UlaZ4c8uuUqdxQmU+oRYxT/IUyrl7UwqTCuz1P2yB9b0e4gkjpMbr 1ztciRU3itnF8V0C5VzXjbaApf1/MZFCaH9RGCpoHRkmAU7jRcFvX03pT1ChPG7whYUL jkzQ== X-Gm-Message-State: AOJu0YzWE9O3rTKgikcAf+8q1DO8N+TQGW7LzmJMnmJXU+FGAEnQLt2x SStKXj8xx0UVUqhV0G+0YzHRbA== X-Google-Smtp-Source: AGHT+IGCIqCObFA80tw7Jta1n2W741ba5hgCsTPwLFmmg3Py4KcfDat3ov/DNtpwRDSPnMG9nDwuDg== X-Received: by 2002:a05:6214:287:b0:67a:2bbf:183c with SMTP id l7-20020a056214028700b0067a2bbf183cmr19404618qvv.2.1701375308866; Thu, 30 Nov 2023 12:15:08 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:08 -0800 (PST) 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 Subject: [PATCH v2 01/10] iommu/vt-d: add wrapper functions for page allocations Date: Thu, 30 Nov 2023 20:14:55 +0000 Message-ID: <20231130201504.2322355-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to improve observability and accountability of IOMMU layer, we must account the number of pages that are allocated by functions that are calling directly into buddy allocator. This is achieved by first wrapping the allocation related functions into a separate inline functions in new file: drivers/iommu/iommu-pages.h Convert all page allocation calls under iommu/intel to use these new functions. Signed-off-by: Pasha Tatashin --- drivers/iommu/intel/dmar.c | 10 +- drivers/iommu/intel/iommu.c | 47 +++---- drivers/iommu/intel/iommu.h | 2 - drivers/iommu/intel/irq_remapping.c | 10 +- drivers/iommu/intel/pasid.c | 12 +- drivers/iommu/intel/svm.c | 7 +- drivers/iommu/iommu-pages.h | 199 ++++++++++++++++++++++++++++ 7 files changed, 236 insertions(+), 51 deletions(-) create mode 100644 drivers/iommu/iommu-pages.h diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index a3414afe11b0..a6937e1e20a5 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -32,6 +32,7 @@ =20 #include "iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" #include "perf.h" #include "trace.h" #include "perfmon.h" @@ -1185,7 +1186,7 @@ static void free_iommu(struct intel_iommu *iommu) } =20 if (iommu->qi) { - free_page((unsigned long)iommu->qi->desc); + iommu_free_page(iommu->qi->desc); kfree(iommu->qi->desc_status); kfree(iommu->qi); } @@ -1714,6 +1715,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) { struct q_inval *qi; struct page *desc_page; + int order; =20 if (!ecap_qis(iommu->ecap)) return -ENOENT; @@ -1734,8 +1736,8 @@ int dmar_enable_qi(struct intel_iommu *iommu) * Need two pages to accommodate 256 descriptors of 256 bits each * if the remapping hardware supports scalable mode translation. */ - desc_page =3D alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO, - !!ecap_smts(iommu->ecap)); + order =3D ecap_smts(iommu->ecap) ? 1 : 0; + desc_page =3D __iommu_alloc_pages_node(iommu->node, GFP_ATOMIC, order); if (!desc_page) { kfree(qi); iommu->qi =3D NULL; @@ -1746,7 +1748,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) =20 qi->desc_status =3D kcalloc(QI_LENGTH, sizeof(int), GFP_ATOMIC); if (!qi->desc_status) { - free_page((unsigned long) qi->desc); + iommu_free_page(qi->desc); kfree(qi); iommu->qi =3D NULL; return -ENOMEM; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3531b956556c..04f852175cbe 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -28,6 +28,7 @@ #include "../dma-iommu.h" #include "../irq_remapping.h" #include "../iommu-sva.h" +#include "../iommu-pages.h" #include "pasid.h" #include "cap_audit.h" #include "perfmon.h" @@ -367,22 +368,6 @@ static int __init intel_iommu_setup(char *str) } __setup("intel_iommu=3D", intel_iommu_setup); =20 -void *alloc_pgtable_page(int node, gfp_t gfp) -{ - struct page *page; - void *vaddr =3D NULL; - - page =3D alloc_pages_node(node, gfp | __GFP_ZERO, 0); - if (page) - vaddr =3D page_address(page); - return vaddr; -} - -void free_pgtable_page(void *vaddr) -{ - free_page((unsigned long)vaddr); -} - static inline int domain_type_is_si(struct dmar_domain *domain) { return domain->domain.type =3D=3D IOMMU_DOMAIN_IDENTITY; @@ -617,7 +602,7 @@ struct context_entry *iommu_context_addr(struct intel_i= ommu *iommu, u8 bus, if (!alloc) return NULL; =20 - context =3D alloc_pgtable_page(iommu->node, GFP_ATOMIC); + context =3D iommu_alloc_page_node(iommu->node, GFP_ATOMIC); if (!context) return NULL; =20 @@ -791,17 +776,17 @@ static void free_context_table(struct intel_iommu *io= mmu) for (i =3D 0; i < ROOT_ENTRY_NR; i++) { context =3D iommu_context_addr(iommu, i, 0, 0); if (context) - free_pgtable_page(context); + iommu_free_page(context); =20 if (!sm_supported(iommu)) continue; =20 context =3D iommu_context_addr(iommu, i, 0x80, 0); if (context) - free_pgtable_page(context); + iommu_free_page(context); } =20 - free_pgtable_page(iommu->root_entry); + iommu_free_page(iommu->root_entry); iommu->root_entry =3D NULL; } =20 @@ -939,7 +924,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domai= n *domain, if (!dma_pte_present(pte)) { uint64_t pteval; =20 - tmp_page =3D alloc_pgtable_page(domain->nid, gfp); + tmp_page =3D iommu_alloc_page_node(domain->nid, gfp); =20 if (!tmp_page) return NULL; @@ -951,7 +936,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domai= n *domain, =20 if (cmpxchg64(&pte->val, 0ULL, pteval)) /* Someone else set it while we were thinking; use theirs. */ - free_pgtable_page(tmp_page); + iommu_free_page(tmp_page); else domain_flush_cache(domain, pte, sizeof(*pte)); } @@ -1064,7 +1049,7 @@ static void dma_pte_free_level(struct dmar_domain *do= main, int level, last_pfn < level_pfn + level_size(level) - 1)) { dma_clear_pte(pte); domain_flush_cache(domain, pte, sizeof(*pte)); - free_pgtable_page(level_pte); + iommu_free_page(level_pte); } next: pfn +=3D level_size(level); @@ -1088,7 +1073,7 @@ static void dma_pte_free_pagetable(struct dmar_domain= *domain, =20 /* free pgd */ if (start_pfn =3D=3D 0 && last_pfn =3D=3D DOMAIN_MAX_PFN(domain->gaw)) { - free_pgtable_page(domain->pgd); + iommu_free_page(domain->pgd); domain->pgd =3D NULL; } } @@ -1190,7 +1175,7 @@ static int iommu_alloc_root_entry(struct intel_iommu = *iommu) { struct root_entry *root; =20 - root =3D alloc_pgtable_page(iommu->node, GFP_ATOMIC); + root =3D iommu_alloc_page_node(iommu->node, GFP_ATOMIC); if (!root) { pr_err("Allocating root entry for %s failed\n", iommu->name); @@ -1863,7 +1848,7 @@ static void domain_exit(struct dmar_domain *domain) LIST_HEAD(freelist); =20 domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist); - put_pages_list(&freelist); + iommu_free_pages_list(&freelist); } =20 if (WARN_ON(!list_empty(&domain->devices))) @@ -2637,7 +2622,7 @@ static int copy_context_table(struct intel_iommu *iom= mu, if (!old_ce) goto out; =20 - new_ce =3D alloc_pgtable_page(iommu->node, GFP_KERNEL); + new_ce =3D iommu_alloc_page_node(iommu->node, GFP_KERNEL); if (!new_ce) goto out_unmap; =20 @@ -3570,7 +3555,7 @@ static int intel_iommu_memory_notifier(struct notifie= r_block *nb, start_vpfn, mhp->nr_pages, list_empty(&freelist), 0); rcu_read_unlock(); - put_pages_list(&freelist); + iommu_free_pages_list(&freelist); } break; } @@ -4001,7 +3986,7 @@ static int md_domain_init(struct dmar_domain *domain,= int guest_width) domain->max_addr =3D 0; =20 /* always allocate the top pgd */ - domain->pgd =3D alloc_pgtable_page(domain->nid, GFP_ATOMIC); + domain->pgd =3D iommu_alloc_page_node(domain->nid, GFP_ATOMIC); if (!domain->pgd) return -ENOMEM; domain_flush_cache(domain, domain->pgd, PAGE_SIZE); @@ -4148,7 +4133,7 @@ int prepare_domain_attach_device(struct iommu_domain = *domain, pte =3D dmar_domain->pgd; if (dma_pte_present(pte)) { dmar_domain->pgd =3D phys_to_virt(dma_pte_addr(pte)); - free_pgtable_page(pte); + iommu_free_page(pte); } dmar_domain->agaw--; } @@ -4295,7 +4280,7 @@ static void intel_iommu_tlb_sync(struct iommu_domain = *domain, start_pfn, nrpages, list_empty(&gather->freelist), 0); =20 - put_pages_list(&gather->freelist); + iommu_free_pages_list(&gather->freelist); } =20 static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 65d37a138c75..b505f3f44d0a 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -894,8 +894,6 @@ void domain_update_iommu_cap(struct dmar_domain *domain= ); =20 int dmar_ir_support(void); =20 -void *alloc_pgtable_page(int node, gfp_t gfp); -void free_pgtable_page(void *vaddr); void iommu_flush_write_buffer(struct intel_iommu *iommu); struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devfn= ); struct iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_= remapping.c index 29b9e55dcf26..72e1c1342c13 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -22,6 +22,7 @@ =20 #include "iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" #include "cap_audit.h" =20 enum irq_mode { @@ -536,8 +537,8 @@ static int intel_setup_irq_remapping(struct intel_iommu= *iommu) if (!ir_table) return -ENOMEM; =20 - pages =3D alloc_pages_node(iommu->node, GFP_KERNEL | __GFP_ZERO, - INTR_REMAP_PAGE_ORDER); + pages =3D __iommu_alloc_pages_node(iommu->node, GFP_KERNEL, + INTR_REMAP_PAGE_ORDER); if (!pages) { pr_err("IR%d: failed to allocate pages of order %d\n", iommu->seq_id, INTR_REMAP_PAGE_ORDER); @@ -622,7 +623,7 @@ static int intel_setup_irq_remapping(struct intel_iommu= *iommu) out_free_bitmap: bitmap_free(bitmap); out_free_pages: - __free_pages(pages, INTR_REMAP_PAGE_ORDER); + __iommu_free_pages(pages, INTR_REMAP_PAGE_ORDER); out_free_table: kfree(ir_table); =20 @@ -643,8 +644,7 @@ static void intel_teardown_irq_remapping(struct intel_i= ommu *iommu) irq_domain_free_fwnode(fn); iommu->ir_domain =3D NULL; } - free_pages((unsigned long)iommu->ir_table->base, - INTR_REMAP_PAGE_ORDER); + iommu_free_pages(iommu->ir_table->base, INTR_REMAP_PAGE_ORDER); bitmap_free(iommu->ir_table->bitmap); kfree(iommu->ir_table); iommu->ir_table =3D NULL; diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 74e8e4c17e81..1856e74bba78 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -20,6 +20,7 @@ =20 #include "iommu.h" #include "pasid.h" +#include "../iommu-pages.h" =20 /* * Intel IOMMU system wide PASID name space: @@ -116,8 +117,7 @@ int intel_pasid_alloc_table(struct device *dev) =20 size =3D max_pasid >> (PASID_PDE_SHIFT - 3); order =3D size ? get_order(size) : 0; - pages =3D alloc_pages_node(info->iommu->node, - GFP_KERNEL | __GFP_ZERO, order); + pages =3D __iommu_alloc_pages_node(info->iommu->node, GFP_KERNEL, order); if (!pages) { kfree(pasid_table); return -ENOMEM; @@ -154,10 +154,10 @@ void intel_pasid_free_table(struct device *dev) max_pde =3D pasid_table->max_pasid >> PASID_PDE_SHIFT; for (i =3D 0; i < max_pde; i++) { table =3D get_pasid_table_from_pde(&dir[i]); - free_pgtable_page(table); + iommu_free_page(table); } =20 - free_pages((unsigned long)pasid_table->table, pasid_table->order); + iommu_free_pages(pasid_table->table, pasid_table->order); kfree(pasid_table); } =20 @@ -203,7 +203,7 @@ static struct pasid_entry *intel_pasid_get_entry(struct= device *dev, u32 pasid) retry: entries =3D get_pasid_table_from_pde(&dir[dir_index]); if (!entries) { - entries =3D alloc_pgtable_page(info->iommu->node, GFP_ATOMIC); + entries =3D iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC); if (!entries) return NULL; =20 @@ -215,7 +215,7 @@ static struct pasid_entry *intel_pasid_get_entry(struct= device *dev, u32 pasid) */ if (cmpxchg64(&dir[dir_index].val, 0ULL, (u64)virt_to_phys(entries) | PASID_PTE_PRESENT)) { - free_pgtable_page(entries); + iommu_free_page(entries); goto retry; } if (!ecap_coherent(info->iommu->ecap)) { diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 50a481c895b8..4cf8826b30e1 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -23,6 +23,7 @@ #include "pasid.h" #include "perf.h" #include "../iommu-sva.h" +#include "../iommu-pages.h" #include "trace.h" =20 static irqreturn_t prq_event_thread(int irq, void *d); @@ -67,7 +68,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) struct page *pages; int irq, ret; =20 - pages =3D alloc_pages(GFP_KERNEL | __GFP_ZERO, PRQ_ORDER); + pages =3D __iommu_alloc_pages(GFP_KERNEL, PRQ_ORDER); if (!pages) { pr_warn("IOMMU: %s: Failed to allocate page request queue\n", iommu->name); @@ -118,7 +119,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) dmar_free_hwirq(irq); iommu->pr_irq =3D 0; free_prq: - free_pages((unsigned long)iommu->prq, PRQ_ORDER); + iommu_free_pages(iommu->prq, PRQ_ORDER); iommu->prq =3D NULL; =20 return ret; @@ -141,7 +142,7 @@ int intel_svm_finish_prq(struct intel_iommu *iommu) iommu->iopf_queue =3D NULL; } =20 - free_pages((unsigned long)iommu->prq, PRQ_ORDER); + iommu_free_pages(iommu->prq, PRQ_ORDER); iommu->prq =3D NULL; =20 return 0; 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 IO= MMU + * 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 + * @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; + + pages =3D alloc_pages_node(nid, gfp | __GFP_ZERO, order); + if (!pages) + 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 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 + * @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 =3D __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 =3D __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. + */ +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, lru); + + list_del(&p->lru); + put_page(p); + } +} + +#endif /* __IOMMU_PAGES_H */ --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ED96C4167B for ; Thu, 30 Nov 2023 20:15:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376722AbjK3UPQ (ORCPT ); Thu, 30 Nov 2023 15:15:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376651AbjK3UPG (ORCPT ); Thu, 30 Nov 2023 15:15:06 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C05A51715 for ; Thu, 30 Nov 2023 12:15:10 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-67a31b64a9aso7885016d6.0 for ; Thu, 30 Nov 2023 12:15:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375310; x=1701980110; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=k1GabcB3edaQg1Ui1Yy9urjYmEO9oSCGrDI9SMXfmmE=; b=ZDPrUwI55qrxwxiYaKAgHSJEkibmfEbOf57CbXXjsiLJJu1wNIUdvfvUc30plQvFXH JPeX50O3fF6yrsC5HltyRc+T62McGmMG07NDdexGHq6OTN3v02XW9QvPp+ukKIiHechl IDm+ffXmiuUft3srZvMzd6WI+kmakkqic+dKU0iGi/I63Ey0tQj+qKEdOkt1rUJGRVJ5 4OL54rzugVEd236rQa+0wYzj+5kgk8pU1zyIPIhXZCW/xW2J9XsTXPM4EXycreOIAoAB /S4CX1qg34fZRzaNI91N3jRYI56oITUM68HJ8W4PxN4FsER55DpnrDZ1God+SdIhIcFn iDLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375310; x=1701980110; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k1GabcB3edaQg1Ui1Yy9urjYmEO9oSCGrDI9SMXfmmE=; b=T5SEM8jvLHZfNIUrkM2jsWnZRifKh9vhH7oiUXPrsABkzq/FsVlRnSCFgAPU+S6Y4r O8kZs491C55tXZKes2M4QHbxnD8V7ns+Ze1jFBzMSYb9dyEOzs3CWlgjSjJrfHLDJjDt AEWl+x49fliaf4Ngi/5rmBnuKGZu/gmnAvbl5deGKS+bjYp2Wk379SHxHRVN73xJsyhh qk/hw0UgY67udPKU0P0KHib056f8Bg+Bo8eJ9gyC7fGfOlrvm9O3JPMsDOJ7ujG1OBFx RlaucaSYA3RplPrRFvIcEw5oVGrBIlXWZb2Z4nFF90c6yYPdWsYr/auylTrhiqGt68N5 IJQg== X-Gm-Message-State: AOJu0YwFrtQ6sp9wwMaRym0drW/AS+jhTQaHvMJZJ0A7HNE/YFoEm09O eWFyhiUmScScEzwYWPb+gRjjcA== X-Google-Smtp-Source: AGHT+IF/Blnoafa9OjCDknxdUTY4F5jBndUc1vQ2ufXTyj0UbD/GMwQrpuQS8tJHsFnHFGhn1lLwKQ== X-Received: by 2002:a05:6214:1111:b0:67a:6041:6f94 with SMTP id e17-20020a056214111100b0067a60416f94mr9016771qvs.24.1701375309752; Thu, 30 Nov 2023 12:15:09 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:09 -0800 (PST) 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 Subject: [PATCH v2 02/10] iommu/amd: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:14:56 +0000 Message-ID: <20231130201504.2322355-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/amd/* files to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- 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 | 20 +++---- drivers/iommu/amd/iommu.c | 13 +++-- 5 files changed, 64 insertions(+), 81 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 86be1edd50ee..bf697d566e0b 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -136,14 +136,6 @@ static inline int get_pci_sbdf_id(struct pci_dev *pdev) return PCI_SEG_DEVID_TO_SBDF(seg, devid); } =20 -static inline void *alloc_pgtable_page(int nid, gfp_t gfp) -{ - struct page *page; - - page =3D alloc_pages_node(nid, gfp | __GFP_ZERO, 0); - return page ? page_address(page) : NULL; -} - bool translation_pre_enabled(struct amd_iommu *iommu); bool amd_iommu_is_attach_deferred(struct device *dev); int __init add_special_device(u8 type, u8 id, u32 *devid, bool cmd_line); diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 64bcf3df37ee..5b8a80fc7e50 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -35,6 +35,7 @@ =20 #include "amd_iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" =20 /* * definitions for the ACPI scanning code @@ -648,8 +649,8 @@ static int __init find_last_devid_acpi(struct acpi_tabl= e_header *table, u16 pci_ /* Allocate per PCI segment device table */ static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg) { - pci_seg->dev_table =3D (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO |= GFP_DMA32, - get_order(pci_seg->dev_table_size)); + pci_seg->dev_table =3D iommu_alloc_pages(GFP_KERNEL | GFP_DMA32, + get_order(pci_seg->dev_table_size)); if (!pci_seg->dev_table) return -ENOMEM; =20 @@ -658,17 +659,16 @@ static inline int __init alloc_dev_table(struct amd_i= ommu_pci_seg *pci_seg) =20 static inline void free_dev_table(struct amd_iommu_pci_seg *pci_seg) { - free_pages((unsigned long)pci_seg->dev_table, - get_order(pci_seg->dev_table_size)); + iommu_free_pages(pci_seg->dev_table, + get_order(pci_seg->dev_table_size)); pci_seg->dev_table =3D NULL; } =20 /* Allocate per PCI segment IOMMU rlookup table. */ static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci= _seg) { - pci_seg->rlookup_table =3D (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(pci_seg->rlookup_table_size)); + pci_seg->rlookup_table =3D iommu_alloc_pages(GFP_KERNEL, + get_order(pci_seg->rlookup_table_size)); if (pci_seg->rlookup_table =3D=3D NULL) return -ENOMEM; =20 @@ -677,16 +677,15 @@ static inline int __init alloc_rlookup_table(struct a= md_iommu_pci_seg *pci_seg) =20 static inline void free_rlookup_table(struct amd_iommu_pci_seg *pci_seg) { - free_pages((unsigned long)pci_seg->rlookup_table, - get_order(pci_seg->rlookup_table_size)); + iommu_free_pages(pci_seg->rlookup_table, + get_order(pci_seg->rlookup_table_size)); pci_seg->rlookup_table =3D NULL; } =20 static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *= pci_seg) { - pci_seg->irq_lookup_table =3D (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(pci_seg->rlookup_table_size)); + pci_seg->irq_lookup_table =3D iommu_alloc_pages(GFP_KERNEL, + get_order(pci_seg->rlookup_table_size)); kmemleak_alloc(pci_seg->irq_lookup_table, pci_seg->rlookup_table_size, 1, GFP_KERNEL); if (pci_seg->irq_lookup_table =3D=3D NULL) @@ -698,8 +697,8 @@ static inline int __init alloc_irq_lookup_table(struct = amd_iommu_pci_seg *pci_se static inline void free_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg) { kmemleak_free(pci_seg->irq_lookup_table); - free_pages((unsigned long)pci_seg->irq_lookup_table, - get_order(pci_seg->rlookup_table_size)); + iommu_free_pages(pci_seg->irq_lookup_table, + get_order(pci_seg->rlookup_table_size)); pci_seg->irq_lookup_table =3D NULL; } =20 @@ -707,8 +706,8 @@ static int __init alloc_alias_table(struct amd_iommu_pc= i_seg *pci_seg) { int i; =20 - pci_seg->alias_table =3D (void *)__get_free_pages(GFP_KERNEL, - get_order(pci_seg->alias_table_size)); + pci_seg->alias_table =3D iommu_alloc_pages(GFP_KERNEL, + get_order(pci_seg->alias_table_size)); if (!pci_seg->alias_table) return -ENOMEM; =20 @@ -723,8 +722,8 @@ static int __init alloc_alias_table(struct amd_iommu_pc= i_seg *pci_seg) =20 static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg) { - free_pages((unsigned long)pci_seg->alias_table, - get_order(pci_seg->alias_table_size)); + iommu_free_pages(pci_seg->alias_table, + get_order(pci_seg->alias_table_size)); pci_seg->alias_table =3D NULL; } =20 @@ -735,8 +734,8 @@ static void __init free_alias_table(struct amd_iommu_pc= i_seg *pci_seg) */ static int __init alloc_command_buffer(struct amd_iommu *iommu) { - iommu->cmd_buf =3D (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(CMD_BUFFER_SIZE)); + iommu->cmd_buf =3D iommu_alloc_pages(GFP_KERNEL, + get_order(CMD_BUFFER_SIZE)); =20 return iommu->cmd_buf ? 0 : -ENOMEM; } @@ -844,19 +843,19 @@ static void iommu_disable_command_buffer(struct amd_i= ommu *iommu) =20 static void __init free_command_buffer(struct amd_iommu *iommu) { - free_pages((unsigned long)iommu->cmd_buf, get_order(CMD_BUFFER_SIZE)); + iommu_free_pages(iommu->cmd_buf, get_order(CMD_BUFFER_SIZE)); } =20 static void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp, size_t size) { int order =3D get_order(size); - void *buf =3D (void *)__get_free_pages(gfp, order); + void *buf =3D iommu_alloc_pages(gfp, order); =20 if (buf && check_feature(FEATURE_SNP) && set_memory_4k((unsigned long)buf, (1 << order))) { - free_pages((unsigned long)buf, order); + iommu_free_pages(buf, order); buf =3D NULL; } =20 @@ -866,7 +865,7 @@ static void *__init iommu_alloc_4k_pages(struct amd_iom= mu *iommu, /* allocates the memory where the IOMMU will log its events to */ static int __init alloc_event_buffer(struct amd_iommu *iommu) { - iommu->evt_buf =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, + iommu->evt_buf =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL, EVT_BUFFER_SIZE); =20 return iommu->evt_buf ? 0 : -ENOMEM; @@ -900,14 +899,13 @@ static void iommu_disable_event_buffer(struct amd_iom= mu *iommu) =20 static void __init free_event_buffer(struct amd_iommu *iommu) { - free_pages((unsigned long)iommu->evt_buf, get_order(EVT_BUFFER_SIZE)); + iommu_free_pages(iommu->evt_buf, get_order(EVT_BUFFER_SIZE)); } =20 /* allocates the memory where the IOMMU will log its events to */ static int __init alloc_ppr_log(struct amd_iommu *iommu) { - iommu->ppr_log =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, - PPR_LOG_SIZE); + iommu->ppr_log =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL, PPR_LOG_SIZE); =20 return iommu->ppr_log ? 0 : -ENOMEM; } @@ -936,14 +934,14 @@ static void iommu_enable_ppr_log(struct amd_iommu *io= mmu) =20 static void __init free_ppr_log(struct amd_iommu *iommu) { - free_pages((unsigned long)iommu->ppr_log, get_order(PPR_LOG_SIZE)); + iommu_free_pages(iommu->ppr_log, get_order(PPR_LOG_SIZE)); } =20 static void free_ga_log(struct amd_iommu *iommu) { #ifdef CONFIG_IRQ_REMAP - free_pages((unsigned long)iommu->ga_log, get_order(GA_LOG_SIZE)); - free_pages((unsigned long)iommu->ga_log_tail, get_order(8)); + iommu_free_pages(iommu->ga_log, get_order(GA_LOG_SIZE)); + iommu_free_pages(iommu->ga_log_tail, get_order(8)); #endif } =20 @@ -988,13 +986,11 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) return 0; =20 - iommu->ga_log =3D (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(GA_LOG_SIZE)); + iommu->ga_log =3D iommu_alloc_pages(GFP_KERNEL, get_order(GA_LOG_SIZE)); if (!iommu->ga_log) goto err_out; =20 - iommu->ga_log_tail =3D (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(8)); + iommu->ga_log_tail =3D iommu_alloc_pages(GFP_KERNEL, get_order(8)); if (!iommu->ga_log_tail) goto err_out; =20 @@ -1007,7 +1003,7 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) =20 static int __init alloc_cwwb_sem(struct amd_iommu *iommu) { - iommu->cmd_sem =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, 1= ); + iommu->cmd_sem =3D iommu_alloc_4k_pages(iommu, GFP_KERNEL, 1); =20 return iommu->cmd_sem ? 0 : -ENOMEM; } @@ -1015,7 +1011,7 @@ static int __init alloc_cwwb_sem(struct amd_iommu *io= mmu) static void __init free_cwwb_sem(struct amd_iommu *iommu) { if (iommu->cmd_sem) - free_page((unsigned long)iommu->cmd_sem); + iommu_free_page((void *)iommu->cmd_sem); } =20 static void iommu_enable_xt(struct amd_iommu *iommu) @@ -1080,7 +1076,6 @@ static bool __copy_device_table(struct amd_iommu *iom= mu) u32 lo, hi, devid, old_devtb_size; phys_addr_t old_devtb_phys; u16 dom_id, dte_v, irq_v; - gfp_t gfp_flag; u64 tmp; =20 /* Each IOMMU use separate device table with the same size */ @@ -1114,9 +1109,8 @@ static bool __copy_device_table(struct amd_iommu *iom= mu) if (!old_devtb) return false; =20 - gfp_flag =3D GFP_KERNEL | __GFP_ZERO | GFP_DMA32; - pci_seg->old_dev_tbl_cpy =3D (void *)__get_free_pages(gfp_flag, - get_order(pci_seg->dev_table_size)); + pci_seg->old_dev_tbl_cpy =3D iommu_alloc_pages(GFP_KERNEL | GFP_DMA32, + get_order(pci_seg->dev_table_size)); if (pci_seg->old_dev_tbl_cpy =3D=3D NULL) { pr_err("Failed to allocate memory for copying old device table!\n"); memunmap(old_devtb); @@ -2800,8 +2794,8 @@ static void early_enable_iommus(void) =20 for_each_pci_segment(pci_seg) { if (pci_seg->old_dev_tbl_cpy !=3D NULL) { - free_pages((unsigned long)pci_seg->old_dev_tbl_cpy, - get_order(pci_seg->dev_table_size)); + iommu_free_pages(pci_seg->old_dev_tbl_cpy, + get_order(pci_seg->dev_table_size)); pci_seg->old_dev_tbl_cpy =3D NULL; } } @@ -2814,8 +2808,8 @@ static void early_enable_iommus(void) pr_info("Copied DEV table from previous kernel.\n"); =20 for_each_pci_segment(pci_seg) { - free_pages((unsigned long)pci_seg->dev_table, - get_order(pci_seg->dev_table_size)); + iommu_free_pages(pci_seg->dev_table, + get_order(pci_seg->dev_table_size)); pci_seg->dev_table =3D pci_seg->old_dev_tbl_cpy; } =20 @@ -3018,8 +3012,8 @@ static bool __init check_ioapic_information(void) =20 static void __init free_dma_resources(void) { - free_pages((unsigned long)amd_iommu_pd_alloc_bitmap, - get_order(MAX_DOMAIN_ID/8)); + iommu_free_pages(amd_iommu_pd_alloc_bitmap, + get_order(MAX_DOMAIN_ID / 8)); amd_iommu_pd_alloc_bitmap =3D NULL; =20 free_unity_maps(); @@ -3091,9 +3085,8 @@ static int __init early_amd_iommu_init(void) /* Device table - directly used by all IOMMUs */ ret =3D -ENOMEM; =20 - amd_iommu_pd_alloc_bitmap =3D (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(MAX_DOMAIN_ID/8)); + amd_iommu_pd_alloc_bitmap =3D iommu_alloc_pages(GFP_KERNEL, + get_order(MAX_DOMAIN_ID / 8)); if (amd_iommu_pd_alloc_bitmap =3D=3D NULL) goto out; =20 diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 6c0621f6f572..f8b7d4c39a9f 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -22,6 +22,7 @@ =20 #include "amd_iommu_types.h" #include "amd_iommu.h" +#include "../iommu-pages.h" =20 static void v1_tlb_flush_all(void *cookie) { @@ -156,7 +157,7 @@ static bool increase_address_space(struct protection_do= main *domain, bool ret =3D true; u64 *pte; =20 - pte =3D alloc_pgtable_page(domain->nid, gfp); + pte =3D iommu_alloc_page_node(domain->nid, gfp); if (!pte) return false; =20 @@ -187,7 +188,7 @@ static bool increase_address_space(struct protection_do= main *domain, =20 out: spin_unlock_irqrestore(&domain->lock, flags); - free_page((unsigned long)pte); + iommu_free_page(pte); =20 return ret; } @@ -250,7 +251,7 @@ static u64 *alloc_pte(struct protection_domain *domain, =20 if (!IOMMU_PTE_PRESENT(__pte) || pte_level =3D=3D PAGE_MODE_NONE) { - page =3D alloc_pgtable_page(domain->nid, gfp); + page =3D iommu_alloc_page_node(domain->nid, gfp); =20 if (!page) return NULL; @@ -259,7 +260,7 @@ static u64 *alloc_pte(struct protection_domain *domain, =20 /* pte could have been changed somewhere. */ if (!try_cmpxchg64(pte, &__pte, __npte)) - free_page((unsigned long)page); + iommu_free_page(page); else if (IOMMU_PTE_PRESENT(__pte)) *updated =3D true; =20 @@ -430,7 +431,7 @@ static int iommu_v1_map_pages(struct io_pgtable_ops *op= s, unsigned long iova, } =20 /* Everything flushed out, free pages now */ - put_pages_list(&freelist); + iommu_free_pages_list(&freelist); =20 return ret; } @@ -579,7 +580,7 @@ static void v1_free_pgtable(struct io_pgtable *iop) /* Make changes visible to IOMMUs */ amd_iommu_domain_update(dom); =20 - put_pages_list(&freelist); + iommu_free_pages_list(&freelist); } =20 static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, voi= d *cookie) diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtab= le_v2.c index f818a7e254d4..1e08dab93686 100644 --- a/drivers/iommu/amd/io_pgtable_v2.c +++ b/drivers/iommu/amd/io_pgtable_v2.c @@ -18,6 +18,7 @@ =20 #include "amd_iommu_types.h" #include "amd_iommu.h" +#include "../iommu-pages.h" =20 #define IOMMU_PAGE_PRESENT BIT_ULL(0) /* Is present */ #define IOMMU_PAGE_RW BIT_ULL(1) /* Writeable */ @@ -99,11 +100,6 @@ static inline int page_size_to_level(u64 pg_size) return PAGE_MODE_1_LEVEL; } =20 -static inline void free_pgtable_page(u64 *pt) -{ - free_page((unsigned long)pt); -} - static void free_pgtable(u64 *pt, int level) { u64 *p; @@ -125,10 +121,10 @@ static void free_pgtable(u64 *pt, int level) if (level > 2) free_pgtable(p, level - 1); else - free_pgtable_page(p); + iommu_free_page(p); } =20 - free_pgtable_page(pt); + iommu_free_page(pt); } =20 /* Allocate page table */ @@ -156,14 +152,14 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned = long iova, } =20 if (!IOMMU_PTE_PRESENT(__pte)) { - page =3D alloc_pgtable_page(nid, gfp); + page =3D iommu_alloc_page_node(nid, gfp); if (!page) return NULL; =20 __npte =3D set_pgtable_attr(page); /* pte could have been changed somewhere. */ if (cmpxchg64(pte, __pte, __npte) !=3D __pte) - free_pgtable_page(page); + iommu_free_page(page); else if (IOMMU_PTE_PRESENT(__pte)) *updated =3D true; =20 @@ -185,7 +181,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned lo= ng iova, if (pg_size =3D=3D IOMMU_PAGE_SIZE_1G) free_pgtable(__pte, end_level - 1); else if (pg_size =3D=3D IOMMU_PAGE_SIZE_2M) - free_pgtable_page(__pte); + iommu_free_page(__pte); } =20 return pte; @@ -380,7 +376,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pg= table_cfg *cfg, void *coo int ret; int ias =3D IOMMU_IN_ADDR_BIT_SIZE; =20 - pgtable->pgd =3D alloc_pgtable_page(pdom->nid, GFP_ATOMIC); + pgtable->pgd =3D iommu_alloc_page_node(pdom->nid, GFP_ATOMIC); if (!pgtable->pgd) return NULL; =20 @@ -403,7 +399,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pg= table_cfg *cfg, void *coo return &pgtable->iop; =20 err_free_pgd: - free_pgtable_page(pgtable->pgd); + iommu_free_page(pgtable->pgd); =20 return NULL; } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index fcc987f5d4ed..9a228a95da0e 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -42,6 +42,7 @@ #include "amd_iommu.h" #include "../dma-iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" =20 #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |=3D ((t) << 28)) =20 @@ -1642,7 +1643,7 @@ static void free_gcr3_tbl_level1(u64 *tbl) =20 ptr =3D iommu_phys_to_virt(tbl[i] & PAGE_MASK); =20 - free_page((unsigned long)ptr); + iommu_free_page(ptr); } } =20 @@ -1670,7 +1671,7 @@ static void free_gcr3_table(struct protection_domain = *domain) else BUG_ON(domain->glx !=3D 0); =20 - free_page((unsigned long)domain->gcr3_tbl); + iommu_free_page(domain->gcr3_tbl); } =20 /* @@ -1697,7 +1698,7 @@ static int setup_gcr3_table(struct protection_domain = *domain, int pasids) if (levels > amd_iommu_max_glx_val) return -EINVAL; =20 - domain->gcr3_tbl =3D alloc_pgtable_page(domain->nid, GFP_ATOMIC); + domain->gcr3_tbl =3D iommu_alloc_page_node(domain->nid, GFP_ATOMIC); if (domain->gcr3_tbl =3D=3D NULL) return -ENOMEM; =20 @@ -2092,7 +2093,7 @@ static void protection_domain_free(struct protection_= domain *domain) free_gcr3_table(domain); =20 if (domain->iop.root) - free_page((unsigned long)domain->iop.root); + iommu_free_page(domain->iop.root); =20 if (domain->id) domain_id_free(domain->id); @@ -2107,7 +2108,7 @@ static int protection_domain_init_v1(struct protectio= n_domain *domain, int mode) BUG_ON(mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL); =20 if (mode !=3D PAGE_MODE_NONE) { - pt_root =3D (void *)get_zeroed_page(GFP_KERNEL); + pt_root =3D iommu_alloc_page(GFP_KERNEL); if (!pt_root) return -ENOMEM; } @@ -2783,7 +2784,7 @@ static u64 *__get_gcr3_pte(u64 *root, int level, u32 = pasid, bool alloc) if (!alloc) return NULL; =20 - root =3D (void *)get_zeroed_page(GFP_ATOMIC); + root =3D iommu_alloc_page(GFP_ATOMIC); if (root =3D=3D NULL) return NULL; =20 --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73096C10DC2 for ; Thu, 30 Nov 2023 20:15:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376679AbjK3UPM (ORCPT ); Thu, 30 Nov 2023 15:15:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376648AbjK3UPG (ORCPT ); Thu, 30 Nov 2023 15:15:06 -0500 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A7B4171D for ; Thu, 30 Nov 2023 12:15:11 -0800 (PST) Received: by mail-ot1-x333.google.com with SMTP id 46e09a7af769-6cd0a8bc6dcso848204a34.2 for ; Thu, 30 Nov 2023 12:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375310; x=1701980110; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=agdpEgslqhHdhrn0hnWdDpIJa9Hen54IbPQiTYhpn3E=; b=N6+uoFB2wt88WhLsaLWnOeoEQd2jH8fTA/iMZowZFS294h7F/spx51c583UWKmPscL m49eKKtrGQEJdnIkqlWqWBmttRU1P+div9qVpIIG2VsB4jINxgBnpb/ChMo4qQUIYexn ymowe4YYBglMpbxcTcv69h+2s3t6SjCxyirdLFQS4qVINbayKipgU+YtHYijpMduuTy9 /P0vP4JZQZzDsYFYD4L5p39M8q+hDM6BTbFW5q7ZLZxNGfaPL1je1q70+MxaEzGNlC81 hu27N8TGaiqsynCUv/0xod56P6UxAVdsoOrjPwWr+fx9wkJSUVd63OJwD/v70VRBSLRh r1fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375311; x=1701980111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=agdpEgslqhHdhrn0hnWdDpIJa9Hen54IbPQiTYhpn3E=; b=IFjbpVe4oF4Lpq/ONXIFAj5H2i7FBwPWaUhM3ALajlnpL7dV1qRCgFGeHYGa8tNDd6 wyqLDan2MLGxwvJnl8sP2PzVv1QUO7tA/q8mXXreZ+AOJuf+I5zXUaXrz5Cm3EfWKv2r kCn4gByQ6z+O0Z/kHluX3Emuzy5VkOgmeRyN4Hs++LGboipLjwJKN//c7Zg0oO9trvRE vDapBK65EnSZHWy29MZRzGcg0n9l209COaTfGynGk+il4UJ5jvzoTXiR6r4oXQnfG1+m pSYZ3aJa5iYF3In0trYj9K6AmQZxd1/TMwA8NIGWt5OuK9g34i+7SVApypoMaWRTL1PO 4kfQ== X-Gm-Message-State: AOJu0YxDtFVodGXS7+LSo75pErhe2hB++W45seuvza1Cq0Mck/bAWqWq bjyapOglZawhm8zGDw04oW/N5w== X-Google-Smtp-Source: AGHT+IGqd1nCfT5mpKZHzFpkRZAyFydlrTR6nVwlbdpa33SL4CJzD0tuFZYwet7aKrGY42Lko6YVCg== X-Received: by 2002:a05:6830:2644:b0:6d5:11f6:eec7 with SMTP id f4-20020a056830264400b006d511f6eec7mr794143otu.28.1701375310765; Thu, 30 Nov 2023 12:15:10 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:10 -0800 (PST) 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 Subject: [PATCH v2 03/10] iommu/io-pgtable-arm: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:14:57 +0000 Message-ID: <20231130201504.2322355-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/io-pgtable-arm.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/io-pgtable-arm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index 72dcdd468cf3..21d315151ad6 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -21,6 +21,7 @@ #include =20 #include "io-pgtable-arm.h" +#include "iommu-pages.h" =20 #define ARM_LPAE_MAX_ADDR_BITS 52 #define ARM_LPAE_S2_MAX_CONCAT_PAGES 16 @@ -197,7 +198,7 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t = gfp, void *pages; =20 VM_BUG_ON((gfp & __GFP_HIGHMEM)); - p =3D alloc_pages_node(dev_to_node(dev), gfp | __GFP_ZERO, order); + p =3D __iommu_alloc_pages_node(dev_to_node(dev), gfp, order); if (!p) return NULL; =20 @@ -221,7 +222,7 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t = gfp, dev_err(dev, "Cannot accommodate DMA translation for IOMMU page tables\n"= ); dma_unmap_single(dev, dma, size, DMA_TO_DEVICE); out_free: - __free_pages(p, order); + __iommu_free_pages(p, order); return NULL; } =20 @@ -231,7 +232,7 @@ static void __arm_lpae_free_pages(void *pages, size_t s= ize, if (!cfg->coherent_walk) dma_unmap_single(cfg->iommu_dev, __arm_lpae_dma_addr(pages), size, DMA_TO_DEVICE); - free_pages((unsigned long)pages, get_order(size)); + iommu_free_pages(pages, get_order(size)); } =20 static void __arm_lpae_sync_pte(arm_lpae_iopte *ptep, int num_entries, --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 171DAC10DC2 for ; Thu, 30 Nov 2023 20:15:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376748AbjK3UPX (ORCPT ); Thu, 30 Nov 2023 15:15:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376652AbjK3UPG (ORCPT ); Thu, 30 Nov 2023 15:15:06 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782651726 for ; Thu, 30 Nov 2023 12:15:12 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-58d9a4e9464so706501eaf.0 for ; Thu, 30 Nov 2023 12:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375311; x=1701980111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=QfgvyeFp1CeiZ4e57mb8EOPAemBVt07ijtdGx6DQjzOhGgJaJKu4iGmhRW07CrttVJ sTOqTjr9pZRSDsJh7C8qB3MQ+VLQS3pJwDvT8vzd2AAt6DnPLfxpTw2ilx2xFTuwBTKn UONhLq9NWEksAr5eaCXmSrwPdMSsU1RZ7bCjcHiOzNi25jzsA3fNwGFgjf01ffpfYw4V o5IBinJC1y2D5EZ3J5duApCuqaTIovT4bhy25qLFT+HC4XNjbbK6m4eq4QPm0fcMdCOS aKtXxrD9+wZdwIlQUW6w1oQbKjHJfc1nFzLTmKDWTc7/6nr2IjWMg+AmsZT1m93S4jsu XxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375311; x=1701980111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=eDG4R84J71WMBayhjuK7aTm8fUqnQ30F/UbKndyDsvDp0UVuHdkfrHAbB2Q/TyAxtD XbZQM4MiIiFs8b+O9fhs0FSIMyXLcFugz6jdi9eLpsmjJ1RitSr05mlYnpY5z4JW45L0 yEl4GjIM/Gz4m+9/l2Q2paxodFpcepVZ5tHMwsUGgPbg0w6ZG1O34ff6ZFJTWR6s4sWD W7Vlw4iQFqmJHU3PaOGU7lYYqlNoV00/MO5p0koC01jIklOZEzOFgj90hw2yiMPhxMo9 1OANZ19v1kMtGjilflbwYc+t1XnYOV+4olJHR8auu1HtKMsiMxrDGUzYDMk9jbSDgqP1 1O+Q== X-Gm-Message-State: AOJu0YzxxCfxgJ9U+1NkfmWbz+uo7aV8WzUcnvusahGXR01bGmhqTTOT i9qXDwSRn8U/7v6sSOg5K2wRcw== X-Google-Smtp-Source: AGHT+IFMEwE+ifBtQCWWH8W7nWxbE36GDcNl4TH5XHATcaDXANsvzTlHeJN6S0z8EPAHXXipNQHPnA== X-Received: by 2002:a05:6870:41cd:b0:1fa:c97:220a with SMTP id z13-20020a05687041cd00b001fa0c97220amr24204427oac.10.1701375311601; Thu, 30 Nov 2023 12:15:11 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:11 -0800 (PST) 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 Subject: [PATCH v2 04/10] iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:14:58 +0000 Message-ID: <20231130201504.2322355-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/io-pgtable-dart.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Reviewed-by: Janne Grunau Acked-by: David Rientjes --- drivers/iommu/io-pgtable-dart.c | 37 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/io-pgtable-dart.c b/drivers/iommu/io-pgtable-dar= t.c index 74b1ef2b96be..ad28031e1e93 100644 --- a/drivers/iommu/io-pgtable-dart.c +++ b/drivers/iommu/io-pgtable-dart.c @@ -23,6 +23,7 @@ #include =20 #include +#include "iommu-pages.h" =20 #define DART1_MAX_ADDR_BITS 36 =20 @@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte, return paddr; } =20 -static void *__dart_alloc_pages(size_t size, gfp_t gfp, - struct io_pgtable_cfg *cfg) +static void *__dart_alloc_pages(size_t size, gfp_t gfp) { int order =3D get_order(size); - struct page *p; =20 VM_BUG_ON((gfp & __GFP_HIGHMEM)); - p =3D alloc_pages(gfp | __GFP_ZERO, order); - if (!p) - return NULL; - - return page_address(p); + return iommu_alloc_pages(gfp, order); } =20 static int dart_init_pte(struct dart_io_pgtable *data, @@ -262,13 +257,13 @@ static int dart_map_pages(struct io_pgtable_ops *ops,= unsigned long iova, =20 /* no L2 table present */ if (!pte) { - cptep =3D __dart_alloc_pages(tblsz, gfp, cfg); + cptep =3D __dart_alloc_pages(tblsz, gfp); if (!cptep) return -ENOMEM; =20 pte =3D dart_install_table(cptep, ptep, 0, data); if (pte) - free_pages((unsigned long)cptep, get_order(tblsz)); + iommu_free_pages(cptep, get_order(tblsz)); =20 /* L2 table is present (now) */ pte =3D READ_ONCE(*ptep); @@ -419,8 +414,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, vo= id *cookie) cfg->apple_dart_cfg.n_ttbrs =3D 1 << data->tbl_bits; =20 for (i =3D 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) { - data->pgd[i] =3D __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL, - cfg); + data->pgd[i] =3D __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL); if (!data->pgd[i]) goto out_free_data; cfg->apple_dart_cfg.ttbr[i] =3D virt_to_phys(data->pgd[i]); @@ -429,9 +423,10 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, v= oid *cookie) return &data->iop; =20 out_free_data: - while (--i >=3D 0) - free_pages((unsigned long)data->pgd[i], - get_order(DART_GRANULE(data))); + while (--i >=3D 0) { + iommu_free_pages(data->pgd[i], + get_order(DART_GRANULE(data))); + } kfree(data); return NULL; } @@ -439,6 +434,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, vo= id *cookie) static void apple_dart_free_pgtable(struct io_pgtable *iop) { struct dart_io_pgtable *data =3D io_pgtable_to_data(iop); + int order =3D get_order(DART_GRANULE(data)); dart_iopte *ptep, *end; int i; =20 @@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable= *iop) while (ptep !=3D end) { dart_iopte pte =3D *ptep++; =20 - if (pte) { - unsigned long page =3D - (unsigned long)iopte_deref(pte, data); - - free_pages(page, get_order(DART_GRANULE(data))); - } + if (pte) + iommu_free_pages(iopte_deref(pte, data), order); } - free_pages((unsigned long)data->pgd[i], - get_order(DART_GRANULE(data))); + iommu_free_pages(data->pgd[i], order); } =20 kfree(data); --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A312AC07CA9 for ; Thu, 30 Nov 2023 20:15:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376743AbjK3UPS (ORCPT ); Thu, 30 Nov 2023 15:15:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376653AbjK3UPI (ORCPT ); Thu, 30 Nov 2023 15:15:08 -0500 Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A471732 for ; Thu, 30 Nov 2023 12:15:13 -0800 (PST) Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-67a91751ba8so1831526d6.3 for ; Thu, 30 Nov 2023 12:15:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375312; x=1701980112; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jRGmXGqyJzQ9dzCxzy8J7vcwlH74KXpuX5+P/ckDUHQ=; b=ldSfYzldNZeeFRfd6WqclZ7cz8U/LZqMc8MlZSEdzA/tkcRw0K87Pz9aOqUllFGjU0 DfTC661dc5RXXFDmuFvyoOLfHUKInF0b3P2nyJ48WBX97wyuaU5qU6w+CI/7s3z47OTf MqpQhsR6X6sBbtIFFII8Eeoh3aLZAddjGC28enTsVM38svDlowQQlRYE3aTRbnGN8zQz QT7vARL2lJMJ3g+Qh9CEhy1iUnbNnjfLa+uK7yvQSeInUpI+8HmN399R8BxWbxd5Fyzv Cd03EkbWyNT7XToZwcAm3pt1v2V0MEub0btvEzMCjC3US9HZ2bv2OukHerp98uhXNoLu 7AcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375312; x=1701980112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jRGmXGqyJzQ9dzCxzy8J7vcwlH74KXpuX5+P/ckDUHQ=; b=snqHBuNKmzSIAK92+9uc7eBtl59xtOvAviuv0I8Yty0KN1dK6sEikO5zPHrPGc9ZBd V7g62EGIGnvV6NZyhY5rG+HaSegK6kC6JuwcBGTug/ZATpzCUXEQJ2/Fp8ZeU2w/tuZP 1rkZi04MTRS7MDQzeaSDdtvKRRjZ05iWy1IYQ5VtPTCpNqvxnfZ3CcGWYCvP/FvMmZSR dMhkO9OWIikj39rADNegAZv/RLmST9mYvcpdin76b2uNyJ7biYf4sk07iyN4RuS61Ahe qUm4/2R8YBbrpBUKTFW2+xldxOd3aq3/noTM7+wQ7wb06hV+0Dl7EmqQjeX+1JurBI4o oPNw== X-Gm-Message-State: AOJu0Yw0ZZerfhosZGLtmtG6cs2UdbSTo/5mXqbqny4UqsoXNRe/w7At OGIdobc24LVkHJAMflFZS/Rt4w== X-Google-Smtp-Source: AGHT+IGcwSJfMg7Wvu1IirdGyJp85Q7AXnz+gps4Wsq6RDzrMQCHyomSRCyLZSC9k8WgNjE2V5K0wQ== X-Received: by 2002:a05:6214:2e11:b0:67a:93fa:b331 with SMTP id mx17-20020a0562142e1100b0067a93fab331mr288846qvb.6.1701375312521; Thu, 30 Nov 2023 12:15:12 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:12 -0800 (PST) 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 Subject: [PATCH v2 05/10] iommu/exynos: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:14:59 +0000 Message-ID: <20231130201504.2322355-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/exynos-iommu.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/exynos-iommu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 2c6e9094f1e9..3eab0ae65a4f 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -22,6 +22,8 @@ #include #include =20 +#include "iommu-pages.h" + typedef u32 sysmmu_iova_t; typedef u32 sysmmu_pte_t; static struct iommu_domain exynos_identity_domain; @@ -900,11 +902,11 @@ static struct iommu_domain *exynos_iommu_domain_alloc= _paging(struct device *dev) if (!domain) return NULL; =20 - domain->pgtable =3D (sysmmu_pte_t *)__get_free_pages(GFP_KERNEL, 2); + domain->pgtable =3D iommu_alloc_pages(GFP_KERNEL, 2); if (!domain->pgtable) goto err_pgtable; =20 - domain->lv2entcnt =3D (short *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, = 1); + domain->lv2entcnt =3D iommu_alloc_pages(GFP_KERNEL, 1); if (!domain->lv2entcnt) goto err_counter; =20 @@ -930,9 +932,9 @@ static struct iommu_domain *exynos_iommu_domain_alloc_p= aging(struct device *dev) return &domain->domain; =20 err_lv2ent: - free_pages((unsigned long)domain->lv2entcnt, 1); + iommu_free_pages(domain->lv2entcnt, 1); err_counter: - free_pages((unsigned long)domain->pgtable, 2); + iommu_free_pages(domain->pgtable, 2); err_pgtable: kfree(domain); return NULL; @@ -973,8 +975,8 @@ static void exynos_iommu_domain_free(struct iommu_domai= n *iommu_domain) phys_to_virt(base)); } =20 - free_pages((unsigned long)domain->pgtable, 2); - free_pages((unsigned long)domain->lv2entcnt, 1); + iommu_free_pages(domain->pgtable, 2); + iommu_free_pages(domain->lv2entcnt, 1); kfree(domain); } =20 --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9553CC4167B for ; Thu, 30 Nov 2023 20:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376758AbjK3UP0 (ORCPT ); Thu, 30 Nov 2023 15:15:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376660AbjK3UPI (ORCPT ); Thu, 30 Nov 2023 15:15:08 -0500 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D99173C for ; Thu, 30 Nov 2023 12:15:14 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-67a44ee7ab3so8311366d6.0 for ; Thu, 30 Nov 2023 12:15:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375313; x=1701980113; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8aM4P70fu6Mpyhz2ZxBL57luN308AqDDoR+bdvrzfCU=; b=NWUMOvHfF5rLd3c5ST2+iIXZR5nCsRJ0wYp0dnfs85gdLMbhISzpSivLftTMfyg5/J AtFDIDW1AOd0VWmJA866ivlNxLQ38V/wNMZEzVdaDtyjIUVFOEf1gYr5QEYa6bbFQPDG Q14+jdqgwlHnkqhc/a4uj2n54iBrf0CWTc4gB2JsPzqn4IuLyJaiQqV+kJT8zTE6NhAI enKoM6VYHg6PUUHCGjG3I9gWE/RWacU7uJJi4uxGabqS3yH5f+2GRnMtcsZNKHZmntnB /g81BgGLDblriXqtLrbqhc/ygmImT9DMoJ8vUmKeaEpORXcW/o51tMO9EXvDbN1vYy5n qKVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375313; x=1701980113; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8aM4P70fu6Mpyhz2ZxBL57luN308AqDDoR+bdvrzfCU=; b=u3hbHXzAfq10ZLzG84Sk//fnarIGD5XD/lgFJCh1thnE+HA7XcNWnqBD1diEXmU1oX fabo3Bt4jK5den5fl6ilBZwjkkJoqpvxpHn7RgkXflVBQOsxY4dCw13kLEFjYF73yicI jnlOcr1V+Xm76HevXCeFPAVId0MoJhB8iXq7Zyw8hJKgCoRrAnTSnqQWMo/eC/Jkvblm 8mgZ9H2nhf4GJzk1EGn/w6YJxfzGHE892LzYf7n6m7KtqMJTtOE2pHOREXjz/ylbTT0i 1LyMLIo8rfVOZ9VBsVoI82gyIEoLrYaXvHw2CSkxiEW6rL27Iqrxew+PdfGomWDwELTP aJ7g== X-Gm-Message-State: AOJu0YycWX3ovyMJnVWAb23qFZoEu+R33wF+dDNnxAHSt3EMx5DgnSi1 GGLHGBP0PDjd6fEhEvxEf06Mpg== X-Google-Smtp-Source: AGHT+IEBs6D/FyJYqfxI4mL3iV1h7OCPfLZXSrKHIqLtLdmOiu4XOIwm8bZeJ7cSdUFCvrQdbklyMg== X-Received: by 2002:a05:6214:5294:b0:67a:255c:c43f with SMTP id kj20-20020a056214529400b0067a255cc43fmr20595303qvb.18.1701375313540; Thu, 30 Nov 2023 12:15:13 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:13 -0800 (PST) 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 Subject: [PATCH v2 06/10] iommu/rockchip: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:15:00 +0000 Message-ID: <20231130201504.2322355-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/rockchip-iommu.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/rockchip-iommu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 2685861c0a12..e04f22d481d0 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -26,6 +26,8 @@ #include #include =20 +#include "iommu-pages.h" + /** MMU register offsets */ #define RK_MMU_DTE_ADDR 0x00 /* Directory table address */ #define RK_MMU_STATUS 0x04 @@ -727,14 +729,14 @@ static u32 *rk_dte_get_page_table(struct rk_iommu_dom= ain *rk_domain, if (rk_dte_is_pt_valid(dte)) goto done; =20 - page_table =3D (u32 *)get_zeroed_page(GFP_ATOMIC | rk_ops->gfp_flags); + page_table =3D iommu_alloc_page(GFP_ATOMIC | rk_ops->gfp_flags); if (!page_table) return ERR_PTR(-ENOMEM); =20 pt_dma =3D dma_map_single(dma_dev, page_table, SPAGE_SIZE, DMA_TO_DEVICE); if (dma_mapping_error(dma_dev, pt_dma)) { dev_err(dma_dev, "DMA mapping error while allocating page table\n"); - free_page((unsigned long)page_table); + iommu_free_page(page_table); return ERR_PTR(-ENOMEM); } =20 @@ -1061,7 +1063,7 @@ static struct iommu_domain *rk_iommu_domain_alloc_pag= ing(struct device *dev) * Each level1 (dt) and level2 (pt) table has 1024 4-byte entries. * Allocate one 4 KiB page for each table. */ - rk_domain->dt =3D (u32 *)get_zeroed_page(GFP_KERNEL | rk_ops->gfp_flags); + rk_domain->dt =3D iommu_alloc_page(GFP_KERNEL | rk_ops->gfp_flags); if (!rk_domain->dt) goto err_free_domain; =20 @@ -1083,7 +1085,7 @@ static struct iommu_domain *rk_iommu_domain_alloc_pag= ing(struct device *dev) return &rk_domain->domain; =20 err_free_dt: - free_page((unsigned long)rk_domain->dt); + iommu_free_page(rk_domain->dt); err_free_domain: kfree(rk_domain); =20 @@ -1104,13 +1106,13 @@ static void rk_iommu_domain_free(struct iommu_domai= n *domain) u32 *page_table =3D phys_to_virt(pt_phys); dma_unmap_single(dma_dev, pt_phys, SPAGE_SIZE, DMA_TO_DEVICE); - free_page((unsigned long)page_table); + iommu_free_page(page_table); } } =20 dma_unmap_single(dma_dev, rk_domain->dt_dma, SPAGE_SIZE, DMA_TO_DEVICE); - free_page((unsigned long)rk_domain->dt); + iommu_free_page(rk_domain->dt); =20 kfree(rk_domain); } --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5231C10DC1 for ; Thu, 30 Nov 2023 20:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376702AbjK3UPa (ORCPT ); Thu, 30 Nov 2023 15:15:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376669AbjK3UPJ (ORCPT ); Thu, 30 Nov 2023 15:15:09 -0500 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB791990 for ; Thu, 30 Nov 2023 12:15:15 -0800 (PST) Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b5714439b3so789712b6e.3 for ; Thu, 30 Nov 2023 12:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375314; x=1701980114; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=WwZxW20NTsAI6OtU2mg3WBn7dc7VhXurLb9lJcGaB3s=; b=GL8qFp09V5Wiu+F/ho2KvnbNKcZG0DYvo4Pm20uRl/F7ijxpOsamWsN/VtKbUFiiSG tAwQGV1ZFXnCHLMaLHLpRT12zGCFjwHDAw7njRVhha6RFgXjzttE8llm4vGA+8BPDDJd hpPWVkqvX6auu2em1j3XvPtvqa4aMwJFN7dPoeBJgF1K6J1kp2pQIjpEfZfM6wVvBPyE 0FU4MzQZ24fdQwX8kwH9CGCET/zXKpOxFcXIq9crY4iS7fsacaXGOuV0i8Z/sJ1cSVgM /OaMlYtoeju/XakvbmQx3VJV/wtcb/4/owqh78jBvvLCqynv3cfNRZ7eiuVz0/0xKvp0 K8tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375314; x=1701980114; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WwZxW20NTsAI6OtU2mg3WBn7dc7VhXurLb9lJcGaB3s=; b=L3x3L0/MeYg2FRHde79HYAggLamO6neMnerSS1HMWke8YWAAEWyvzQG0FE44hYK2bD vgvZMyPUsRQI73pcLjuaCHmN+tsDTP2P8/fSd1JWpXBXx7SuEG60QKrysSAiLYrs00DX +DMYvv7deeapvEiL3bcdMqiu+huJIfi2bJCLozBkw+pUegpsg3R8BI0geuvIoAgwPZeV 7xSW87Nz524mEB72jueLFy8FukwEMJTQJTNnELW7L4V4u7Yy3kQ7Y292+YSqO8SfbGlJ RZcetSACmTSBbzuTrA2HCS7F/0yCK/wDis9/ahUHLhd3uBhe1qmyVnQ7ca6beW03mX1Y 8kgg== X-Gm-Message-State: AOJu0YyAAGQhgqbbfsbiRgMd9QEFfO3IAtNFtURNwh+u1lCfB9wG9K3Z n6MZdjc2PpCh9R+W+NqWDgSlTQ== X-Google-Smtp-Source: AGHT+IGTxsoHsoEZ+jaTqaWghyHDgBjLPZzal0bywx3elLmQBrrmBhd0Hv9BOGHbfQGzeWmE2Kea2A== X-Received: by 2002:a05:6871:3281:b0:1fa:5890:7840 with SMTP id mp1-20020a056871328100b001fa58907840mr16958744oac.35.1701375314449; Thu, 30 Nov 2023 12:15:14 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:14 -0800 (PST) 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 Subject: [PATCH v2 07/10] iommu/sun50i: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:15:01 +0000 Message-ID: <20231130201504.2322355-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/sun50i-iommu.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/sun50i-iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 41484a5a399b..172ddb717eb5 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -26,6 +26,8 @@ #include #include =20 +#include "iommu-pages.h" + #define IOMMU_RESET_REG 0x010 #define IOMMU_RESET_RELEASE_ALL 0xffffffff #define IOMMU_ENABLE_REG 0x020 @@ -679,8 +681,7 @@ sun50i_iommu_domain_alloc_paging(struct device *dev) if (!sun50i_domain) return NULL; =20 - sun50i_domain->dt =3D (u32 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(DT_SIZE)); + sun50i_domain->dt =3D iommu_alloc_pages(GFP_KERNEL, get_order(DT_SIZE)); if (!sun50i_domain->dt) goto err_free_domain; =20 @@ -702,7 +703,7 @@ static void sun50i_iommu_domain_free(struct iommu_domai= n *domain) { struct sun50i_iommu_domain *sun50i_domain =3D to_sun50i_domain(domain); =20 - free_pages((unsigned long)sun50i_domain->dt, get_order(DT_SIZE)); + iommu_free_pages(sun50i_domain->dt, get_order(DT_SIZE)); sun50i_domain->dt =3D NULL; =20 kfree(sun50i_domain); --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51678C10DC1 for ; Thu, 30 Nov 2023 20:15:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376779AbjK3UPe (ORCPT ); Thu, 30 Nov 2023 15:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376685AbjK3UPK (ORCPT ); Thu, 30 Nov 2023 15:15:10 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65A611995 for ; Thu, 30 Nov 2023 12:15:16 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-67a51ad638eso21300036d6.0 for ; Thu, 30 Nov 2023 12:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375315; x=1701980115; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=CTqyv+/QBqQRpLXIT6J0+RNMQRf6NZoT619SVstW8Ks=; b=Jl12uQ8+8PlkCMR8zLtQCD4lT9s+In1qyYwLdLfsfEMCacSASnWrGt0p3KW/JE2r5M R7o3ybf/QPqguwivZy74zrUoIlJn6fF3UvYT3zsTjnEku2XOvoEs+/bOEQb1f4tCPO73 rU7l4OKXgHr+IcYivqGdJ0WpSsQOkbmBtBKCvaGCb7ikFCZA0oemmtlg6LmPLgCZxZ/H BqZfnLdbEylNSX8JThw1VSAJ0Vv9LU1B4q5I/UIByr+L8I/zISt5UsbFxUx0DfnfiluT 3W/iUP+76z8yhrzqt6HFHexjsTn81eVv/ZiB0hEa5syzPJ0KooHmMCsQsTDmnc6X42eP 9GpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375315; x=1701980115; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CTqyv+/QBqQRpLXIT6J0+RNMQRf6NZoT619SVstW8Ks=; b=xLEJ6kR1byWmSr045NHXuQQXKZHB47Bbn8sYl7rsG+acHeZoA8tzZxXzxKmaU3WyXk gLB5mkc7Pgi9pYEZQ5Ra2zjk99+R2z6CRz2ZH561muhogfxtScSnwmLpUtGlC/sdw8sd bAsEmoMNwjwO/kHKVFrLF44ipmXJliRlB/KBBEOj227gRuqgtSixSKZVmTkoGI9Jdjzc g2sv+KI1sqKDNzFuM91pzGmRxKRgRHvlatU/3GzWSEAiZ049u4/DAieIJZhgbVoJNUZU MtrDq/JS2zKjf1Or1KflC/8tSc+uDrhXwVNJCJaJA2bgmfwmgmJJT9X6C0bdE/Rfoatd PShw== X-Gm-Message-State: AOJu0YxJa04ET66dBgUE2ISTjmDAcfnEhs4sI1wDyFUNt+6zKaQKy3bg 7QJfUJnytJ7dhWMukYOmEUtZHA== X-Google-Smtp-Source: AGHT+IE4JYPLoA/tNY4x2pKdpnHf/W/XblnfOPtcPXpbeLos1tHq3JCEAsQT3LPHq1ybHp62KX3VJw== X-Received: by 2002:a05:6214:4115:b0:67a:3a51:8773 with SMTP id kc21-20020a056214411500b0067a3a518773mr24916856qvb.5.1701375315320; Thu, 30 Nov 2023 12:15:15 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:15 -0800 (PST) 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 Subject: [PATCH v2 08/10] iommu/tegra-smmu: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:15:02 +0000 Message-ID: <20231130201504.2322355-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert iommu/tegra-smmu.c to use the new page allocation functions provided in iommu-pages.h. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/tegra-smmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 310871728ab4..5e0730dc1b0e 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -19,6 +19,8 @@ #include #include =20 +#include "iommu-pages.h" + struct tegra_smmu_group { struct list_head list; struct tegra_smmu *smmu; @@ -282,7 +284,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_pag= ing(struct device *dev) =20 as->attr =3D SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; =20 - as->pd =3D alloc_page(GFP_KERNEL | __GFP_DMA | __GFP_ZERO); + as->pd =3D __iommu_alloc_page(GFP_KERNEL | __GFP_DMA); if (!as->pd) { kfree(as); return NULL; @@ -290,7 +292,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_pag= ing(struct device *dev) =20 as->count =3D kcalloc(SMMU_NUM_PDE, sizeof(u32), GFP_KERNEL); if (!as->count) { - __free_page(as->pd); + __iommu_free_page(as->pd); kfree(as); return NULL; } @@ -298,7 +300,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_pag= ing(struct device *dev) as->pts =3D kcalloc(SMMU_NUM_PDE, sizeof(*as->pts), GFP_KERNEL); if (!as->pts) { kfree(as->count); - __free_page(as->pd); + __iommu_free_page(as->pd); kfree(as); return NULL; } @@ -599,14 +601,14 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_= addr_t iova, dma =3D dma_map_page(smmu->dev, page, 0, SMMU_SIZE_PT, DMA_TO_DEVICE); if (dma_mapping_error(smmu->dev, dma)) { - __free_page(page); + __iommu_free_page(page); return NULL; } =20 if (!smmu_dma_addr_valid(smmu, dma)) { dma_unmap_page(smmu->dev, dma, SMMU_SIZE_PT, DMA_TO_DEVICE); - __free_page(page); + __iommu_free_page(page); return NULL; } =20 @@ -649,7 +651,7 @@ static void tegra_smmu_pte_put_use(struct tegra_smmu_as= *as, unsigned long iova) tegra_smmu_set_pde(as, iova, 0); =20 dma_unmap_page(smmu->dev, pte_dma, SMMU_SIZE_PT, DMA_TO_DEVICE); - __free_page(page); + __iommu_free_page(page); as->pts[pde] =3D NULL; } } @@ -688,7 +690,7 @@ static struct page *as_get_pde_page(struct tegra_smmu_a= s *as, if (gfpflags_allow_blocking(gfp)) spin_unlock_irqrestore(&as->lock, *flags); =20 - page =3D alloc_page(gfp | __GFP_DMA | __GFP_ZERO); + page =3D __iommu_alloc_page(gfp | __GFP_DMA); =20 if (gfpflags_allow_blocking(gfp)) spin_lock_irqsave(&as->lock, *flags); @@ -700,7 +702,7 @@ static struct page *as_get_pde_page(struct tegra_smmu_a= s *as, */ if (as->pts[pde]) { if (page) - __free_page(page); + __iommu_free_page(page); =20 page =3D as->pts[pde]; } --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02AA3C4167B for ; Thu, 30 Nov 2023 20:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376790AbjK3UPi (ORCPT ); Thu, 30 Nov 2023 15:15:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376661AbjK3UPL (ORCPT ); Thu, 30 Nov 2023 15:15:11 -0500 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D8501735 for ; Thu, 30 Nov 2023 12:15:17 -0800 (PST) Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6d856210057so803648a34.1 for ; Thu, 30 Nov 2023 12:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375316; x=1701980116; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=bPnoAUi9Mqlaj2MW8DUbnk1HFhAILmRap6jsO2xBXzj5XkFCTRTucPKv31jqdjl+Ua 3glj8AvwbiQ/xKX/TEpyhnxr+bOVUXGZaauETAuPQgN/25elsNdQjPvs3VBCY0Rjq1Jl 15XMHYmZ9WMqF4gXdVM1jJ3S6y85kkD7MqhrjpZtaUStpLKdH2JHnmWjw4almXjf3r1R 9JXkZn9Qk3PUHdlQj+40L2M/t2r4BWVq7xEZSBfxf8m0s0KSH3btJi5SlHr2Nzt9++KR 3EV16pTiJ/CPh3YbYixmvFqt6DLb6LuhhsfFz6JSXN8fcmg/kVGXmOlm+/m5YPQezPID gTtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375316; x=1701980116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B42Ompk/0S+0FHWlF0c0WCUF97rKJOKtrfjrMLAbFqA=; b=fh70SRQWyNyBEWZDZnBZqhfcvNdN1nRQhWzgEQU84BpnCI3ihPEgiLMRaEEYzQPIyX OU0Zfu3adEljV3YXXgBBnwTTwSVXM8nHgL3NjAxBbxfgAwwYsag1Qi+p66Eq/s4bgw39 EEjXZDPyqg04dFokMrJmCwamnGph34EKK+MW6OkKvABvyCFqrIcO8D/+ZG6TpzqoY+9i eXVj5srxOe8N1df9DcRfzVMfJZSo3MBUVLcSe4u2mDmXpYYoFYK9uhPQOlGOS5n2BM3/ kav57U2qoUZHS7TSwA2LWCr9rEnUDmNWQxjzTntVFJ9ug97INxV9PPOilaVM+NRZZDd1 SIBw== X-Gm-Message-State: AOJu0YzWgnHzhtkX0KA15PLceUSgqa3498J8mFuwFLLEfPVOR5SgroH3 VnSrMIPwUOIhHfuJy3U1nJcW6A== X-Google-Smtp-Source: AGHT+IFm2VZamMYGPMsf9vCHQb4stofA9P0lnINgFWclhv2SjMIVDU5Q4H8UbP8D1DLG6NZm/4QG2w== X-Received: by 2002:a9d:7dd2:0:b0:6d7:f02f:dcc3 with SMTP id k18-20020a9d7dd2000000b006d7f02fdcc3mr809535otn.28.1701375316245; Thu, 30 Nov 2023 12:15:16 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:15 -0800 (PST) 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 Subject: [PATCH v2 09/10] iommu: observability of the IOMMU allocations Date: Thu, 30 Nov 2023 20:15:03 +0000 Message-ID: <20231130201504.2322355-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add NR_IOMMU_PAGES into node_stat_item that counts number of pages that are allocated by the IOMMU subsystem. The allocations can be view per-node via: /sys/devices/system/node/nodeN/vmstat. For example: $ grep iommu /sys/devices/system/node/node*/vmstat /sys/devices/system/node/node0/vmstat:nr_iommu_pages 106025 /sys/devices/system/node/node1/vmstat:nr_iommu_pages 3464 The value is in page-count, therefore, in the above example the iommu allocations amount to ~428M. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/iommu-pages.h | 30 ++++++++++++++++++++++++++++++ include/linux/mmzone.h | 3 +++ mm/vmstat.c | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h index 2332f807d514..69895a355c0c 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -17,6 +17,30 @@ * state can be rather large, i.e. multiple gigabytes in size. */ =20 +/** + * __iommu_alloc_account - account for newly allocated page. + * @pages: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_alloc_account(struct page *pages, int order) +{ + const long pgcnt =3D 1l << order; + + mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, pgcnt); +} + +/** + * __iommu_free_account - account a page that is about to be freed. + * @pages: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_free_account(struct page *pages, int order) +{ + const long pgcnt =3D 1l << order; + + mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, -pgcnt); +} + /** * __iommu_alloc_pages_node - allocate a zeroed page of a given order from * specific NUMA node. @@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages_node(int n= id, gfp_t gfp, if (!pages) return NULL; =20 + __iommu_alloc_account(pages, order); + return pages; } =20 @@ -53,6 +79,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp,= int order) if (!pages) return NULL; =20 + __iommu_alloc_account(pages, order); + return pages; } =20 @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *pages= , int order) if (!pages) return; =20 + __iommu_free_account(pages, order); __free_pages(pages, order); } =20 @@ -192,6 +221,7 @@ static inline void iommu_free_pages_list(struct list_he= ad *pages) struct page *p =3D list_entry(pages->prev, struct page, lru); =20 list_del(&p->lru); + __iommu_free_account(p, 0); put_page(p); } } diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 3c25226beeed..1a4d0bba3e8b 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -200,6 +200,9 @@ enum node_stat_item { #endif NR_PAGETABLE, /* used for pagetables */ NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */ +#ifdef CONFIG_IOMMU_SUPPORT + NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ +#endif #ifdef CONFIG_SWAP NR_SWAPCACHE, #endif diff --git a/mm/vmstat.c b/mm/vmstat.c index 359460deb377..801b58890b6c 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1242,6 +1242,9 @@ const char * const vmstat_text[] =3D { #endif "nr_page_table_pages", "nr_sec_page_table_pages", +#ifdef CONFIG_IOMMU_SUPPORT + "nr_iommu_pages", +#endif #ifdef CONFIG_SWAP "nr_swapcached", #endif --=20 2.43.0.rc2.451.g8631bc7472-goog From nobody Tue Dec 16 16:44:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 819EAC46CA0 for ; Thu, 30 Nov 2023 20:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376863AbjK3UPm (ORCPT ); Thu, 30 Nov 2023 15:15:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376678AbjK3UPM (ORCPT ); Thu, 30 Nov 2023 15:15:12 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 070C71708 for ; Thu, 30 Nov 2023 12:15:18 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-77d6b28aa9aso70182585a.3 for ; Thu, 30 Nov 2023 12:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375317; x=1701980117; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; b=DG3KIdcPWSPhvrI24R2yPywnWd22F+iBx3WlRdOltvRY0Sii72Lc1kKHEDP6+GWAzC a1YyCvr851G96f6nsxNcxKrEv2IojfTTwq4F9oyqTuWkCMSCU4BXK0rJUeDjrR1Cmbgx Ftlrexb+4koXwddoNm8+26IdW25lYphdEMRwtYEOPE+EN/DZ0hR7fzyrXZG1oHrVQjpz 9U96cwYZuZZ6zW+Nfi20znE5cxiKfH0nimxd+1QGK/3Rt/QwiycSA/v94nME74OWxfsk lVV3xtnzoRur7J8d3eLocUUi6tciH5+UWjYGLQKbDe9ovY8/kDfRdhGH82VaDQq03vVN B9nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375317; x=1701980117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nk58INbxx30xLOHUnMGn9OdPuZubp6H+G9gT2CVk01Q=; b=m5TeQ/VAJwefhM3IR0GvBrWd51/0WdUVCJRyFDcRiEqCtx2XayU7VXV5DjO6qBmETN g/Bl96yzwfbhTAALZPz6WsSyHWohnWiJc5Tj+NjNePZRdL54E0VXfuvjM3bjvt10bw58 9wpEPnuHINWfqbY3RUgKIakeaDK398cKNXUIaTJWLL5mQcqFuoxYiB/0digMwEPCfwZy s20RWFxyV+FZi2skkdqzEYfxQMC5iwcLVhcjpstd9ZDxcgiL2R+T6+p0gLzcj4ErNdR+ u2BldRBuW/s/5JLULm0KrcK+gZOlThrdZNAnisbNB5Qrzh2maWfhB8vbFtsrbuAIrgY0 RcQQ== X-Gm-Message-State: AOJu0YymhNDpNOsrUEo3ZqesTMPjcdrqIuZrLxfhvoODSUw/gKdmpYWJ vLfoP48plh5V81mpPfNaauWUDA== X-Google-Smtp-Source: AGHT+IGvd2g71GGje9dR/iX9F2NrVDVxx6CHTrqO1K3GZh4lvqRPIVhnZdc8oub8jQLvnHQLKAhyCg== X-Received: by 2002:a05:6214:16d:b0:67a:2942:988 with SMTP id y13-20020a056214016d00b0067a29420988mr18670319qvs.21.1701375317117; Thu, 30 Nov 2023 12:15:17 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:16 -0800 (PST) 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 Subject: [PATCH v2 10/10] iommu: account IOMMU allocated memory Date: Thu, 30 Nov 2023 20:15:04 +0000 Message-ID: <20231130201504.2322355-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to be able to limit the amount of memory that is allocated by IOMMU subsystem, the memory must be accounted. Account IOMMU as part of the secondary pagetables as it was discussed at LPC. The value of SecPageTables now contains mmeory allocation by IOMMU and KVM. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- Documentation/admin-guide/cgroup-v2.rst | 2 +- Documentation/filesystems/proc.rst | 4 ++-- drivers/iommu/iommu-pages.h | 2 ++ include/linux/mmzone.h | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-= guide/cgroup-v2.rst index 3f85254f3cef..e004e05a7cde 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1418,7 +1418,7 @@ PAGE_SIZE multiple when read back. sec_pagetables Amount of memory allocated for secondary page tables, this currently includes KVM mmu allocations on x86 - and arm64. + and arm64 and IOMMU page tables. =20 percpu (npn) Amount of memory used for storing per-cpu kernel diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems= /proc.rst index 49ef12df631b..86f137a9b66b 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1110,8 +1110,8 @@ KernelStack PageTables Memory consumed by userspace page tables SecPageTables - Memory consumed by secondary page tables, this currently - currently includes KVM mmu allocations on x86 and arm64. + Memory consumed by secondary page tables, this currently inc= ludes + KVM mmu and IOMMU allocations on x86 and arm64. NFS_Unstable Always zero. Previous counted pages which had been written to the server, but has not been committed to stable storage. diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h index 69895a355c0c..cdd257585284 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -27,6 +27,7 @@ static inline void __iommu_alloc_account(struct page *pag= es, int order) const long pgcnt =3D 1l << order; =20 mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, pgcnt); + mod_lruvec_page_state(pages, NR_SECONDARY_PAGETABLE, pgcnt); } =20 /** @@ -39,6 +40,7 @@ static inline void __iommu_free_account(struct page *page= s, int order) const long pgcnt =3D 1l << order; =20 mod_node_page_state(page_pgdat(pages), NR_IOMMU_PAGES, -pgcnt); + mod_lruvec_page_state(pages, NR_SECONDARY_PAGETABLE, -pgcnt); } =20 /** diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 1a4d0bba3e8b..aaabb385663c 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -199,7 +199,7 @@ enum node_stat_item { NR_KERNEL_SCS_KB, /* measured in KiB */ #endif NR_PAGETABLE, /* used for pagetables */ - NR_SECONDARY_PAGETABLE, /* secondary pagetables, e.g. KVM pagetables */ + NR_SECONDARY_PAGETABLE, /* secondary pagetables, KVM & IOMMU */ #ifdef CONFIG_IOMMU_SUPPORT NR_IOMMU_PAGES, /* # of pages allocated by IOMMU */ #endif --=20 2.43.0.rc2.451.g8631bc7472-goog