From patchwork Tue Nov 28 20:49:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13471786 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 15A7DC4167B for ; Tue, 28 Nov 2023 20:49:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 093566B0354; Tue, 28 Nov 2023 15:49:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03F9B6B0356; Tue, 28 Nov 2023 15:49:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D87E36B0357; Tue, 28 Nov 2023 15:49:47 -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 C22086B0354 for ; Tue, 28 Nov 2023 15:49:47 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A133D1C0297 for ; Tue, 28 Nov 2023 20:49:47 +0000 (UTC) X-FDA: 81508554414.19.57CFF3F Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf01.hostedemail.com (Postfix) with ESMTP id E2A2F4001C for ; Tue, 28 Nov 2023 20:49:45 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=RcuZHkEF; dmarc=none; spf=pass (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701204585; 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=4JJWGGhifJfmWwzsRRAotq/YxAL9K3n4NSfU3ou+3rE=; b=PUC1var3RAMbrkMAbe+NO9+AcaSnqem6qlGvIXbFyl6jWnCUPUYc09+63Hc7UW/9MAM0of bhR+q+kdh88FwhdP54s8rN+QYfpxZtaSZm1IHZZ55hel+Fdx9Z/SnYbpQ3/ucva04VPY/R ikzXfYHEN4LmJDNBOVA+aO6Fe1SkUiY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=RcuZHkEF; dmarc=none; spf=pass (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701204585; a=rsa-sha256; cv=none; b=dsfxGW35b8IEzwMorQxAAOumpR6qGsgpbhFsMNqvho4QzslI3mA3jq7DgBrK6TOoItn5cI hzz+TaR9JvVFdS/mJoyZvGvLbdBUYpeu/3vdWtloGoLNv0pn40L1XpmEb76Rz5Q7VWK7EE W4e1RqQHqs8U+mrmElgRnYRr0a7CQ3k= Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-67a3e0fb11aso16258346d6.2 for ; Tue, 28 Nov 2023 12:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701204585; x=1701809385; 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=4JJWGGhifJfmWwzsRRAotq/YxAL9K3n4NSfU3ou+3rE=; b=RcuZHkEF1HyP8jVsAGHTFXSsNiKzMCEHCEcDKqJUCDFi7DcdBu5flneoVVUdl077Nt 2igliDDWwG3Al4xgKxq3z7QfFb0B9+08/qdH+/l6cfnWpK+BcuCtl5pTpqTIZZoR31FM FuWOl7F0h0znMVRQJ/YmtMo3uA7eqxV667L7S5hOwMETu7EKVPfHm2jknTusrl0jjN8h 2oINB5Cf+q5Eyw6cxJqf9ayR+31XraTJ/mc8lN1KG6/iy9rJSPatS2oIGhtQ73AQ53El Hap4S8oVag1Ls5Fa/5o8wWBaR1D98NVHEIMPWQb1q1NKmbavIvHPAEyZkOUwMwnfKya7 AWjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701204585; x=1701809385; 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=4JJWGGhifJfmWwzsRRAotq/YxAL9K3n4NSfU3ou+3rE=; b=MnR51/pq+/PdzkxSDeqkTfZcRJHm34sB9ciMRaWeojvNvGfF7oR+zWTCiuKK1khm4O F356HlK88oOSgfGWLO0LYUk9/+ojvO17JkULStRWs0+uzIf2PpOR1Yxyn3w4RIO5+M7n yhRsEHAtiSC2VLXp06tci0r8JLRFey3LT1EPLlE1zn3V7fn5Wkb7X/Frm4eA2PsxZR0I 2pkK87QYNOJg5k6D+icHmIJayX1Tq8GsCK2rRM4pl0s7AA54GC60t/XsyNBYKqPF8MQS s0TTGiDoHPRUhql9arQcvEZhU5F7i0tJNtDbseYVXFfB2mZlveeUfuM121dDI/n+ndY0 ihzg== X-Gm-Message-State: AOJu0YwXglCcqPd5uWIR2xd/H23GTq1NXwDDn40SzYBq2ijFNjCgdltB 46lrhixHRHW42z68ejMblt214g== X-Google-Smtp-Source: AGHT+IEDZ/ij59NC+/N0WE8v2site2Dd8U3b4CDvl6tiF76N0ZJEMNbYN0ZJKJUKEFAmf3sLjyNRCw== X-Received: by 2002:ad4:5499:0:b0:67a:5744:264c with SMTP id pv25-20020ad45499000000b0067a5744264cmr3635072qvb.55.1701204585073; Tue, 28 Nov 2023 12:49:45 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id d11-20020a0cfe8b000000b0067a56b6adfesm1056863qvs.71.2023.11.28.12.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 12:49:44 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alex.williamson@redhat.com, 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, jasowang@redhat.com, jernej.skrabec@gmail.com, jgg@ziepe.ca, jonathanh@nvidia.com, joro@8bytes.org, kevin.tian@intel.com, krzysztof.kozlowski@linaro.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.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, mst@redhat.com, m.szyprowski@samsung.com, netdev@vger.kernel.org, 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, virtualization@lists.linux.dev, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com Subject: [PATCH 04/16] iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h Date: Tue, 28 Nov 2023 20:49:26 +0000 Message-ID: <20231128204938.1453583-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231128204938.1453583-1-pasha.tatashin@soleen.com> References: <20231128204938.1453583-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E2A2F4001C X-Stat-Signature: 5dhdpbyff1swdti17rdhpcgzsfpx5wxi X-HE-Tag: 1701204585-417476 X-HE-Meta: U2FsdGVkX18qbM3hFTsohppKNr2H9Ssf0qAXKAMOj3enoH255MGZl+prj7ndC4GnTB2dKOhSlx+ih+seFrQYscyb/y+B0Qg5dU8isoWbXzovkfkRsqZpQpU2spbTitolH6yC3peC6+GCiJyzLKtAMOQTUMuzTh++hqbKxn9rXws6mHYyN4lPeHJlTo47kVuZ57dFTr0G2peca3iG/EPi1HjNZ12UIzxrtVt4XYnBTf7pSGnQeBOWOV1TAwrBvRZVnSwV1gI4CCSwqKfisvU1f0qgLeAc5G4zsE7rTm3LlZR3BrUbfI4bKJc0IyP0oizqdlCi9SpRZEk8T+PZndjlNC4uI9k5VuIs/JFecmZJ0QgzQ5L9jSvACoxLvOKzz3aJazDemxcOJEySYPEj0+LWs2BuKfDQsIwA7D7yM0CKtWArnv34vRL9+jc1fs3D9Sz3+X1lYgbeAobwP38q0NAB6MGYVBhZ0ydbqEji9Fbp4aRlLK4p87gh1ezZS5XGejcLb/p8lePy0nveohZBXfmVhUfwTr9eYPwcU7hGywGsoLIi2w4wE6juZJciJneOtlcFuIqH7Ra+c9/+CAkMuTMjMaYyyerk1634j+qTY43/qpAeNiOSOvEn6SB3e6WDgLaqHt8tN6CbUb//G53p6LhdlRqMnVeF3VheGsHnV3+H8WQ5k6RSL+8dP4OHlQKETxNX2XoxCO+2elSzIm93TQKYPkKyM6KnMlAp8ihkxA/Ws4W4hoPYbaznUSmCwc2bw8tB8YPKxFhXiTBBe8xISbsIT65tlmfTeS4qjF+Ffms5YQ+4v7eNKzprEsirEm6FjgRUpuJhkhYE26eW4FLW5xhMS3RR1mGg/GKPtz+V1awmoWkPDfAFuVMNwt4OlfewBPuHFMyqXbDo5ruiJJxJbqwtia7tDyOt4npAM7s+zHNYGVXm78+hvd9kRKXruAX+xGYUIAUDMJZBIhXD/1dVvbt uTqg7/CB qwrasENEzLsLPpOiAgyn7IHSxSdi6QwaMQPf9ZuC7HHkxpfNeOzdTWoTMilmEx7QmERCrXr1I+1yDoUmmwynPIk75Uy1SZz5b0Lr2VBuM4H5IqO2Mn2HAq3qRkrcwlCqf53Z81RCCqjRxP4oaz4/YaGlCNLZ7B380BCEMWMXkBu8NN/bYOn5raRnmNpe6K+Y9eOuB8MysnnUChAtRQUGsC8jV2PrLxDCaEClOqobUOoYT3NafX5s87msiowzmHg05ffWeY9aHC7jVJeMctKXsAUwv7rTOTOg8LJhY3sCig7CMasnxcNSZXua6hf71zfIZhYjzHuzi/PSJ8fVUoSHm0aaSKgILXSIxBst2 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. Signed-off-by: Pasha Tatashin Reviewed-by: Janne Grunau --- 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);