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: 172102 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp658484vqy; Thu, 30 Nov 2023 12:16:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5i6oJ6F5pkH7m406y9qeR0VL2mqHgF1gqymLptgrVYFw5AF8/pHAfViu9lCsibWLdrMDJ X-Received: by 2002:a05:6a00:18a8:b0:6cb:6cac:71d7 with SMTP id x40-20020a056a0018a800b006cb6cac71d7mr27839776pfh.31.1701375373703; Thu, 30 Nov 2023 12:16:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701375373; cv=none; d=google.com; s=arc-20160816; b=LQ0hyx9ndlRgjhlNntc0K/LcbF34qlJ6DU1Z5zuYXgXIc7KDKWIcZmOHZX6ZsnkaB+ 2zqMjAPo5VIhgI2z1yRfXuY2kklNVMFdwvw9yA17Mojb6NX6mOAYEndIIYo08Urkg1CG 3ZzSVaie/2uYmboNAyzwyUcrWO1BPHy+k2p9zg/FwvRudI8lorVL7BKeG/vgNpHVwTJJ UOprzLElSQ0FHByoLTzlDgFZL/2yMe44ETvz6pO3FKWfbU5ABXvLFbTzKy04cgWMYlXR spzpfpw6ebbO5dkPFq8oAhy25lD6aukR8Rt4eHLU2DmYzN+fDrkHENHdI0jC6pD6pN/E Wuuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; fh=EWgL8IBvHPGC0Y7opUuF57pNES+TiFvURSlxmGDMOzg=; b=r10OeKjPOQCRRuizd2CJ+GpRbuZY69HQkmt4/yGRTUqJ1rFjqSh0iwYjQOniPyWWLw SgIrzN80YbsWM19wS4wAQAsf67JT/rn4x3DIJ6HnESMlr2kcU5E1Hb/QYicpU1EjWtzR bWns0Zwd5YHJpVoufYbq21bdaZHy9o7IJcyVpYizw4UTLkMPrwVHcwbxzQSzabeWDImp B9p9Eb/fryYnOWz4DEqQVW/jGXzD01DbcYWI/4a9BwetQJnVy++FrRB+zz+3hv2dJAUO zKEEMeKJ10nQ/AvZ57AVNLgpwVnjOmTFgC74+MiSGFvVdudSQIUoi9s55JIr59T4dt9q oJKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=QfgvyeFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bw18-20020a056a00409200b006cbe638cd99si1936314pfb.368.2023.11.30.12.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:16:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=QfgvyeFp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 702D38090FA3; Thu, 30 Nov 2023 12:15:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376706AbjK3UPU (ORCPT + 99 others); Thu, 30 Nov 2023 15:15:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376652AbjK3UPG (ORCPT ); Thu, 30 Nov 2023 15:15:06 -0500 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782651726 for ; Thu, 30 Nov 2023 12:15:12 -0800 (PST) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-58d9a4e9464so706501eaf.0 for ; Thu, 30 Nov 2023 12:15:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1701375311; x=1701980111; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=QfgvyeFp1CeiZ4e57mb8EOPAemBVt07ijtdGx6DQjzOhGgJaJKu4iGmhRW07CrttVJ sTOqTjr9pZRSDsJh7C8qB3MQ+VLQS3pJwDvT8vzd2AAt6DnPLfxpTw2ilx2xFTuwBTKn UONhLq9NWEksAr5eaCXmSrwPdMSsU1RZ7bCjcHiOzNi25jzsA3fNwGFgjf01ffpfYw4V o5IBinJC1y2D5EZ3J5duApCuqaTIovT4bhy25qLFT+HC4XNjbbK6m4eq4QPm0fcMdCOS aKtXxrD9+wZdwIlQUW6w1oQbKjHJfc1nFzLTmKDWTc7/6nr2IjWMg+AmsZT1m93S4jsu XxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701375311; x=1701980111; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yfTdzFG6SHCh2UHnxot++MviNj2L80bFYdKeG3yhIm0=; b=eDG4R84J71WMBayhjuK7aTm8fUqnQ30F/UbKndyDsvDp0UVuHdkfrHAbB2Q/TyAxtD XbZQM4MiIiFs8b+O9fhs0FSIMyXLcFugz6jdi9eLpsmjJ1RitSr05mlYnpY5z4JW45L0 yEl4GjIM/Gz4m+9/l2Q2paxodFpcepVZ5tHMwsUGgPbg0w6ZG1O34ff6ZFJTWR6s4sWD W7Vlw4iQFqmJHU3PaOGU7lYYqlNoV00/MO5p0koC01jIklOZEzOFgj90hw2yiMPhxMo9 1OANZ19v1kMtGjilflbwYc+t1XnYOV+4olJHR8auu1HtKMsiMxrDGUzYDMk9jbSDgqP1 1O+Q== X-Gm-Message-State: AOJu0YzxxCfxgJ9U+1NkfmWbz+uo7aV8WzUcnvusahGXR01bGmhqTTOT i9qXDwSRn8U/7v6sSOg5K2wRcw== X-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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 12:15:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784021383805489277 X-GMAIL-MSGID: 1784021383805489277 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);