Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1520486pxb; Thu, 4 Mar 2021 13:35:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxi2EUjEz47NxvsQGB+M8ywDB48/58EPi0wbU4jaGEcfIddcNGgpWX8sUNkMwU5jv/337I0 X-Received: by 2002:a17:906:c0d7:: with SMTP id bn23mr6464933ejb.94.1614893724125; Thu, 04 Mar 2021 13:35:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614893724; cv=none; d=google.com; s=arc-20160816; b=yUnMRMBzTdf1bsHWwnGQ1C4b/F2zEKG96DbYOxDq1gAB943yLrFN868p/BwTRic7Iv nC+Gs8GpUr9JPoBZn9x7SJ1g0a4Rbd8ERF73erhjJ29bmDlYdQpoGUBOqvFsx0Aka+5B NOlXCx4eWhGSG+ZnfR0V3EpUimksJ/Cv7WRsA1ghskZ3DUvJZEWro2GZ7nMAbPIWYYsW aDkplEs8CHXuAGPiwGE8uhKstFJymEzM4dDtt7Kd5ao0P0P0yIHhQqrjH3uFMxXld5iO PwfkEVQ/naTQvA9d4x8j9o7PcH14ZYO7iFRXfmxWDM4J14mxAmVXf7i1Bjp1oxhv8rLg ttGA== 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:cc:to:from; bh=4Zy9OY6fx2/oU4L2eni2q/jcefF37OJjrso/hpuWwQw=; b=y1CrLyr/Tdj2FHNRBNB6LWB2erODWZJZQutQJ/js+3b19ANWFjOBsaqC/K8352Bgap VjUp3PsPOM+hYGXAXjvZQJ/3qCPWM4gzkqNtCvObJk1ixffhlNug+wmP/6peDVyt0wiv dx7LP4Iga97tV5ncfMJsb5RovJIqtVr/mQ4U7kxXd2wRMwxvspgfWdvBOlQVQR6ijcg1 wsWAO5CsmRgCtemRGLl2x2EsaUsWdej9gjgKLa4g5BNIRYBOuUHtcH72EA5KHkxbEMwa fzxoQxJBde5sV/evlkOmEbIN8L3kgAi3ANzDmfXzli4fVBCLsNFySBTNNcCiA2EtFdP1 1tcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx24si436363edb.541.2021.03.04.13.35.01; Thu, 04 Mar 2021 13:35:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380240AbhCCMbE (ORCPT + 99 others); Wed, 3 Mar 2021 07:31:04 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:13048 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1452295AbhCCHV3 (ORCPT ); Wed, 3 Mar 2021 02:21:29 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Dr5272kJlzMhPF; Wed, 3 Mar 2021 15:18:23 +0800 (CST) Received: from ubuntu-82.huawei.com (10.175.104.82) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Wed, 3 Mar 2021 15:20:24 +0800 From: Jing Xiangfeng To: , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , Subject: [PATCH stable v5.10 5/7] arm64: mm: Set ZONE_DMA size based on devicetree's dma-ranges Date: Wed, 3 Mar 2021 15:33:17 +0800 Message-ID: <20210303073319.2215839-6-jingxiangfeng@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20210303073319.2215839-1-jingxiangfeng@huawei.com> References: <20210303073319.2215839-1-jingxiangfeng@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.82] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Saenz Julienne commit 8424ecdde7df99d5426e1a1fd9f0fb36f4183032 upstream We recently introduced a 1 GB sized ZONE_DMA to cater for platforms incorporating masters that can address less than 32 bits of DMA, in particular the Raspberry Pi 4, which has 4 or 8 GB of DRAM, but has peripherals that can only address up to 1 GB (and its PCIe host bridge can only access the bottom 3 GB) The DMA layer also needs to be able to allocate memory that is guaranteed to meet those DMA constraints, for bounce buffering as well as allocating the backing for consistent mappings. This is why the 1 GB ZONE_DMA was introduced recently. Unfortunately, it turns out the having a 1 GB ZONE_DMA as well as a ZONE_DMA32 causes problems with kdump, and potentially in other places where allocations cannot cross zone boundaries. Therefore, we should avoid having two separate DMA zones when possible. So, with the help of of_dma_get_max_cpu_address() get the topmost physical address accessible to all DMA masters in system and use that information to fine-tune ZONE_DMA's size. In the absence of addressing limited masters ZONE_DMA will span the whole 32-bit address space, otherwise, in the case of the Raspberry Pi 4 it'll only span the 30-bit address space, and have ZONE_DMA32 cover the rest of the 32-bit address space. Signed-off-by: Nicolas Saenz Julienne Link: https://lore.kernel.org/r/20201119175400.9995-6-nsaenzjulienne@suse.de Signed-off-by: Catalin Marinas Cc: Signed-off-by: Jing Xiangfeng --- arch/arm64/mm/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 7da912bf4222..05a1c2773629 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -42,8 +42,6 @@ #include #include -#define ARM64_ZONE_DMA_BITS 30 - /* * We need to be able to catch inadvertent references to memstart_addr * that occur (potentially in generic code) before arm64_memblock_init() @@ -188,9 +186,11 @@ static phys_addr_t __init max_zone_phys(unsigned int zone_bits) static void __init zone_sizes_init(unsigned long min, unsigned long max) { unsigned long max_zone_pfns[MAX_NR_ZONES] = {0}; + unsigned int __maybe_unused dt_zone_dma_bits; #ifdef CONFIG_ZONE_DMA - zone_dma_bits = ARM64_ZONE_DMA_BITS; + dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL)); + zone_dma_bits = min(32U, dt_zone_dma_bits); arm64_dma_phys_limit = max_zone_phys(zone_dma_bits); max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); #endif -- 2.25.1