From patchwork Sun Sep 1 06:12:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 13786346 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 1E4D9C54FC6 for ; Sun, 1 Sep 2024 06:15:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=NRNTfqBl798Ee2DssnuhOKyelRG+deG+EvYHiG8EOv8=; b=K3nnB9rX6M1TD7i4/Ne950T+tJ jBCAtacZ/s+h/woRe8HH1jUfJEszVyHUXA8fqDbijOtptErs4IpjplN8EEIGda5FgnSHBBvxtTIv5 drxP9UwF1ck7N9nuLGmA+zIO9BxJpGAo4OG9LTbp3uiQ8o1UIwwrph2oMuu/kiBBPr09TwI69jNef z5hBWCj4H77O96+Ddi3UTdY3FZPVGFI3fcy6lc59JjRzmRlFXbMwLI3XEDAfMPC5JLBBJ8dS76ROz 1tfvwBk6cbjNtXkExr2pxqMNUM+NQTCqIc/esfHgBcheq4t3SNFqkZfXZWzUf7Z1QJW1sBY+l87j0 WMUOwSaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1skdrG-0000000B0nS-0gIR; Sun, 01 Sep 2024 06:14:42 +0000 Received: from golan.tkos.co.il ([84.110.109.230] helo=mail.tkos.co.il) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1skdqM-0000000B0bj-06nY for linux-arm-kernel@lists.infradead.org; Sun, 01 Sep 2024 06:13:48 +0000 Received: from tarshish.tkos.co.il (unknown [10.0.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id C33AC440EEB; Sun, 1 Sep 2024 09:11:38 +0300 (IDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1725171098; bh=+DqHJLaU8lg/UL16LyVK5wZi9kSTSpPxP7netN7Dp68=; h=From:To:Cc:Subject:Date:From; b=OcRDoQS5mVjG4ysRzK4YEfknFkK2D9dh1xqQbkXWdKPEc1vi0rYyWY1Bsxkfs4o5T N9QVSq9zsXwBkHFkjyG2dKzUIZrlVl9A8h8KU0n5LajdCxKMjQNEUuNneUde1cFYCl A2U0vvzExlwAEbW5Pxby1oss1kTQvhPx/3wei+RaLawmaBrRXUh4+R50eg53NwsgoN jbl0FTOB06OpHYtJaVKdyxC9xw9LrnYy/nYP91dU1t9DiQ+cLhAo78o4YHnciuSb0Q tFRWNXtl/RVrMgJtSEAyP/yWpQAOO95rD5dCUWxRCM6W8UQKgnMZvf7pFkhxksiHQ7 P1BM/wpZOPvKg== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Robin Murphy , Catalin Marinas , Will Deacon Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried , Elad Nachman , Baruch Siach , Neil Armstrong Subject: [PATCH] arm64: mm: keep low RAM dma zone Date: Sun, 1 Sep 2024 09:12:34 +0300 Message-ID: <3cc8abdb1d6a2d882d16dc2b9890df3ce2117d0d.1725171154.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240831_231346_610314_B35B121E X-CRM114-Status: GOOD ( 15.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit ba0fb44aed47 ("dma-mapping: replace zone_dma_bits by zone_dma_limit") optimistically assumed that device-tree dma-ranges property describes the system DMA limits. That assumption ignores DMA limits of individual devices that are not encoded in device tree. Commit 833bd284a45 ("arm64: mm: fix DMA zone when dma-ranges is missing") fixed part of the problem for platforms that do not provide dma-ranges at all. However platforms like SM8550-HDK provide DMA bus limit, but have devices with stronger DMA limits. of_dma_get_max_cpu_address() does not take device limitations into account. These platforms implicitly rely on DMA zone in low 32-bit RAM area. Until we find a better way to figure out the optimal DMA zone range, restore the low RAM DMA zone we had before commit ba0fb44aed47. Fixes: ba0fb44aed47 ("dma-mapping: replace zone_dma_bits by zone_dma_limit") Reported-by: Neil Armstrong Tested-by: Neil Armstrong # on SM8550-HDK Closes: https://lore.kernel.org/r/1a0c7282-63e0-4add-8e38-3abe3e0a8e2f@linaro.org Tested-by: Marek Szyprowski Reviewed-by: Catalin Marinas Suggested-by: Robin Murphy Signed-off-by: Baruch Siach --- arch/arm64/mm/init.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 5710129b8033..eb76ac6d87c0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -116,8 +116,14 @@ static void __init arch_reserve_crashkernel(void) static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit) { - if (zone_limit == PHYS_ADDR_MAX) - zone_limit = U32_MAX; + /** + * Information we get from firmware (e.g. DT dma-ranges) describe DMA + * bus constraints. Devices using DMA might have their own limitations. + * Some of them rely on DMA zone in low 32-bit memory. Keep low RAM + * DMA zone on platforms that have RAM there. + */ + if (memblock_start_of_DRAM() < U32_MAX) + zone_limit = min(zone_limit, U32_MAX); return min(zone_limit, memblock_end_of_DRAM() - 1) + 1; }