From patchwork Sat Apr 13 00:25:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 258E9C04FF9 for ; Sat, 13 Apr 2024 00:25:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9720C6B008C; Fri, 12 Apr 2024 20:25:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FA1F6B0092; Fri, 12 Apr 2024 20:25:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74DC26B0093; Fri, 12 Apr 2024 20:25:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 504726B008C for ; Fri, 12 Apr 2024 20:25:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 05BFB14102E for ; Sat, 13 Apr 2024 00:25:29 +0000 (UTC) X-FDA: 82002614778.25.7780BA4 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by imf17.hostedemail.com (Postfix) with ESMTP id 342E940010 for ; Sat, 13 Apr 2024 00:25:27 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=cVHqT1FD; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967927; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oiP8UC90cd5KxXzrbJg0GLX3uruD53Hpy3rdG4dJgI4=; b=rXsVejooDRlC92ZNyXAfWKhb/ljMsR4ZCn/ABkoSXlrSU5rFRgUlcFH43ppy0v06Xs5xcr go7R5TdsEYx6lZeCDWofmLQUh7rcz0/dZBTNeP9RKeEdOURgN/jVokaYPwLh/V1XkxvEGw 7ZmQh+AZaaDtZfXRM8/du1bUO8OlE+k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967927; a=rsa-sha256; cv=none; b=TRm+5Ng5NUK+bB824Jv05JSURuzCCXR+8ZY6cITOWCZk3BqEOYieYlJeS/ZRJP91yttUet zoxlFLJ/1/fL6kYf1amfgqw2gYBRL5zwTkRuho0JuCGGQBnHZHNiErbPku0rVSljcTT93E 0WVk+eAr01pqFoE9nwSmmsWewzcncKo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=cVHqT1FD; spf=pass (imf17.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-78ebc7e1586so247567785a.1 for ; Fri, 12 Apr 2024 17:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967926; x=1713572726; darn=kvack.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=oiP8UC90cd5KxXzrbJg0GLX3uruD53Hpy3rdG4dJgI4=; b=cVHqT1FD53jIM/nVfwrt9lTou2R2n6CZaxklKYMnB9au4Af3X7n2Y83QsI62OZDPEt E/eUggU1CCoEjzSFq+EaOMBerWzUsLPbcJbL0VAnfvZu2ikA6bYLQxyb0x8gHvGUnuoA 41I7XIC4ggvqcsjDnrnl7qsGe+hsws8cQ4e2umomPzqvzJhAxDwsT6CWPC0t8Rv6OdFq s1oOAuDs/wdejV2HuABd89xqVIZeaK0GnxqyO0mgfC8Ep0VnK0a+HInvIOAYPhQPnKg5 48ae1cLlY25ZoKs3MDUUgqdfhdaq2+2Pzq3yRpFDxPcY3jofjhQanyRBxU1qlw2rBp9J lVpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967926; x=1713572726; 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=oiP8UC90cd5KxXzrbJg0GLX3uruD53Hpy3rdG4dJgI4=; b=DRoc/3gTgzHu+P5F/XSifDkgXzt41MFcBz1Z30Hzj/af3wRqQxgtTu9cHVw890PA39 IWO7WEBsQpibqvGcGPpKYXutAO0IlyXO07001uAy1WqzCNdL23fZzuhgA6tQamPhZN19 txyk+a2rqOiWOD27qliwOrYNjO7NJdi19V0o3ZRg+VnApSmh4IFyhAqBUBWj8LpXef9r QPpCS9Z4/SayRpkAiEgrHu3OAe2tpB3zbjRusF33Km1QZ5VzXOYcgUv4jqe5+qq2vSYe lM6eu+oTjlf5eYmKu9mHjQpHMF1kW70iwspjJgkEmjjCiVs4LX/i80GMynUGeBiHFDf8 14SQ== X-Forwarded-Encrypted: i=1; AJvYcCWIvBpdj8eGn68+vpHtGgxaQxiy/QrZj2t875unElGUJ1CR/ol56RF0wcRp5fqk/jSaPUKTUeKhXQGK72taR91DX9o= X-Gm-Message-State: AOJu0Yy5IW2zOgqKEh8Z5VJOOlNuxgD1U5iUp+0pc5C8Bb92LpdL+HsY 6Md9dS7vqtBjTCLZEeH1rH4EVCgakNvuLO3lAp2dvWQuxb2RUwrcTA6mIS8/+3U= X-Google-Smtp-Source: AGHT+IH1tL1T2UBZKwUG+40tYDzHI0evrIR/OJeSig+4+S3Y2HeJ3HZ8yc2wtJwmzZSSxRzAx0lscA== X-Received: by 2002:a05:620a:28c6:b0:78e:c654:2ff0 with SMTP id l6-20020a05620a28c600b0078ec6542ff0mr8918726qkp.23.1712967926229; Fri, 12 Apr 2024 17:25:26 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:25 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 01/11] iommu/vt-d: add wrapper functions for page allocations Date: Sat, 13 Apr 2024 00:25:12 +0000 Message-ID: <20240413002522.1101315-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: si8yzsurrzh389hacpskbdyybnugwj5i X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 342E940010 X-Rspam-User: X-HE-Tag: 1712967927-188692 X-HE-Meta: U2FsdGVkX195MHEE1O0TD3kOXH/E7xoWimLffo0rs+x1rrD/csMZHYR6xG85y+Zb8ov5FC42Dk4KWBfgYux/coBfgTlRODnplyb0HghV5SYMtVwy07Sn+GhzCJ3dTM0hZcOh/n1kFa/hmwimaUyABQSTFwcffX2P0fXhd3E0/7I2aOL39LCBpCvYXO7BKeL2364eMZsUQ5SPy2kjw0ofiVZqZpIW0bCoxlhjgQZhi5sXVpYpMEGqNkpqoEp/fCn985J7s1yEpmMFNqQCIQB/tFcPeEYnyrRdmeBa/krV7KkMDeDUNzLN+tazFln9uyuWegGNT/CZy//AcFItm9EY2Z+ycef8Sa+nM2Llaa6DhWerdQAy/KJ2JR/RM2/66T3mNz6fLFTxQt0HKh4PP+8Z9adKWcBFo7MJukhbFdtIa/E60boO4Nw3rlj4s5TqAwtb3kiPp+/2OxX1J2uP/IRpj9IE0QU3mrp661yyAzkCU+GI0itLdD9OG27hrPv8jHeylqMCw/pOkYdBw3nk21I+8SS3aJILdX1qbPSQGZfcXqiOPebOx/uRh+OsdQSgUNahswc+j3EybS2heMWj5N+iEvCC1ncdEZfTFPWPxOALoq9rEzLqwbNxhGqS46YQa+piQOrsdaeJASIUYTVwdOa17gSYcXloMkkQfvUe+NhFnchoaYV17+bW7HP78xoZIYAsQiGSsf0kSVWYgz3R2o50thRA9AWD7lfLHJtAgLwzD1fD318zeD2X731FG1WCFuToxZBpb9mDyqyxX9OTwJClosWpsd4UN6hPtpsGNWcr4PlQGoc0UMFE2U1VwB3pnVGaV0p9alCWbFvuFSkRxYGlq4LZByNxk/OjV/H/8hX9l+afhWqRvVoiTVs9PAGDuv8zf8ljxS1rQjSuQ2Q1wgGLjqnzyp3BN9ccP9nl1+g9N5/epaYU96dRWTmEwWWxmFDKE9FeMN/L98uJ7aOY4tC tqlTas/s dB4kc45WgSwgVk8TBpNcIfWyTb5QHutKo2gooue92BiF8lFs2YgD95NwY1hBJD13Z0EYAUUtDSHCBOHnJn6thJ+dKBHCpoTG33t+XTsJC8AS9ASr5x6x2wC5yNRWt38lpWd4IkE5Rq3sognuVCM2M39Xq8d2DehCpZdUlTCDoVXMy2pGvPXKH7UIqWLyi10GUhWbzZDdjGW+nN/OItMiUCop2vNDs+Pgpt0TP/RjYlKuQ8k80iX0N98jIFifCOelj2NPvDGHLJDiaZB7I6j2r2fGUNl9LQRCr7BUNFoHLn5MJttra1NNvcKZRn0wVuhn3/nV8Y7DFyDnjldZo699BFh3doFLP8V1vY+9MqnO/oWchVDwbbKNkMyyC5Xvd0tDvnRt9Ac1cf2NkKtyVRbgkRKRWMdOc8nX2Vkj4Sy5jBt321AR+BFqnC8PBdTCeceCKYOn1XTN1tgsdAXBpJ5SKaqcmPGs8otL3cIT4hIIB1MhJlxQzV8Fujx2qjsd3Kvs9EUOBPPlHlKwaTfWCsOoL3eRDdD1oRghulyiDkEkFl6FXTgAu/m6wrNovIVbo0pNgrt5T X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: David Rientjes Tested-by: Bagas Sanjaya --- drivers/iommu/intel/dmar.c | 16 +-- drivers/iommu/intel/iommu.c | 47 +++------ drivers/iommu/intel/iommu.h | 2 - drivers/iommu/intel/irq_remapping.c | 16 +-- drivers/iommu/intel/pasid.c | 18 ++-- drivers/iommu/intel/svm.c | 11 +- drivers/iommu/iommu-pages.h | 154 ++++++++++++++++++++++++++++ 7 files changed, 201 insertions(+), 63 deletions(-) create mode 100644 drivers/iommu/iommu-pages.h diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 36d7427b1202..87ad996e5257 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -32,6 +32,7 @@ #include "iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" #include "perf.h" #include "trace.h" #include "perfmon.h" @@ -1187,7 +1188,7 @@ static void free_iommu(struct intel_iommu *iommu) } if (iommu->qi) { - free_page((unsigned long)iommu->qi->desc); + iommu_free_page(iommu->qi->desc); kfree(iommu->qi->desc_status); kfree(iommu->qi); } @@ -1755,7 +1756,8 @@ static void __dmar_enable_qi(struct intel_iommu *iommu) int dmar_enable_qi(struct intel_iommu *iommu) { struct q_inval *qi; - struct page *desc_page; + void *desc; + int order; if (!ecap_qis(iommu->ecap)) return -ENOENT; @@ -1776,19 +1778,19 @@ 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 = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO, - !!ecap_smts(iommu->ecap)); - if (!desc_page) { + order = ecap_smts(iommu->ecap) ? 1 : 0; + desc = iommu_alloc_pages_node(iommu->node, GFP_ATOMIC, order); + if (!desc) { kfree(qi); iommu->qi = NULL; return -ENOMEM; } - qi->desc = page_address(desc_page); + qi->desc = desc; qi->desc_status = 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 = NULL; return -ENOMEM; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a7ecd90303dc..daaa7a22595e 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -27,6 +27,7 @@ #include "iommu.h" #include "../dma-iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" #include "pasid.h" #include "cap_audit.h" #include "perfmon.h" @@ -298,22 +299,6 @@ static int __init intel_iommu_setup(char *str) } __setup("intel_iommu=", intel_iommu_setup); -void *alloc_pgtable_page(int node, gfp_t gfp) -{ - struct page *page; - void *vaddr = NULL; - - page = alloc_pages_node(node, gfp | __GFP_ZERO, 0); - if (page) - vaddr = page_address(page); - return vaddr; -} - -void free_pgtable_page(void *vaddr) -{ - free_page((unsigned long)vaddr); -} - static int domain_type_is_si(struct dmar_domain *domain) { return domain->domain.type == IOMMU_DOMAIN_IDENTITY; @@ -545,7 +530,7 @@ struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, if (!alloc) return NULL; - context = alloc_pgtable_page(iommu->node, GFP_ATOMIC); + context = iommu_alloc_page_node(iommu->node, GFP_ATOMIC); if (!context) return NULL; @@ -719,17 +704,17 @@ static void free_context_table(struct intel_iommu *iommu) for (i = 0; i < ROOT_ENTRY_NR; i++) { context = iommu_context_addr(iommu, i, 0, 0); if (context) - free_pgtable_page(context); + iommu_free_page(context); if (!sm_supported(iommu)) continue; context = iommu_context_addr(iommu, i, 0x80, 0); if (context) - free_pgtable_page(context); + iommu_free_page(context); } - free_pgtable_page(iommu->root_entry); + iommu_free_page(iommu->root_entry); iommu->root_entry = NULL; } @@ -867,7 +852,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, if (!dma_pte_present(pte)) { uint64_t pteval; - tmp_page = alloc_pgtable_page(domain->nid, gfp); + tmp_page = iommu_alloc_page_node(domain->nid, gfp); if (!tmp_page) return NULL; @@ -879,7 +864,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, 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)); } @@ -992,7 +977,7 @@ static void dma_pte_free_level(struct dmar_domain *domain, 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 += level_size(level); @@ -1016,7 +1001,7 @@ static void dma_pte_free_pagetable(struct dmar_domain *domain, /* free pgd */ if (start_pfn == 0 && last_pfn == DOMAIN_MAX_PFN(domain->gaw)) { - free_pgtable_page(domain->pgd); + iommu_free_page(domain->pgd); domain->pgd = NULL; } } @@ -1118,7 +1103,7 @@ static int iommu_alloc_root_entry(struct intel_iommu *iommu) { struct root_entry *root; - root = alloc_pgtable_page(iommu->node, GFP_ATOMIC); + root = iommu_alloc_page_node(iommu->node, GFP_ATOMIC); if (!root) { pr_err("Allocating root entry for %s failed\n", iommu->name); @@ -1841,7 +1826,7 @@ static void domain_exit(struct dmar_domain *domain) LIST_HEAD(freelist); domain_unmap(domain, 0, DOMAIN_MAX_PFN(domain->gaw), &freelist); - put_pages_list(&freelist); + iommu_put_pages_list(&freelist); } if (WARN_ON(!list_empty(&domain->devices))) @@ -2497,7 +2482,7 @@ static int copy_context_table(struct intel_iommu *iommu, if (!old_ce) goto out; - new_ce = alloc_pgtable_page(iommu->node, GFP_KERNEL); + new_ce = iommu_alloc_page_node(iommu->node, GFP_KERNEL); if (!new_ce) goto out_unmap; @@ -3426,7 +3411,7 @@ static int intel_iommu_memory_notifier(struct notifier_block *nb, start_vpfn, mhp->nr_pages, list_empty(&freelist), 0); rcu_read_unlock(); - put_pages_list(&freelist); + iommu_put_pages_list(&freelist); } break; } @@ -3833,7 +3818,7 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width) domain->max_addr = 0; /* always allocate the top pgd */ - domain->pgd = alloc_pgtable_page(domain->nid, GFP_ATOMIC); + domain->pgd = iommu_alloc_page_node(domain->nid, GFP_ATOMIC); if (!domain->pgd) return -ENOMEM; domain_flush_cache(domain, domain->pgd, PAGE_SIZE); @@ -3987,7 +3972,7 @@ int prepare_domain_attach_device(struct iommu_domain *domain, pte = dmar_domain->pgd; if (dma_pte_present(pte)) { dmar_domain->pgd = phys_to_virt(dma_pte_addr(pte)); - free_pgtable_page(pte); + iommu_free_page(pte); } dmar_domain->agaw--; } @@ -4141,7 +4126,7 @@ static void intel_iommu_tlb_sync(struct iommu_domain *domain, if (dmar_domain->nested_parent) parent_domain_flush(dmar_domain, start_pfn, nrpages, list_empty(&gather->freelist)); - put_pages_list(&gather->freelist); + iommu_put_pages_list(&gather->freelist); } 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 404d2476a877..8d081d8c6f41 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1085,8 +1085,6 @@ void domain_update_iommu_cap(struct dmar_domain *domain); int dmar_ir_support(void); -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 iommu_domain *intel_nested_domain_alloc(struct iommu_domain *parent, const struct iommu_user_data *user_data); diff --git a/drivers/iommu/intel/irq_remapping.c b/drivers/iommu/intel/irq_remapping.c index 566297bc87dd..39cd9626eb8d 100644 --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -22,6 +22,7 @@ #include "iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" #include "cap_audit.h" enum irq_mode { @@ -527,7 +528,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) struct ir_table *ir_table; struct fwnode_handle *fn; unsigned long *bitmap; - struct page *pages; + void *ir_table_base; if (iommu->ir_table) return 0; @@ -536,9 +537,9 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) if (!ir_table) return -ENOMEM; - pages = alloc_pages_node(iommu->node, GFP_KERNEL | __GFP_ZERO, - INTR_REMAP_PAGE_ORDER); - if (!pages) { + ir_table_base = iommu_alloc_pages_node(iommu->node, GFP_KERNEL, + INTR_REMAP_PAGE_ORDER); + if (!ir_table_base) { pr_err("IR%d: failed to allocate pages of order %d\n", iommu->seq_id, INTR_REMAP_PAGE_ORDER); goto out_free_table; @@ -573,7 +574,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) else iommu->ir_domain->msi_parent_ops = &dmar_msi_parent_ops; - ir_table->base = page_address(pages); + ir_table->base = ir_table_base; ir_table->bitmap = bitmap; iommu->ir_table = ir_table; @@ -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(ir_table_base, INTR_REMAP_PAGE_ORDER); out_free_table: kfree(ir_table); @@ -643,8 +644,7 @@ static void intel_teardown_irq_remapping(struct intel_iommu *iommu) irq_domain_free_fwnode(fn); iommu->ir_domain = 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 = NULL; diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index 11f0b856d74c..abce19e2ad6f 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -20,6 +20,7 @@ #include "iommu.h" #include "pasid.h" +#include "../iommu-pages.h" /* * Intel IOMMU system wide PASID name space: @@ -38,7 +39,7 @@ int intel_pasid_alloc_table(struct device *dev) { struct device_domain_info *info; struct pasid_table *pasid_table; - struct page *pages; + struct pasid_dir_entry *dir; u32 max_pasid = 0; int order, size; @@ -59,14 +60,13 @@ int intel_pasid_alloc_table(struct device *dev) size = max_pasid >> (PASID_PDE_SHIFT - 3); order = size ? get_order(size) : 0; - pages = alloc_pages_node(info->iommu->node, - GFP_KERNEL | __GFP_ZERO, order); - if (!pages) { + dir = iommu_alloc_pages_node(info->iommu->node, GFP_KERNEL, order); + if (!dir) { kfree(pasid_table); return -ENOMEM; } - pasid_table->table = page_address(pages); + pasid_table->table = dir; pasid_table->order = order; pasid_table->max_pasid = 1 << (order + PAGE_SHIFT + 3); info->pasid_table = pasid_table; @@ -97,10 +97,10 @@ void intel_pasid_free_table(struct device *dev) max_pde = pasid_table->max_pasid >> PASID_PDE_SHIFT; for (i = 0; i < max_pde; i++) { table = get_pasid_table_from_pde(&dir[i]); - free_pgtable_page(table); + iommu_free_page(table); } - free_pages((unsigned long)pasid_table->table, pasid_table->order); + iommu_free_pages(pasid_table->table, pasid_table->order); kfree(pasid_table); } @@ -146,7 +146,7 @@ static struct pasid_entry *intel_pasid_get_entry(struct device *dev, u32 pasid) retry: entries = get_pasid_table_from_pde(&dir[dir_index]); if (!entries) { - entries = alloc_pgtable_page(info->iommu->node, GFP_ATOMIC); + entries = iommu_alloc_page_node(info->iommu->node, GFP_ATOMIC); if (!entries) return NULL; @@ -158,7 +158,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 ee3b469e2da1..71c1b2a0ca16 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -22,6 +22,7 @@ #include "iommu.h" #include "pasid.h" #include "perf.h" +#include "../iommu-pages.h" #include "trace.h" static irqreturn_t prq_event_thread(int irq, void *d); @@ -63,16 +64,14 @@ svm_lookup_device_by_dev(struct intel_svm *svm, struct device *dev) int intel_svm_enable_prq(struct intel_iommu *iommu) { struct iopf_queue *iopfq; - struct page *pages; int irq, ret; - pages = alloc_pages_node(iommu->node, GFP_KERNEL | __GFP_ZERO, PRQ_ORDER); - if (!pages) { + iommu->prq = iommu_alloc_pages_node(iommu->node, GFP_KERNEL, PRQ_ORDER); + if (!iommu->prq) { pr_warn("IOMMU: %s: Failed to allocate page request queue\n", iommu->name); return -ENOMEM; } - iommu->prq = page_address(pages); irq = dmar_alloc_hwirq(IOMMU_IRQ_ID_OFFSET_PRQ + iommu->seq_id, iommu->node, iommu); if (irq <= 0) { @@ -117,7 +116,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) dmar_free_hwirq(irq); iommu->pr_irq = 0; free_prq: - free_pages((unsigned long)iommu->prq, PRQ_ORDER); + iommu_free_pages(iommu->prq, PRQ_ORDER); iommu->prq = NULL; return ret; @@ -140,7 +139,7 @@ int intel_svm_finish_prq(struct intel_iommu *iommu) iommu->iopf_queue = NULL; } - free_pages((unsigned long)iommu->prq, PRQ_ORDER); + iommu_free_pages(iommu->prq, PRQ_ORDER); iommu->prq = NULL; return 0; diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h new file mode 100644 index 000000000000..5a222d0ad25c --- /dev/null +++ b/drivers/iommu/iommu-pages.h @@ -0,0 +1,154 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2024, Google LLC. + * Pasha Tatashin + */ + +#ifndef __IOMMU_PAGES_H +#define __IOMMU_PAGES_H + +#include +#include +#include + +/* + * All page allocations that should be reported to as "iommu-pagetables" to + * userspace must use one of the functions below. This includes allocations of + * page-tables and other per-iommu_domain configuration structures. + * + * This is necessary for the proper accounting as IOMMU state can be rather + * large, i.e. multiple gigabytes in size. + */ + +/** + * __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 *page; + + page = alloc_pages(gfp | __GFP_ZERO, order); + if (unlikely(!page)) + return NULL; + + return page; +} + +/** + * __iommu_free_pages - free page of a given order + * @page: head struct page of the page + * @order: page order + */ +static inline void __iommu_free_pages(struct page *page, int order) +{ + if (!page) + return; + + __free_pages(page, order); +} + +/** + * 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 *page = alloc_pages_node(nid, gfp | __GFP_ZERO, order); + + if (unlikely(!page)) + return NULL; + + return page_address(page); +} + +/** + * 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 *page = __iommu_alloc_pages(gfp, order); + + if (unlikely(!page)) + return NULL; + + return page_address(page); +} + +/** + * 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_put_pages_list - free a list of pages. + * @page: the head of the lru list to be freed. + * + * There are no locking requirement for these pages, as they are going to be + * put on a free list as soon as refcount reaches 0. Pages are put on this LRU + * list once they are removed from the IOMMU page tables. However, they can + * still be access through debugfs. + */ +static inline void iommu_put_pages_list(struct list_head *page) +{ + while (!list_empty(page)) { + struct page *p = list_entry(page->prev, struct page, lru); + + list_del(&p->lru); + put_page(p); + } +} + +#endif /* __IOMMU_PAGES_H */ From patchwork Sat Apr 13 00:25:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 904B2C4345F for ; Sat, 13 Apr 2024 00:25:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6648C6B0092; Fri, 12 Apr 2024 20:25:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 614CD6B0093; Fri, 12 Apr 2024 20:25:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4674E6B0095; Fri, 12 Apr 2024 20:25:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 273BC6B0092 for ; Fri, 12 Apr 2024 20:25:30 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F05BC40BF7 for ; Sat, 13 Apr 2024 00:25:29 +0000 (UTC) X-FDA: 82002614778.20.9DC3D2F Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf07.hostedemail.com (Postfix) with ESMTP id 42E9140003 for ; Sat, 13 Apr 2024 00:25:28 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=ncdzX76i; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967928; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pZlpX3txUE4TJWo1dAHShmrFptGg2d9oY1hNAoNGiuE=; b=xvfJFvDncYjMhoriBgBX5UinMpOAY7uqndDgWqUfuP3iCrL7KL8LGFGKDqulkC7lujG/nK /V19DG8u4iayngosCaqW5vwM0ygVnsKmodyhyeHGXYB67keuhiQAl5hLhb0SsrZi0emO42 bMi8qPxA5fZMzqhjO/EHHeKJMusKWhE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=ncdzX76i; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.182 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967928; a=rsa-sha256; cv=none; b=RK7KwGicV2LA/rFNHJLEcMzpePjRrDGRv9zwJeEBH/i7gOus/kkqwDKi3MRt/WD+yG5+fG EvSIllA65prpRnoHuickHCVj0xoNyWFNFpVawrCUzn7JL0cZM+0qBkU9H3YqzMTdFFIDsj inmvV9yT1Ir50uaWZg/d7r+qkRpFDlw= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-78d6021e2e3so80255785a.1 for ; Fri, 12 Apr 2024 17:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967927; x=1713572727; darn=kvack.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=pZlpX3txUE4TJWo1dAHShmrFptGg2d9oY1hNAoNGiuE=; b=ncdzX76iCu2XtUDDs/uJeDIFmau/XFCFnhexpeW1PlDFHqSzxCj1FxU9vL4/fIZik4 m/9BlizlKHH7PIZ2LdXGHEy7MQUfbHvPS6F55+Zz8FEUNCZCQIQLqp8Nut8bXh1cMy3m zL+8LKkbKaSNlCfS+xLFUSMccMYAjT06ATNsk2cSWrFmah83JU29ie+l9dCKQssL4l94 1A20wZS/fZTlcs/MltYI3uXlIOvt4lWJRS33kcjj4kiegSJ9nswx+qyoY9WRglsBH+u7 uzVmyNin1YDn1ra4gKO6mMXMNs6TALE4iFbZtfoZY/PfWIiX3BEUBps6vj3QJk2Io50T 5MxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967927; x=1713572727; 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=pZlpX3txUE4TJWo1dAHShmrFptGg2d9oY1hNAoNGiuE=; b=D6gOfIS8F4arMEkN2B3BDWfPS4Kx8xkF+4WtBcFqEli97sRHqKhN7Xrc5yrjWrY7QA ZtjvnIeEH/9lElIOOiFRFAxbXSYh2Izarhhwueb4RNirRtmhqbzD4pQ2zit8x4X2NM0U McPC9q+L+E5IIgFViPUH9BK0kB/pUbK435vanvbzo1wp7V8FnWdgBy88fB27eYiWTe8d f5JIKB1O2NlLCRsIB97rwPUYqyPr1KD5thaJFgdsIHHtWZShOlxmu6gLuttmATERiad2 GDAMovCxzIjGEuD4LoY7v1hUtPy7zLijL2gmRtW3YJDc7E+0/JIizSQb2Gg/9EXXP9+q 5PkA== X-Forwarded-Encrypted: i=1; AJvYcCWx3zBnnX8c1L7LEXpTDyOGNUBh6CWqkh+oR/EMTZpPDfbjpRJnUwgvScw8nCioigytV9dHihbF+6kMchyN5xc44Uw= X-Gm-Message-State: AOJu0YzZYkvf4vzLtnO4+SBdxaQH7mOll2r+Oe5+O21BvprAQFRoaPyb hVTlQ7N2v6u/suBGOAjg92AykfR7Xe8TtG3WyEDqKT5V0bg4eH9WO8urJ+EqKEY= X-Google-Smtp-Source: AGHT+IHnFRJRktafMl8iFWoPD2wZry7L4eUZEKmr/HQPmjiBtsCGzy14Fj8Nir/jZCpUWrNk2ovbMw== X-Received: by 2002:a05:620a:56a:b0:78a:f5b:ed05 with SMTP id p10-20020a05620a056a00b0078a0f5bed05mr3835236qkp.22.1712967927419; Fri, 12 Apr 2024 17:25:27 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:26 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 02/11] iommu/dma: use iommu_put_pages_list() to releae freelist Date: Sat, 13 Apr 2024 00:25:13 +0000 Message-ID: <20240413002522.1101315-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 42E9140003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: eaa6ab41p9k1bz7z8rhw1ejcygfix74n X-HE-Tag: 1712967928-934949 X-HE-Meta: U2FsdGVkX1/uQHMbNNDN1k+TkhuLBWCgenaDwus8FBe3XVz3qlNLI5+xDYann8yTfWf+sT1IPhp9P8CsgVcYefiCu9TAuHZGk1SiWtoSyjqEFdiBr4dlwpoktokZn4QcCnlbjyu7rINLxA2djlilGMAE0HiJdIVfwyEZTiUInCt5IDNM6N5/LVjtsAJUX6M10bofF9DAx2xrcT6X3nVqpTJSZ+mQQ/v1mc0J85ZxHQdAXmBIc92pyMiMGelLtV3UL2bSVZwup/7Hu0sYrgAJjLFXnNguZzH9bAr5UBd9NxF/ItXMzrWXNIC35/PBDWO2VYeaEZJ3rY9R5gKPWisBmhGgHdoinC7gIdTiZKYJe3+SDBIwwvLcx5fp8sCe3n7dVOQ30H+dJW5vrJ8fzrnO6Cl4FdTfqF1G1LUNPzt6CbVzVgvCU//ZCGAmVr5YiSU8X5HItQ4EBCiNpljGEU7oLzrAQNUlEjtE228l7B84p7ayUGQ0UW86B2Uj2C1LLVRt5Un5ERZuBsoIcej79NkyzW9ky7FdGHzojqkdjO/3Dy3HDzaSaaCk+hVL75bSpwd2h5PJvFqIVbk+d1cl+sTtjTmW3j1FlZjGPjxRyHUXVjMSjzmoU5Ksw/oVSQLN/TsGtBBaTE0nf+d0Q7Gwn3pLBPQpZC8yMQ2iAs5yReC0lzvzb6k6GtIc76gdG6arX2jokjVE4FDI6BNzzvjdiijRg7z0CC7hF+3A4raS2gpDWLg7eDxXjma2Lg3eYvhjUj2pk7vYgiUP0b9nCoQD6vKHxnvIjvJPwvkgEdgz2OPlylsqb2nFWW5fXVBYkz0VZ1dcrRpmwAPfA3Tv25VcurT8kInq/IutE61okCiJcan0ksdtGtCZo5pE+q148aAcOoXCsLRdZHrSu8sjdMFxJKnZNTgrkhzrWC5Yq9E3jPVRymZ4okyhzY4p33LwLwrAiHuCmAFrX4+cToRKVFW904a jz40FE90 lI+TIw6UWSnC9iwQAfbK2Dq+SjMsVvtDTcur6mgPXzp7/mm2XB89DAPNFF6i8CTDPBrClDEVYP/2pLtqcybaEMmmT3I6o/0nNQztbUQy6akbqrL+QMLjn8sosGSdRROnBzdmTXF/CYvjcyY9ADqBfchkZPXv1Fzs9AyPYOaOhEYK2is1nn+swTPiHvXuQLQDVKFINrgkGmGU6AkRu7u6dofQCPI/zs3iNwrEkI/4KQDSaXVkMCFx/Gn8HVOcX8S+Mi5yrzSvvUT46Vqf5YuA1FXa3bSKysVtdRlxROsIAOcmkmpOo5SvGeeDAucclIeXQON6ztP7qn3kVEcuv1EKT34rTzgLcl03gTjgX/XcnvUP72tEduq6BwozyrQp4efykEAWL5qMy9MjFQo4vcXrPkMhFzMQ7ltEeDwyC6I8PgObqT+q5HrOVGMnSdEfkDkuyo2xzl4MdGRkZvfoRqPj+Xv3TyHaR70f0OD7OufaR6u1m/cm+GXo5xKYaqhmzZaFIpCfcysGAu14Zu5yZtUYi9hscxoy3+Q9NEPWV98+33afpxYfyCMqGDBYe+7KRBtDpdbdpHzFSEpWSLod3FoUoo0GBImqD1jRRA/FJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000036, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Free the IOMMU page tables via iommu_put_pages_list(). The page tables were allocated via iommu_alloc_* functions in architecture specific places, but are released in dma-iommu if the freelist is gathered during map/unmap operations into iommu_iotlb_gather data structure. Currently, only iommu/intel that does that. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes --- drivers/iommu/dma-iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index e4cb26f6a943..16a7c4a4f3db 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -32,6 +32,7 @@ #include #include "dma-iommu.h" +#include "iommu-pages.h" struct iommu_dma_msi_page { struct list_head list; @@ -156,7 +157,7 @@ static void fq_ring_free_locked(struct iommu_dma_cookie *cookie, struct iova_fq if (fq->entries[idx].counter >= counter) break; - put_pages_list(&fq->entries[idx].freelist); + iommu_put_pages_list(&fq->entries[idx].freelist); free_iova_fast(&cookie->iovad, fq->entries[idx].iova_pfn, fq->entries[idx].pages); @@ -254,7 +255,7 @@ static void iommu_dma_free_fq_single(struct iova_fq *fq) int idx; fq_ring_for_each(idx, fq) - put_pages_list(&fq->entries[idx].freelist); + iommu_put_pages_list(&fq->entries[idx].freelist); vfree(fq); } @@ -267,7 +268,7 @@ static void iommu_dma_free_fq_percpu(struct iova_fq __percpu *percpu_fq) struct iova_fq *fq = per_cpu_ptr(percpu_fq, cpu); fq_ring_for_each(idx, fq) - put_pages_list(&fq->entries[idx].freelist); + iommu_put_pages_list(&fq->entries[idx].freelist); } free_percpu(percpu_fq); From patchwork Sat Apr 13 00:25:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 403E2C4345F for ; Sat, 13 Apr 2024 00:25:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41BA26B0095; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CCA06B0096; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F7316B0098; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DE93C6B0095 for ; Fri, 12 Apr 2024 20:25:31 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 74F111A1055 for ; Sat, 13 Apr 2024 00:25:31 +0000 (UTC) X-FDA: 82002614862.18.76296FB Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf25.hostedemail.com (Postfix) with ESMTP id A9195A000C for ; Sat, 13 Apr 2024 00:25:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=EmSg+qLF; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967929; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Fv5XjUyHQAdWl3bPoRKg0WmIlKdHELCmSaFid/+Qq0w=; b=4tzo5S0dYqOknrycja9s1WLy/0K+RP4K9Nf1Q+n49t0WZhTxxPWyeVMyRdB2jzicf+ZOAU oTjBJ18JKdhzvfzzQOqHmJpDpjFrx5JdA2aRHBKmR6ABtQiWT2qh6Sz9CFN05J10o4csLE MSDehcpZFiRm0Mg2Mf8NTE/JYdFIB04= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=EmSg+qLF; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967929; a=rsa-sha256; cv=none; b=tBbKsV9yi1iIA9EdE7XkcqbeqDVEMbzY2/7QdIwmbTCR+eQvBkeR7+GdZkvF419R2g6uhU 0aeHOR/Mn/mkngwsAwOQZW4ZwzK8xOg1Vgof85nHOvpi10qfrf6edkxUJgG9PMIHwx6+Zo nAiRaPkF/pa4rVvu0gdqMaWx8T0yYQw= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-614ec7ee902so14727887b3.2 for ; Fri, 12 Apr 2024 17:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967929; x=1713572729; darn=kvack.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=Fv5XjUyHQAdWl3bPoRKg0WmIlKdHELCmSaFid/+Qq0w=; b=EmSg+qLFGWxn5XXXYvXl3OBtN4k+HV12OHyP3JJTkA1ff5zbkWQ3EDUWkiBjLW8Lst KOWL7JoXUm4/qO3hwFBGyX1/SClksWGXvCWAWHtIYVOwLoYzgMB2gA2Cxp0X119IrcSn OEOadsrY1cm+Wm7Ho89RC1TfLtAp5ra1kxajd1HLzkDfBJvJPmAaz4kWAVkDJIGrezSs 4mGeCTOTSk8twDyjd2MizudT4X4UOdAqu7aNC25HQ8YplxBfeoSJMNLVGf+2zi9zooCE w5F6WI0zGSD4n1g67/vyKKRBntOrRezFTrVEiaodz1rsQ+CFW/SWwuNrFC16EVF79b8A aBxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967929; x=1713572729; 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=Fv5XjUyHQAdWl3bPoRKg0WmIlKdHELCmSaFid/+Qq0w=; b=NkvMIEjhl/cam6Oe6U/77WH24FM8JRMKImVRDIuFwL7kRTj22LMOG2Zk4arc6qgJE1 7CI/IAFwkIHD5xupCZlthBgFhPgairFx7kXv4P+9gpbDLzvAR1UcDWHZ+iZNCHMSkXyK g/Ta6ASpLHb+bJ5DGvIIrlYfVkr/FBuStivzd24jDtPS7zhQ7qpsKhNOFE0iX9phSGda zblLz3Qbi4N6XdIPwt6eHcQWSSezZgbBg73IyFAf9vNHoZZuv4ii4uB1FTkpq6/+RZXU f2F+MfQAgBk05pbpS62gCS3kjhPLDFCMqkzDHEHaNoAStpWLUIRyeC0HbcKx1Q3O37QN xEBQ== X-Forwarded-Encrypted: i=1; AJvYcCU8wJjXNMUxLTMT4xBSIKR3AyPKeZ90sbROf6iDLLCzBuDfsFblXLLAB6cVc4XWqxaJ7qGbu1+XLEP7TdNt8noGbxw= X-Gm-Message-State: AOJu0YyF8IbOQk4PAcqzKDlXvUBj3fMf2UPFXlRCXifyT86rEVDFv2RR 5x7j23uCWSKXC9yukrx63LIzQj1an2ZGWec1ix1R6fJ7G5a5FgcAwFn/EpRqN+Y= X-Google-Smtp-Source: AGHT+IGW898pCeGLPa+VWvrRPz3hbxFV00Y+MnKqLO1UnlnMcO/OnmtgMSPxUoES+7xDasPhpBwxcQ== X-Received: by 2002:a0d:d442:0:b0:611:3105:93e5 with SMTP id w63-20020a0dd442000000b00611310593e5mr4391402ywd.17.1712967928280; Fri, 12 Apr 2024 17:25:28 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:28 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 03/11] iommu/amd: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:14 +0000 Message-ID: <20240413002522.1101315-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A9195A000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: omb4zxu9b4zbmtbe6re4osuyipkg7645 X-HE-Tag: 1712967929-978369 X-HE-Meta: U2FsdGVkX1+w/U+r8kIcvgFdFBKE8V+vO4LlGegLifIL2x349T3P5Eryjr6YB51hTyfcC3mFA4mIlE+MQN6VTS86pqIzzAmB+MbahCKHcaXr+Sdqg2oZQSk3j/NZ3HJJdEW6XK5tTBgE6CQ1pSK1a5vnq+PbxvsiQ8LofK+Bxs4KrXmq1kfzrx0+wjXCC17uqAK3/XY9RbzTShWayajI2nzaJUn6/xi6VywCpK09rYhjS0fb4Lw+nFkMLSAvpZ9AgFgCsHW9UKGxNyXHrshQ/mNEm7mmjNwE8UOKmtYbfSJFndyTNrQI8q9C9sRunDqvDizBsmLPVfstbWH+j7NrqfqiICE2jyEZc03IVG/2d8CWJ2xjCVnB+lg92WS1uqhzFkzG+17QP1bTpOuML7fmhu62KaNulXAQ36N4VXbE5O0LBha7cej8g0WmZ5ucUK6tiei4cZ1VwaFbHP4Mwocg6V1oVwTTlP62MfTPi4SbZjt1/jt1wnel/ywLZ5UHRw3L/3iLFJJ2o+l1Xxd3pNiTTi/4TnsFL1jEFR9HKey71WZU46kqcT5SLk4lbPhHejV9yy+Ce0VG5aGkjgIsVZvTBQ9xzM2aVWxpFobMBP6EBG4XNqAxa4Q3CqZqRv9UXrRkI50HhDxzaz5yv3YNYgo45Gl0uCzjPjrjpHgelgL/kzYb8Jb5KIXBkDCo+T7KqZFwuyuqsRTDFRht8/lf6+jsrYb+UwnBkoPLliNzmCZUYneZ5mOGZPANKw6ALeKyx03Z2hYwNn/By+dzNbbocZ7xxkGG/mmnYtGfCwIhBB+1ipjbzRj6PpuOTBtyrajvpz2hlSVxBec+htD2YewmltqE0ebkXz1qVsOCI8OIqKuLRMgsfbjKQMeF0p28hL3eVoAdBoTUAxzwd+v24lCxuFpzHSEbGdI0BhbyDGj/3GYt/LPchszcaAM5g/Bu0FVG2SYgdv45VShxO1wWxscr+s7 jD23akzb AtERMokbA9eqnAFlUEdbp4tqYKWa3YwMdfh1CAG3beRFH1FQyHIJ40dlI2MkA3j5qXenlnnwafQq3YVJj8AErvI+Kfx/IvtlqxiqEYBTn4s1I8Qn11DuoFivbhLJZUgz8qfE1AMILjnihkdQfEeTTAUZqR96YHxYkmaPHMnB4mUtVUcqNVF09/TD6pvRcoj4p4Re7dREjq/TZIxSCC9YAowwtadPjL62N0pWblbsi99vZx5lU9Hxlv0LhbXNAOs2GXwC0iKirKCWSS5QLXvzcbemTHwgU/OYS4EAawMi1hyoyY8UAk+zCEeUs63cw+ASpxdt1lpL+EJjN7uDSyDkdXnXUbC4rGcfDdAzxQB4cZxKRd8zHdhk371oQfcypHvhQpXOHoI1xWlUxut/QXJHrgGXkoMOpnfzLI+KTomfZCyEn+gMxqf7U94+kn3AYI1cXrxFDHCXQzozXhrWiA9o2lfPIU89VaB3T2PoYytuGA9c4HbFs/JrgUEFOz9OlFBcP9f7rnDh+uPoZPDXhaWn2/qEQVIJjAMPwCpeVp+Xpy3ZmqeahAxFEKDzk5J8vt4NRmj6D X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Tested-by: Bagas Sanjaya --- 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 | 18 +++--- drivers/iommu/amd/iommu.c | 11 ++-- 5 files changed, 62 insertions(+), 79 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index f482aab420f7..e01409037206 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -134,14 +134,6 @@ static inline int get_pci_sbdf_id(struct pci_dev *pdev) return PCI_SEG_DEVID_TO_SBDF(seg, devid); } -static inline void *alloc_pgtable_page(int nid, gfp_t gfp) -{ - struct page *page; - - page = alloc_pages_node(nid, gfp | __GFP_ZERO, 0); - return page ? page_address(page) : NULL; -} - /* * This must be called after device probe completes. During probe * use rlookup_amd_iommu() get the iommu. diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index ac6754a85f35..40b3b9cffade 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -36,6 +36,7 @@ #include "amd_iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" /* * definitions for the ACPI scanning code @@ -649,8 +650,8 @@ static int __init find_last_devid_acpi(struct acpi_table_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 = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, - get_order(pci_seg->dev_table_size)); + pci_seg->dev_table = iommu_alloc_pages(GFP_KERNEL | GFP_DMA32, + get_order(pci_seg->dev_table_size)); if (!pci_seg->dev_table) return -ENOMEM; @@ -659,17 +660,16 @@ static inline int __init alloc_dev_table(struct amd_iommu_pci_seg *pci_seg) 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 = NULL; } /* 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 = (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(pci_seg->rlookup_table_size)); + pci_seg->rlookup_table = iommu_alloc_pages(GFP_KERNEL, + get_order(pci_seg->rlookup_table_size)); if (pci_seg->rlookup_table == NULL) return -ENOMEM; @@ -678,16 +678,15 @@ static inline int __init alloc_rlookup_table(struct amd_iommu_pci_seg *pci_seg) 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 = NULL; } static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg) { - pci_seg->irq_lookup_table = (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(pci_seg->rlookup_table_size)); + pci_seg->irq_lookup_table = 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 == NULL) @@ -699,8 +698,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 = NULL; } @@ -708,8 +707,8 @@ static int __init alloc_alias_table(struct amd_iommu_pci_seg *pci_seg) { int i; - pci_seg->alias_table = (void *)__get_free_pages(GFP_KERNEL, - get_order(pci_seg->alias_table_size)); + pci_seg->alias_table = iommu_alloc_pages(GFP_KERNEL, + get_order(pci_seg->alias_table_size)); if (!pci_seg->alias_table) return -ENOMEM; @@ -724,8 +723,8 @@ static int __init alloc_alias_table(struct amd_iommu_pci_seg *pci_seg) 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 = NULL; } @@ -736,8 +735,8 @@ static void __init free_alias_table(struct amd_iommu_pci_seg *pci_seg) */ static int __init alloc_command_buffer(struct amd_iommu *iommu) { - iommu->cmd_buf = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(CMD_BUFFER_SIZE)); + iommu->cmd_buf = iommu_alloc_pages(GFP_KERNEL, + get_order(CMD_BUFFER_SIZE)); return iommu->cmd_buf ? 0 : -ENOMEM; } @@ -845,19 +844,19 @@ static void iommu_disable_command_buffer(struct amd_iommu *iommu) 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)); } static void *__init iommu_alloc_4k_pages(struct amd_iommu *iommu, gfp_t gfp, size_t size) { int order = get_order(size); - void *buf = (void *)__get_free_pages(gfp, order); + void *buf = iommu_alloc_pages(gfp, order); 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 = NULL; } @@ -867,7 +866,7 @@ static void *__init iommu_alloc_4k_pages(struct amd_iommu *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 = iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, + iommu->evt_buf = iommu_alloc_4k_pages(iommu, GFP_KERNEL, EVT_BUFFER_SIZE); return iommu->evt_buf ? 0 : -ENOMEM; @@ -901,14 +900,13 @@ static void iommu_disable_event_buffer(struct amd_iommu *iommu) 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)); } /* allocates the memory where the IOMMU will log its events to */ static int __init alloc_ppr_log(struct amd_iommu *iommu) { - iommu->ppr_log = iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, - PPR_LOG_SIZE); + iommu->ppr_log = iommu_alloc_4k_pages(iommu, GFP_KERNEL, PPR_LOG_SIZE); return iommu->ppr_log ? 0 : -ENOMEM; } @@ -937,14 +935,14 @@ static void iommu_enable_ppr_log(struct amd_iommu *iommu) 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)); } 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 } @@ -989,13 +987,11 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) return 0; - iommu->ga_log = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(GA_LOG_SIZE)); + iommu->ga_log = iommu_alloc_pages(GFP_KERNEL, get_order(GA_LOG_SIZE)); if (!iommu->ga_log) goto err_out; - iommu->ga_log_tail = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(8)); + iommu->ga_log_tail = iommu_alloc_pages(GFP_KERNEL, get_order(8)); if (!iommu->ga_log_tail) goto err_out; @@ -1008,7 +1004,7 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) static int __init alloc_cwwb_sem(struct amd_iommu *iommu) { - iommu->cmd_sem = iommu_alloc_4k_pages(iommu, GFP_KERNEL | __GFP_ZERO, 1); + iommu->cmd_sem = iommu_alloc_4k_pages(iommu, GFP_KERNEL, 1); return iommu->cmd_sem ? 0 : -ENOMEM; } @@ -1016,7 +1012,7 @@ static int __init alloc_cwwb_sem(struct amd_iommu *iommu) 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); } static void iommu_enable_xt(struct amd_iommu *iommu) @@ -1081,7 +1077,6 @@ static bool __copy_device_table(struct amd_iommu *iommu) 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; /* Each IOMMU use separate device table with the same size */ @@ -1115,9 +1110,8 @@ static bool __copy_device_table(struct amd_iommu *iommu) if (!old_devtb) return false; - gfp_flag = GFP_KERNEL | __GFP_ZERO | GFP_DMA32; - pci_seg->old_dev_tbl_cpy = (void *)__get_free_pages(gfp_flag, - get_order(pci_seg->dev_table_size)); + pci_seg->old_dev_tbl_cpy = iommu_alloc_pages(GFP_KERNEL | GFP_DMA32, + get_order(pci_seg->dev_table_size)); if (pci_seg->old_dev_tbl_cpy == NULL) { pr_err("Failed to allocate memory for copying old device table!\n"); memunmap(old_devtb); @@ -2805,8 +2799,8 @@ static void early_enable_iommus(void) for_each_pci_segment(pci_seg) { if (pci_seg->old_dev_tbl_cpy != 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 = NULL; } } @@ -2819,8 +2813,8 @@ static void early_enable_iommus(void) pr_info("Copied DEV table from previous kernel.\n"); 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 = pci_seg->old_dev_tbl_cpy; } @@ -3022,8 +3016,8 @@ static bool __init check_ioapic_information(void) 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 = NULL; free_unity_maps(); @@ -3095,9 +3089,8 @@ static int __init early_amd_iommu_init(void) /* Device table - directly used by all IOMMUs */ ret = -ENOMEM; - amd_iommu_pd_alloc_bitmap = (void *)__get_free_pages( - GFP_KERNEL | __GFP_ZERO, - get_order(MAX_DOMAIN_ID/8)); + amd_iommu_pd_alloc_bitmap = iommu_alloc_pages(GFP_KERNEL, + get_order(MAX_DOMAIN_ID / 8)); if (amd_iommu_pd_alloc_bitmap == NULL) goto out; diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 2a0d1e97e52f..9d9a7fde59e7 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -22,6 +22,7 @@ #include "amd_iommu_types.h" #include "amd_iommu.h" +#include "../iommu-pages.h" static void v1_tlb_flush_all(void *cookie) { @@ -156,7 +157,7 @@ static bool increase_address_space(struct protection_domain *domain, bool ret = true; u64 *pte; - pte = alloc_pgtable_page(domain->nid, gfp); + pte = iommu_alloc_page_node(domain->nid, gfp); if (!pte) return false; @@ -187,7 +188,7 @@ static bool increase_address_space(struct protection_domain *domain, out: spin_unlock_irqrestore(&domain->lock, flags); - free_page((unsigned long)pte); + iommu_free_page(pte); return ret; } @@ -250,7 +251,7 @@ static u64 *alloc_pte(struct protection_domain *domain, if (!IOMMU_PTE_PRESENT(__pte) || pte_level == PAGE_MODE_NONE) { - page = alloc_pgtable_page(domain->nid, gfp); + page = iommu_alloc_page_node(domain->nid, gfp); if (!page) return NULL; @@ -259,7 +260,7 @@ static u64 *alloc_pte(struct protection_domain *domain, /* 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 = true; @@ -431,7 +432,7 @@ static int iommu_v1_map_pages(struct io_pgtable_ops *ops, unsigned long iova, } /* Everything flushed out, free pages now */ - put_pages_list(&freelist); + iommu_put_pages_list(&freelist); return ret; } @@ -580,7 +581,7 @@ static void v1_free_pgtable(struct io_pgtable *iop) /* Make changes visible to IOMMUs */ amd_iommu_domain_update(dom); - put_pages_list(&freelist); + iommu_put_pages_list(&freelist); } static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) diff --git a/drivers/iommu/amd/io_pgtable_v2.c b/drivers/iommu/amd/io_pgtable_v2.c index 93489d2db4e8..78ac37c5ccc1 100644 --- a/drivers/iommu/amd/io_pgtable_v2.c +++ b/drivers/iommu/amd/io_pgtable_v2.c @@ -18,6 +18,7 @@ #include "amd_iommu_types.h" #include "amd_iommu.h" +#include "../iommu-pages.h" #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; } -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); } - free_pgtable_page(pt); + iommu_free_page(pt); } /* Allocate page table */ @@ -156,14 +152,14 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova, } if (!IOMMU_PTE_PRESENT(__pte)) { - page = alloc_pgtable_page(nid, gfp); + page = iommu_alloc_page_node(nid, gfp); if (!page) return NULL; __npte = set_pgtable_attr(page); /* pte could have been changed somewhere. */ if (cmpxchg64(pte, __pte, __npte) != __pte) - free_pgtable_page(page); + iommu_free_page(page); else if (IOMMU_PTE_PRESENT(__pte)) *updated = true; @@ -185,7 +181,7 @@ static u64 *v2_alloc_pte(int nid, u64 *pgd, unsigned long iova, if (pg_size == IOMMU_PAGE_SIZE_1G) free_pgtable(__pte, end_level - 1); else if (pg_size == IOMMU_PAGE_SIZE_2M) - free_pgtable_page(__pte); + iommu_free_page(__pte); } return pte; @@ -366,7 +362,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo struct protection_domain *pdom = (struct protection_domain *)cookie; int ias = IOMMU_IN_ADDR_BIT_SIZE; - pgtable->pgd = alloc_pgtable_page(pdom->nid, GFP_ATOMIC); + pgtable->pgd = iommu_alloc_page_node(pdom->nid, GFP_ATOMIC); if (!pgtable->pgd) return NULL; diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index e692217fcb28..922f5d42c18e 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" #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28)) @@ -1728,7 +1729,7 @@ static void free_gcr3_tbl_level1(u64 *tbl) ptr = iommu_phys_to_virt(tbl[i] & PAGE_MASK); - free_page((unsigned long)ptr); + iommu_free_page(ptr); } } @@ -1761,7 +1762,7 @@ static void free_gcr3_table(struct gcr3_tbl_info *gcr3_info) /* Free per device domain ID */ domain_id_free(gcr3_info->domid); - free_page((unsigned long)gcr3_info->gcr3_tbl); + iommu_free_page(gcr3_info->gcr3_tbl); gcr3_info->gcr3_tbl = NULL; } @@ -1796,7 +1797,7 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr3_info, /* Allocate per device domain ID */ gcr3_info->domid = domain_id_alloc(); - gcr3_info->gcr3_tbl = alloc_pgtable_page(nid, GFP_ATOMIC); + gcr3_info->gcr3_tbl = iommu_alloc_page_node(nid, GFP_ATOMIC); if (gcr3_info->gcr3_tbl == NULL) { domain_id_free(gcr3_info->domid); return -ENOMEM; @@ -2245,7 +2246,7 @@ static void protection_domain_free(struct protection_domain *domain) free_io_pgtable_ops(&domain->iop.iop.ops); if (domain->iop.root) - free_page((unsigned long)domain->iop.root); + iommu_free_page(domain->iop.root); if (domain->id) domain_id_free(domain->id); @@ -2260,7 +2261,7 @@ static int protection_domain_init_v1(struct protection_domain *domain, int mode) BUG_ON(mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL); if (mode != PAGE_MODE_NONE) { - pt_root = (void *)get_zeroed_page(GFP_KERNEL); + pt_root = iommu_alloc_page(GFP_KERNEL); if (!pt_root) return -ENOMEM; } From patchwork Sat Apr 13 00:25:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19C6FC00A94 for ; Sat, 13 Apr 2024 00:25:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6E096B0096; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B21506B0098; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9724D6B0099; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 75DAA6B0096 for ; Fri, 12 Apr 2024 20:25:32 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 412CD120FA7 for ; Sat, 13 Apr 2024 00:25:32 +0000 (UTC) X-FDA: 82002614904.19.74EF7F9 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by imf07.hostedemail.com (Postfix) with ESMTP id A23E240003 for ; Sat, 13 Apr 2024 00:25:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=lxghCS30; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967930; a=rsa-sha256; cv=none; b=xxtp9PcrbuaSug21yt9F+rfqujH1upvG62EBNq5i9wW7JoCkG2IJcFV52rPPKKAomjXMbP R9IZ/tQFTirU4lvZUDBlRetw0lQVjhZ0OwXGzetAI2YKcNa60aI4LiGNNW4S1GXsBDeado bBFDLJ8DvAcApKSfioQZCrjjf9wA8NM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=lxghCS30; spf=pass (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967930; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8/4w+T4tucdgPG/H173cldAS0HyQQ6sjlO97Kz+1k94=; b=5ktK7OImjluwPN3cuI9RwcwfFXhnWYVOY4NBZhwIw9ITcCdSoC/kR6imfgmh91Gwr9Cz9H EKDh6N4KbYfjDsFRIrbz0b3/71IX27i4qJZiRYkGma4ihU/HGs9f3JX93qAEwEv0/+0NWA 8dfReWfQxbibg1hQE0QN6EO/3ZGsisI= Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-233f389a61eso356024fac.3 for ; Fri, 12 Apr 2024 17:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967929; x=1713572729; darn=kvack.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=8/4w+T4tucdgPG/H173cldAS0HyQQ6sjlO97Kz+1k94=; b=lxghCS30yGQUUy4mqwMothErQKLnzUfC+hIR9sPIZcMGQnbVZ1XJCH+8GBRrrxX8m3 Q5L9WN0yJTgMBn2/BltfPmo8+oYxzgY8kJDe9HJd0uqvDoNJceRtl/4MXXX7j4mR+jbx sx8vS/sGLxE3Rel7NKmcddpySseEAlKgZ95yzAe6TK1JGa1xPYeTi5pM7ItoJavsOFx1 LqWyjr/L4bU4Tc7fIhkmT6aBeJPxPCpRLZTw0B71OeocYQn/WIfgJHWwMq/gYGA/5ex3 THgp8qljHm8do1924TpBGe0d7FjfkRtVFbQQLZ0eHlXrRolLH/080ZRsj2vj8tmjBR+L YsTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967929; x=1713572729; 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=8/4w+T4tucdgPG/H173cldAS0HyQQ6sjlO97Kz+1k94=; b=o1JzLSZNtUuQcV1lujSsh4SWOFI8kLUbpe4916Z8SOo7DUcRitKunT9s68NYW0leQo oKP9zIDlCo0p4kWdNzRtAhsNaglWkURkbBok59VfACd5ziO/0kZjVowIlzuHlYL5iQlt Sy9IQytbjaw7R0RBnPGgfJrThhd3TxPJY958ZHDz6JkrFWotgYkcRMChHSUO0u+nZltv iHa6jUSiRS9886UW9NwSaAa0qhDV+w6NlMhPMVuKU9TCMiy9OrueNJKqvlWiSme57TE/ MLObsTCJfsCyCm8jYFlLsRL6UmE939Abf9M51rous7c/0q/PrKycUosimjDcU9YSUm9H bzEw== X-Forwarded-Encrypted: i=1; AJvYcCV4VZ5I0gu7BJi7/mEoMjn4l5Og628uwEf7fSR8raBr138SXdjqWrejDISqu0vkb87iqmp4oZ3IDGDwnHRud7mCJas= X-Gm-Message-State: AOJu0YyPioFVQmX93leUTaFFd2jSLQGxwz2vti+n+FI+ULyZRQWGDkfi aDAThlUBTjIiRuqWlqZDtRPPdwh3zUgrNSpU2QJdTDz6e0s2Yr8G460tmzKdxxI= X-Google-Smtp-Source: AGHT+IGQ8QPk+98rhr31FfHy1KfwN56vAk+9hMwwlY09C3v6VEVpJ5zGBKiShhcihkczGu9koLGDjQ== X-Received: by 2002:a05:6870:2254:b0:22e:8ba0:921f with SMTP id j20-20020a056870225400b0022e8ba0921fmr4264166oaf.52.1712967929611; Fri, 12 Apr 2024 17:25:29 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:28 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 04/11] iommu/io-pgtable-arm: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:15 +0000 Message-ID: <20240413002522.1101315-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A23E240003 X-Stat-Signature: ihf8yyqk4t7eobedao9gasjeery598cg X-Rspam-User: X-HE-Tag: 1712967930-779653 X-HE-Meta: U2FsdGVkX18JR9qy40wgBQm+5jVaVjL8uilBa+JXUFbcp+sZcNBDnrJyCWIpf5FvKzGkDY75JyIJzpHX3k091mBlWyqy5zppvW8cLSviBDlLlh4mdH4YSSpZu9uV6bTmwIq1D/rK4SkyMMt7FE7GoTz9iHaWP6vUHaUHUBP6byreeUp5KHak6reauf8rkmLDz/N5GXNdj7Ck6qo37+rR9iEpRpPL5PrcbfbIEH0l6cCUtgDcEM8kNDQmWWHf4bTBqmAKk4zVKy1uScn6hFNLEd8KhCPfFO35JEaA70+r0gDF2Do9B9XAJBkdAIk+wagFLt5TC18rF/QbAPwSgKPXNln/GoS77Xpwd1dvUODwsdIfBaChfkUVulD0usvwapXLqrSz0x/I/AJQdtBJQdeHHTGKaLAAWmBAw5yufxdexjAjNnDXA509wTmV8w1EGuxSJiYGxt3flZ66FxIWc6lVsMrdkaSHtkQXYf5eErIzsl+jtpa+PMa2qbUJrEkfQ4hCN3G+KteF0ixRYKlL+1kf31Z/3CiY5Wx2Ul+tjyUZZWG9CzqUQ2/pvtMkp6yT8NFH+6Eo3szz3yOCmKKVPv5H+wuesvrHGisUMO8fwsUMrxLyEXcvEx7XdG2iKgHBnw9mPDcz0UCynecoJV+ritNjTcL8r6IxPeBDpxflg4vzIXTV5VmSzqvtHGMG4Qokpw8hAmFP1hxllUiRVV32A+7AuWjXXjDF8q1so2H1GL8/bnKS73E9luNmBnQ3CuIsKc19aKG2VcASaDNFrVYW0hlmGWhnk8mR5IrdAL76QuWsDz5HeB6r48H9gBjxJOWKM0M/WD38e0hrtHUw20orHNXdfDw3ZbVvMIab2vHBbFlYX/tCQZow/Eh/QB1Lqnfrcst1KWov/NuR3Ku7JDDu5EPOMUULSglKplMcDRZE4vv3WhqTVgsmI7+tJiU2J6vFO3GJmxtTXnlTAId246RGEcp 3z5yY+Eg KWyl1M3TBKXfe/s71oObCqkuWip5xR5dKCWiuc5i2q4K1n5Nv3sY9E5svd7AOTqagEWnUbVlMQD6F44vVSgkK7u5njUqzryvRxbNLo2Z1UHviJMNg4u2xiUp3woLncOvls3RrzyhnRt2TuQY2CgiJA1neKMcowl7vti7RT/UF2HOZBJIoQbM3JoIof1LekPsKW6ipy/QEBF5W0St8Go4DBKlCgSOlNXIZKQuO2pPdE8xdfH4HvYwjf89xfw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Tested-by: Bagas Sanjaya --- drivers/iommu/io-pgtable-arm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index f7828a7aad41..3d23b924cec1 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -21,6 +21,7 @@ #include #include "io-pgtable-arm.h" +#include "iommu-pages.h" #define ARM_LPAE_MAX_ADDR_BITS 52 #define ARM_LPAE_S2_MAX_CONCAT_PAGES 16 @@ -198,14 +199,10 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, VM_BUG_ON((gfp & __GFP_HIGHMEM)); - if (cfg->alloc) { + if (cfg->alloc) pages = cfg->alloc(cookie, size, gfp); - } else { - struct page *p; - - p = alloc_pages_node(dev_to_node(dev), gfp | __GFP_ZERO, order); - pages = p ? page_address(p) : NULL; - } + else + pages = iommu_alloc_pages_node(dev_to_node(dev), gfp, order); if (!pages) return NULL; @@ -233,7 +230,7 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, if (cfg->free) cfg->free(cookie, pages, size); else - free_pages((unsigned long)pages, order); + iommu_free_pages(pages, order); return NULL; } @@ -249,7 +246,7 @@ static void __arm_lpae_free_pages(void *pages, size_t size, if (cfg->free) cfg->free(cookie, pages, size); else - free_pages((unsigned long)pages, get_order(size)); + iommu_free_pages(pages, get_order(size)); } static void __arm_lpae_sync_pte(arm_lpae_iopte *ptep, int num_entries, From patchwork Sat Apr 13 00:25:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B82C2C4345F for ; Sat, 13 Apr 2024 00:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAC4C6B0098; Fri, 12 Apr 2024 20:25:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0D786B0099; Fri, 12 Apr 2024 20:25:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812556B009A; Fri, 12 Apr 2024 20:25:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 602606B0098 for ; Fri, 12 Apr 2024 20:25:33 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 24D85A1053 for ; Sat, 13 Apr 2024 00:25:33 +0000 (UTC) X-FDA: 82002614946.18.8374638 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf30.hostedemail.com (Postfix) with ESMTP id 6546580011 for ; Sat, 13 Apr 2024 00:25:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=cNdP2DEl; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967931; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BdzMORim0dHB7uEOtMEVFDL6Z2C9ADZmlFONNgiqMWY=; b=0gXTAWHQBagCDN9mxAlO/GgC7+hPY0AnvJaPewdaawu6sSmR6rUgcyloZdWkBKt623wnql GQ/BvRnjMKD6tfWmSyCoiasRuDogdDdXUOIZRFOd8Ha2//N5LWDmeem6UX/b7pYCUXCI8K Y+b4QbmNQV2b9xYi93HBAHviUB9UD6c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967931; a=rsa-sha256; cv=none; b=geL79fWPfTcv75UVB9wPrVLbLidjqTeyothJToiCbdwWF0X/OmFqgK2kVesbA7fxLH6y6h giwi0PfCg5ImMNTme1P/UpOHouEgxAwpXwg86nT9YaMCQrjLrWslZTdziGuEQKdFk33TrF gAi/uzJsGCCAsvvzhoy9PDOTQcyQ3Zs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=cNdP2DEl; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-78d677dca70so95746185a.0 for ; Fri, 12 Apr 2024 17:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967930; x=1713572730; darn=kvack.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=BdzMORim0dHB7uEOtMEVFDL6Z2C9ADZmlFONNgiqMWY=; b=cNdP2DElR/9VYlz44ZcDBRN9bMZTW+VQpO63mK4Foe5zvoEHH6g66GwB2Alp0ju3Xh /z+sWAcX4p05QIuIcT7OCELUU+SP4mc1IIBbR+gcGhu3MEyuyVNEncDCFVL1Mg5WzrF1 1a3THVsRVmTCXvwuQMriPPoqSlEDr+ZJFObDGl/IPB0GUcFOLnBoyx/u6QxemwqFvz1J dBxovrIreRBzfzITg4Y3VZQgx0BwyUUCk/Tg6KD3mtXjVXdrfP9al25IszEIrpJC+bKK 1wzXq6S+WLf4hpV543y44DHVgSsTfKBeEOEDBK4jsUmdbvS42aY6vi3tMEYOQKnlz+bX w/bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967930; x=1713572730; 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=BdzMORim0dHB7uEOtMEVFDL6Z2C9ADZmlFONNgiqMWY=; b=MLq1kTuBnYiXRxqd/mnblwM2UpVLgaDy1DZF/d1HuEyUeW7vqSWNUHjBAlzkNxQAbk qz2U6QsE+9+dyk3qn3aH9wLLc42+OJoJyOrqYJddxESgGbnPJd9yhWEwc+dVEe+HEvKp tcGjuAW4ZsgNI/t340tMta4HoGcS9C0RjWhzUFmw0tAej4Remdlj5CCGQi+Mteg2Lylq InWJxMulbMXMfKc2MUAdJRPxLIyzToyG0rlM3FnIdWdASo/DtJ+lI3EE3fJMgVvujufS Tl9iWEIep7y96mhp0JxXcrg4uWWKFVr5DpB2yaueKIHyAKZMpOhneKCRPdRFjUQrLvLL CCIw== X-Forwarded-Encrypted: i=1; AJvYcCVK4YmBQbiNmIEW/1EMVEqdYhsyeYClNYiw9b4DJmxaWzmyaGXiHnYiPHRVtjrRPNjwO6UIjpkm7/c0XnrH4tbBtEI= X-Gm-Message-State: AOJu0YwXPAbXkXjRyk7N5+dHm8vpve/AxPxFXvCQGrM/JC8IgF0vRnnp v6BEB04YqLTQgg4GF4odk9yUh3YO3XZOv+fx8SGugQiZB0aylcdLsgPo0Eh8h/Y= X-Google-Smtp-Source: AGHT+IH5Os3iRz2ANP4F2z0zw+BDU7+6X7QWkqdDRIDhPQUP0t1/fto88yhC6Si55lvEExsYEHVs9w== X-Received: by 2002:a05:620a:28d6:b0:78e:d7dc:44ff with SMTP id l22-20020a05620a28d600b0078ed7dc44ffmr198409qkp.75.1712967930559; Fri, 12 Apr 2024 17:25:30 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:30 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 05/11] iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:16 +0000 Message-ID: <20240413002522.1101315-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6546580011 X-Rspam-User: X-Stat-Signature: 9inr8o98gnebb76ah6wzekzeyahthjdg X-Rspamd-Server: rspam03 X-HE-Tag: 1712967931-324773 X-HE-Meta: U2FsdGVkX1/NyzKtqW5vNf22MJ6ZJqTdX1r+TJ985KYVqiYP9a2q3y/E16vbVktfwxumZREbMNRn8+UtN0czmwnWqcFJ8NOCbQ818CX8Hxv3BzOs05vzJ02IUuzVcyHe3dWlBTiW1AypBe6EfSDze3kCwDFLr3a/ARjs/gRKq6Cbm7gjnhRuBu8jXi2duuWDrRc+4BAwIpZly4lkXvIPO9qR2mPjZIxXbYxAO1Na6ER/nF3XWmnEjEq+ACzPNY8dZpimsJxxWIthlOZvbPaK1EAfWFjZXNntrlD04r8PwBVFNXskLrnqMPvS8Bq0/gRzfbbanwLG73DDLOcaVhOYW0Hzos/rd8uMl3ZwPvuy1PIKXJS4ktHRhaGYhaqoKOduyVpOQ7Abz6zQ2ta/PKZMxPxhUbQALiMtbqIXeuKfd+mj5Rwcavrvtr3Tsvz8ifHEtYzQFCj8rqQiag6/GvUPLONfrNBqrJGhq8oQM+39xR2QVpy1A6JS/TDj+kipVvUZBj8iS1CEU3wWS/N8Fn4kRONaJDe07Wzu8WnKuWu/u6VoF1T6lQxPyTLE91VYRy6ChUom2taQUVg5n0nWQd6njTAjvv4da8jseQCLu6rayIXcUzz/9AQ256WpLVdDhf+E1PO2jiBk+XHv9SAKFZu0egC6q6mjsdc8QG//NyfmLp4geFV5anaxxzdsrKEfVd7fWoBOUy7LeXQUJrcrsuynb+FwPHcPZJbZ/5sjo76Cqb1LuEXuSFnZuqPU70A3uFv9+9ah+nYtoeGBxcLTBUEklJbYlBBiNlnAChHj95PwJc5gHaMKetpHIuhiijSNr/DVZVyRXnegB4NoFNkFzGA1cHt7x0hAFmxTaFyudVV2jdNNk5R00Y/3XayjHTdmvPSmpbx8Bze4s4KQIz0B8e1Zo1PYybIhm/OcnOtS+AMMI+5zFAw3mNNOk6jkBS3TzTQkEhWnDfXOBcgI9aWwNnb omF9RagM L6K9RBnqMK6DvBqTO5JgrnsGXw42Fen/p0oWVmnF3Mpz8a6kSmGPjeOJRCRIvnu4p1Q67yoReyCh1Xp6dz8p2qUGXPZ0dqWEKWeMdFCPsmcfcdxRNPUVifRZXO/PIEUBNc99at8ihgXfifPmGNb0x7GCLvTWsCQ4DJ/wsZ9jh8AH+3rNbglHPjy4ZjdqGo0Wek0u3OIbgRbg7SRHf4ZLHNjWRxegc1+pzhJgxIMdX6vBLvCYmNOehgc73unuHnGP9KLkQXLTn+TlGX8aa1xAq9AaSu8oEBKBEBY/LRHpdAWGcUJZ75/znAr4w2sHjH6QEKY5aZNAUuqxB/k3f6ERBLGiSEX6Hggvaia+jWifzvf5l2AYQdGg5TAYs8HtZsiqbC6h0O2FVs3io2SdDmFld+jkaJLfaS9UP70taYbXToJCktHSPqm5L/M3EX61FcHbY9GridK4H/YxLgctUXGr/l4ktuRhvVaw+9N5AVBgz2cXtwZx+Wvnow09Q1zrPm5+VJOUpsWwJ/TCK9cUhuT+vln3cBMdgjH+k4RZvnZOvKhcvNwJ6m7XnXketFCf4pFOsvUHPpb8bPSM42EVl+heLTcT0V4+H2++bWAMv99Rm0bVAlKyznQZir3ahIkOs2FCROP+I X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Convert iommu/io-pgtable-dart.c to use the new page allocation functions provided in iommu-pages.h., and remove unnecessary struct io_pgtable_cfg argument from __dart_alloc_pages(). Signed-off-by: Pasha Tatashin Reviewed-by: Janne Grunau Acked-by: David Rientjes Tested-by: Bagas Sanjaya --- 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-dart.c index 74b1ef2b96be..ad28031e1e93 100644 --- a/drivers/iommu/io-pgtable-dart.c +++ b/drivers/iommu/io-pgtable-dart.c @@ -23,6 +23,7 @@ #include #include +#include "iommu-pages.h" #define DART1_MAX_ADDR_BITS 36 @@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte, return paddr; } -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 = get_order(size); - struct page *p; VM_BUG_ON((gfp & __GFP_HIGHMEM)); - p = alloc_pages(gfp | __GFP_ZERO, order); - if (!p) - return NULL; - - return page_address(p); + return iommu_alloc_pages(gfp, order); } 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, /* no L2 table present */ if (!pte) { - cptep = __dart_alloc_pages(tblsz, gfp, cfg); + cptep = __dart_alloc_pages(tblsz, gfp); if (!cptep) return -ENOMEM; pte = dart_install_table(cptep, ptep, 0, data); if (pte) - free_pages((unsigned long)cptep, get_order(tblsz)); + iommu_free_pages(cptep, get_order(tblsz)); /* L2 table is present (now) */ pte = READ_ONCE(*ptep); @@ -419,8 +414,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) cfg->apple_dart_cfg.n_ttbrs = 1 << data->tbl_bits; for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) { - data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL, - cfg); + data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL); if (!data->pgd[i]) goto out_free_data; cfg->apple_dart_cfg.ttbr[i] = virt_to_phys(data->pgd[i]); @@ -429,9 +423,10 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) return &data->iop; out_free_data: - while (--i >= 0) - free_pages((unsigned long)data->pgd[i], - get_order(DART_GRANULE(data))); + while (--i >= 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, void *cookie) static void apple_dart_free_pgtable(struct io_pgtable *iop) { struct dart_io_pgtable *data = io_pgtable_to_data(iop); + int order = get_order(DART_GRANULE(data)); dart_iopte *ptep, *end; int i; @@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable *iop) while (ptep != end) { dart_iopte pte = *ptep++; - if (pte) { - unsigned long page = - (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); } kfree(data); From patchwork Sat Apr 13 00:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E595C00A94 for ; Sat, 13 Apr 2024 00:25:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBD386B0099; Fri, 12 Apr 2024 20:25:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6E2D6B009B; Fri, 12 Apr 2024 20:25:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 997B16B009C; Fri, 12 Apr 2024 20:25:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 795AB6B0099 for ; Fri, 12 Apr 2024 20:25:34 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4505616104F for ; Sat, 13 Apr 2024 00:25:34 +0000 (UTC) X-FDA: 82002614988.28.AB18883 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by imf13.hostedemail.com (Postfix) with ESMTP id 8B1772000F for ; Sat, 13 Apr 2024 00:25:32 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=zhNMZ7x+; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf13.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.210.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967932; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=63yVyQgEqo2cT7rWVkBtS9/N+xrka1mo9DBNzoSqbsM=; b=ljGTlTfFTTUkurkdpUR8L3DvZmbnzrU/jqtmiXjyFMG+6PWc5KCrgFj+7gA24h8zQkhcdf WRjbbhT0I8NpchN7FsQIuGZRB2ssdvBX6cXUDp+abhrHz5KPyAwOZmD42kQWz//tvZe2uc MgWbAqQK9XXPARk1wWFpzyZZ0MOhNWk= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=zhNMZ7x+; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf13.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.210.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967932; a=rsa-sha256; cv=none; b=FfiF90CGDhjjPz0BmsMXd9INaaJD53Z6us6lqLNffuaPBFCyCwmSzUq01l9Ot0kMiXuLo6 QGcbZ1DbyRybCq/tAIoY25G9VjB2hgNZnA+MYiUa6u+LKIYpfxOSKChKKASqzT1rGdU2kH AXKIJ+SS02/Atytm5d6G6rZ+Jr75kCw= Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6e0f43074edso1069062a34.1 for ; Fri, 12 Apr 2024 17:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967931; x=1713572731; darn=kvack.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=63yVyQgEqo2cT7rWVkBtS9/N+xrka1mo9DBNzoSqbsM=; b=zhNMZ7x+ZFqD0tqloj3hrq9BZtWH5GSXx/bdZU2EPm9CE52LZkHQ7vt3MP237Se3yK 1oC2XLka6c5ME0my/9TTTKawIyxoSIidwRlbekRLyA9ucf7Z8R5i9IEUf8NmdpvLZchg nIC6YHx4ghSkrpMu4drTAfP4rCk3sWL5NnrfsLDasEDMUxNpGe7Cz9e/MxSG1TLTqMwN /FgBnlVAJOenWxAl8CUSVI3gbH3zDT+V5y5S3iBy6wdlfndmaemG+cavJ93vft7hZTbe jrqCgj03rDb/LL4nSg4Ez78EwMZROzyUpqb1LMXR1rFqEaZZ/scDyq+TPqU2+eYnsxh5 z6Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967931; x=1713572731; 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=63yVyQgEqo2cT7rWVkBtS9/N+xrka1mo9DBNzoSqbsM=; b=cSuIaagueLnAvBKc4HbFf4huI+bfGULAaYkfCY5iA5hBN1RKAo9VC2bEZghR2eByox BIXX9GD00M4VNOaWa6akWBmdgcmQyHLUgMQZijmnvpR6n4W5YLD1LhsSYleTRs1d9tds lBoBMOwOfU6X5vcwVsiX0BdbOJzUnrZsOvhJ6J/+OWEjNTX8qzVXRL29BnvuhYmQPK+E lJ+ggTjvB0J/yxVoew7ECWrG9xElO2F0chK4fUqjJWE6j2x4HeVyTIrJdJ5vxrLxQVxu 7lLvayJS65j6I8AdVEgpX/USLgWUfsJ97q64g00KQdM0JQOg59+9t+1QA1qTX5bDDvwH FKWw== X-Forwarded-Encrypted: i=1; AJvYcCVP1NrQTcEMKMrHAiIYvAHcIS48Rn3Ure7kZQys2EmvrfAf7GdPPF4SsTAiLVbhTssf4GqEq/a0z4+yPLtgz8QQwCk= X-Gm-Message-State: AOJu0YyrqufcbqANS/py496SDIxVhC/G83eWfOBH5GeaNJ4EtpSHM5Hg UqcgoVEQ//8VSPCVqnY7N9HQwuAk4VmQaeE55KJzZS4ggzERcW1My201UZ7cvUM= X-Google-Smtp-Source: AGHT+IGmmSLufriFZ7xkUlQYwmHrJvWk6RRFIShCPmF9PtgFnBnMl8wu2EFFWe8ZzLIq79vC6G5l9Q== X-Received: by 2002:a9d:4d87:0:b0:6eb:5654:d77f with SMTP id u7-20020a9d4d87000000b006eb5654d77fmr4234028otk.15.1712967931426; Fri, 12 Apr 2024 17:25:31 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:31 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 06/11] iommu/exynos: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:17 +0000 Message-ID: <20240413002522.1101315-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: r3ekwko163o99j96yu5w6w7bs8donkha X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8B1772000F X-HE-Tag: 1712967932-392339 X-HE-Meta: U2FsdGVkX195T4Ou259zW39Is/48gW26XAJhrcJ9VmD7H8RfDMzShMwJonqnZLv5i81QakJUHQujzS8cwScglLGM+NE1CNdktCjMqAj1TnJukBCknaWGU3p8KKoXktY4Slgy6O4s5O9adieMPabfdbN905p0ih57hfAORR2OsegPi+ZjIYxjXBGWjoQXf1etvT5Ncl8XMwvJgf39zLNNvFrgvRehphVMHNRbfW6R5PdiDxsu88BueKr+0q2NXl847JOBidWQRmI0GE3WHEyWNmR5iyKmqTXveYfNaP1W92nvZq3jWai4FBpg+pKL76STcvIJtPSxpf+l1i/DLr05+TpoD5KksTymiTPPYptVw47Xlw58BNCZc1lX4cC0JK0axIE1iHfxfuaiC+xRDNtdD75ZM8vUXuwq1h/x4o4Oyk3mkvrdcnb5MPjfn4g84nOl4HO/Oi+J04j1ZIvdCSK7gEF5L5Dt5IHyO2PwMmBBCE02oo+OwcQcCLwjwzWG8keUwWm+6BuEhxrBkR9pX/ckT39lKgppzksKFuGrHfPQ0AG5wiCvBHJGXlkd33FM81xPO1WmKh7il0flhrbynWyl5Y3eeUWha20lonVZD9GjAynG+HBrqIPqU9Si149pQxuo4A5u04UhjbqbNS3qLMyfBApDzYypYBuaUcopJOtx8B21LXCXeejECvKMPhU1E90v95HC6TRg8TgOBueqK6IOQ0EP3tWlyuPV6bVaUaCWjRZEz5sEc4CYCPEJ+epNWY6UMMC0qWH2wCXVK7NyNtDTLa7k+5QEhBmlzqUKRb2MCTerVW4S+pHLNi7a3LY9EYKE4bB+ouONaFQJKmg8VeIuluEL6CMb+SbiGMQJ0QxXapAGYPolSsd4FyKmjYTecFwcvt8SVw2w+Ii85Seol/W1cJ4/qQ9268CX42VF7boj2S5DYtkUNTy+yzZ6nI/YCznhcZKm1OS0D4XKpYH18JV S0dhGAMR LS2mtD8WXhQHc4Yedk2YPQR/9hzuhhURRVONYhVTC46dIYo4g08+WXP16GBD/0hpz2COpLYareylvm8YASNZE9pBmR8aCZ+CWpaREe5DEKQyEtuQ3MSWb7LyC6VLka7e48pMrSK1ijztt9EU0/LaMASf2Db7z1GM0g0L60oMNfAZK4kTw3fizdzuH5sewct63bNShErskk13wz4egKInZAA1Y3WQV8jVSYy9ngrNi1mRqI0/xCUMSODVwG9DsOg5KSg2/zLWJ9DLLni0xNGG8j4W6SUUFAfn6CjYf9sf0VJDTEqgABQb6xU9EEZuN0PJWvvArIkh5P9Z2BO5AF8ukEGZXznXukItlcjRFl50v0c+qKfOMVO0OD6rlPDOeKFbpXg9Xwo7Cgsnp3yxv0TTWjeafCxW7A1nSi6VrRxSMQRNsTWHi8pNd8yt5QUC0VwNU9a6djcULKdVZkI9CmyO/KQiYqr/Z0Rosm+2FPuFMQQammNwN8oO2kuetDd7tNa/autWtzZxJexXRaRqd21HGwOIFlm1TtTmAo/Xim8FUr5lw0nLzyc6xu1k/nZaKKJ1qSp5ifU3ZZdsGcJR0ZYTCF3nlsg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Marek Szyprowski Tested-by: Bagas Sanjaya --- 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 d98c9161948a..c666ecab955d 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -22,6 +22,8 @@ #include #include +#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; - domain->pgtable = (sysmmu_pte_t *)__get_free_pages(GFP_KERNEL, 2); + domain->pgtable = iommu_alloc_pages(GFP_KERNEL, 2); if (!domain->pgtable) goto err_pgtable; - domain->lv2entcnt = (short *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); + domain->lv2entcnt = iommu_alloc_pages(GFP_KERNEL, 1); if (!domain->lv2entcnt) goto err_counter; @@ -930,9 +932,9 @@ static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev) return &domain->domain; 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_domain *iommu_domain) phys_to_virt(base)); } - 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); } From patchwork Sat Apr 13 00:25:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAF6AC4345F for ; Sat, 13 Apr 2024 00:25:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C369E6B009B; Fri, 12 Apr 2024 20:25:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6C3D6B009C; Fri, 12 Apr 2024 20:25:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BE266B009D; Fri, 12 Apr 2024 20:25:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7EA3D6B009B for ; Fri, 12 Apr 2024 20:25:35 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0D1C280E68 for ; Sat, 13 Apr 2024 00:25:35 +0000 (UTC) X-FDA: 82002615030.19.6A21AAA Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 42E2A1C0003 for ; Sat, 13 Apr 2024 00:25:33 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=HuEQA6BZ; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967933; a=rsa-sha256; cv=none; b=AVzbt31+X70Ojc6mbSJUv3U0bei0/f67buYeGXe0PZBPvd5aQO4HqT3v/8aUFGvNMYWniL hMzKoT98ipvRJfWW7qJQqyGEyGGntpNOsNjAwI1fIuKBEQt2/Q+i8jd7gEtm9a9s4eLdjS GhtlfElffjljW90jYTbTMMuGO/6Xr+c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=HuEQA6BZ; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967933; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GxsyMTKANsChLuxDrkmJaktgLM+pVsQuG3GqfblYy+c=; b=mFhH3QjJSWCGZvmMKg/wX1iR7BCWz0QLq6CNYSLWUYSve2gXYigA5jmaqK/sjo5WPj3Bj0 U42xra6A6IYeVYc/DCoVQa0/TuH/4KTuZP0JFv5saAqIg+rAR2BGD3CVXAwyhnWnmKqiTb uggr+oMYnK5zvo5jBq1H8m+MOqRKc68= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78d777d7d1fso86384185a.1 for ; Fri, 12 Apr 2024 17:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967932; x=1713572732; darn=kvack.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=GxsyMTKANsChLuxDrkmJaktgLM+pVsQuG3GqfblYy+c=; b=HuEQA6BZX2frwhrcntbdoBSL9iphrqEnXZeyPyKO6UhXo6FykxGddQQ+6HvDVEr3/+ M6M1NQWYUmpTjj5T7bwQUZjvqHNEQYY+zSUmc0JBlSacnSjvs9LR+YtwFuJ5zzxkkcMt 5+JjVK0Qxj/eh4SbbzKnZGN93cXdcSwYtQ9dw5XIflgV2cfz85sCDKkwk/GLgPFweFue NfqVXyHEszAuYlIJ/ZqWg1HWz8Qu+bqOzVhEAkm8Lpe+9MIZpgFeZpdSG+HEKd17PElj zHjb1iN25wTKEwqBTr971+gzHVlAs3vyrgLAd1ULLEZN66U0/qy/fMSrPPsUEYvOOrjM lfWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967932; x=1713572732; 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=GxsyMTKANsChLuxDrkmJaktgLM+pVsQuG3GqfblYy+c=; b=gMxQzRcFpMzgyrpN1bgTZiHgb3BWyzdCgY/xG3nzqv4tLy/dKdK4cFrFub4kTIgWL3 WQwoM3/t1N4+6Fzqz2Wnd7dFbcDPRavBbmhY3Q50a3a815PPYGgD+ZHiwWsxaPPMwDuQ f8ciBZ+cTd5KiDOhTXxwGcJ08JN+sb3Rb3Vvd4x3nmuvkWJ2mzB5GYjlWFaCTmAitfi9 fawFKfHHAp67I/60Mt/43tKvaya0/PSklrAZdXeRHRNrIvTO5B2DiDFGMSi6Wx86m2Hx KjFGE4Q/hi4eyk2+nAByi4ScJzmmeP7Dll5WCSAl9lkwiiZnr2QIZm7vqZ6DuWl5ZCBR XM9A== X-Forwarded-Encrypted: i=1; AJvYcCXbnWsfwbd94MQvypne0Lp1Usv0/T9dA5cIN9vFzYyisl4MvIqijEVaEiHTwu1gnRl4SySI9RG6dAGa74OrgL8EisE= X-Gm-Message-State: AOJu0Yxsc7nrWw5BA3zIbvATdeDCuzFyr0fQl1wxAugpYWjn8gbkO1/K lYFul3Wp6wkVb8NvgNlWrNXa8jRHdhusaabqf54bmzp6k6/kRBYdE6B2V+dQaeA= X-Google-Smtp-Source: AGHT+IEkNWXvNi+BSDc9at/eU/P3rQB2xk7v0rRabM9OChaVToo3gqnYxXYIGwdXJVnOXaB2E6eCQQ== X-Received: by 2002:a05:620a:45a4:b0:78e:a3d3:eec1 with SMTP id bp36-20020a05620a45a400b0078ea3d3eec1mr5189213qkb.47.1712967932439; Fri, 12 Apr 2024 17:25:32 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:32 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 07/11] iommu/rockchip: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:18 +0000 Message-ID: <20240413002522.1101315-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 42E2A1C0003 X-Stat-Signature: o9jqx6i7xpjepeb1whgkdodr4cbnsb9m X-Rspam-User: X-HE-Tag: 1712967933-114321 X-HE-Meta: U2FsdGVkX1/hoO+Aq4si3QvFCShg1QfjSd4xn21ezq4TM9/G9UI+VojVgpt414qjqq4rAlrnACyIk96mnBnBuVw2iUPCeoD4O2Px9kaQuGaVu/VcCYmN1Qw3pJD2U5ZH3xKsOhgY6MYI4BlVj20BbpCLBu0y2jQV11+d6PxH0VVQWdE8Z9cgOJmSTxr60apnMwKqNeAb1z11vDkX8EhHdrBOJftRXtbXrjtHZNRYvPdc8XSnUMqQu9tZ+NUfvunlN0pKbSY3bAYOXy8O0quoHPkKTbgEOKiaJd/dd/wl9oAI3SYV5pOYEXPUKMeQtzQxJl+M4pRb9BxGdS29wiDIQfVn4IVLK5rTGfK7Iwh3EdNPwpjIKiOsKCWhzcbEDB5zkmf5xDs2xBit2DnpLRKri6UuYoDQ3KfTn+mFyY/qcc9lkhRVzfOduWrflmubUqnp7hO+Tua2f2Z+UePtEOwidpexhUWzQR2Q5UNE5ugr31JsHJIGsX9igFz5wCUOR38hURBgHpDIi6Rn8EQwDNWYi2rZ1cww5Br70mkzofSWPjOOXahYWz3Vj+qTHvn5esHsHQsdgQCAwpa3GqlHx88vTzWck/2p0HRcNf5nVt4BwUnaXXfOQp7w/O+b4Y/hktcsXCXOoXeYMq8qdwCbPwGzyftt4gQPfn3/pS34Hu+4K50y1h/6/5xxkl6CSUXnq/YLTD5yEeqkU3CtG1PP+Ha/NJSuW6+T8lTo2yd+AAr21xkV13Ma4+ZK+mGwhQuR/giKt6At9gQQ7i9uDQazy+MTnKhHMQvt9LKjFTw+9DqpWJXydyb624x0B4ekz9c0eqRBgwberunjbBfiEgZgKjMD+0suZg07ns3l9/0xQlTplvMJWI3CEt6B3KfyJM24LBuUpTVG709pQsYyf4DXx3vlh1AkCZ+GVxBRm2Kg/llnXt+QZL2SNNuwDfIuQRSQbOVK91bE2tWahtUsIMh14IG oK88USEF tVMDNJfqh31iQO7OL1R/wjkGjl9BV1W6vCGKNNmBp/VhIBeoVWPiKklIcWY3KrhBBnkhkyNZhzhQM0Nn+1IEoGE5I2E595VFqhfHPD0FKmuVQz7CuBHIe41ezPGtvlNHLRck4kIfxswqvrRT6mG5m3YAVMzCh8UwstK/AF8GuHYne0+36HCr8fm+o2k6x4pQYZLtOsGAnfH5cM26qRLajmDwcURsf+K9UWuCCahQgEAi3KvQjmqKfzdejnifvsJfWRbsSxgazx4BZke3vJDwbSWp3Taieb9gZcHejZr0VhWBCIhdGkuQg2P/IercoFdF01+eL/8nxv6cKDYVrAq7xvjFIcIOZuN1kwKXmKhg02XZhUXHYR3D9BMKzs3AuZBXk0agii1ebAInCJ1voX2UVZ3kbi4IfPlNdxLqJscLN2HK+FpoEhKUguQdhSSvZyIfxqdWsykw0Y7QbQ0r5GPCF7aaNqYaVFNxCnAOA7mrWxlD/LEc3y46PePx1HNQ9coLf7PBR2uE3cg18DYvww9h/qyJamN0yXieNOpvvy46bAVAvvSFoETAQCfBtgHMUposcftke/pJ9SmUY7Hg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Tested-by: Bagas Sanjaya --- 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 da79d9f4cf63..4b369419b32c 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -26,6 +26,8 @@ #include #include +#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_domain *rk_domain, if (rk_dte_is_pt_valid(dte)) goto done; - page_table = (u32 *)get_zeroed_page(GFP_ATOMIC | rk_ops->gfp_flags); + page_table = iommu_alloc_page(GFP_ATOMIC | rk_ops->gfp_flags); if (!page_table) return ERR_PTR(-ENOMEM); pt_dma = 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); } @@ -1061,7 +1063,7 @@ static struct iommu_domain *rk_iommu_domain_alloc_paging(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 = (u32 *)get_zeroed_page(GFP_KERNEL | rk_ops->gfp_flags); + rk_domain->dt = iommu_alloc_page(GFP_KERNEL | rk_ops->gfp_flags); if (!rk_domain->dt) goto err_free_domain; @@ -1083,7 +1085,7 @@ static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev) return &rk_domain->domain; err_free_dt: - free_page((unsigned long)rk_domain->dt); + iommu_free_page(rk_domain->dt); err_free_domain: kfree(rk_domain); @@ -1104,13 +1106,13 @@ static void rk_iommu_domain_free(struct iommu_domain *domain) u32 *page_table = 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); } } 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); kfree(rk_domain); } From patchwork Sat Apr 13 00:25:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B530C4345F for ; Sat, 13 Apr 2024 00:25:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A691D6B009C; Fri, 12 Apr 2024 20:25:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0BBB6B009E; Fri, 12 Apr 2024 20:25:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 838E66B009F; Fri, 12 Apr 2024 20:25:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 638806B009C for ; Fri, 12 Apr 2024 20:25:36 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 319A6A1DC6 for ; Sat, 13 Apr 2024 00:25:36 +0000 (UTC) X-FDA: 82002615072.05.7239335 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf28.hostedemail.com (Postfix) with ESMTP id 33FFCC000C for ; Sat, 13 Apr 2024 00:25:34 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=tlzG9ILN; spf=pass (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967934; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MO45TG6xfzZsYhTVPnL09wSWtApUT5YGrrbgII3maTY=; b=IFvWOzwpOxnL6ilBRU+Ff5GnoThcIhDt8chs/mmkfmXn9jYJ+IdHoqWqd5eIqm6oqhsSD+ h11G9nZ4Q0HLz0umq3XCqYWsFtGnPlbOjlNszBRtxcx/o6OGUzIRmAiTDv9i4hs7j6sq7V ee7BeeFwmw27PPSKqOL6hdOSt2UldyY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967934; a=rsa-sha256; cv=none; b=310vxPd7bZyR/iAGApGIW5sQYOWhpqdJDP2EBqvY7iJZLBts0KIFkdFthWT+P2tEih554M 1BxlSgmDvBxiqInSp4KIkCxLV5bo6OyEdH4CKlgVC87J1430oEZ3v6tesWR+oc+21T3DlI 2OL7/U8dCo3XwxOOifzmyuwQ56mxxnw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=tlzG9ILN; spf=pass (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-78d723c0d9fso92613285a.1 for ; Fri, 12 Apr 2024 17:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967933; x=1713572733; darn=kvack.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=MO45TG6xfzZsYhTVPnL09wSWtApUT5YGrrbgII3maTY=; b=tlzG9ILNpun847s1YGhbKT3SfXmOVVZh3qUn3dGZ00wT+vRAK3FXjz6224d0oeYH0H CCBXejunYkmC3ukJSKDsptYW9rVjWBMU3UaBSr0OSp93UJhiG0U7kTLwd8hBhnu4vUC5 a63g4hbiH6tkHg2LSgce7Kw0lbKyxAIYrcVIzysPSGw9BhGJvflWBgyke4Q26KS+uRhR Fm4034TW3INDyxilNZDbUWTSH2DI/cgla9JouLq/lRVCk3XUsXZY+x1PNKqBGNSPNvZq R3mt0Okzucw0GBmvWKJ837d3750oN1BZwAXzlkXw1RJJMHcOd/RJUscQXe39lqkhYvyy yV2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967933; x=1713572733; 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=MO45TG6xfzZsYhTVPnL09wSWtApUT5YGrrbgII3maTY=; b=A6EZvIwkisc/owZ/mb0iDqa+5L53NRc1UUB1/Kldgv1GNhQSyMKRwR6Do6Uw8j+nDn ndZmCWeRosa2ZNFLJURET/cn/06usx+hXqijGwZJvbywVaCp+rjVLSzhvnif0ii3zHtJ ELbMHXEGmr2zBKu4MHvNzGXUw2ZRwckJLIKsZXUN0+V5SNIPJNGoB83gROFpyxnVymXX 2xRuuI2QDjM9byVAAyFQt5O2Ix+9t+L4eKkO1qfGmREq4abluCNxCz1HYVNt6jvoM7gg pTbrIwIjE7cmUXKXKX4AEo/PDDDLbzbJcAdP0+ChGbQrTI6mlE8eK2O45bS/hXx9THZF pr2w== X-Forwarded-Encrypted: i=1; AJvYcCX0n0niXx/jtOGa0V0wvpNxWPmR6D0JhcXalsoWXeEn7Yg7hAS3WWrsCkF5yLkGcEGa+7hfbg1M6W0UXxaFQML8SKU= X-Gm-Message-State: AOJu0Yw+a+vwYE8O0h8siEOkTtAbV4Ey4y9QiPKSw2g3xCF1G5v52vka rV0pCH9hovJRAHZsbcJasQ5lRpzPZs0gcDwjIo4zcRB4PS7BKhEPZb/QzGlQPbA= X-Google-Smtp-Source: AGHT+IEXUm4h5HemGXduoWJF1eYDhRYKVLtFqnvpNR6ns26vxx0/EdOeXta2X/OaQb67WRloCqHbfw== X-Received: by 2002:a37:e306:0:b0:78e:c0f7:54fb with SMTP id y6-20020a37e306000000b0078ec0f754fbmr4866171qki.50.1712967933251; Fri, 12 Apr 2024 17:25:33 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:32 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 08/11] iommu/sun50i: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:19 +0000 Message-ID: <20240413002522.1101315-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 33FFCC000C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: y7ma6uhp49urbgc4uuume5hw55j8q1ou X-HE-Tag: 1712967934-674391 X-HE-Meta: U2FsdGVkX1/sRgyO6lUazFou+kq7TXRUyhIqbNwi9veL907Psb3MnpWWbV9QKK+oZJRA7JnSTvFs/WdbKKLpLZUZIsSnlPjeEhNeLbTFpg9caIKJ2/gO2vlVezC4keVEJmKLO9ekNWDB87EFmUVAidz7e1jqiRlIqMSuqzBXM+NrM5efvM2d3Tlg9k5Sj+V9NT8Q4LhKZE+df38QuXX9omtE1Inbpy3vjZJt6QnVt5BOLFI+CEMs2wQsH7UFPXpFecGEeti6l2j9j5nn3s0UXtHzSgivIJZdJ2HfLhUYR0k+BuCBOPvYTg2tn5S60jX7AtDEZJWXM74DFjLJKBKPQsjB/q8JzuZCpAGvp6aLGyp+gyOuwJ41kW3TPcV3P1yOSEf41nxsrvdT68pBp65PeHGInA3rCmbYkhbb6xPNqYUPq9MlIokDTZGSlsaAyJ0NZnAe2+gJ8xFcNJO4oP0dqwGG1vZOSE3WdaX8ECIfYM+0pK8OIHmUWmmQ0K5QjoCZW9TskpsGzxBcXYB/+CYmoH9VQN6quIVjnoOyf7JFihfk7NzgQ/8Bn5IzhOXArR5mw4i47KuXHJC4LmkdK7Xn8SReOj7eBOoT2e4vN+W2tV9FgVhPNrCRyGWw/H4oXdlvUJiG7fqR94rR2hUb9Ei7ggk1H3w5Q61Z0I0nF2gHVsrk7J0JVT5qjn0IlzxMMZi8kmZN7WZxkh8k+Ub/alz2rbP5Ss5chq11SZEMu1oq6gS0jBrvhrVxu9n8yvUq50kId+7bgWOiPVcAvhLDd/8cUHCXgHDbVUyD0bKP22KK8+bLzm+BUbIPAuSPfIE0T0cgcZGQoCcCj9+NKtedG0pDdWJ41K5ef2UtjAfWIJrRN711xAJHPSkhdhfQscUZoZdVe7wqAST8Zr6YvtTA2HH84DWgg1JalaKEtLQRvd2FSRhUyfaOHxtw32bIm1k4eN4cxKivDv9pmfPddzhzZoU gLrS7GtT jhUsJK52UAvFj8l7QcsawT8knHCr4T1/eRsDwXYG5cgiDebrBaR2bbFEm4nKDNobpeLWdR/4F+eIhJRGuR++fIPtZfDw9Ru7vJLXE4BDeqqxTPFn87KF9uETbspppUYq9R0r/69dWtUiNrz7cLrQSlRzugb/NyfsGxMN/iZLCQdvQkhUC4+q1K5jY8QhHwnOtuCLHyKjbhzcFcfdK/w+BVyLHWRC7BAoIYKIyGe7RCLtyHa00NE2V65sTYJsnQqiyuEmDb0H6MHCegTZzVd9IcNuU/d8Lrz5IPfOxDOqZ0eD10ifbgF/tgc/PF7ZcXAMv1dkdRx7BnLlKu8ugCAWLFngcSDKpD9e4Exnv/zxe3dRXaZ2/17XpjBnnsYf+j1ZCdtICO/ji9fmNwJmMYo9XnyJVHslJpCs0jon0shxxbMcMS2sTk6LECChLAkdTa0oXo4MqgvJPb2lUWwcwce25KOa8zafX+OEt0EP1qaMhjqDOIAsrn6kzbgTlmiJAytH/AAI6zuCW18V8kMii24VP1LpDt8leej+ZQc/BF9lrzwsuooz9+3aSIjh24KdtNkeIXu3w X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Jernej Skrabec Tested-by: Bagas Sanjaya --- 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 decd52cba998..c519b991749d 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -26,6 +26,8 @@ #include #include +#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; - sun50i_domain->dt = (u32 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, - get_order(DT_SIZE)); + sun50i_domain->dt = iommu_alloc_pages(GFP_KERNEL, get_order(DT_SIZE)); if (!sun50i_domain->dt) goto err_free_domain; @@ -702,7 +703,7 @@ static void sun50i_iommu_domain_free(struct iommu_domain *domain) { struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); - free_pages((unsigned long)sun50i_domain->dt, get_order(DT_SIZE)); + iommu_free_pages(sun50i_domain->dt, get_order(DT_SIZE)); sun50i_domain->dt = NULL; kfree(sun50i_domain); From patchwork Sat Apr 13 00:25:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E43BC00A94 for ; Sat, 13 Apr 2024 00:25:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAEA46B00A1; Fri, 12 Apr 2024 20:25:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5B236B00A2; Fri, 12 Apr 2024 20:25:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812886B00A3; Fri, 12 Apr 2024 20:25:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 56AED6B00A1 for ; Fri, 12 Apr 2024 20:25:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9FEFFC0F80 for ; Sat, 13 Apr 2024 00:25:36 +0000 (UTC) X-FDA: 82002615072.22.260BF40 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf15.hostedemail.com (Postfix) with ESMTP id D3CD1A0006 for ; Sat, 13 Apr 2024 00:25:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=yfCiMQtS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967934; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3Msq3s0T9jYWGepWyMOjVGhKtsGemyt6YXf5qXgBQII=; b=fldVWQrkbAaN+lrXc5Ylk6pw4mHHKJB/7KoVmHRszi3CFl486JfAwMMmVQr5I3BfaR9RWs qjk5GNkzjkKv4h6lOefpUx2gPAVw0u5+sDeiAKYsmd562G+nu4SEazB88CFrDSCYfa8W8b vcLIoDL3JQwaWxmuflSgUG+cY6CwWaE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=yfCiMQtS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967934; a=rsa-sha256; cv=none; b=z8Mphb7inWNGSwS7QMsF9A6KiQTKBhKkhiygp3BdjhL2nkuJ1FV2Qh6k+9Nz6O4iRqEaCz Ta3K4vtGVZdJIZzRgf1hVvjhzDOogaxcD5J3R6AQbnxho60wYVLhxNN3pf+wNvpC30EQTF FHptKZo+ZTugmBbar+xXJVuqsQE/JCM= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-78ebc7e1586so247572585a.1 for ; Fri, 12 Apr 2024 17:25:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967934; x=1713572734; darn=kvack.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=3Msq3s0T9jYWGepWyMOjVGhKtsGemyt6YXf5qXgBQII=; b=yfCiMQtSQKH/jXbiV8qgYGLiGBOhgYcCE9xEla8kpkP12wFZKETkeQk2AlJuA6dBb5 N6n7/jC7m81CorDu2Ja4O6RZwTpXJ0Ug1q2CB2ZTARZCY+nzhIML7GYxlc7A9DGxsj3E MkzUZkL4nrw+Pkpc0sIUn2UBS9qHnqIAHwVy3wMLrfi/qe+0Z3i+1qh03bchXuIqsRsf vPc+3Hlwf9nZzjc8c6e27nFXnerZpZsUP35A/BrDpP7idQhDFxbo/2XHbzZT5stUXWk/ oY70YmNyk/E9uaXHpT3rSvvLJ8/S1107596ejMCTUL5gU2vDvXyQvFkgOUV+JKaZI7Q8 DLaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967934; x=1713572734; 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=3Msq3s0T9jYWGepWyMOjVGhKtsGemyt6YXf5qXgBQII=; b=XU81avW4tiIbclXtvymqyefYunbFRHBiSz2VKOLbFLuw+I10nreoUe1+4TRgjbvpg7 q1djh7gx4sCWk7HNz2GaDvgwLlxEOQsEg+16auS8LMCGjkx6/Qetz8kDHi5kqzC2bQJZ kvlfi9gbtTPJ7Foo2L1zAr7xkq4lCcVTfAaUqBHPraFk5nWk4lLiBdFQxajzyok3XsYA NtRrSGrx2Z7/JXospw7ruuDUNQaFwzvPZBaXAyA3GIfvL20FiHqIDwoJepZU/5+OOWiJ iCjsvfGBV4x/si9OjOpL/3Fb1R82/Y1ITJhJGA+LRJFzI82ZH4k9c1mLYP7ZoxcZfBI2 cbuA== X-Forwarded-Encrypted: i=1; AJvYcCXDA6G272U75p1IVnbF+auUU7HwZvaB8oty/u+Dx1jaKAf0/aCojAiDqvfc3CDQV0gWbztlIeRaRgHmqFcD6FHe2Cg= X-Gm-Message-State: AOJu0YyGZaEw14xg55OInSpV5fNXKEB0vTC8KpKJbYMljeKuNkTx0DMa h0D4FDFU6CcRIJlEJ4bgTEFQx9pw44rq1jdiXT9tVgVsmCQ2iA3U8PKzRPtFhhE= X-Google-Smtp-Source: AGHT+IFLWyccRHbQF5BJmQAmIq2yaafFcDxYEvTdEMzon+yR8BjvOaupqITKjDvsX+13T7c1AAimFg== X-Received: by 2002:a05:620a:4606:b0:78d:77f1:6043 with SMTP id br6-20020a05620a460600b0078d77f16043mr8190515qkb.6.1712967934070; Fri, 12 Apr 2024 17:25:34 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:33 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 09/11] iommu/tegra-smmu: use page allocation function provided by iommu-pages.h Date: Sat, 13 Apr 2024 00:25:20 +0000 Message-ID: <20240413002522.1101315-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D3CD1A0006 X-Stat-Signature: q7ondy7tg41qoqxw4zyg3stzbm11t8kf X-HE-Tag: 1712967934-983759 X-HE-Meta: U2FsdGVkX196fumsNAiWdAm8+F2ZAP8soW2ZUsMiZp5Hg/aIb4SNRp8r+epkrx/hwceaNX+FfLofLZ9mp4Qa/svTKtcHeY206bAuV8Sv5A/+/Y5B5mfy6R6JZq1MMg5ciTVL6VyjUgLOV+i/IU/ubwRNmWWz6vAKWIGeQnD0axMt0weg6hXZC2AevwMMtkoTGAVMqUl73V1VMYJ7v2AhPiPOT1du8BFIHfdaob7zCyDUEpHNdGnuK1rFehPjXJL2EsI2/9kTFDD6aBFR0kBvSrqjdnqJR7zjN9nQLkvCr4LKzLeF2EZ1vtc6ZK+l7UNP4lBbsgPSjJezezz/0aYvTpZ7XlqcHcGZ7zu5gSJlX+QkkRIQXjtsEYiDUi7aEyW9IW0Ow+T0cPb662HHSOQB0MXgrIyvy1wzaMnrrVtfBeR54g9uAUpeeeiuyzIm0XQRXBZ7zwbwxp2NapW9EIGDxjsOr7tQ1fMWggna8NpkZzCGHudenu/0MGuqO+FCh0BXOGRLxPjh1q3rxmBVKJT5pgXqgy+EgNsysL8ZUuh2DqKUIiJgUz5hkzXlxWTpdRMSvIKE6pbiK/T0e+XH5mpbCTCbxXIKHdfnk6cnQJbcdSA2nhqn2mHimeLQAB49/RjlbFFJfaT9ntCkvXqZ41PAM8pmM4K3zSxI2yuskRA8/TFtqZ8RIQpV0mMySkzzrAf+L6OfgJNtMW8lNgip8LwjU4ZroxgkHY+HBCCfFXw0AzRbxgZxKfsiZAkpdhuiar3Dz08AiAqhssnwEzkA+qamTmdi6cX8xdj8hKr962r4ySLJfDVFz7itbxByDTTozYpcmpKxdUoGl+iRavbEVZrkzdEfF2hmw9sp0jbaNZS22zye8z5YSnKMTGi2bd2vVKMQ1mrSR9urasZLyWIiwIhfvwIPr/jf04DAzyAhcsDcrQzyTM4i9Fer11q29R2i9DzODv32gIWGcAXWJ0qSI95 y8aHu8KJ kGwNUdEMZey3JbOpqUVjJDelAXoPppQNJwUCSY5Mk7JKz9prKoGqDXOZsb4z1LHUpNZVKyc5H9UTf+VE5uIiMJsOsc/8829ud2/+u3xVH1Kn0Q6rnpUVGziokwJnYgQrqI8dh10SwQq+fj3u0Q3XAhOqXAK9v/WVpd+JskkPRyJtBqsK6A02sDBM2YEsLlD1/dT/UAr6VSPwLqc6ZsOjVAwXw4KrnJ+jE0nmqHsqk8fZ9A9pdF5mHdQYE3vmW7fUBCtDUNuDcYZVubwuQmRJ85U9L7lkVDrTxFZBcYSeD7En7AApZRblk81wU7Jz2qXmioBxR+Hdu65hwwYxwQj5y9p2Z0uJb/cYRKiG8/IjRF4AtoxYRGSeTxa/me1DS0H697k9ZwqpDZxMM1b4AJnf4W9LTY7DntidG53rcvnj26oaDoXI+4hf3wlA/2rCbpS1+ms164rsnBzQAWMAk4lBCjdBQCftc2BfjVGhfDCBKpeN+Q10puKSmbq0X8otIL0KevxFmjaaml8w+oYr7wyAmFDHwwG6CSlcC64sCrcUuSVzHYV3GlnIzSWKbbhGYbBzGf25jnQZF3ES8WBudtkBK5TPUZrLFplHOTl7G X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Thierry Reding Tested-by: Bagas Sanjaya --- 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 14e525bd0d9b..f86c7ae91814 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -19,6 +19,8 @@ #include #include +#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_paging(struct device *dev) as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; - as->pd = alloc_page(GFP_KERNEL | __GFP_DMA | __GFP_ZERO); + as->pd = __iommu_alloc_pages(GFP_KERNEL | __GFP_DMA, 0); if (!as->pd) { kfree(as); return NULL; @@ -290,7 +292,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) as->count = kcalloc(SMMU_NUM_PDE, sizeof(u32), GFP_KERNEL); if (!as->count) { - __free_page(as->pd); + __iommu_free_pages(as->pd, 0); kfree(as); return NULL; } @@ -298,7 +300,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) as->pts = kcalloc(SMMU_NUM_PDE, sizeof(*as->pts), GFP_KERNEL); if (!as->pts) { kfree(as->count); - __free_page(as->pd); + __iommu_free_pages(as->pd, 0); kfree(as); return NULL; } @@ -599,14 +601,14 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, dma = 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_pages(page, 0); return NULL; } if (!smmu_dma_addr_valid(smmu, dma)) { dma_unmap_page(smmu->dev, dma, SMMU_SIZE_PT, DMA_TO_DEVICE); - __free_page(page); + __iommu_free_pages(page, 0); return NULL; } @@ -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); dma_unmap_page(smmu->dev, pte_dma, SMMU_SIZE_PT, DMA_TO_DEVICE); - __free_page(page); + __iommu_free_pages(page, 0); as->pts[pde] = NULL; } } @@ -688,7 +690,7 @@ static struct page *as_get_pde_page(struct tegra_smmu_as *as, if (gfpflags_allow_blocking(gfp)) spin_unlock_irqrestore(&as->lock, *flags); - page = alloc_page(gfp | __GFP_DMA | __GFP_ZERO); + page = __iommu_alloc_pages(gfp | __GFP_DMA, 0); 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_as *as, */ if (as->pts[pde]) { if (page) - __free_page(page); + __iommu_free_pages(page, 0); page = as->pts[pde]; } From patchwork Sat Apr 13 00:25:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71D66C46467 for ; Sat, 13 Apr 2024 00:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E08E56B009E; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D68B56B009F; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B939C6B00A0; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 99F886B009E for ; Fri, 12 Apr 2024 20:25:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 66FCF1A1059 for ; Sat, 13 Apr 2024 00:25:37 +0000 (UTC) X-FDA: 82002615114.26.3978474 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf16.hostedemail.com (Postfix) with ESMTP id B293618000D for ; Sat, 13 Apr 2024 00:25:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=uj+ZOi2p; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967935; a=rsa-sha256; cv=none; b=yCyVM/YFmlkNLdRp90F9veBu4q5JM7fFb9+MtWSlKAmh8cLpbO4pLqW1Sa90ZNBowbErBp wr1fTExpVeDY2B6MzfFsiS90UIXbDY0QCFcGfR/fyQZsMsEj7hsb2w3Ukt1IjCQnRP6haV Q71w0saP5K5yv15HCy+X+gw85B5C1+g= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=uj+ZOi2p; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967935; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=Q/3aVp8xqb6Y14CGfsafmqlJ40+M1vaFKNzWRPiz7uACP1BqrBtWUZlrQWKnmB9gDFdXHw 1QkM4oBIJS70It1xeGKmfTF1W7PJVzf81eSvetrfsmB3JobsPKrj06duMRAjUdBiSqeMO1 Gsh0RuyR2P1PDnVYnNGaVFkoSQEsOIM= Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-78ecacab93bso84638885a.3 for ; Fri, 12 Apr 2024 17:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967935; x=1713572735; darn=kvack.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=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=uj+ZOi2pg8QDjhM4wlmUkuWMZvYdlsOT/qaQqJshZNSQx4X3U+qASbX3HdQI2NYtVt onnKDsuHXS/7OF6269r0TqztVhNNwXzZIdneUje+SVZgB8Eatyetom55JD6PcxsTLWBG h3/yW90ncVG4OCnzE569DnC04z8k4Wiwx5DW29h1B4aSbj6PI2KqfaG8JCtE7QcLmvPZ pzmnLZTOyqqafSJEgQiVS7OEDg6Rn26SQnnUf/Vj+qo7jnkeyB+yqjfTqYPyn3/OT6Qy sYDNaMnfMUWMirWSUNjWSKditHb7ykryYeqrAURkO9O+yUMT9pdNxwT+Zq6Eo7AUhN8O aW7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967935; x=1713572735; 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=lsGN5WIIRNrc7OxFwMhPRXWLlVhvYQL3ZDijKX4hJeQ=; b=h3zuIUTfTK3oJQr4NAgGUUYKSfVpG4B1cJ5BjxcdpwlYC+eODu0uR4OBeIgd35yXlr xj6hjdHeBd4qPotErQSY4BPoHmnJb47HBYezic2chBM6hiKtbEgoo/83F6k3BOW3Z0zN sXQ92YEID2x468mq7wVKlTZ3bjoLabbLmV+x576TnSFb/kegSYy60OKbIEX6qAknAhgA uFJiKPaNSz5ybCYFjY04SfFp5AtysjQrkbV1XRYvwnMcTQ2xhB+jj3PeekfOcQe3d9fH 4JIOVDjKhGpEpq9MhixGD7uLiT11XDO6KN0SMFLqHsnVt0VuVJSeURzWfuFRR0MoWB/J SuBQ== X-Forwarded-Encrypted: i=1; AJvYcCXuhGGvcF7gFKVythfgI0rYdefBz6pDT5v3sqVa+v7lvJw2+iT8Fx+Cj3tAOGasIgWC9a5aELQtV5ZXYxEgv+cPzCU= X-Gm-Message-State: AOJu0YxVaeWM/ZwHHX/fsJb1375HU965fUOJN98lkM7AT9PCjQo/vv2L stWcyA+uuDZatzFtUDJd4U9rAWt9/2Wz4QdC/r7VjV6foVZyoQmgf8iXZ9Nn+2A= X-Google-Smtp-Source: AGHT+IFlAsPoHG2FDkZGPGOgYKbc0L/VN/uoaQSjmKoP15ZCmJynTAbwXmhrnqPB3wz5ZBdnnVJffA== X-Received: by 2002:a05:620a:b41:b0:78d:53eb:c256 with SMTP id x1-20020a05620a0b4100b0078d53ebc256mr4232583qkg.72.1712967934863; Fri, 12 Apr 2024 17:25:34 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:34 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 10/11] iommu: observability of the IOMMU allocations Date: Sat, 13 Apr 2024 00:25:21 +0000 Message-ID: <20240413002522.1101315-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B293618000D X-Stat-Signature: 56rtqyamsm3cx441suk3wzrfkxu94e1t X-Rspam-User: X-HE-Tag: 1712967935-956980 X-HE-Meta: U2FsdGVkX1/qcAgV9ddTWEdEET8JwTt51AR6kwKx4BVIx+WaoaiGR3k8/X2JLk+h9LPlxC6EHK0+dItxNfoN87BxPZ4nfN+O2bO6xZi5oip9oTgeDb0EuS0t6enU9HeBXeZVH03JIJQqUdAbEgvcxsVSLH+ofFrJpa4OmUf9Qm91HV3tv0tJJoC5RcEmJhwTgO4J2CEjOnKFKexgctkhcyEmlRDzaCWKlaR2uWKb1PUAh0QzR+iT259knXgE7S+TChmmpgjsM0S4poQY7/Kpw1cHEuqIfWV1HpKTJJU9TOWtVLI4RXwJuGZaEvx4O9hYxmvXU4rPvFjPL8RxQK4uQqb8MglcdkV3qC8si9B0UuEzqdr+kSIVopA/FOVPNsGRf57UOa0V9NTT1PoVJjbpoqkLz5Dz9Yfmb90oFEMjlEsVm5DWu9tm246BP9WVl1+DoIrgVPT402s+YcGWTSnuU+B+YAimwueo/KxuXG/11San3l4+PC9S/BDgB3Y90WlJUM6npU7sz80A7KSBd+JNDwd37keoFOlVve3tz1u9i3rY2DKloJiKil4zu3NuUUMXEVHf1M5GJJsCYHQwb2291i4OSZ+BEol1xT3Zeg7fjPKxU4Ioaw9OGeTOnUQZiXIOdV8ILt936ZI/cDnQO1ownBBgWnoi++G6PyxrHDfXz89pLSm/d9xgYJazCgVKR6d7D9EirYYYwSKINVjyNQm0RAEMvumq/Ewc4EFGpUf0qrHGVa7EX3D0I1jU9Zfe3mU4+qdjn4L4Krbnz56qskRIdmsBouLPWOH0O3oBAZIVtJshByTBAK0IYdFvO/oKGnBvHSq3b7iZbSxtmdzH0KlXtQfHYNhmi3d1ch9WGJIfm06VzTyz44XYkXTi/wDMGLcBKSsjQ+3OpPtXqBdYMQw6zDhuVeuZeWkqzCmnoNgqebUxnN6yYdwwr2o5fYC9bGsCwrTvY3vv0qATJDIJxI1 4GCYfTfU kA/BfzoURt8phKyoRTfbpNRj2cPZXqzvQfGz/trATZUmkI2s9QWoAqBVynKr56KK8B0Pw7rlGuH36eW1R8YCWcNM7kd+dwBS2bCDGV9jY63xW/XqC0k3KjExUoc0ByIDgcjfWVJR9A6L4YwLw09DOFb2KyHG0ijcRUfvFrfPfPAIM6CUyEF3gOV1ecV1h/AUTRRDdOvSIi81pPvaqeRu35QRzPbDx+OW89egSQKwdUtxQQLvjN7c1dcu1xgODNNPeg4/37nu29MAiHcCn7GX6WO9G4hd40+lm57aa2Uxg/EdI0z1hScpI0i92IgOHOY5AmGjUJpv2MRmqRek4tcgq6gUX1BkZNmxw74mRu9GDD4w8MESVed6U1fUJ4bOFsKVI6g1eD1Q3WYJ1cK1Bv3a033hR3FgiP0eBfa2WHqFeR4znT8W+X/GVQNR8pHwaR4czByFRpnv1rFl0AUFIlC69u7tgt2jqrp6+R023JteajIMDV2/ApzAORy0FPZjludSCerspepFD6l/FU0HTf7UbleiEzszGGtEQbNHFcoYCsrisT2jhkNz2h9pajEf7GN5tOlkJ0dR2phyRwjc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Tested-by: Bagas Sanjaya --- 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 5a222d0ad25c..1264b0f6b6c3 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -20,6 +20,30 @@ * large, i.e. multiple gigabytes in size. */ +/** + * __iommu_alloc_account - account for newly allocated page. + * @page: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_alloc_account(struct page *page, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt); +} + +/** + * __iommu_free_account - account a page that is about to be freed. + * @page: head struct page of the page. + * @order: order of the page + */ +static inline void __iommu_free_account(struct page *page, int order) +{ + const long pgcnt = 1l << order; + + mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt); +} + /** * __iommu_alloc_pages - allocate a zeroed page of a given order. * @gfp: buddy allocator flags @@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages(gfp_t gfp, int order) if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page; } @@ -48,6 +74,7 @@ static inline void __iommu_free_pages(struct page *page, int order) if (!page) return; + __iommu_free_account(page, order); __free_pages(page, order); } @@ -67,6 +94,8 @@ static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page_address(page); } @@ -147,6 +176,7 @@ static inline void iommu_put_pages_list(struct list_head *page) struct page *p = list_entry(page->prev, struct page, lru); 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 c11b7cde81ef..be17195f6f86 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -206,6 +206,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 db79935e4a54..8507c497218b 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1242,6 +1242,9 @@ const char * const vmstat_text[] = { #endif "nr_page_table_pages", "nr_sec_page_table_pages", +#ifdef CONFIG_IOMMU_SUPPORT + "nr_iommu_pages", +#endif #ifdef CONFIG_SWAP "nr_swapcached", #endif From patchwork Sat Apr 13 00:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13628413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE8C8C4345F for ; Sat, 13 Apr 2024 00:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3F016B009F; Fri, 12 Apr 2024 20:25:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEE7F6B00A0; Fri, 12 Apr 2024 20:25:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A956B00A1; Fri, 12 Apr 2024 20:25:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B200E6B009F for ; Fri, 12 Apr 2024 20:25:38 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7EEEE161051 for ; Sat, 13 Apr 2024 00:25:38 +0000 (UTC) X-FDA: 82002615156.19.0FA9BF2 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by imf02.hostedemail.com (Postfix) with ESMTP id B82F880008 for ; Sat, 13 Apr 2024 00:25:36 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=Hb9NPKLS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf02.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.54 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712967936; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oW/KEiSNsnRBw/l+ZCWeQ/h6Gx3xayfzLPqYuXkw+Zo=; b=mMzxN3+rpeBgDnJ1qsmPnsb335jtwwF41beWHyocp/Egs5UhnpDFBGckeCXtG2rBVTTNWJ FsUdrDSKK5v/fWrQkQUm4A6CXMsJnYjIU12eo1NP8XVRzBKlpUjFMEdrR+/164nDQ8RDJU Me2T7RiTo4R+CM00KUTI0eHjidoaOUE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=Hb9NPKLS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf02.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.54 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712967936; a=rsa-sha256; cv=none; b=Y5F9W2Qdo1hKseiUS9VaM7igQLGLm+QBFmGlc09kHXT6LslGW420r+dLRUZwkpNJo5e5LD 5cc9GnWAaGX6uzZReDOfNHFj9OYOg0j3RGLHMExTfEW4Kw+jwrUw+3lHeTuDOejWaKA9yw ZZLgdYRqL+Z1VyxiJ9Gp9017TroPfPQ= Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5aa17c69cf7so984095eaf.2 for ; Fri, 12 Apr 2024 17:25:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1712967936; x=1713572736; darn=kvack.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=oW/KEiSNsnRBw/l+ZCWeQ/h6Gx3xayfzLPqYuXkw+Zo=; b=Hb9NPKLSIPsu+r4zhxTEpjB81xfCYi5FkuYGXud/ExzvlliTf0CZqOXJVqQi3Enad/ PnhXYp4Ki9Tk4hdEpOy7tI29WQl1S/tVdlOttpUZUBNanWu41p+sbXhTcvqna4LWCRMg YjHI50Rx6MHNXx+xqgg1277xopIQ+dy61e5vO5tPPrteFDdZtRzlada0a3YsgWH0gBcg L67dmD0QgX/riiVcrLAvLHTnMMiaZfNalWwMT3ctwd5AjZxlrtW43byV20UVgtjbF4oL QTwYFhqWOCWNoVHPofrLFnqjYsi4krAZ4yUvEzUTTnlqQUTO97GLiJ1qYyzNDuMhUc+s aEOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712967936; x=1713572736; 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=oW/KEiSNsnRBw/l+ZCWeQ/h6Gx3xayfzLPqYuXkw+Zo=; b=OE7BfyPq7Wai0FokvPn99DH/mF/hr2cBrvvIhxBCF/aISfizy62rIR6GLHfN9v6pKj uv8/rwMLvKalmDqb9UerkyPf3AcDWORpVPfOdZICX/2BeJKWFjJVO9nbmJzhqb9ikhJw KFSCbfnvbcfRklm1S5e8gXiv6l7T18AXUQ8ejuU0N0Je4iEapDsyX//sMgGmus3pnxn5 szHv0X6tfre7L5nXeCat26oKawhQFj0T5xRlptw3DW3fotFqaBut8T8VMK1HHIxdYeQp Am1Gly5My5GXaZlqPtlZSSId8Qqn+z2VNCrAWYHCQDjeb0EU3t+7qAQIu/Xt6RzTnnVL gHJg== X-Forwarded-Encrypted: i=1; AJvYcCVwdIbH8bgbuQ4eAe5tAs28G7MOKo+xbmPWNf1C6iVBE0pRiGyfQP22MPTPkbJGMF2eWvnF/p0Sr0On8TKZWJS0uKo= X-Gm-Message-State: AOJu0Yyp7w0TI7bVNAo0o4XTP6y0G6CHkJ4XCWeTF2je7jIQwSwd1jBx o5pJDhg9Vd29HPz4bq2pEFexPGGpLnveVpJ17R59Oz+uDlTCBX8XSrVjRBr4D4c= X-Google-Smtp-Source: AGHT+IEyUReT/k6LJnKcktKQV3wXgSN/KWZ97Vz9yLFBdXAq+5mOndsoGpnTEJQKhqddAuehqON2DA== X-Received: by 2002:a54:4393:0:b0:3c7:203:789 with SMTP id u19-20020a544393000000b003c702030789mr42394oiv.37.1712967935759; Fri, 12 Apr 2024 17:25:35 -0700 (PDT) Received: from soleen.c.googlers.com.com (128.174.85.34.bc.googleusercontent.com. [34.85.174.128]) by smtp.gmail.com with ESMTPSA id wl25-20020a05620a57d900b0078d5fece9a6sm3053490qkn.101.2024.04.12.17.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 17:25:35 -0700 (PDT) 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, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v6 11/11] iommu: account IOMMU allocated memory Date: Sat, 13 Apr 2024 00:25:22 +0000 Message-ID: <20240413002522.1101315-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240413002522.1101315-1-pasha.tatashin@soleen.com> References: <20240413002522.1101315-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B82F880008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: d81ifk58tcwx5qnpc6kstey7z8hfmbph X-HE-Tag: 1712967936-759359 X-HE-Meta: U2FsdGVkX19aLYpiiAjnhZcUrU8klDbsTSzfsGuVp7+zJJmTfZZ9bpstbMQWhnu7nFUdnjJR5C84Q4I7VkY0oQ7PhDGyOu3A2txUE/YenFeKWtfMewUjm8mFq/C/fyq3DKNITw+Z3tbEh4itgUr5J1b35/cngBvlr79vfbVJpx2M9wY+CGy0nEKcfkNBsh3lFswzijivLrIGWQ8oYy3PMXd8/TDyk4GZWTCRbx+gnNRvxTR7yd3PWwdGsiklRTSAW7rzSMi1XX2NN67GBUz2IHTnu1YmhREZkN4FiB974ivSKq198mMBYlf1fGHx87XlI0vYyB7ryUZuxXXyhdy9fuT2+uwIKArbJHOMe7N0CZFBCdiFRM1+KH+Scgwq4tHHzhs5PEXeG+w8jh45j6i5hOZX39LhCC1GDCSpoUjt8IIDsk+eJyplYeB3KT5UV2GnZIqWsgHmCv9Y4vAROf8uo3iVnmgTl/RavMNtvv12Apddj2jN8NGzg9jqmqudwbgRdtru5X3WDOMWyxp2SmlKUaIAGXSR2z8MLlHAyIUy6nbzkG2lehwLA88oGHo+2ToUefi5oETQror0NAEADG14n7UyDQTADTOqk0c+JWGm3GYxAgiJrC11oj0H3G0ZNJD1xBUlIsYlUEB5GoELDkJSXDH3lz8zeJ+sydZyz//yL8wqcRZKwU58bnx/vZrj+ieZtcqaMmD8SxrwYdLwLqmnlTPtEX0Aag1q5gGOAcTB1Hn1x826pidfxRAQ4iD+c7yzhtzvcW/s+0Jrrz2lgvHeWxcnbUeZPebrxKpTqJRDiINQ1ttC8jwEBRZoIomm+ug6etQj7nC6grgACcmDh137cSxrIsqa4vxW7MPtPtU2+DsBVdq4W3ObHl5p+a5zUp3jGrVQy9cZ18zd0cxiTMONafIJR8loyZdJzwR7QOd/seR1JEOmdAd4guy1NET5FHpIMit21ir8tnylV8+mpVM Izcby8HC 4j0RHP7QbjHdPz1oGqW7Eg0NgMo1g3wnEfsPy58aTqZWembA7R9VaOAN3YiXrCGKALjW7ntQaePMqsdU6e7uVI41DByqJxQZPC/C0jSzA+08K+xufs3AmJ3ebdOZ9efgBkUfaRWvzR0FWq9ep3Mbhdi4HrglXaCcgcK40SfuY9U45JbEFTAtGWAf94Klz9l+7Y0JfpaD7dzIxC4wZ4sa+dX7H6bFWBlS/0qyUER2YxDTJOq/SmWNs6Mw9GsF8m3WNIUDzCMuJsuNzMrdR+56jr54vKhRVRg4wwFWjW5JX9nZIw4JRoKp3l54OngOb5wp0pBCaNS8y1800sHulkT5hm7dF8Py/7QB+0iLLsUYcgd7cC3cuwnrFte2Jpo7fITj7Av0/KU4tNFHdj7vB4svyHWwWnE9IZTZmh5Ej4yraUnVSBSlEiSgpntIjBez1iKERC4Nft+1z096enk6UTXNgv/GNQyK9EBv532HQtzyQd+RktMzxkBy2TBtbFd2CRhf6Mt0hOrbYEcpm8uPzQONs66XSu8ZHIOqO4TRCWf6uTE01PbUH5Wuw7M1N4xfcMS2vwiyT X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. There is a difference between GFP_ACCOUNT and what NR_IOMMU_PAGES shows. GFP_ACCOUNT is set only where it makes sense to charge to user processes, i.e. IOMMU Page Tables, but there more IOMMU shared data that should not really be charged to a specific process. Signed-off-by: Pasha Tatashin Acked-by: David Rientjes Tested-by: Bagas Sanjaya --- 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 17e6e9565156..15f80fea8df7 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1432,7 +1432,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. percpu (npn) Amount of memory used for storing per-cpu kernel diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index c6a6b9df2104..707e39280a9a 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 includes + 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 1264b0f6b6c3..82ebf0033081 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -30,6 +30,7 @@ static inline void __iommu_alloc_account(struct page *page, int order) const long pgcnt = 1l << order; mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, pgcnt); + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, pgcnt); } /** @@ -42,6 +43,7 @@ static inline void __iommu_free_account(struct page *page, int order) const long pgcnt = 1l << order; mod_node_page_state(page_pgdat(page), NR_IOMMU_PAGES, -pgcnt); + mod_lruvec_page_state(page, NR_SECONDARY_PAGETABLE, -pgcnt); } /** diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index be17195f6f86..8f9c9590a42c 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -205,7 +205,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