From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48509C35FF3 for ; Tue, 18 Mar 2025 10:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ClRhoNXGPLF8hVLhhp1uGDZXdZglbsBsyVlSEPJSU48=; b=rG6RNTo6wwx6/T foJEedvJahh5pGO8GZhruatnm4X7urO1Pw9bBLUeZD9D7pcIAuFPubYrAf8fGcMVOpda3FMja1Puv dVPvPhPV0vE2SXmsCX5LdK4X9aDurpkPnCryKSRInRHGpu8hG/Gha24NFWdam9TKL2dK0A6MXBTJE hBoFr12i6ENW0IxXBqtJ7E3EXOwv2KRkOu4nDxE+CUiLaHGeYGTxF5eSl5HdULPZy/JYZiTUsxvKE 8AdnwrsKaW8ldLzfXkn4/V3GKcbtciyiJDh0sWubV8DV2RkJXNRwysJ2TwbNB+QNMRYtzshrnsAM8 KoaTVb/A9usElV9uyxAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tuUfc-00000005cbI-1sTk; Tue, 18 Mar 2025 10:59:40 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tuUdv-00000005cSs-1Iey; Tue, 18 Mar 2025 10:57:56 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4ADA713D5; Tue, 18 Mar 2025 03:58:03 -0700 (PDT) Received: from [10.57.40.187] (unknown [10.57.40.187]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DC01D3F63F; Tue, 18 Mar 2025 03:57:48 -0700 (PDT) Message-ID: Date: Tue, 18 Mar 2025 10:57:47 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 20/23] iommu: Update various drivers to pass in lg2sz instead of order to iommu pages To: Mostafa Saleh , Jason Gunthorpe Cc: Alim Akhtar , Alyssa Rosenzweig , Albert Ou , asahi@lists.linux.dev, Lu Baolu , David Woodhouse , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Marek Szyprowski , Hector Martin , Palmer Dabbelt , Paul Walmsley , Samuel Holland , Suravee Suthikulpanit , Sven Peter , Thierry Reding , Tomasz Jeznach , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Bagas Sanjaya , Joerg Roedel , Pasha Tatashin , patches@lists.linux.dev, David Rientjes , Matthew Wilcox References: <0-v3-e797f4dc6918+93057-iommu_pages_jgg@nvidia.com> <20-v3-e797f4dc6918+93057-iommu_pages_jgg@nvidia.com> <20250317133500.GC9311@nvidia.com> From: Robin Murphy Content-Language: en-GB In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250318_035755_443776_4547967D X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On 2025-03-18 10:46 am, Mostafa Saleh wrote: > On Mon, Mar 17, 2025 at 10:35:00AM -0300, Jason Gunthorpe wrote: >> On Wed, Mar 12, 2025 at 12:59:00PM +0000, Mostafa Saleh wrote: >>>> --- a/drivers/iommu/io-pgtable-arm.c >>>> +++ b/drivers/iommu/io-pgtable-arm.c >>>> @@ -263,14 +263,13 @@ static void *__arm_lpae_alloc_pages(size_t size, gfp_t gfp, >>>> void *cookie) >>>> { >>>> struct device *dev = cfg->iommu_dev; >>>> - int order = get_order(size); >>>> dma_addr_t dma; >>>> void *pages; >>>> >>>> if (cfg->alloc) >>>> pages = cfg->alloc(cookie, size, gfp); >>>> else >>>> - pages = iommu_alloc_pages_node(dev_to_node(dev), gfp, order); >>>> + pages = iommu_alloc_pages_node_sz(dev_to_node(dev), gfp, size); >>> >>> Although, the current implementation of iommu_alloc_pages_node_sz() would round >>> the size to order, but this is not correct according to the API definition >>> "The returned allocation is round_up_pow_two(size) big, and is physically aligned >>> to its size." >> >> Yes.. The current implementation is limited to full PAGE_SIZE only, >> the documentation imagines a future where it is not. Drivers should >> ideally not assume the PAGE_SIZE limit during this conversion. >> >>> I'd say we can align the size or use min with 64 bytes before calling the >>> function would be enough (or change the API to state that allocations >>> are rounded to order) >> >> OK, like this: >> >> if (cfg->alloc) { >> pages = cfg->alloc(cookie, size, gfp); >> } else { >> /* >> * For very small starting-level translation tables the HW >> * requires a minimum alignment of at least 64 to cover all >> * cases. >> */ >> pages = iommu_alloc_pages_node_sz(dev_to_node(dev), gfp, >> max(size, 64)); >> } > > Yes, that looks good. Although for completeness it really wants to cover both paths, so an unconditional "size = max(size, 64);" further up would be even better. Thanks, Robin. _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip