From patchwork Wed Feb 7 17:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548801 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 71DF0C4828F for ; Wed, 7 Feb 2024 17:41:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5D706B0074; Wed, 7 Feb 2024 12:41:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BBEB36B0075; Wed, 7 Feb 2024 12:41:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A37AA6B0078; Wed, 7 Feb 2024 12:41:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 946226B0074 for ; Wed, 7 Feb 2024 12:41:10 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6659B140A00 for ; Wed, 7 Feb 2024 17:41:10 +0000 (UTC) X-FDA: 81765723900.01.3B0FB44 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf21.hostedemail.com (Postfix) with ESMTP id 94F201C0012 for ; Wed, 7 Feb 2024 17:41:07 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b="cUElX/NJ"; dmarc=none; spf=none (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.180) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327667; a=rsa-sha256; cv=none; b=vgfFWvL6vvppAKYKpD/Z/luosVU2jLfBOUGD64sFpQ9AHGu6uGAa9AWWdMLJbQ8xpOH01S b+xUf3ffSzewAv3vCeKUKCm6eJNwwNN5CPdhLM0e/Xjb/B27Iau6FaXu7/gEtXLurZPm/J Rotb4FvlRjrTNERapaKmQ/eWepjjbHM= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b="cUElX/NJ"; dmarc=none; spf=none (imf21.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.180) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327667; 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=fhDOSWkos8j2XnPjoAZB6lU3EqOYdg7M0aCb6iAvNKU=; b=tTaUMdtoSPeOhHlEW6vfU3U3XFMDX1mQQUqY1K2/G6LK7LhfOVkap695CTk9bbXxUAlHHE R0USg3pDoKpWnSh5KWfacATc8pR9vj7USBf77NoJhN14Ouy7Jcw1jvQB0d8Vk7TfW1IP4K yU0MnCunY+2jTFRzJO4XtOFv/qCpFbs= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-783def87c8cso46566085a.0 for ; Wed, 07 Feb 2024 09:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327667; x=1707932467; 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=fhDOSWkos8j2XnPjoAZB6lU3EqOYdg7M0aCb6iAvNKU=; b=cUElX/NJnPKRv69uxHKcZhyBcce1iPHEut3QhibGf4A2k03vq2RVHOhKuyhOd+0Tlp w4Y2Fnxn09fcKmi19eTT25yzcA3khQp/5RLX5SOuJ8urD1xMNbPFeHeI7SUT9eQvhbNv 7yQlip4deTdqBLNxD+QbYKFNq7Hj/Hro8TP9lrXPqHVNww+4uh0EPLX/tXxe4wWyptWv LFL6TLR8oKPOW8EXywC8c1R531IiVSGeVBjaR30or8KZCCUF/rJIYYvZUNrBO3sbccU2 NiEhbKBKR1WJrG31GDumBEpJg6M1tNYxyf5SqkJTyvpVgrenoD1SKSLEF0gYddeubH+b 8dDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327667; x=1707932467; 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=fhDOSWkos8j2XnPjoAZB6lU3EqOYdg7M0aCb6iAvNKU=; b=qej3E7BuUb/kh8GTquuxNwp8lTOeJuu4WRULykqTxGp8AmPceqQ6LWO5ETGdUEXvpT Kq8dx3xxDipmMM6TQVM7XsuAXNGBrcmfgqkA85MOX7zpJJ172xX8cKAhXAo0j8ZEbhRD LT+AeQjFpW3zjMJe0Kca6JLuwIENSQk65gApmv16idT4FLK7huALdsNzsazFxhfMxIFk VU5zTmn8CmN+HQlDhHuDRZMq5fwCl0a/1xUFZnx68+CKkEkk5+MCUKhbpDa/upQC4u46 1hVPC4Tc6+4/HvMzmI206jZhocju0Ss0NHWM8p038LJc8sc42upGPVFmseIHEn2axetY CmQA== X-Gm-Message-State: AOJu0Yw6O02MibORIkOAZwRVkKH8elUohh8K6maUTg5FS68hdLEJBUZw JRjnxdsz4vwQQXaH1TIEas0locaanrtGA8u0Tvh8/KqI1Yv0AlZONFm2eup5jPc= X-Google-Smtp-Source: AGHT+IE4XQdazP3av9sxH0Ec8w6OzK4LULXb5fUCSEjJPmcuG9JUrjC221RDz2UA1gAIyCitPlfNog== X-Received: by 2002:a05:620a:2227:b0:785:3f80:40ee with SMTP id n7-20020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JMIaGGSGy3cTjq58cSybMTwQdIVW4NiNTkTUZ5X3B4jYu+Q0wIU8xrXoTr5om0/9HroZ0w9LHv7e4+J/pheG5fC1pdaZKrrbE5nfW3lzayiejiZRdbBGUb6zgasOFU54XJEZmiYvtZlUROyQNwjHkmZSivnK0Vr/T3z032NS/BSfSbAev0xilAGwJp+0vgGyYjk3bZJGPHozHxcRWO/8bwqpaxlQdJl6V5yy3TyvfqBFz7mCXEy3sSmFybQwg7aft0Vl3VR1b86Jok/f5lG+4Vw9WexOFA+bfpkro3x4/Rv/YJa8KZ458aqEtfoiBU9Iv2xFWbDpQrdiweOg8w6YMdRRrpxdIkSeRIzFrfRfWyLO3SPVNm5CMC0tWlf0aZnMwJi0kH02e/XTf2bGP7c+hWVHKOeARfDcw/4AqtBouTP6Kx9CC3GPConmpndOI/UXrb+gLv8nu6j6l1liEEO Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:06 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 01/10] iommu/vt-d: add wrapper functions for page allocations Date: Wed, 7 Feb 2024 17:40:53 +0000 Message-ID: <20240207174102.1486130-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 94F201C0012 X-Stat-Signature: sy9b9psa1eamjsrxciinw3poui4m7mzw X-HE-Tag: 1707327667-521811 X-HE-Meta: U2FsdGVkX19PHeW68wyzHtw4kHCpZrk0wiCafUaWVHyQX3pI2Dwup1mc8TH2McIbQ6yeJI5k21hADwd03ybQ7Kp9l620OYztmxrBW0UoKsOmjHXGjkeZF0yweKEyxjJyZauLy90uoAKzJNWK9DTil9+i+eYnj9orGi4VGW1bU9MnKVXw/GoPI1UIWbXDHf+izJK60XOyV2Lr094HplQgWNMpndgCjxebKiu3eEJW/3P4MGzlzHijEYbNdJVljwzgd7eU7RfuqLN7B+yauXQe7ObzSHP6CNl6k2ErwP47scXTmry7prJe4PT9rDJPsr8aPVBs+eOP5d8LY1eLTPb+o6JeF0RCU8Iz1s/mqET7SOjZVybNGv87ggA2SVOAvWLQBf7JPYsoJdvmprS33+0cSybGImxJPEC2CacO65D+n6fzmrqKMTBO6jxaMS+dvX3/0ARUzMB0x7a4JnfdXxcpo5RNsFmOItqAufFl0xi0PVnOZHKoVHgn7ekIvYs6ujFEvdjtiDxk8VhG2BweNmOlhbPnUAWWZp5DNRpWRUH1YgOz7MNbVjLES1EDutaGXW8PyEAMfEar92MFSfZA7R+sVus4vyMOaFYOsA/IySOs4JBaJPMvRWt4QxgdmQfdxpXLOhJKDIUYT4VxJcKuV0ao5WpVRRwWHCjWXIBrrMRIwOQ40yAawGbtwSwBPdHlfiRooRa9j5qrGhvPQH2dRHE6bc2h2NCnreukh+EE7QB705xUClHB/51sq+puSQWzmiQSb/7w0ajz7Ip+wBvMRbX3eRlicz8JF/GAhF47WwRgbXwh4EYFf/YOwLvNk49OGra47OGd02tMAR7h7UkHHFSCPaamBRCFG0JPm1IUMbQ9jLww4VbsHbFXJ58Wdy23Fut/q89OrfIXBQwaprjLOfaltQN0MURBmVQeooAWduqHZX0V0eFcnI6UZ3F1umzSIW9MWFg2D+Q1vbeIHWWxn5v nn8+ccxF qZ71p4D3d2ExU+hPDAJKFKqaRn8rKoIaqyfWqV1ees3K4K88yzWrUz2aKCHjCp1F1IlnX7B0c1Fcc7IBf0n6dcFURO4w71KA+0n4yzlDRtui6P5sro8yvB2BMCUqecFLBD79zb+aKTrM9YR1BgwU7vK8yNCgcSnYCAhoEk5QLHO40Ip//egZHww0772TCUoeFaTf393wQxUyAOZrGSxr7bkFu5KLzeUZ7W8WiOmb2yaQp2M3gx9M+radZVu+9qW8vws2BgUh6CuwvgVIpcuNBShTV/U0+PV+RBmayYhCkXVWip2Xb+hoH0vOCJlRHq7zzJ7RWi3SZMuNucixup5xkSYACn3AoRuK05GZKd0VJyOtvdhQ3chv/7/koofywR/xdPOX+BEjoE3+bQhehbtdFa3Xv/B8eXlP8fkWG1GLnHPkMCmSVPMX0x4AU5o2nniHUPnaB 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 | 10 +- drivers/iommu/intel/iommu.c | 47 +++---- drivers/iommu/intel/iommu.h | 2 - drivers/iommu/intel/irq_remapping.c | 10 +- drivers/iommu/intel/pasid.c | 12 +- drivers/iommu/intel/svm.c | 7 +- drivers/iommu/iommu-pages.h | 204 ++++++++++++++++++++++++++++ 7 files changed, 241 insertions(+), 51 deletions(-) create mode 100644 drivers/iommu/iommu-pages.h diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 23cb80d62a9a..f72b1e4334b1 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" @@ -1185,7 +1186,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); } @@ -1732,6 +1733,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) { struct q_inval *qi; struct page *desc_page; + int order; if (!ecap_qis(iommu->ecap)) return -ENOENT; @@ -1752,8 +1754,8 @@ int dmar_enable_qi(struct intel_iommu *iommu) * Need two pages to accommodate 256 descriptors of 256 bits each * if the remapping hardware supports scalable mode translation. */ - desc_page = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO, - !!ecap_smts(iommu->ecap)); + order = ecap_smts(iommu->ecap) ? 1 : 0; + desc_page = __iommu_alloc_pages_node(iommu->node, GFP_ATOMIC, order); if (!desc_page) { kfree(qi); iommu->qi = NULL; @@ -1764,7 +1766,7 @@ int dmar_enable_qi(struct intel_iommu *iommu) 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 6fb5f6fceea1..a9cfb41a6a94 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -28,6 +28,7 @@ #include "../dma-iommu.h" #include "../irq_remapping.h" #include "../iommu-sva.h" +#include "../iommu-pages.h" #include "pasid.h" #include "cap_audit.h" #include "perfmon.h" @@ -224,22 +225,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; @@ -473,7 +458,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; @@ -647,17 +632,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; } @@ -795,7 +780,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; @@ -807,7 +792,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)); } @@ -920,7 +905,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); @@ -944,7 +929,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; } } @@ -1046,7 +1031,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); @@ -1718,7 +1703,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_free_pages_list(&freelist); } if (WARN_ON(!list_empty(&domain->devices))) @@ -2452,7 +2437,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; @@ -3385,7 +3370,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_free_pages_list(&freelist); } break; } @@ -3816,7 +3801,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); @@ -3960,7 +3945,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--; } @@ -4107,7 +4092,7 @@ static void intel_iommu_tlb_sync(struct iommu_domain *domain, start_pfn, nrpages, list_empty(&gather->freelist), 0); - put_pages_list(&gather->freelist); + iommu_free_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 d02f916d8e59..9fe04cea29c4 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1069,8 +1069,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..4af73e87275a 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 { @@ -536,8 +537,8 @@ 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); + pages = __iommu_alloc_pages_node(iommu->node, GFP_KERNEL, + INTR_REMAP_PAGE_ORDER); if (!pages) { pr_err("IR%d: failed to allocate pages of order %d\n", iommu->seq_id, INTR_REMAP_PAGE_ORDER); @@ -622,7 +623,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) out_free_bitmap: bitmap_free(bitmap); out_free_pages: - __free_pages(pages, INTR_REMAP_PAGE_ORDER); + __iommu_free_pages(pages, INTR_REMAP_PAGE_ORDER); out_free_table: kfree(ir_table); @@ -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 3239cefa4c33..b6ecff24bafa 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: @@ -59,8 +60,7 @@ 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); + pages = __iommu_alloc_pages_node(info->iommu->node, GFP_KERNEL, order); if (!pages) { kfree(pasid_table); return -ENOMEM; @@ -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 40edd282903f..ed3993657283 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -23,6 +23,7 @@ #include "pasid.h" #include "perf.h" #include "../iommu-sva.h" +#include "../iommu-pages.h" #include "trace.h" static irqreturn_t prq_event_thread(int irq, void *d); @@ -67,7 +68,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) struct page *pages; int irq, ret; - pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, PRQ_ORDER); + pages = __iommu_alloc_pages(GFP_KERNEL, PRQ_ORDER); if (!pages) { pr_warn("IOMMU: %s: Failed to allocate page request queue\n", iommu->name); @@ -118,7 +119,7 @@ int intel_svm_enable_prq(struct intel_iommu *iommu) dmar_free_hwirq(irq); iommu->pr_irq = 0; free_prq: - free_pages((unsigned long)iommu->prq, PRQ_ORDER); + iommu_free_pages(iommu->prq, PRQ_ORDER); iommu->prq = NULL; return ret; @@ -141,7 +142,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..c412d0aaa399 --- /dev/null +++ b/drivers/iommu/iommu-pages.h @@ -0,0 +1,204 @@ +/* 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 allocation that are performed in the IOMMU subsystem must use one of + * the functions below. This is necessary for the proper accounting as IOMMU + * state can be rather large, i.e. multiple gigabytes in size. + */ + +/** + * __iommu_alloc_pages_node - allocate a zeroed page of a given order from + * specific NUMA node. + * @nid: memory NUMA node id + * @gfp: buddy allocator flags + * @order: page order + * + * returns the head struct page of the allocated page. + */ +static inline struct page *__iommu_alloc_pages_node(int nid, gfp_t gfp, + int order) +{ + struct page *page; + + page = alloc_pages_node(nid, gfp | __GFP_ZERO, order); + if (unlikely(!page)) + return NULL; + + return page; +} + +/** + * __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_alloc_page_node - allocate a zeroed page at specific NUMA node. + * @nid: memory NUMA node id + * @gfp: buddy allocator flags + * + * returns the struct page of the allocated page. + */ +static inline struct page *__iommu_alloc_page_node(int nid, gfp_t gfp) +{ + return __iommu_alloc_pages_node(nid, gfp, 0); +} + +/** + * __iommu_alloc_page - allocate a zeroed page + * @gfp: buddy allocator flags + * + * returns the struct page of the allocated page. + */ +static inline struct page *__iommu_alloc_page(gfp_t gfp) +{ + return __iommu_alloc_pages(gfp, 0); +} + +/** + * __iommu_free_pages - free page of a given order + * @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_free_page - free page + * @page: struct page of the page + */ +static inline void __iommu_free_page(struct page *page) +{ + __iommu_free_pages(page, 0); +} + +/** + * iommu_alloc_pages_node - allocate a zeroed page of a given order from + * specific NUMA node. + * @nid: memory NUMA node id + * @gfp: buddy allocator flags + * @order: page order + * + * returns the virtual address of the allocated page + */ +static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, int order) +{ + struct page *page = __iommu_alloc_pages_node(nid, gfp, 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_free_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_free_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 Wed Feb 7 17:40:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548802 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 D0B9BC4828D for ; Wed, 7 Feb 2024 17:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 470936B0075; Wed, 7 Feb 2024 12:41:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41DCC6B0078; Wed, 7 Feb 2024 12:41:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BD1A6B007D; Wed, 7 Feb 2024 12:41:11 -0500 (EST) 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 1D2EF6B0075 for ; Wed, 7 Feb 2024 12:41:11 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ACADD80DDE for ; Wed, 7 Feb 2024 17:41:10 +0000 (UTC) X-FDA: 81765723900.03.D869C02 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf08.hostedemail.com (Postfix) with ESMTP id E7289160017 for ; Wed, 7 Feb 2024 17:41:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=HSuGWd0A; dmarc=none; spf=none (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.181) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327669; a=rsa-sha256; cv=none; b=JWfO2x5tqKySAuqldxShjY0XO5rZjnXI70j6gqQkyjusG1Kz0bJyBal7q5U3RdK4aNRGrn ve1Rg8dQIJN+leqlQQVKnWeGTVAL7y7cRtsqvbVgg0ft3vni/VJcaCSt+xNA/YpfRxEuM4 naT/v/BpO9LYb/O4+ldvJz2odZhJfHk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=HSuGWd0A; dmarc=none; spf=none (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.181) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327669; 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=1p6c0H8WTvJk6gi2vvmtKHr5lJOFWnxgAzSISbVOa0Q=; b=XHcE1oH3hkLM/L1ASZv7e0vJKtVxtg+qb4E3qKDc8G+BU40uvnUcDf+qVCsBmjpdNqeudu sJFJETzumKCzzlfuwtRZoQpgkSBsc2N4oTcS3s5Z4WKg70xuWbbjpL1mEoUbXYHRfqXFGw lsW9AkbZSUUQmgwAEUFS0bRT96k4XmY= Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-783def87c8cso46568785a.0 for ; Wed, 07 Feb 2024 09:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327668; x=1707932468; 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=1p6c0H8WTvJk6gi2vvmtKHr5lJOFWnxgAzSISbVOa0Q=; b=HSuGWd0AYB1ArphmvJMaEj4wiXPlJsq5wFes/kmvIX3R1I5bfCY5uAgFNk6AWIslZ0 LTdQX89jMQP8z7mZ/wRS/H5J7gha/X+sCwALeUVIs96zYegTaK7ZJT0G8RpPE9d/4Idn 7gNE+GwSMH0D+he23e7roVa7gz6nigiA/1/sY91cCt1y7jlRFibTKGl4UeULqvKSxubT XyMfZnG4LpIzcjpQHbXzbdxrStmjJQR0jbNvaTbeDpDdi75vavDtkljrvYfVMGDJ8xL5 aUF67Zh/ZGmD+h0vJgcQXfGJ5KR1Df14yLUFIq8Rewy89rCX6Qtn0MK3JQ9ikFNpgS17 82qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327668; x=1707932468; 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=1p6c0H8WTvJk6gi2vvmtKHr5lJOFWnxgAzSISbVOa0Q=; b=WK9hWeeBUSIB+gNDUbQi3rZcwrRVDF9xPjJWEL2EsZcu7eA4NKoHU58Ue8n5yrWymN 4RWVHFvUfzESB35pc5kYAlxGmP545Jl67ombkw1iknmvqUvAFXrNsy1gX+/JfchICxXR 5GbpXbrvsPfakENbMRwcNQqIJk/P1lHbjqmV6wMUN+KQ/WJUJui8h1QUeQCmPHkM66FE dJ2lFEJxq+dU6GlLm+QBvucdVChp8rjRjwl6V0GKL36OEtNslRDeo5DK+OC2petazzxo sByJZcdkywhHztmEilIU/50H5dRoYDme4QyziTqS1MLQMXOP7HSpMMhshM5RIbDj+LSx UIQQ== X-Gm-Message-State: AOJu0Yzd97+mQYodvRPFomVhQJs4ktigX53b3Pz1+U5pHRWom2Aoldpu LPVUvPsfNBfiKF8zWi9c9YQeU05sM+rTXgV+BQNeSN9Uwfr/YEyyZhsaO2S2RIM= X-Google-Smtp-Source: AGHT+IFqsKvbYxnsl607lpwUnjdcEC2VTwCJMsnUUJ+7cj6jPT1gdZy4znTZwiDYd+P63yLvfl8CGg== X-Received: by 2002:a05:620a:5d:b0:785:8bb1:5d6d with SMTP id t29-20020a05620a005d00b007858bb15d6dmr6330373qkt.32.1707327668043; Wed, 07 Feb 2024 09:41:08 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW6WbJCv2xiMWVXy51m5+spYoiETKd3c9i/GdyqQjSTWjcTfDFx513A9g5laMMpceSxDIAufK6NgvJBAcobhIY+AiA8qeNFzNf8jPbXwADU97BCGk0HRgCSgypPOE53mzzKxD3GQVRbYhArys/w5F7U05bjXxVJlMijTpas0JbqtUULs5Tyt5h7UJsPeJ0nKvljkcxCSTt8GStEf0WxIUBM3Mbrc7a4/tjHrcMj3EKeC8im4aw3UQrmlNsWoQeRCgUJQzPoK5GVUFsffOpyxwRTEBXuJ9+z/dl70zYihkksq3xTMCc9pKPof1cwSAMPTT7hpdr419oVNJPD37TkF5WrdqrI9F+mU1tZPGnbfJD6z8F8l8XysVAixyI4V6sFy4O52xEgIxzMBmirv7EsV+JmB8H26UXAEragpyt6By+XsvpFatLprzjTmHDhKrCcp7Mrkr0ej/Z3g1pBmRkU7ufcFUy3wl/E9b0dWwaP3Cxkt8qequLso5ItBzn3ISDVBRNywxWk+yPrtODVQ/G8FLOWmNzy9FwmuyEQsZcjoYAkCSJoQE80JK+55qOO8y9xohmDxFNps7Gp6BzmXPYg89NauvNDtOLu1chrRGj55Wg3uQi+iF7cPFPs4rUh4CNCBj5HlsGO6dpQQt8bbvm814jGorl7sIUtl1Hr7nMW80D7MSJb3AOTfu1V6QI9ryFy24Xyz2u3lYpD9BnLZbsvq9sg/XwYeSdRfFt2FrWbCzycLdxCxkR44MzmgW8QrUX/INt9qsKQzwEoSNYVklkOXf7FpaifttywkEuQEq0aRzBSJ0FFZlU+u7PvZ2tpCxH6n5rtmYnTC3s4A2j7tqGsfHIVmCEJ28RnaJ/MBIarau/1yJqiTF6a6il2dKQnxucq6ps/WyANhdwOydPWZAFl0xI7vuc0xDyBKPB0LIaadrjx9dO/w+UumATSuJ+Ppv QNitnshK yy3f+r6z4KEHNfiot5FF3BJlNeTqEbxt9rzbDfFCAX4g1MNO5o3GhcBtdTuyCkLVHtsJgd7VI92MFH37B1Dy03HIzzN314nriNgqPup8HvufpjxyKYX6/LFMUk9N3bA/ykNzkjCuLpXIDAgb8Uu71XKYoV4+7iuu38Yv7+ybSXOaJc+v4HlSTbtQkWlEO1ol0eX/AXMvH7fV/QCXvGgecaE0GqUB6Ab0gyiY160uPhYfskl7Fs3tJnHqWISq7F+PZvL4UUr+L0fekj/0y/QFE91XYflkFSVoSwHIKb7gxas/vgnqRYTCZP72Ap/YU3umpgKMj5qW91RiFoTgdVm7W0Ziv++alXQa1XxnDLjKJVeWrihh6p4pVvYnB2j30vNeiUasr2MTymxEOdwLFMZuWgAkTicMzEP2gBfxDBSa1AalS19fUB7dcLoLZnFBd3cC83ECHV8i7P1QZkX42bYkG+EkExjV07jjX0l8Vq+qBrgq+l Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:07 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 02/10] iommu/amd: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:54 +0000 Message-ID: <20240207174102.1486130-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E7289160017 X-Stat-Signature: jyp4zwj11z1jrtxdcppeytwm9qx4wqug X-HE-Tag: 1707327668-406031 X-HE-Meta: U2FsdGVkX18Bj+JwlkXsz2m/LsENtysLVGN6ZCn6EESX14QBxtSZyV0zkYz1vbeWmBz/Dv4nB55a/hTQeMf+SKgxWx6vwMZ+4McxeWpJQXryEjlWVIFpdkokoGPcTusD82ri2uqRULKxKq3BHmyI+NjMM95/3EqnClaHkfQwD6fYewG7bd0fez/HTxT0aPDiZok9F3LiPe3sF5HUNW7YUajSN16vv7EwxAFwHILcn/9LpZq0xWRATh81tsb0X1f5OrHizWaMbPqyoYrDhu908bWDJbZ2rnUfJLhgVxYRvvbqUHnESDi33g87OENDy6yN3+x4TPSkCi/uAq1f/rY3U4IKumE3Z8tDa2fsfUzHTcCJVDJO7cNPKLLB5d1lhJN7pVNNhWr5ZnlSCFlbyoZBzGI9QU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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 | 20 +++---- drivers/iommu/amd/iommu.c | 13 +++-- 5 files changed, 64 insertions(+), 81 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 8b3601f285fd..9270c820a2ab 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -142,14 +142,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; -} - bool translation_pre_enabled(struct amd_iommu *iommu); bool amd_iommu_is_attach_deferred(struct device *dev); int __init add_special_device(u8 type, u8 id, u32 *devid, bool cmd_line); diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index c83bd0c2a1c9..239ddf46426f 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -35,6 +35,7 @@ #include "amd_iommu.h" #include "../irq_remapping.h" +#include "../iommu-pages.h" /* * definitions for the ACPI scanning code @@ -648,8 +649,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; @@ -658,17 +659,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; @@ -677,16 +677,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) @@ -698,8 +697,8 @@ static inline int __init alloc_irq_lookup_table(struct amd_iommu_pci_seg *pci_se static inline void free_irq_lookup_table(struct amd_iommu_pci_seg *pci_seg) { kmemleak_free(pci_seg->irq_lookup_table); - free_pages((unsigned long)pci_seg->irq_lookup_table, - get_order(pci_seg->rlookup_table_size)); + iommu_free_pages(pci_seg->irq_lookup_table, + get_order(pci_seg->rlookup_table_size)); pci_seg->irq_lookup_table = NULL; } @@ -707,8 +706,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; @@ -723,8 +722,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; } @@ -735,8 +734,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; } @@ -844,19 +843,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; } @@ -866,7 +865,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; @@ -900,14 +899,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; } @@ -936,14 +934,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 } @@ -988,13 +986,11 @@ static int iommu_init_ga_log(struct amd_iommu *iommu) if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) return 0; - 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; @@ -1007,7 +1003,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; } @@ -1015,7 +1011,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) @@ -1080,7 +1076,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 */ @@ -1114,9 +1109,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); @@ -2800,8 +2794,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; } } @@ -2814,8 +2808,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; } @@ -3018,8 +3012,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(); @@ -3091,9 +3085,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..7676b0f019d0 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_free_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_free_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 6d69ba60744f..477371b1ed54 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; @@ -374,7 +370,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo int ret; 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; @@ -397,7 +393,7 @@ static struct io_pgtable *v2_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo return &pgtable->iop; err_free_pgd: - free_pgtable_page(pgtable->pgd); + iommu_free_page(pgtable->pgd); return NULL; } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4283dd8191f0..0c7bd09ab617 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)) @@ -1637,7 +1638,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); } } @@ -1665,7 +1666,7 @@ static void free_gcr3_table(struct protection_domain *domain) else BUG_ON(domain->glx != 0); - free_page((unsigned long)domain->gcr3_tbl); + iommu_free_page(domain->gcr3_tbl); } /* @@ -1692,7 +1693,7 @@ static int setup_gcr3_table(struct protection_domain *domain, int pasids) if (levels > amd_iommu_max_glx_val) return -EINVAL; - domain->gcr3_tbl = alloc_pgtable_page(domain->nid, GFP_ATOMIC); + domain->gcr3_tbl = iommu_alloc_page_node(domain->nid, GFP_ATOMIC); if (domain->gcr3_tbl == NULL) return -ENOMEM; @@ -2074,7 +2075,7 @@ static void protection_domain_free(struct protection_domain *domain) free_gcr3_table(domain); 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); @@ -2089,7 +2090,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; } @@ -2762,7 +2763,7 @@ static u64 *__get_gcr3_pte(u64 *root, int level, u32 pasid, bool alloc) if (!alloc) return NULL; - root = (void *)get_zeroed_page(GFP_ATOMIC); + root = iommu_alloc_page(GFP_ATOMIC); if (root == NULL) return NULL; From patchwork Wed Feb 7 17:40:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548803 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 74267C4829C for ; Wed, 7 Feb 2024 17:41:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61AE06B0078; Wed, 7 Feb 2024 12:41:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CBB16B007D; Wed, 7 Feb 2024 12:41:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 421036B007E; Wed, 7 Feb 2024 12:41:13 -0500 (EST) 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 2F0FB6B0078 for ; Wed, 7 Feb 2024 12:41:13 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0215AA067B for ; Wed, 7 Feb 2024 17:41:12 +0000 (UTC) X-FDA: 81765724026.15.AF901E0 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf01.hostedemail.com (Postfix) with ESMTP id F1E5340011 for ; Wed, 7 Feb 2024 17:41:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Dmh+7nCP; dmarc=none; spf=none (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.182) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327671; 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=0JA+g9MenvDAdiHbGDRChMbxLGZk1W2zcwaqv2KKBmE=; b=zFmwrGSw7WCIQLNdbeOvqcgLNdBd/rGsWj0wagUguYpwnuNvYw3I+s7bd/7/+nUk3rgALX bDrNkrTAGtAxlfLVoWgxx3ER1dR7kdZoAUWCjNBWxzhJUasv32bs0vVMZXTBOjFvwhFtBZ zC7JCl8mpA7IRe9efSeHZbqJRHodC/0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Dmh+7nCP; dmarc=none; spf=none (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.182) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327671; a=rsa-sha256; cv=none; b=ImTHt3L4I3SjMXRK9DBr9tHnqD8Wv4NK59Eu1umyvrZcGgW2Xb//q8CK7Huuf/dd2ZA7wN pjDblVWioqRZZOrZdCJnXmguCE4tTfgZKvanhvh2lsP19FalAhLm91ppBvWy+Vt6xkqZc9 L5uYGU8d+JP3/Yw1ifmutFLPHCkvJyA= Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-783045e88a6so59383385a.0 for ; Wed, 07 Feb 2024 09:41:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327670; x=1707932470; 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=0JA+g9MenvDAdiHbGDRChMbxLGZk1W2zcwaqv2KKBmE=; b=Dmh+7nCPmrPKDRa2OH9C/nnsqM4R8TxEi3hVDZ6sFdLv6X7IBmx8D8L2nsGibURyOS 5EyQpyxQQjwFGVv56lhDWoJJPalmyVlX3bowTCHUAQ7r9stqqJ5BixZOYvC61+xKlLNO HlRpn7gfbr32NnApjIvgJAYG4lhvHvuc5Wnr3hFif2Xnfq2/olXnMxD44PikFWTKmrpU T9OZj6FKcPcWffRk/h597ffpsjj3tODya9Xqxuu+UmMhTBgEQx5j6QpkVyYgK/HJHFyE 9/YJCUyXxLthwLPHR8OfN75sFfa/Av1VsR+EuMpztuPd+pS+Pexs3qvmIeN67UmR8sNt oq3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327670; x=1707932470; 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=0JA+g9MenvDAdiHbGDRChMbxLGZk1W2zcwaqv2KKBmE=; b=AbmZHeb5oqgFDs57X9hm/ulRFeZSRkrlukeekqob5+pCW1M0GlActHUBnTcuZD2auW PFHBgTVPvqqIod5T6GkcH8JXeRrbu1cClguah5XOIrKgo7R+DQJr7ArkA0pI/0fLcF5c lzI9ZxNOZ7SStKtFjfP55nLybqB7o56mJP46D6GQ5W9/TUZ1DZ/ysa5LflhNeXIViyTa SxqKMtJMVHMIakCrfbTd2NTupVhUklWBwhDSUw57l8Zbq8r8V867/W40TrAGjC8HtOmd lxJAD5VdOLLvjlVay4mIQJ1mZmR9juEm/cOf4cldTGNbFYHT1v+DlNZRbw5KJZsaqKf4 3GZg== X-Forwarded-Encrypted: i=1; AJvYcCXeVgRjd25gUd9+g7OSFNMr52SL28f2NXqX5ODp1TjEVTI+QToX6MFYr07szb+zD3AwRbUouCXQdVsOnCziP/+TBg0= X-Gm-Message-State: AOJu0YxlF6hI4USOX7KY0jTIm/eiG7at/l3kjQbiS7sqVSoUx4TP4ynO TTvEnOwNPLpZjxNsTXlVKKOfUsR0H1lyjmgBrjhnKXQwBsdlhUzwPlshFHn35LA= X-Google-Smtp-Source: AGHT+IElGFXh4B0vtRDxKd8uklPl89u5PGWF33uvo1vT3Tprks3bAAOetfH+2TcFICeRh6m1eJF/jA== X-Received: by 2002:a05:620a:4393:b0:785:98ab:8898 with SMTP id a19-20020a05620a439300b0078598ab8898mr3650487qkp.18.1707327670170; Wed, 07 Feb 2024 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gZCWxdDiUkyWmSy2erf5ZmNoCCvTODBILMexUleg+8Zh/lUkX0mcQ2a3MEsLeys6KUqvNvWS18JlWOiJw7TALOzXDz3BxJS9qCWzgIT7MpIfbZLqPPjvO1RwhcvaMoGpFJABn52u1L64O87/jK116UWlhgXqQ0Xvme+jQrcJnwQxdgnLFl1NuOU9EBjTG0MLF2Zs9CkGuzI9VfaEAw6FFDPBRx/3kRTFC+HLR/teJ9sN6aRXkgugBq3eJQbqTGhWa6RM01Mqk6tgSJO978N5R3lGHqQkt5pjjpX5hqYiMYIyWldRmjRI1ZqkL3m60FfU2mFBF+CA91okBT0Jdtj/YeL/cJRGUvYR6Uqz6L3ShLyC2UepAwEUE9xgfVRs8EEJx2MJn6QdFO8I493pkNddkbzt8GpT4eFRrro01q41ZILmvRYLx0l Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:09 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 03/10] iommu/io-pgtable-arm: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:55 +0000 Message-ID: <20240207174102.1486130-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F1E5340011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: bwz95rmw6wu691perrpkrrgzpyr5jjjo X-HE-Tag: 1707327670-412358 X-HE-Meta: U2FsdGVkX19RFBXcd5h17KWPLDsMAFtLN68fybNp1ILU/5/t0YiL7BACcPPSPI1GvTsH1cVDWq09pKOctTBsLFuqbFYR0ovVodkOPKqQYGlX/jc5hsOd/DmIQc65CsR4aHfNPqxqzj8UwVAb6Gl9LC2tXuYc1uVLh8ztBPVeqdq1ZMLQxWWxKUx9M0Cfp5BbMipezTgDGAzwDQ/JLU9AymDxg02bbOBlhIEvw8IEpdAzDjDVWQaAjQANlix/suVgLSEOqktTPCv2Abn2BvcQb25PVvzu8PkBzvEQB6CqrQ4lVcJILEMIQTeJFJFu5owe0jdxHhThGHDxukPMPx5R+P18jQC9MzCynknM2xN7qYsDXDk9p4naEA1zRiVU5PwHcAa3HxbcJfAPI2sZ8oncgk8KzQxAvGoOHWDd7zcGJ6i/C0HwOeqJokDPUjBUVCBGdT1FAejUC9iL+KUHQaUi9pwQs8EgpU5U1FS73rAHRpbsHcfrJYCSLMEy+cxVB7OM2e4uFgzFVqu4livIZZ/XLjyYyk1XVgY+Cgd2GsIfhKc9vzVuzbxlxgqSHCUey7ixtfHE5CyeGXq7qSJcj/DSW28IdGnZt7erM8k/wFpD70mHlMVtXJ+YNefpYur9EBKJ3BPWp4h5v8+MWHyRqiKz6oqXzQ6KiJi+jV/7DjNnm5uJGxbLg1Ek0l8hmgThkG+4ZygkM7ZP6G5T7SaFYO7MNt5W3U3uuKW0+91fvWiv8nopIcEHWzl/t8iCunBQU1TaAYqKXomQoMXQtGXMCgV+8Jjn1gdszuBlZoE8QY3cwZfg4D3IGjpz3ycGaG1VTQ7bdVfzZMrQutP0nk1XVsBm8ZM24cO0GDd9s526wTnd86CKpkFdCVJ/F2391LDhtlVZ09e3elc2HGwnYEdNyHVoZOKTyUciPtUJwWZgcG2tckAY9EdjCxKdc0N0P4btzSxIXME0dMGcUmy3RhVX4GQ 0IBUGbG5 SqyZIWSrCWtiGGESkZZPwGYK+0Fw0/6RbkrvKXs4DveRinNbsKSg77wi90nqJq2uEUT8BSV0S42WFcdgp+MBthEvLRw5JVaxQ2VURDZ+kj3aOg/xK7hiLhNYmgdahBsW73TMc8bi0ccqk6hvMY5nGx1/Bpr48XJjqJ3wDC3Dy1yPie6h3sWLTt8q9wRJQlPxL7PUw7521E5xhqGr1NGw96urmG058dBXktgD3WSBibe9GmXJVWKvJ93fNI/t7hs+loUZhttH1ncFSOZbtanFHMg43U4Kr7ZBDI5BKiC+Y9boSEJnjszSTM35FJdLqTKubUUk3IrX2BTig8FdeAq90yljeFjz95KWbYQWbsk7K+cjj28OY4+dCTFHlb8c0hjWX3sRqoyfX17AEvoXVLBdRDMBtYjqlU3EOkc1fPtNRRfJx26FLXBuYNdQJwXjJXy9cIwQl 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 Wed Feb 7 17:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548804 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 CA44BC4828D for ; Wed, 7 Feb 2024 17:41:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A38B06B007E; Wed, 7 Feb 2024 12:41:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E9C76B0080; Wed, 7 Feb 2024 12:41:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 814CC6B0081; Wed, 7 Feb 2024 12:41:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6EBDC6B007E for ; Wed, 7 Feb 2024 12:41:15 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EDD8080DE6 for ; Wed, 7 Feb 2024 17:41:14 +0000 (UTC) X-FDA: 81765724068.24.67ECB90 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) by imf07.hostedemail.com (Postfix) with ESMTP id 34A9C40017 for ; Wed, 7 Feb 2024 17:41:13 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=oPnlaIQE; dmarc=none; spf=none (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.167.175) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327673; 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=nU1hsaMMETz5PI0ifQcx6wtutKo5o6JsITK4WP9xIfM=; b=PDh2OLmOHSjfYIqCpjwMvdQwGyP6pWiMefWny1iAFeRTgv2Qh4vBvg6vxRo1PPiwAU4Vcl QopkBjRFQNE6Q5JLdatcZxgFppyYXfqR9yWWKDH1qSOKNnTKBtszUy4DH4ebj9PLNBq1al 1MVYpUglU4P0iEE3ZL7F06566Q4+Bho= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=oPnlaIQE; dmarc=none; spf=none (imf07.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.167.175) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327673; a=rsa-sha256; cv=none; b=CVVt+joAIHYIoniRIoyzwUrlWM5RY8hWq1nWO9+DlSo20pIilIFCqw+7rsh/BLaIhxYS8N FHdTxEFp07JByT8J3BVLVwnVYhcyQTQgym7m9YzXX/vcabLdN7zem9ji8AIeBc15z09znV k6Vf1laAGm+BKT0UKaVSFT4zKUidxgM= Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3bfcbfbfd92so480867b6e.2 for ; Wed, 07 Feb 2024 09:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327672; x=1707932472; 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=nU1hsaMMETz5PI0ifQcx6wtutKo5o6JsITK4WP9xIfM=; b=oPnlaIQEluu3JQPYnpkz5azxZNNX0B2BNpqXlKnjl8XrSMbssksRilyHX2F3jnJ9Xi NQYr3x9OWcpp5nGtGQbcld/bEmAnDiFCWmxQha/7kpx7GLrOseNpxjLQcPzy7x6bU/jy P2YjPlyi2fjxZ+InVye6FDWM2Bozj1jXxwwnr9s1eVpxzTeNFdpKYd4VH+ZsrcXxdjHa VBRGGZuSD3qCR3J86/oiphSI46+absU8AZ/MCz/ckwSW2CAIhokagVKCCMSCzzcCkKcB C7zjkpWK5duF1dx4XkhUH48ojYirM1a1UiBSLltzCxRBB8Nn50yPDMJePlh8QtrjNE5x OdCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327672; x=1707932472; 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=nU1hsaMMETz5PI0ifQcx6wtutKo5o6JsITK4WP9xIfM=; b=uzFCxBveJ5Py+8pC5gUATOcMkbBdpZZ6ZTTUoLKn7P9oDjvDEOAnMpVurk+pn0oNF0 CRZy1hOJY63qlqTW4nvBPoqlUrT2/dsHeNjoQEAH79WBxQWHq3qN8qddmP/ulQJ41nop g6j/t5STUqbiYSS6FJURFrHkChHBvDPvydZxzqOi+nb/FVUMrI4HQlmKtpMrrdHs3Haz 9764unulqmyP8mHl10RfiQV0VQBGAvGUDqfOESHmm4XiFsc/v0S2LMKoW/5ZO/dJMok7 MVBgDZetutHPnMSyyJv7HaMrXscq+BdEURn4a8oEFwRk6fxLFiwfh822AvGRHpgg6kvN C99Q== X-Gm-Message-State: AOJu0Yx8KTxO2JLW+DiNQAQLOQqpfZNfd0GFKO/TfqwuVLNaWUVFWWd/ L6gw8JnfZirrHtc04SaUgDZwLvskxup06AN3hv4THGbrIw+medbV8vc+Z/R9nG8= X-Google-Smtp-Source: AGHT+IFfEVUCKzT5CwUfTWDGYwi/acQYuhOxMwLwTqPmmzQgMoM1RPknF1EO7W4FpUIP2TDEpv0nmA== X-Received: by 2002:a05:6808:170b:b0:3bf:cd78:6759 with SMTP id bc11-20020a056808170b00b003bfcd786759mr7147363oib.54.1707327672178; Wed, 07 Feb 2024 09:41:12 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVZFB7U9B7PRWrPSa4Vm9JmfrqIfgvQmXJpEOBtNUmvSOjpwYquO3trQQgAz1YG9ML/HHjiBiy6VD9fRFGt91lhuf7+nYjR4rQlDPNeLxvlF7lf5fsIURb6D/+FPxIXEfNHePjZwn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D7GlZiZcBKiOR5Qp+pJOxYhfqNe75t5Ma1xpvmJToVXrNx4f475KpOmW/LBYXSiN9TZX3XEhD6Wo9gSGAkZbyQZHNbpp88as+ALb1ZUQCQ+hOh414MHuPZKbmNdlt+6/7W4P2qOp/U/IiG3Xg0qHla/DOU+J437gr+hBNBiHCguyxl3s04AH/aHOLV4MCYYur/xHb0eZWBCD6XhOuBZv9h8Tj/knG/C05njAez74oc Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:11 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 04/10] iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:56 +0000 Message-ID: <20240207174102.1486130-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: p4hqihjse5gnh96b7jccgzzhpnz717it X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 34A9C40017 X-HE-Tag: 1707327673-562673 X-HE-Meta: U2FsdGVkX1/PjMYqiQGaND+Ej3IBTS8AotyiE/BIykVQ2SIyehP/wkyKADPQPZQ6DKSHqlXauhf1WsoNetRo/KrlRlste4ewBVN8mgyKbR3iN9Q2ciuB2oRCX6Ln6eZgyT4pQE6FdV+o9KtSlRWubPZsQkIAzO6NWbBwtfsndC6KYTlCI5u8fn3VJ5czsGDD6cAXgafiC8K5fftid2X8UvE3cdjEuyUGPYzEsGenIIZDdRkOxW/Pf8vWn5hYeTOrIRMFcSS/En9iSxtRWhUPqeIaY2uLg5En7+LX9+bvJiQtHikH6C0kBcBVMVHPvihJFh9ppc6gYJlO3jMUsIL4nxXPtqfgpdw+dMC20aEQVRXn24rRwDqYDTzta2y1/mxegSG2JkWIHWCksDFIe7SY4SLP3JfGRgedDFXRQUs7x5cprbp3MAWt3FSMNFEdo6aOLslfi1R1QmUHQ0kZYbWIYTpgM/zXiX2YKlGNHuE3ouIE34afzazYbeuQrGgC81DmW/kRDfaVEL1U0aP3THDqGekqT19lJLddHhQbaXM19LdTn+tDYd9vAoaM09kzh9tFTv9F8Jt98enJD4k+lCaofFVtnOaNixy+4l+HXSaAz1F/LU50R47OGRstZqgy9VIXvLcohBLEeNvUMwi0Zcdp+C/EzXnMfP1MGhV92wjZEBPlBgEr7qmfhVmA7wbQBjIgDU7aRZgmT0fioagZvfS920w7+DmOqtlKSaEqWTrIPIIN4Ojec5xfCqMlqzGSzL8lRRgysJrvL36nyVcqPv8TQu4x0rxJt73vmOzueL5eVJWd7eK3BBW/LucW4IrUUQ5bejgIdaOGz1oZdoL1F2vQmeRDvV3UL241Vjl0JPdShRwybOV0Njv/ZhBJRyh6CIM1EHGa+xfbMrei7Yp+px1SALEUmtflBdhVymxsx8Sh29Slk9/K7FxHDRQaA8BZS2rLoTbkPn8FEI4SMeGySDg rA+zbg5J oRZHfEv7tGakR2d1NmRlJINKju8MUY9bMu8KQVqH48LRgGhIFopPXIdhB/PEa1V94eyLPdQLxLMm8fROkgvwkncucdEgxOaa8lJjh+p1bCHIAdCvcM+HbKwgQQsO+xqc7h/p1h6612KuVKaMtXWWi8/KJcvRvQ2HmEyllfqzZf0ijBGnEic7MUqmiVqzgHb6eJIzqJDmlQ3pFR/kJncsjtE68PV7VLvzImSbTxSUbkzw+ymAqpp7nfDrld/FhtR45wV+79ViyvPY7opDg8vumE8rlKttj7HuhbV3wbL+DDN0gK9il8IJyWkHXISGgCSYmH60yadnMxdwZsgUuoOR7ILG+O/nyGJjihwZ3kDogAN9PcVRldlyyVQ63JaVQqTxmAJd4svZVzIvRBDtQ6OBa8cWUpf+63OG3s0MfyZwuAlfOQ8Kwb60rX+hejTmhZRtFa7lQgai9IlC+f8jlBJNdOIrSAmv4moJ6FSx9XiK40OSd8Fwf+AupxJYdOhoaXIQRiHnz 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 Wed Feb 7 17:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548805 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 28B13C4828F for ; Wed, 7 Feb 2024 17:41:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1FBF86B0080; Wed, 7 Feb 2024 12:41:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AE4D6B0081; Wed, 7 Feb 2024 12:41:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 027EC6B0082; Wed, 7 Feb 2024 12:41:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E291F6B0080 for ; Wed, 7 Feb 2024 12:41:16 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B243C1C17CC for ; Wed, 7 Feb 2024 17:41:16 +0000 (UTC) X-FDA: 81765724152.06.673ADDA Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf12.hostedemail.com (Postfix) with ESMTP id D8F3540007 for ; Wed, 7 Feb 2024 17:41:14 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=UJQTMpdA; spf=none (imf12.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327674; 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=HRs2+3L7reOpWDJLX1eglKVbVfztnuhe5Gbs6bYq4mk=; b=2j6zSb1QnWzbQBsCYwoR8NgKG9Ayn0sSIIHmM6vy9jGUYF1mGUt6LBLsnzlYXykGfnTs5D dCKiwYptnEgZBB1XLUoOEGmnbK2h/+x7YqiSlCJdwG/wikmaWr1u3jNTOqQjLd58zlTwQE BKdcnP0l3ryT3eDxWdfZjlHGvkIMUrw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327674; a=rsa-sha256; cv=none; b=198ErCNBPxy9T0SQJuzY9f5ZKGXbtV0CCKxBZU8uvbEydPieRZQbgf2lFaWmHXvO4sHHuf JsdmJaijsW2Rfth4maJv7UFfmGZOlTtMcY1DUYTy3ebXCuRZwGGwlropQGNo5ROFoNYeDF wKcTzyzIrr3q6+9o7KZa/fgVXbuy79g= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=UJQTMpdA; spf=none (imf12.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-7857bbfb25bso52359185a.3 for ; Wed, 07 Feb 2024 09:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327674; x=1707932474; 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=HRs2+3L7reOpWDJLX1eglKVbVfztnuhe5Gbs6bYq4mk=; b=UJQTMpdAXkvR3aJUwro6Ao5kGIBtZSsl6WSV62k8tQpDyDqnUVelbz2/is1ysfnup5 UYSJYe1kc40njx8NZ6tjSrUevHe5+ML/cK02SZiJmtrGfRW7acfO+WqO0dZ0uBM10INu M7iI1vd7KjWulJpCEOi9/YsH9/3dujesIQ1YR8tipsNZCkXePYriDB57ifeO1l5by1pH vjuVakNutczNFKFw6p3KzD776dUoyXqLchnxFxKluYakHvvE1ehyU7PcONvBSSgPqP6Z ozdXoeaUgtUhDta4VL+dvZHrEI053YpheuxEjeDQMVYOKTsLjo0czANLbSPb14IpRMx6 1/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327674; x=1707932474; 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=HRs2+3L7reOpWDJLX1eglKVbVfztnuhe5Gbs6bYq4mk=; b=uD+guOQjUhzDxdhYRfQ1g7GuBmYzVbNySnJIBvpRHh49wmvjMhSl8nyOjhLAbTh9PM A6cetb0AUp8Wyr6bi6ueMNWkt5m8sXAZ5+G53pd5OZh47OJ56gw1rs7fNZM38P4caN+d GbmT5MYkVSRaHmJ0tcPxP0NHR/XE6WOue/n31iCk/Rge0FSUwEydqHPbVAOwwyiaB9oV 6ji1wTxgOqkLhPN5TCnIbEilehPO45xe2ehVXy0alhp9nJC0FKYQxuUQUsxnnRwHOFmS 1iJNEMv9EpnMzdRAbJeaccByZX/SgBZ0NgVh70LWk8UIOI8RzSRhcswwyaS9hI0S/ch6 xjOg== X-Gm-Message-State: AOJu0YxGxcXKr4yC4KGPjYmr3+9gBORQmljoV05iI6hgxyrIUjIYaeGu ie6sIvf99xeh+nqz9mRUaOECcL2bWk7STbbmXd7QzjrsaNGrJ1hNtSE3Djb4gbs= X-Google-Smtp-Source: AGHT+IHjEFIw63ES6/svy+aJUbNe0c3qyC0BVt1dJGlizw8NcPZWt7xtHW6wZZRb5sI3CTWzt+qhwQ== X-Received: by 2002:a05:620a:8d5:b0:785:9e66:95d8 with SMTP id z21-20020a05620a08d500b007859e6695d8mr1885336qkz.48.1707327673940; Wed, 07 Feb 2024 09:41:13 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVc5nMONWxYqW32x/6V7C+9nsKXLKoua7ZIdfEJQ9x8/76Jss63+h6JD1mwJGehXsdSfnoSE6+lpv6Sp1vmZpeaIMONknbVszHoRqTt5fTy8P12Vq+8tTBuH7Uy4QgZ6fXnpFyK380IN74Don8Zz0sp/QqAdGZSQPsBKW8sjK0Fst0EbZ95wEEG8YOmR/P2K++j2TCeaX3xfIWpaQbA4nhqcOc0acSAOLM83i2FUlU6UMphppieS3cN7iuYDfW0oEQgrLqh9GLJc0dHqVBbY9sQYR6Fdh+6ZhcEk9HvMUnkTYfVj3uRBfn3nZYgvk8J50svOXjNvbwCqE72I1PhyrfREcu8sv4mo83W7LLp26mCaaRaLhCFbCdBTVM67IPzB/v7k3n558PzJ+iSs9ZY/jx/sRmUzJgfYvnYEuUdriETHQv5iiXvKDxws/t5ycciWe07r26/gYd7DiqDZYqc54wrZakFHgVcdyHngL7pa9VuPchRKaGPU+7w9c2Hzx4I6X1pscVNNtydVeaBUks33NqUx39wSKcNdEfcvSWm2+GTDzrOAxxRWrbr/t2ufdNbl0aDfRNhzbEZyzWLVwNv7fMAHTpJ6omPUzOqVXTEyojAN9ghrOeGm7Dk7xVk3uIqvRy0DSPI8E+Ze+jwOc0pGkL++sx17P19vuN5F/WKF70+28kLiFtKPh9EEQMzE9Y+eGyK7u4jcJcdmhWeLzz9Y9xuQ429YF6B7vdicCw4DsR6QHTJ91JqRu7YmoMKTGscsZGBWVPk5I4iXH+RgowpMH0OHu8dOQT03o3NRZZ3TaDetzJRsZFy1j44IFOIQ3EV6DNJ9EjTCG//WzyV9wD2pFnbL+Of4xb/EpC9P62qIVMoWPBpO6KemXj5aQ+LEwYdUBXma3LPINQtkBPh/qWeSt2PBWoCqF0UZTeCakLLkwC4IkPycERVRKkrcA0R9q dTW+gehB zBIIjQzpGRxu8l7H8HwrUiovJ7fXKfCLuaCVsXH9ExLnfN/ZaGHlIleJ96WFudMmoD1G61fCa/wZ7yyJt7xQwppSTHNqYVRIuB9/1fvOhzh08uUXo5ePZgiP9OkKTN8Zy0LPuIQVUhgt4xH+BK1s6cypKWqf5wIxZBH2qjEPeOKI/sJ7D5CUKDS/PxMSV4xM4AObmMSQ6XDZY5bkJQYcGkAhwZ5RGigbS/5NgMI0Q16vYJRG5+JDv6lRT9ua8vg7jGy1zzv/ZH7GebBVJ15gy/mZW4P58ZyHkrIWYMtjRNiy4LchEOcm3vlX3jSaGGuzqY8X4RGVcrkaRZ+Siz5FY7UZaWnCoG3k4aMUGcm0IU1zwsz3RnrOR1YyhTAihG7LRMINuGCeYroByqcTuKYMaJIdQBiGr8oZuSWloHGpuOLRmJcdPTtxdEXvC1xiyJ+MEbmpS9Rrpw/f92KkqyRaC1mk94U5VPxRjV5upOa72CWOm+ Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:12 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 05/10] iommu/exynos: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:57 +0000 Message-ID: <20240207174102.1486130-6-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Stat-Signature: e4r9oc5krxf5o389wzxps5i6jaoi6un4 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D8F3540007 X-Rspam-User: X-HE-Tag: 1707327674-848677 X-HE-Meta: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ImyATeFACIeOL4sU4jU12KAzePjRD73zZzNM7mBmJomvYQ87MGGnh1hfYBkJHKrULx8RVlqLbx7UkohqeH97WgX6iG9zkco46ChgFHRLhJBqzIH4Eperq8UI5tFTskr8ac8VQeQCpyaC4OfBzt+wJwCNSv0t3FY/C/9uRPWfPK+ZJVRXQybdM+NSH/S3nZmtoqhIem+3SCEMKDdY0qtAqOXbywyeYzh/Dcw+BuAWQpQpUDbOtqxO4qp0bQ4c56tH41T6ovc/V2Di/qblji7G51k2zL96ILuOUQt/el/BCOlVCGkW7qriu+2SlvU/gL0jsUfumYtbF4x0bu08xuTNLWwaE/V4FslQIaok9yUD+KLgHI 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 Tested-by: Bagas Sanjaya Acked-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 2c6e9094f1e9..3eab0ae65a4f 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -22,6 +22,8 @@ #include #include +#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 Wed Feb 7 17:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548806 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 6FDD7C4828D for ; Wed, 7 Feb 2024 17:41:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1116D6B0081; Wed, 7 Feb 2024 12:41:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EA246B0082; Wed, 7 Feb 2024 12:41:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2F396B0083; Wed, 7 Feb 2024 12:41:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D48326B0081 for ; Wed, 7 Feb 2024 12:41:17 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AABCE140E43 for ; Wed, 7 Feb 2024 17:41:17 +0000 (UTC) X-FDA: 81765724194.27.6DC5357 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf03.hostedemail.com (Postfix) with ESMTP id D0D9720016 for ; Wed, 7 Feb 2024 17:41:15 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=We+0Jrm+; spf=none (imf03.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.172) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327675; a=rsa-sha256; cv=none; b=WCgX8GYNjYQXJOadj8/8db/5OYn6jd+zKB1ffjDcJzmKjTBHhVqpHQmH7a3aHAYRtf78zh kownvWA5CRbgMQeMufb/5trL4Kj7h6livw6J5ALg7S3J+MYUkg2Jag7cg39WVxqBIoWGJo 7NBCdb/2Xw+eH9a5apSXXG2p2yc8txo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=We+0Jrm+; spf=none (imf03.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.172) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327675; 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=Xz6G05O4wA+60kCmvmgiGx9JBrU5EV4e3uvGda8jyEo=; b=SBDgqebDx2lwtiSJQKcYV6+j83195S5h60JohS6q0wCz94zYi+HTrARl2FhIGE7/VyarH4 KAf5BMsio5eXMXpmn9+gtFwcOXwIMe7zzFA0qX4rYKbGzG6BluYFxlwIcSdP3Yr6QvxwJh inlvUVOQP9KTZHzonBS+dCap9YoKuwY= Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-783da26489aso54123285a.3 for ; Wed, 07 Feb 2024 09:41:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327675; x=1707932475; 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=Xz6G05O4wA+60kCmvmgiGx9JBrU5EV4e3uvGda8jyEo=; b=We+0Jrm+t+1jGzO/l+kBnBb1thE3wQ0RcHAwL2Fc8GX+WICSA35ZlKEbgUVwf33U1P pf9AB6uwk31uPcpwRtWjNv2ILHqv4yqeQ1bZwCJ4fZXqlPlIkqV93VQ/9vH746l2z0yu DqxwSKtUbikXtEQQUVHC8V91/yd71o2QLAviqtqlVSlR5cwKiEQMXcieEO36angync8+ QbWrlROpLf083CRKXjLTM2HDqE6pfVdxKr7pfgAfHCqZZj/maQRqEavARFMVExQE6OOb cBJoHL8GKAipPASQMScKpj09hwTbkZc7lbsOX2YHr7hb1xjNtgpJP23qvUn4fHGeruc9 5xnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327675; x=1707932475; 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=Xz6G05O4wA+60kCmvmgiGx9JBrU5EV4e3uvGda8jyEo=; b=MjA8Bf14B118YEkVbHQJ3tqKC2n0NnbbWHHzAFJxU9JetGM2HU7j2wKBWnfnkNZuOF 2AVkTKoblzlhYrbiRAviNdus0gU8lzr615oXDZQCbHtYLCU3lmPr9pndtppayPq18kto RViSoqEKz1LmXNIZuKc7URWvKL1nTyra1ngJ98UgwefJx1fZ/FEg31SDSN9sR35L+kqc x9a8x0UtQGZ48AktCm75K5AKV++89sJ4uXRyjWF5ONb29JmEr9iRpRKMVab8DksjdCvj KgR2EVW07/1lg3eV9cO++NXnyX1VVPBX79noxFD9HbvfG6BeB59tUS3B3Gf2QiNZ1JZV gZ4A== X-Forwarded-Encrypted: i=1; AJvYcCXVSXwj8Ijdqd3zrVe9q5nxItdDMSMCirR+jhwxGyrWbKZNvvXkBF4cY0zi7whqNmwzvz77JBggOBAbz5y8Jc6wVTs= X-Gm-Message-State: AOJu0YyCyaKWd3P7M/T6kcR3n3Sackuix1WJ3ksVCpxCnPAk3vWFD5qf dFR4+tAZp6DJYkppZs64U7XjfJcooUodXzAKeAhJUL1vQsOimw5zDZUIzydRja0= X-Google-Smtp-Source: AGHT+IGm7HEOEjYyU6ceEAyCJbj5ZSiZHtVoT/GGu/ljbSy4K2SHMHGE1ZU+Mc3GOvN+MGgdJxPt7Q== X-Received: by 2002:a05:620a:458f:b0:783:c945:f774 with SMTP id bp15-20020a05620a458f00b00783c945f774mr7801189qkb.16.1707327674945; Wed, 07 Feb 2024 09:41:14 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVrjHWstAmPKNKmmOZss+LrnMGoMozP5bewBJMtBvsxnSH4qAA9cpPi1oYJJyh0BUiRXx8vEuPicCaLWIj7WkRsbPVXs5pF2kWy9iUO8oTShW2B8fsnkt7jYBRZir8Fz5+c72ScE95t4q5LHZ9pZO7lVdBZaewRpE/NRTtfPSseusbUyGGDy6h+O4ovY7nXnFPIJ86SUz3Dtek5Hgc7y2J+Z+WTwUQs9aZpp8P8Z9mAsQP7dpGv5qpZgJJc+KhJ+3YbNawEbDn6BoSaBFcWYvC2iawUphmoa955poBq4d8NK0bieLstlnhd0+F4aMp03PTWFtKgeeGN5BNwOh+yuYSDzJGEgx+Q5FLBw8GUMq8ADEBNdGsxltHxrZkxkDb2Xzr59XaH5uUTXdxZtdNzyKd/WvxprwrkKL/Y0V496ab8itUl+7v63ZAXPuiao/r15D99xjNwwYyQ8MaIZMWx5oBm0W4viPnDezsxhm1S6ldjOX2GYSvbBKZjZKgO8JfaqW7YgAadHrhnWydYP7q897L26rp4R+PTyEyDm1Ttr1BvzrEkF14wY7DMd4cE9vnRmgyMpc9MIV1AS8Yeol//B7sedMHGx9YUlhHmMld6IvICVHr9cPlSBhKJhEgP95TiG37l5tWnPBTjqAnvQXaQ3/ssibX8uYPmb2YjK65W4/kv6al+yX4cpi8g1qWOJc/jWs0DVzguf/yN9hfoKE+C5iMFHsXGhQa+lvEGly3VLu8DY96oAirk3p7ee+Vr4Nq1Eem+lyudfRY8QGxu3vMiiocWWsFzPg+N0ka5b3Ss0zDaGpOtLPitRJvp9TSELiK4t5+VNOo5T7rOmnLnYkmtovz4hQgWWiD7cFKVpP8pPPeuXJf+RIb459I54+kbjtiIBSnxktVzV12pdR/i32lYdnVpfsSTS2IeyOGtJQzkFdR4D+1gKDfQFxHWHeFI5z ESLmyLNW Ao7b6FgzEQATp9gXBFjnlk2upisqGrCNtgs4ViYBAYCn9VIpKTTVJx8QL1GCc6lwCUdWzqqZUFQlS3tf8uWIjDjC6W1SRrYk4pE1Y7e8reWeyw9aF+as40OW4Ezw8RGpi0muxi4Y1aZNhTeh56EfSELm+bOXEfcS787PLN7zzTynHNy2FN+1NnoUfBaolqV9bj4KixvnEsdzHzOZstfc5xGz2ZLCGLAhOGO7jdNWScuTX7NExkhEbv3PnLl9I73PUAjg+brm+juf8r9qQgk+jmy4lk6xDFQ7ssb2ubfZ9vQvNU2uJBgWMc4JqfaH5NW72z05Ap4JDXNghrCFVpeYufB7XyHzfwtAT+J8ApXxOu9QYjpzOWKVDxbi68ugpqpPv65NucRhhZdFJ9QHW8MZrIvjX6h2JEqzGbspJ+yissL6+wfnzJmBK8zVJlAOnxnmzfF5TCDMHoHoER7Lr1dMpSAzmj0/EAtm4Af6trtfEIkamc Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:14 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 06/10] iommu/rockchip: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:58 +0000 Message-ID: <20240207174102.1486130-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D0D9720016 X-Stat-Signature: ogb1h8oogcmp6hsq3q3yfkamptre8wew X-Rspam-User: X-HE-Tag: 1707327675-980076 X-HE-Meta: U2Fs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6c0NhFmHdgpFdZQTCZxHjA3CMIOQiAZ/05UTjYkXIXbgKOXJC2857bTArFMrHHqnhN+vsIqCe8rR5b5uxsxMQY3Vjhf+/IN+qUmnBPJKDdIWfIldnskMflJ7K72gWVaoDrR2DXa+svwotWM9Ol6AFGPWy5lXdVxdv48C/1kbt0C6if/PE12PRNotAN/PgnTHvThM3Rxv83B/x286muYvZR1V8Bbx7tr8cQYKXO9e/a992gO1TxaMsiYbd0BsR06/zcUSe4leA7GyfOUY1tJnPZng2lfhvskwknXuq9qPvjPImjvaOk66l0qaoa5iI0SmWxxTxZa2iZPeBPRaaH8AlO8b9dtwF/SFAh04JXQpu 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 2685861c0a12..e04f22d481d0 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 Wed Feb 7 17:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548807 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 AAAFCC4829C for ; Wed, 7 Feb 2024 17:41:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 556BE6B0082; Wed, 7 Feb 2024 12:41:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5097E6B0083; Wed, 7 Feb 2024 12:41:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E6466B0085; Wed, 7 Feb 2024 12:41:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1935F6B0082 for ; Wed, 7 Feb 2024 12:41:19 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ED6E8A071C for ; Wed, 7 Feb 2024 17:41:18 +0000 (UTC) X-FDA: 81765724236.11.8E32767 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf26.hostedemail.com (Postfix) with ESMTP id 2B346140011 for ; Wed, 7 Feb 2024 17:41:16 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=LOUTKgvx; dmarc=none; spf=none (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327677; 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=wfVh0oPEahUZvzrBZ9xf+/i5rxN2+U5mi493evzNcuQ=; b=A4Zv1VmcLNlV4zVjRSarSCO7pilZX/SDn7fK9qwd+pblGj4uo28wn/iOq2x4Gr27FISHht hYXY6uUz4OZHxZWXZW8fjEvcHTCf65k8HhqUxY99iinr0X4d6qYw7DvGR1i6EbsWCHuDiZ +rkNHz1Y4+tjGORbFrWJfXw7qbW/6Gw= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=LOUTKgvx; dmarc=none; spf=none (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327677; a=rsa-sha256; cv=none; b=vEOok1jVPCmpvOp+nPkyyF04RorzbCCaxVqWNaSumXCRTwvCPMskyvBQ1cOVIWdjTrZiV7 EVZgDgDPvZAPRAvFZ3Uipu3pGuWpG5OjbiIx79/cw8UhKyjwQMDXsbqPiOJkgfh/pGm1Fp xYVma7GJdiQZrHYIKa17I4XeYKOU9Eg= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-783eb452e01so5232185a.1 for ; Wed, 07 Feb 2024 09:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327676; x=1707932476; 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=wfVh0oPEahUZvzrBZ9xf+/i5rxN2+U5mi493evzNcuQ=; b=LOUTKgvx+cAvfmWzYXbVPl5AqiVxjxQ7JaxG25H3iRlm2sskw/fr1FOXjwzJKQ37wI RkfMJTJG5+USN9hOL8gT+BLMGLlzjAwtErhAyn/quF6s47opzSBlhBJngtD+W8wAn2NG K/OsfI6BVrKQh0JTLuvmBfEZNA8A8uAWTjfL/5dxbpqe5vd9V0NPU1gMh6v202xGYRHo SYamymjRHu4jEVgtKxhwyqNL8qELG/Bg0/wacP/EB3CPCgqp19TxfNGoSt2NbE3tiJXC VAl+MuQVTzIUbZk+IynD/x5r5R5LbhrJ9XEUnr+eR8EcMCdIqHmgJ5XEKzdW+fJou/wk 4Jmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327676; x=1707932476; 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=wfVh0oPEahUZvzrBZ9xf+/i5rxN2+U5mi493evzNcuQ=; b=iS2CnaUIDi54VmKBuIYe7x6sUCBm6n0pQhHfHvke9dYIoW3UzR+SOmJtHr6jBsvczO V2V7u6xgywo1zFAX+VcFKEBxBpEv1aOfWKTfOKJ0O/HKWM8STYKxtMN2mdyirrcXbIKs lElzLn7IY+EtCMvBtPxhRCpvlVxzx7Z2H544gCNEyiTIkg5KL6yLMdytRmP64wefWLnC pSsQJyO6d/rVbDZe97LoVoBZe7VcAfRbmiF4G2uU3KA7KUCSM9ryf2NlmFf+c7sWSA8e ejWZf+pp7vEzzhenNsdEDWboJlnTVCosvgEjMTjzVGIyaRMQGTmW1clHWW9xe9e/iT47 ULeQ== X-Forwarded-Encrypted: i=1; AJvYcCV8G4POvAd/3yJgDVz/8iqg6G5SctPz2CB8wAheAfRnNldCqoKYXFG5WsU6Rt31Cl7Abl04E1Zq3NDEHWnt/hgCvo8= X-Gm-Message-State: AOJu0YzL8wIBXom1vZVw0xsxd0/vhqWntnDW0HUdry3bOXfElpmUQ7Ma 5zjQoVNVcIrvFUFfhkYGsbUaEJ4HrUZd3WFnK5BtEpRkfU/iabQJCJB6LjO/eGE= X-Google-Smtp-Source: AGHT+IEYw/oN3ccwsdwQFv2jRl2FvfT6B6nkPyMXJGG4ZBtYYD02TxlhcFEf6LXGuUiTE1mdL7ys/w== X-Received: by 2002:a05:620a:2191:b0:785:a0fd:26c with SMTP id g17-20020a05620a219100b00785a0fd026cmr230165qka.36.1707327676289; Wed, 07 Feb 2024 09:41:16 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVXXSvczqKSyNm43JX5/tzjrxJXXar4QNtSDMhqU2+N72ON7heLA3zeXwN1sPD8iNP1Ua3viph4VSvSaigEeBs+4AB16FSQoHG3nR2ARKpJ6Z6eqdW6RZ/Dx5gVULGUeNiZJ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tLN291FEcNxHSFVc9VoRJotuYKq+P9z10tdNS+gaUUxRVwOH60jk5JdNq6iqwWPhfb90cWSdU5X/SASbKNAWT2TUn7fb+cqTPdJqZU5F61vo4y6m5LgEiIZFuY8ciAZqGeXCJ4KoNYNcloHQYen9MDAb9yvPdMPytSIThAuivd6JL/t1mQ68T7pjNDeJUQ62Bl8xjmJOCkONVL1QfNYzX6G15djtpimeWhgGmyglvGJqsqIKWUnJObt/eRFoB8y Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:15 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 07/10] iommu/sun50i: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:40:59 +0000 Message-ID: <20240207174102.1486130-8-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2B346140011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dgq8nu6ty1ynwxdpbgjbkfmuoumo8hh7 X-HE-Tag: 1707327676-928666 X-HE-Meta: U2FsdGVkX19uVj9IGKcqNtIs/sbW3oWbv1/Nx17LICpQapz6DKBQUY3Rd8WEkT85hOxDlvVjHA/qnyIfM0ow2Tvh0KQbmsG671V1QCqRtJ2jT5jcS/p/da7irZanasN4xDoo/rCk23CDtH/C8CzSu/zTw89uh5S8mDGmvOGCNza/KmsBXtHZxQMZTNkDoQ7EUZ21jdpJT3GYaHlyzch6GGQH5jb66981UOI2uWGPsahyKyxCiQqfCVDhjRD2GrvBDVaVeMtMslUHv/3qoCZeCLc58KwHNBk1ZTV4KxG/LWK3b/O3qv2TWWzDMylrSsrYnCcJQxazPNxX9GM2At6Z5Kn4dqyiNuOfUBlEnfE/3fL36pA51dRE/O/joLD2XrH2dOo7ZN/f1zp7KLnGbn7yMI7SnR7AqegLD3aMQXbMBCQQVJf4xv/BzTfrI4V2aFo7OHq563d32/EYHVKV2RI00qbp0a+HHg4qL7c5QpP46r8bGkAWY8SNIv2AKdKAn1RN9ZxqjyEQn4Nl1le1tj8cLb9jZAs6Yu7VVzxAPDaCrWdchYkwpO3m0Ld9bLL9w+JUOOhi6AnjWvCCJayDVona2yFSW+ecIFFDw5M49edW/ZaBbNyhL03ISeeMrbG8jgU2YFNJZrv198kbE3nwxje6xYT7vEmu5vqOepJsWAdioTEJPkx/ZG91fIloRYVm8n8hfqhZgwrxbtoyAP6jUntTdm/SzPtNZ1csUNyfN8y0m+7VTRRZgJjdC56U85vwx4E96XY7i+BqTyi3pLL2FyLXDvz7+Lnaos04ywDRFpeaNSI9APOGB2OefjhVlWE7HttAmjJftpWRXG+3Vv62kIsDkdfHMo4PDUebS0ytengnP5b51sYqnbwcq4HGcBBpaLKLHQGZlGkwWxN3eMpB+h0zeYACfRM/BdBeIy3cLtR3HPurAmtaErfPpxOMVKLuNVi017oBUP2yUOdRwqDRGSC iQ6eNBy1 3RlvgMadoPjD304xXdzbHpD/K+8iFnj45RNR0tpAbSSpualMkRRJ/lutWlRJ3jwOI8RU2wSYWOOkNLmKYBtU3SfKZ/lAf5J5ECrqi7e4mwff5XcENYsPZ50oh6MRz+AVASqhuSd+Vr/f5bRa8eBcJSNjPNrNHnZ38+K8c++2Z77/R65o87j0aHLfvHDNkIrRjPbFbfyePtltia0phU8pesSkBjfBOC1KrWi9QkCMO4EJ3VfZbhz2k8lMdPSKG+ZBT4l+qFFuXn/+gUahm73s0Jf7DDeoSlLDsp6I6VEnTBq3Rn69L9aw+WLmZnAsTtdsLEdAKss8hXuxzGVbYI7lkYXQDwheI8hjIrbYjdFJNKodGyLXCo7rS2Q0nH+hVQu1lZrTnDU/dGmmjJnXF5HrJH5W/XTz6qFEv1kZNpLqVri0hSLcbekU4vQvSAF7H+p1OfvKo 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 Tested-by: Bagas Sanjaya Acked-by: Jernej Skrabec --- drivers/iommu/sun50i-iommu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c index 41484a5a399b..172ddb717eb5 100644 --- a/drivers/iommu/sun50i-iommu.c +++ b/drivers/iommu/sun50i-iommu.c @@ -26,6 +26,8 @@ #include #include +#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 Wed Feb 7 17:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548808 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 2265DC4828F for ; Wed, 7 Feb 2024 17:41:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97DDE6B0083; Wed, 7 Feb 2024 12:41:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FF806B0087; Wed, 7 Feb 2024 12:41:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7783B6B0088; Wed, 7 Feb 2024 12:41:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6886F6B0083 for ; Wed, 7 Feb 2024 12:41:20 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 38BB416054E for ; Wed, 7 Feb 2024 17:41:20 +0000 (UTC) X-FDA: 81765724320.29.539E11B Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf22.hostedemail.com (Postfix) with ESMTP id 2E586C001E for ; Wed, 7 Feb 2024 17:41:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b="M/+qSCQM"; spf=none (imf22.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.177) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327678; 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=xWt6Kj9gOwsVhKnLqI4ecc+RWbgSNCQCfN6SnKHrmRU=; b=IPApgT5LdTSTyM0wQbx/xO1EIFqxE3DBDoa5utc9gkB0JRDvHCHNgGjtInFyx6dHr1Ej7/ cBqlpZpBzQlbM8ArlQUujC0EKgTj2fA51f5pNa9YD6e354cSJsLeH3japjHdnwxgpPn3Is oh36q61KNbt1glfvEVIrQqaaccHQkBQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327678; a=rsa-sha256; cv=none; b=3mPFcAlQigMK/ZVzRRHzPeG5UGHBjiWKLMNBgHfBu/GKig7XnS4G2y8u8/oQe5+jlNiWZ0 up9fyjfGB/GJWosB2/2wQ362//c9D9x8QtPqTjpu4B2ODLsTmtnl1fOxuSJkoGyLzO85B6 yIMWlDyKFYl9NaLByohQ3kEYO61wpOI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b="M/+qSCQM"; spf=none (imf22.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.177) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-781753f52afso47877885a.2 for ; Wed, 07 Feb 2024 09:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327677; x=1707932477; 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=xWt6Kj9gOwsVhKnLqI4ecc+RWbgSNCQCfN6SnKHrmRU=; b=M/+qSCQMSiE03W4wtYFORWD/xOl/gRkFeyyyq5pIdgQKvx0xpn8Hv/GNdkBqLQwEN2 +ceTCw7k+2X0xlFHMVbtLTwP4Cw5GiZMIb6OzrsY+vSthmR9C5kngqPl5Zl+dfpnZ3ut +9FhP7WMAMjfff+lBZZpSksqxUrEt3t+6ejGjTxsl1YIY6YdakOAzRtnUKuKIvW3R9NJ x+iJqH67Ulc6e31YNqqVf/zwXOPNah/fQcZQxkfpjXrXn6/LTrFhnPr5TIlmP/ixk0oj nFJJjDCiC+U/t2BnTCYR/7VvzOWVKywv+NFWPx4o01noLp2Ng+bQ3Dqp5y2siWNAlVAl fSiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327677; x=1707932477; 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=xWt6Kj9gOwsVhKnLqI4ecc+RWbgSNCQCfN6SnKHrmRU=; b=I7eTKIoLJBiWFMZtYt+4wYc6wkAAOXAgln8lscYCaAAoZe0E4+YutwjjFK6UO9Epdv m4T03dhNmuzyDAX4fZDe2outT7qtSSIO61X8uPeHc5YmHjf8zaLbik2iBHW+cuJEPj/i h+/iwY06B4o83aPv77ANgkR3biMw40kX75YMtLgg9yt8vYK9JmaWHbwRHWFvpRIeR96d PSI0sYgkSY4/CHQhxpXE8WtWsu4+rQ3l3mts22iXC8wNQ9BWXocMWBdmbyOYclEE/r0z oZI07IUsARy59nbu+NTGSqFv3HVnq9/HD1pfjH6Mka2xm2jf8Uk5ZseRbaKnS/L5xB+7 0Ssw== X-Gm-Message-State: AOJu0Yykq9r8TaOxP5NbH8qmjNN4XODBb+wQas/Inew5JQwea2wieS7N hOhrivI3Rs6qENo6mgJT21bixM5bi5I8+83aV6MK6Mb7RWDftKtawkI5xzlqpDg= X-Google-Smtp-Source: AGHT+IHeQy+PfPTf7nBSLMGCvJMntsBufk0Si/3gJdM+srJ22A2iBif8tXuqrNfbof1VrQoYmJ+haw== X-Received: by 2002:a05:620a:24c7:b0:783:4c2b:cd31 with SMTP id m7-20020a05620a24c700b007834c2bcd31mr7624063qkn.44.1707327677315; Wed, 07 Feb 2024 09:41:17 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV07MGvI4Ypo2h445jSLHybue8b/Jl//KnDW5a0waD/mCyzQoo4zwqN1ovns4RyMBF7dWelEXf+y/BMce8UTxxq3OAOyEJdx84aMHu3Xj3LNN0h8+PWnMFEE+z2yOaWBuE59sMW37SvqeY2r+eddvdkbwQQ0visKlJywOwTrMUf8bZCr+C97H8x5rJJN90UubbobWaZA/xY1wS0vWPAquvxEg1hW1l28JQ53ZJx95HU0khGFmoTf79lupjMXxqjmuiNshSoarMoqYJlkOScCqu+AzutOUb3hemyHowzfJt4oQ5vEa1AqDVWJc5qq9GwVhdBQpQ1bjwh/41lfRAoS+zdREj8QtB0yC8Yf3fqjP0bV/AQWGDWDl7AfxCGkqvXaWAi3c0FFJ8LHhlIOPCAfJXSiFfWf6hJY4gnlh1zdcTkDpX5vHjlux7o9mLm8xCEuso7GlAvyaCahljtfdJ3n9He1HG2A1JKk14Dp91svBMy4ACi4YjPBYxU5G6arqfc9Aa9ID46kIFxHAabnsJdGUmoWrSiLJ37J4zqxIFPKteeDOU74RPNvqXXZbrh+kwbVkpkNyZe+ausHvzpbhe53+69z5xvpe5yz9LDtoptdeoq/e95bHyxU06s9O4xJWgegjHXaE/TG9CVzS7e8EQ6S+o3PSzjPJiw2FxqV7XKMv5fNqsaq3ZnMqYOZquy2m+v/zhJILWFJWBJQYb1rEPYtmsadOpw3HuDIXjsc7+VkSguFrWGSWLv8KpJD9KFIRW3LI+MvaImrkmCSzDiSVZ6RDudqEFvZYSmqwS7dR+c9ojQ39rqDcRoUTVPgcq9hYxerx4Zb0hKQlrxZdYZlaeEYtvs70TKIyQjNh/90ivUw0nvVBM979zJloyZT0luhm0T77jolZ/+DUh8NcXLhU99yGpN0jycxaJdWQ/XTPQ3YblLvB/JYpeG6+dinfywPf ndj0evBQ cjwGWfxcAlsvta7HagMoAKkZDmGrKu6IQAXTkfceEaOFQjobeyFL7uPcD9WqPNUuTcinn6O2hVSaDE3sB91Fe25TnZxotHh7OfdDU6pVyT5VjN5xHg8ym4Qy8zTk7FhXznhJubrj5oIYVZd7dTTCR6P0f+WG/aKlC2Uv1CpzhAUn5GH/Bc11h/mtj4gUypoq0KQEevPp5E+tw4JPNQGTKi05iYJiEoXJXGCV167QIg4d8lnRnJM41YFlpwAVduF39jQYyREhtCqzsX9O5lpM4WNzt5CxhwcXH3TL905ZjPt804cwe+TFZc+HM/tZC5gRtjBtVeZb/l/cV0C8UVs2UJsWZqdeH83YNXz6q/p4t7x9MRhw58c7FqTjP4PppYzx7DQGiI/8b7Yz5uKM+/NZUCMppthUMAdoId8salBi+S/s5S9pMfWNkj6O/yEOAkekKT1ezCkB+lRuTIX+hjVWjWA4AxIqA8e/PiDfl4OamSHsHK Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:16 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 08/10] iommu/tegra-smmu: use page allocation function provided by iommu-pages.h Date: Wed, 7 Feb 2024 17:41:00 +0000 Message-ID: <20240207174102.1486130-9-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E586C001E X-Rspam-User: X-Stat-Signature: rphhwyj9pw4r1bzxykhtx7pf8zei4t3j X-Rspamd-Server: rspam03 X-HE-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roam9hd0mDTZ03gK4i/oiN4dHTIIzIQgoLKo2miqMNY/X4WrS8X7OHf4U/XeDwAg+CAa07UrzVjSgw0x6JR2bS0QCIZHg1CT1TgsiL0h3QrKwYavGvcEpcMPxPwQFRWMxd9903sWhnhz1EJqUd+vsGd58DnYunOFgDt6QTTioWP1Sjhd1aWzTz13kWC1gPsFdMVzMxMUHoQ/ATf0FH16jTTrPI7O4+J8c3uqVZWgrCeeHuT4s1R6L0EEZvJMN3YXAO5AdxfTdPlnqRbQePxiB6lF9+a7CroA41FAtp+eG+/VP8dcyfa9I4Ho4wschDNhjnGymxHMg7Pmz9By++IHwOqbjdNK+5+bbPULEZZLQ5OzOdetU73xuWvPLT1/uVRCEB5kV43w== 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 310871728ab4..5e0730dc1b0e 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_page(GFP_KERNEL | __GFP_DMA); 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_page(as->pd); 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_page(as->pd); kfree(as); return NULL; } @@ -599,14 +601,14 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova, dma = dma_map_page(smmu->dev, page, 0, SMMU_SIZE_PT, DMA_TO_DEVICE); if (dma_mapping_error(smmu->dev, dma)) { - __free_page(page); + __iommu_free_page(page); return NULL; } if (!smmu_dma_addr_valid(smmu, dma)) { dma_unmap_page(smmu->dev, dma, SMMU_SIZE_PT, DMA_TO_DEVICE); - __free_page(page); + __iommu_free_page(page); return NULL; } @@ -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_page(page); 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_page(gfp | __GFP_DMA); 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_page(page); page = as->pts[pde]; } From patchwork Wed Feb 7 17:41:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548809 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 74A3FC4829C for ; Wed, 7 Feb 2024 17:41:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE6B96B0087; Wed, 7 Feb 2024 12:41:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B98436B0088; Wed, 7 Feb 2024 12:41:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5E596B008A; Wed, 7 Feb 2024 12:41:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9749C6B0087 for ; Wed, 7 Feb 2024 12:41:21 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6CAF5A059C for ; Wed, 7 Feb 2024 17:41:21 +0000 (UTC) X-FDA: 81765724362.21.83A4465 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) by imf28.hostedemail.com (Postfix) with ESMTP id A5B56C0017 for ; Wed, 7 Feb 2024 17:41:19 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=hr964bqj; dmarc=none; spf=none (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327679; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=ySsYR0ZT3+LB5nMa+IC6V2tfjlq4FsyP70sCmdO/lK+/DUAh9cJ3JtPn5jSZfSvSTD0PMV 0WQ8d0rOow5lXSlmDJw2LHzSkSvJEe6zK3iefWJAIqDdm4P18DIjInl5Cos2eWUqQCZCfC C8Ol/VvpkPOGDViRGIFzU8u5Sx+u2Mc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=hr964bqj; dmarc=none; spf=none (imf28.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.170) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327679; a=rsa-sha256; cv=none; b=8pzjcjHV9vk8Xjs7xD1nXxbu62nWubDtOI0P9W1EJcLOwvoRj9WkAohZMK6Tz07mvcmiWD 2juvma+i0Hn+d8jNz+tkSOoBR4ByfNf0gOFTCv9i539XCvrF0DyjwMJ3CaOTdhpZzaiPRU JbvTE5T958sK2pcvp691hbAtynznznQ= Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-78405c9a152so56943985a.1 for ; Wed, 07 Feb 2024 09:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327679; x=1707932479; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=hr964bqj30gg58icmHfp/dcnahR83UBkQj0/sukFq3u3o4exBhr+OMya8tbmuhfOoI YBR69ccK5ZAfkD1Lp+Gi+iK6whwW697SAHPJufWwSYJaTMqnse1+2k4IKyu553XgGLC0 l9E3XyeL5f9ixuRrbrm2rBigrGZ+YdU+LsrvE2H/O4gVlt6c0tOa+1K0sIqM82MIFLdC dJ9l6yXRIBLwyHffqN1f5tpbrrqezNa4+dhIA973HqeNclGj8LK2zSZ3QPGXhEh0VlD9 0eATAoArlOuSBHynb+rDi42RC/JW906lgXeh4XDTx08tduh3aazXSxHDOZXYgaf46lmU QdWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327679; x=1707932479; 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=aOJ5ut398ow/2WlP29EDaCAozkqg/KeyQvQPT/mKdCU=; b=u3Y531ryBv3iCaQOAT/fFH0I423D5rp+aGlTyFRsKXkNjejGqFR1iUVFq8CE6nnQiQ i6B/rq1MuIwmrCBlbZPUffhb6rKBj30TSN/HoO8jXMurwOTwM05f+Q7hTyQ3QkPZxRjI OhEr0/PUilSGcAw1fICT075+FcJGKq9LI98qtcvMF9wTkEpJpEFsf7++lxJK7/vAHKob yt9yuLagbsPWKsUmye5kyob7VSo3UOzmDQABCdGwU02sH1+Vvy5KVVl/gG3J9OXaYdGm La8dkBLF03HcGZgR+vChfkhm+lrMADrZX24L3LRJCOIVygjQ4wkeEk5e/R5WvXsFzIm6 SmZQ== X-Gm-Message-State: AOJu0YwgXmGSgjKTV8sAmImfu7ynG/9eWA5I5FLVm3k+HzmDQOSr25H2 XdKtnYQtWQsIy+nXBydtc2Hbq5hY+8SzloJlsb5214TRmJf5gHbPXWVLCVHuPsA= X-Google-Smtp-Source: AGHT+IGzHmYfHKKzBsKfi2sS1p/R7NZ/BV205sSyGSsoTpCiCT38UMcgyp+aJmcRhxrEuO8FJ5t6XA== X-Received: by 2002:a05:620a:190e:b0:783:549a:aa3f with SMTP id bj14-20020a05620a190e00b00783549aaa3fmr6972919qkb.67.1707327678787; Wed, 07 Feb 2024 09:41:18 -0800 (PST) X-Forwarded-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hobwhz309FnEBGy3p4duYtaZy1zL2a4zFrNv5tiNnNcl0oJQIymIZEpA0gTG5Efh7EhezVq+BSrf/HYiigfcwHL2Kk0NSzTpZ1MdpdyJIqYVNw8qE0NZs/+w1hYGvTx09SD5Nyi9xL3/BRW2rCQxgyeyXpqGjk4oyXoKnR3l8WNiJ1iJD0nmckKOAXNplAPi/pNtSQ2aFjtC+ApLt075lhvFnm6wSPA8FBaPLrsV4jV48R7yNVf4gpZmuobPWdbcSx3DBmdJTRV3njPssZ/V2j2NiSDHtOBbh1aUz+Ua+gQUiepqzMS1Bw7UsDY3XjEzkvcpINTtsFGpTHvY3dZcb6W0ggjjMkZ309cd/5G3Qjk/+SEAoMU1Z40QF5/SV8NcemsKNKcbEDW6SFstkb0TygjllY Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:18 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 09/10] iommu: observability of the IOMMU allocations Date: Wed, 7 Feb 2024 17:41:01 +0000 Message-ID: <20240207174102.1486130-10-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A5B56C0017 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 6j3juceyxgna1d9ud5d4kzc3s3daioau X-HE-Tag: 1707327679-916237 X-HE-Meta: U2FsdGVkX19Co3Dr98yTTU9NNkasIz0aq8wmNd1yvh1OSHOYLtGCqPxizq5TlJCJiVBXFwGx6zzfjfCFTtRv+6dNUdDDP7ylD1IlRXcmZ1AKarl2TLOkMTb2trkgPWUOMtaGDWBI2kBaDj4pvTWQFgUEmttovWqyGfdRJK8+QxADpMhWoljMNXHrrOcg0GRJdHB+ONPoP5QNrxBFG4bykmIBZx+MVfOWXmT0Wh1r7J42f4PoN2+OUiFV98504a3d2d0CsuAw1jDfOoHsl2427yolc+RaDSBz+LvxyrYCvu9a4aAM33krUW9KscUu4RBmQOl8k9LN7HuMBUDXX4XiInApjqYFWX2mnWZ2F/xCybEF+uiNwYILNokRWiaOScLd7OQTdy0gzgCnhVEuCWkfBSKlkVKRl9ApSHqh/4SBehdrOHVnfd7N1AzIgkDEQ2pW6oCLWb7HjkwPOs9O/hqpP0+m74JgU+tH4M8LYNtBaamVLitW0AxXH9eso8REqemDnRsspCGz/57rkQ4HsCVgbGDvjFYc+5kHjTyNKkwkYA1DXnDsDhKqSHpSG6yg18vNL7uPSFRgDhrKpCAqTVhiO2qAjkgCGFeq8J+XuNIPAWXRr8c9QsXo34P1U7ls/c1Sm7/FZrwhoyzOW5xxZpE78zIUPSAQz2Oinpc87ahNq9+ui+ccSEzKyPC7OxmTKqBx3si3zAlGpJaktf+qwzspr21NJXHDJHaEsXlrkG1v4EQ8ghs6RWh8fR+3pR3bt81QpSRLmIzm5SHanCSWCoaV4v1dGprzsAJwf+4a8aAG9mfPWvIUC3xYIfio7O/GXe1U16nMr153JTZWTYhWJ2kiVXv1UgCFxnYSdoK4Z3qg5iUrlKkcQdbPBYACjcl+2MQS+mGhDMPs2thk3PXmxP9hJYRNqFPFe0lLTYTzztcTwJh+eucDa3bvm5YATJmSUwVXvVgdENLInhUF2kIkbKn 9f9RQ5aX 9epNqkhu+NFOoFB85wvbB1RtHA3VJxzP97rG7isLE2JEi/hzheBrxRfoIIzMfaKX5wpaBdCt1icJ7DTaMK53QFe2giTW7s4ddwVcVRtwDTTAfa1+aSOqVRLo21cjiieNRNizjzpFtl+xtj2Y6NZV6IFTfv4n7zcYXLG5qf21oICZaAJ7FijZcDC/7/veb60xPA8V9B+AQN9bbnSN1OJh7HngBx/x/11C2LWcil1/w5+vU9Q0Xwegp+iWamo1L7NEydWRdKYPlhIMThjRNHUw8GwGgV6FW8JAHcyMwpGprvTg9sLfKholLlcrWkKL/2m6tEGP2bPIMW4CyZg6dTgC6LpQMClrax4s8gklHk3UPri13l1+XNNXg94PbfVopTqgaQV2Sac6Bk6zjK7TRg7VXiEdYOrrbu/4mlDyKFNXanpVAVyRV1ByiLdliWv2FyMDGJcGA 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 c412d0aaa399..7336f976b641 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -17,6 +17,30 @@ * state can be rather large, i.e. multiple gigabytes in size. */ +/** + * __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_node - allocate a zeroed page of a given order from * specific NUMA node. @@ -35,6 +59,8 @@ static inline struct page *__iommu_alloc_pages_node(int nid, gfp_t gfp, if (unlikely(!page)) return NULL; + __iommu_alloc_account(page, order); + return page; } @@ -53,6 +79,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; } @@ -89,6 +117,7 @@ static inline void __iommu_free_pages(struct page *page, int order) if (!page) return; + __iommu_free_account(page, order); __free_pages(page, order); } @@ -197,6 +226,7 @@ static inline void iommu_free_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 a497f189d988..bb6bc504915a 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -203,6 +203,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 Wed Feb 7 17:41:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13548810 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 F00C4C4829F for ; Wed, 7 Feb 2024 17:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBC436B0088; Wed, 7 Feb 2024 12:41:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D944A6B008A; Wed, 7 Feb 2024 12:41:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0D706B008C; Wed, 7 Feb 2024 12:41:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AE7046B0088 for ; Wed, 7 Feb 2024 12:41:22 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 869801403F2 for ; Wed, 7 Feb 2024 17:41:22 +0000 (UTC) X-FDA: 81765724404.06.7106F3D Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf04.hostedemail.com (Postfix) with ESMTP id BCFD74000C for ; Wed, 7 Feb 2024 17:41:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Uh1jK89E; spf=none (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707327680; a=rsa-sha256; cv=none; b=nHapokAsBtLDxwgQlXFMq8kb46P9m8OPm8IxDelPgKt8pBk01iNyeub+d/nyrQwunz/uYy ih3bHlyzPzi3HtjKiwnkXjLwBsyDdhOxWgPBtOpsqKVFoDwgQOpEKuJqlFwmmfDdVWesUb Tkbj3/DbrfmYP61C5GLubonJzg9cumM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none ("invalid DKIM record") header.d=soleen.com header.s=google header.b=Uh1jK89E; spf=none (imf04.hostedemail.com: domain of pasha.tatashin@soleen.com has no SPF policy when checking 209.85.222.178) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707327680; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=oHsMAviuDZVKIjx/fFpjANVNk3rH9WlMi++04PJuUNekGwVN076CbxSm+tKF2GPgzS2HED akCC+pEaIFcFWDHOX/CZD0ywqdjpL7XePFTzAIhxHevrr2DLXAA/NozHZCGRBEiUOEQdPt xirC4XBLDfGgw+tkPVuq/PzEWE4Wx3A= Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-7853a9eb5daso33241685a.2 for ; Wed, 07 Feb 2024 09:41:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1707327680; x=1707932480; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=Uh1jK89EMRQfOMjgO3181uHl4xGWtdi0TFRf79u6h+x91vUrrKDljar3MLAHL3/xa2 NaEzgEG6Ow2a9UxTY9feZdRElLg9TptnzzWozd0VKuJhU8kk/mSjJuZQ6ExEy4WMe3Fs pMv4Yhu6cNwDBJY9wmVwHuUo8x00MkTZ8W12cchbPPoOLPLCJaJvrJjc1lmZL7w9vIaq 1jq5ulw8cpMjZ8C/prK31DmbU3CxTFzeg22c7o/kIw21a0O/MbxPeuq0Zj3VQAAUgnGP w4AmcZpXNMQB2PvQkFlbmAgwayOfOLFUGirlyMEr+TS/Tbgy6OozFryXnoOr9O7ZeXjC JXww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707327680; x=1707932480; 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=HrRTSlkta7nD8c1SJPx3AxPn1tn9y9LkFmhcOlF4lks=; b=IKkcLMNuPOwB7Jr4yXNHHKNC4uTE7XSbeVsLY6ce9yHs40kiZxmxOAOZYcj1yUE8ll 1tFhGqVN/KaXlckhnSejFvME8jlqdsUVMrOOjnpyKIN60IMJzEZS64IGeH2kAz7MC4fM WeksrgCJY7kzGqPIDJT70OdhxjwLu1zMxt3ZT0IU1Kx7PzSnRtXnhNYOmDyv1qHFqhyE kBtB1emzXTQMWhndJdBsQXAtHeT6ryUmeEe90lj6Tj2eIiLb42dUvxRNMCgyB+QlFRGy LKiqTlfRUYXupdwT9owsP2S6NqZdoLURx/JnKbk/maQEHrGHls7+PCCl7qjJHgOQENWa puCg== X-Gm-Message-State: AOJu0YxlDBj+CTwYS46lLDunTL+coUKBuzriVbgu0MMGZIlXfagqo8mD O9bkaKCGBzrfmrIde7wPmcmGtg3mwJJbIbGJ19iNQBMcIRu2gqeYJR4pj5Siu3I= X-Google-Smtp-Source: AGHT+IHhb+pueaISZV6Y8tJp2t2CFo0mWlpmACo7IYuyoV1N2oy7KZrIG0XVhtVG+SmB5cwuhpqy+Q== X-Received: by 2002:a05:620a:12c8:b0:785:3887:de18 with SMTP id e8-20020a05620a12c800b007853887de18mr6401324qkl.65.1707327679899; Wed, 07 Feb 2024 09:41:19 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUCDfKWFIl6QUubNKHOK+J/TQZfBk6GOATQV7+UROelHHizxj2bMScNb5yjy+7wEKvrKAVO938EhFK3MDp4QvVuIEMns3aJNEfZ4lLhVczSUx4hYdn3X7Qx8HTpAiobpDi+dY9UU0JFYWP3sxFQVS1xxl7fcBVSx0blttAqIQWkGbtG/8OFxy5YJX+xNhtsJb3t9pvZsef+YcrlQh+9z7K1HEh5YIvRBqpPod3dD8oKW9DDybH9+3HAaHHBY8iiIHdHyvvhg/Qqh/tY8U66rdo6r4QvsxgmBFMyxznrxlOPKUwMUFVhM2YvFghVr6hKgb6KzPzIvg28q6LrAw8lD7weD0eI2MrfirCmooqnAA/zgK7D0KurMOIDpabn9VkUHuhE88OEKQ8h62/Wa2gdcl4YDdMkJY4DDjELGulQmsDVBCrUtil9loYc5aX8Gh2jq/ztHo3kv5ymJnfZ/h7e7WZdfaZvxSbUL64wc23AYR/EczgayCdZpmGXX2jQE3/KPfSIPAL6DXV6qvHIwUWL4vG18mc7tiVYDE//uM4hJo7eMbISiBgH4sundju5RQWqxyjeA3VcVHj+VPU4vBDpsrZVdnHRZeaGTV3rwC8oZXb19D/7KR1Wm7euJ76N5bgFnA7vjZhfsEp+F03DZsEUpCkkLYMsxrQWrLbAZIy488QP+Zdz41QqcwwktLByJIdIxAeRSxHxin8RRSgrxaqXRKius9NFl4oDbRCD6svZoHMd4UnX0vfYrQ0s8umvFi83/7gbRVCzXY4TP8NJFByhRuhTVTALB1EBu6ny+PtNXEQLdFexeijpQwT5/ahI+mpZ9ajMM7oM3At8FGk5pnU/BL1Nonz5Y8fjdV6tPG/C5Zk6RhURg9qAf+9R8Omad1eFWXxT9K6yqaix3pq9xGAZ8o3pF+xFI149xhPQNCmvLnHRgEmJUeIIm7boC4Kgdr C5bBoaux c6ozrLySOAxoy5JAAUBKnlhPctpWnwmvtfHeBXAM+mRt1+c/cu3MhP0MSUMt9WZHns3r/985c1KNIPq0blR6t+yh5SOQk7YDqh0wPxUpt4Kax6NjryE1iCgR1+E5QeDElNdAVf+hiKcPe5+DO4dGivJK8C2DQW1E5U+dX94X2hiWwHcHd0IHOFqpQBMw3MYyXVibLuxNZq6E5ml+47r+bMOyL/Bqfi3ViLUhztHQ6nikGjlZcsJYY7JUssc0W5vg58IiiHspK92+rwN2jGd4sH3ALx4bgyCF0SF9flcBEtXUjRUNSmob4ETrVkz7HKMS7If6nnJcyM0Vbo0UMoOZmd5knYt1xz+hu+YULQesXnetGwV4BBbVo0WA5dRc2eIzIsQXmdql1aXqiSjGCn5mug3+d3TEVV9PvmDpKEou6WN731U4KQNAZjHoQUf6UFZNlFysQJQPL4NE73c76duMdmUXiGxzZFehKgNvB7y4Wu+1/j Received: from soleen.c.googlers.com.com (249.240.85.34.bc.googleusercontent.com. [34.85.240.249]) by smtp.gmail.com with ESMTPSA id e10-20020a37db0a000000b007854018044bsm696310qki.134.2024.02.07.09.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 09:41:19 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com, rientjes@google.com, bagasdotme@gmail.com, mkoutny@suse.com Subject: [PATCH v4 10/10] iommu: account IOMMU allocated memory Date: Wed, 7 Feb 2024 17:41:02 +0000 Message-ID: <20240207174102.1486130-11-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240207174102.1486130-1-pasha.tatashin@soleen.com> References: <20240207174102.1486130-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BCFD74000C X-Stat-Signature: nijcy869iim15b9oqzchcduiypwr815n X-Rspam-User: X-HE-Tag: 1707327680-804622 X-HE-Meta: U2FsdGVkX1+efKno/E7bMFXu1vDx4eg4ePFxaWLjStJtf+t+wczeb0RK0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HztfzR94nqfMFyv+7PN5aq7GWjCcrup0NHX/pZi/G4fmlHWjuVcF3vIJmomkLe5k82tqW6YYCQniL7hoVDUf15t3b7cNHbFQ8UzbFRMqSklcpaxWHyeV8FsOloAWNWGWLqFAnK8LQpn6fYzzsaNbHdNvnOT018xlJ5oLdX+hMBuY2T18XGmFfPWW8VogRGbatTW3AsgO2rG9iRIa6vGBOZj03A5bFxFC/VPPA/PRoHNymclkSX3altJlkBvAN6HnyKdqUm/TQtK0H+RXaaDAeaMyBjX39bKmVOmz/xQh8+tmSGVH 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 104c6d047d9b..604b2dccdc5a 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 7336f976b641..e3eb93857a73 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -27,6 +27,7 @@ static inline void __iommu_alloc_account(struct page *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); } /** @@ -39,6 +40,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 bb6bc504915a..a18edcf12d53 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -202,7 +202,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