From patchwork Thu Nov 30 20:14:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13475016 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 02C78C07CA9 for ; Thu, 30 Nov 2023 20:15:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC6976B049C; Thu, 30 Nov 2023 15:15:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B5A6F6B049D; Thu, 30 Nov 2023 15:15:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 952476B049E; Thu, 30 Nov 2023 15:15:14 -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 7867E6B049C for ; Thu, 30 Nov 2023 15:15:14 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 57AC1140313 for ; Thu, 30 Nov 2023 20:15:14 +0000 (UTC) X-FDA: 81515724948.10.637C42A Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by imf01.hostedemail.com (Postfix) with ESMTP id 9660A40006 for ; Thu, 30 Nov 2023 20:15:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=NNA2UTJI; dmarc=none; spf=pass (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.43 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=1701375312; 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=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=7OBCdkidfIwOxvPkqayF01o3zk37nfHSjtfNvFUo5rcwuYLq1eM0XxiaAHYQJyCLOgCQAb P04IUps7eTCqc3bDJmpUmHEefqL/4HL1Ufx4JmNyIqNmAHtB8qiJMv9yFGtQXHgIZ0QmXI ElZ7CQAS/+bPHiSpchg8F0gVljwokZs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=NNA2UTJI; dmarc=none; spf=pass (imf01.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.161.43 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701375312; a=rsa-sha256; cv=none; b=puNuihe6o5C4u1oophkulc4uoMCFFfj+hFawV7jbpCVzgsDFH46p+jj4mKZ90hTnJmG+ur WqHY016VvRVlzkQeQxfo6v37fKbBsohGFZKEtHeZg9hdt3/V3xPV6iVemjliDWwuhTZSUe qlwRxQP3kIN7KQi9WReVONO3ycssxZo= Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-58ceab7daddso698029eaf.3 for ; Thu, 30 Nov 2023 12:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375311; x=1701980111; darn=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=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=NNA2UTJIC9H719SihmmwVST9bjB3PCMP44pbT/Sk9khvW56pKW+UxGfip4POEqh7ep LX9AOKlRa+XV3NvPkElxXsTPLpmLSR2FpwlzQrVPUKOsn0RIO1uGXXqEsHSpfyjZCZDg oushfEAGXo6kfVegvSTqVg8qaKUlf/KkNMZCiygDfOQq/B25rf1ZLSKj9o5FGiA/ziHc ebCWahkkDbFZiDw8dc/fu4UT9JR1IMm5AVXiYDEPkNsX+wsBQryU5l1qa9qwAdaL3tNe XIVX3N+HeSkRunqMD8k0siwowdJ/aWWky92tS8jea4BNpeoxZ+EwULbqI+jnogq15a7b /3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375311; x=1701980111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=Iz9OelkpAZgLj0E/IZQodXt5oWuLu4YZqQ6dpvP6P6+xActJn5Yky8xvW9l2PpjbGz fj7isO7Z509qrzE054Ktk5+oeuX4YjuPz7AYTKAlZ/KR9M64F9L+/wOQjpGAHStWrv9J MxZkY72YAxykIM+hXZw29+NAsat8gBPzBHE2yiX+ZJJp7PjX9wl2lVuD/G7apQ3+MVQ+ PZ/jOcGvlPFkn1nVHJOOfSaORS7zmQqXlQsygiRCBqNGIKXd0e+FRz/y7Z99Mjen++ZT e+LqDncgQxvZd7GScy6M06NZ2bBlcVswyeHnk7etS7s0N10it9D7IEMzXnestNI443Oa vU/Q== X-Gm-Message-State: AOJu0Yy6P5//oejG6UYMohJZ2pgmPvpHR2Bz3l43MuuFroQNLhCsOeP3 Cc7b5qanbaTDmAGqVpqADzCXXA== X-Google-Smtp-Source: AGHT+IFMEwE+ifBtQCWWH8W7nWxbE36GDcNl4TH5XHATcaDXANsvzTlHeJN6S0z8EPAHXXipNQHPnA== X-Received: by 2002:a05:6870:41cd:b0:1fa:c97:220a with SMTP id z13-20020a05687041cd00b001fa0c97220amr24204427oac.10.1701375311601; Thu, 30 Nov 2023 12:15:11 -0800 (PST) Received: from soleen.c.googlers.com.com (55.87.194.35.bc.googleusercontent.com. [35.194.87.55]) by smtp.gmail.com with ESMTPSA id e1-20020a0cb441000000b0067a35608186sm795252qvf.28.2023.11.30.12.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:15:11 -0800 (PST) From: Pasha Tatashin To: akpm@linux-foundation.org, alim.akhtar@samsung.com, alyssa@rosenzweig.io, asahi@lists.linux.dev, baolu.lu@linux.intel.com, bhelgaas@google.com, cgroups@vger.kernel.org, corbet@lwn.net, david@redhat.com, dwmw2@infradead.org, hannes@cmpxchg.org, heiko@sntech.de, iommu@lists.linux.dev, jernej.skrabec@gmail.com, jonathanh@nvidia.com, joro@8bytes.org, krzysztof.kozlowski@linaro.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, lizefan.x@bytedance.com, marcan@marcan.st, mhiramat@kernel.org, m.szyprowski@samsung.com, pasha.tatashin@soleen.com, paulmck@kernel.org, rdunlap@infradead.org, robin.murphy@arm.com, samuel@sholland.org, suravee.suthikulpanit@amd.com, sven@svenpeter.dev, thierry.reding@gmail.com, tj@kernel.org, tomas.mudrunka@gmail.com, vdumpa@nvidia.com, wens@csie.org, will@kernel.org, yu-cheng.yu@intel.com Subject: [PATCH v2 04/10] iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h Date: Thu, 30 Nov 2023 20:14:58 +0000 Message-ID: <20231130201504.2322355-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231130201504.2322355-1-pasha.tatashin@soleen.com> References: <20231130201504.2322355-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9660A40006 X-Stat-Signature: o66qoew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Vv1I6GjObWf7A0WxC/4KzEjcO6hnPPyFcI/G7zGM6j4UZBE73EfaEKxY8QLtd1JL2vDBlu0kCII3VFhcUQ9nXqggfWeR0l7MICNL75hkSisgEfE1EnH0fg2nHXvl3B2iywrIiPWsZtRdsSj47dU2mgCtSjoW1hci5bC7haUlEV9RGdq+aMFPTLQoV5wJO5EtTjIvWMoAPMN01bFKQ1NJneyHDALmITbUgXIaXpCBD8FcoPZ37SJ0qUvGrtaUnSJz3ulTnt8ZOWVO2ppaiqQCs01wYw4jNt/qUrHqDmqTeDQt2u4iXYol1/YIiGI0NKRPTkm/bhqVi/sskleAi89CTAUDOu7Mdds1JRxBqMt9j4K2fGrCrL32vzKBtkTbCl7VBrrw4D+x6lNWl1cLkrQE1l8ZCP4KcJ2zqpVEcNMhZ/fJVdkbN4AT2oLFzL4t9RGG11dEBb1SrYwtSH5LXQle3gOSuJXiox9bUiKnws+jBIp5eieBiPIvjbKz6e6bMsYFO 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 Acked-by: David Rientjes --- drivers/iommu/io-pgtable-dart.c | 37 +++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/io-pgtable-dart.c b/drivers/iommu/io-pgtable-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);