Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7265816rdb; Wed, 3 Jan 2024 09:46:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtJaXO73FpLl/OJTa+mibui1r5EkJ1qsYToBznS68Dp7u98aVxubo5lm33AvuKDWYLCAha X-Received: by 2002:a17:906:5306:b0:a25:1acc:ff45 with SMTP id h6-20020a170906530600b00a251accff45mr8004867ejo.143.1704303962777; Wed, 03 Jan 2024 09:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704303962; cv=none; d=google.com; s=arc-20160816; b=f93n8fuw0jj54lvqayRFNRBt099zQKNZMMBgD51FT922JgdJWiWanUT1YCC5TgBCN8 Og77S8PKNLEBmm8OuVmFqSdPeKKxYzMKHrA5TlVtdSNetaZFborzDCcTBETwNpOCa7uT Y6wdYC7CjPcI9NJOP5ZGtA+4pz2C++v4/A6eLFaSmW9xpY6GATlS+TvB/cekKKLaTN/K 1PcT9FlrVUg1TywAQcZyplozBgt1jg4YAxOZ+gjSuONYzk32Pdr+J42PX9OO/rxuzlbW tqAKAX2pGNULiuRMZg9Yci//SA/v+fTdxKC2hU//CNKIZ58tSC1Mi4uKbHjd67xt2uDr sE1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=GIuNpt/5VkWlbeJxf8zffACOqj80G7ls6ys8ZVlm1Lk=; fh=O85cCicvehhyQPflDXJv59HembQlVCqg9C1PA/JiZFA=; b=TGnpU+CmMZU5Qz/NsEQq7M9oeMLP6odXRbi+4LoZBBnn70D/RnC/TrAl8mTUr33ZIG Y11p8RhWh/RWebfYFWqyBr5ixx3mbqi+WPkrxey0tnkShfJj0i35EMWMn9ybmpD9pTBm gf/8zQhNGDAq/iOECWCPBPe+VgPULOGmQKZx3xyj7Kou4JaRp5y9U4Eo1DvX86wbsLr1 wqSdWwVY0y9xlsULXIR3jvvOLVicPGh+LKD0Kw5eV7q6OdGF2m1xX+4MHPIvZsk82vHE Epzh9bw9rZVv/FfLiM5hxgZBobjDAmQu+hJ/5fB4QskeG7LqaKQ3YfRwfADXY0K9FL6S au8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2IlVFI5; spf=pass (google.com: domain of linux-kernel+bounces-15816-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15816-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id vw6-20020a170907058600b00a26f02b8c29si7968803ejb.1043.2024.01.03.09.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:46:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15816-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2IlVFI5; spf=pass (google.com: domain of linux-kernel+bounces-15816-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15816-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E9DA51F214CC for ; Wed, 3 Jan 2024 17:46:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B7F41CAA0; Wed, 3 Jan 2024 17:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u2IlVFI5" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD0D11CA98 for ; Wed, 3 Jan 2024 17:45:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66CF6C433C7; Wed, 3 Jan 2024 17:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704303938; bh=/4dVKaf541G+sc8duQTMeRs7/R1QzyO3O6dn3yMRbxM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u2IlVFI57SKaomPzPJssiMq1AJk53XApMfLbYpHz22r+d5EUB698Eaos7tveBNH0M s18IXtYBuAs7LOt9cNZ/iLPRI5LsqICqh8jUVal/Ypw+8pzCEKZbwgO+BLLGAwRGH1 K8HIi9PyJEfKtENqKywnPBQuhAqSEJuuoFiMedY6Knjh8X6F4Tt2nZTzsSYJGqSJ/t /8gyc5UhjVQWoXRgbm8hFgQKBJ/UIxQnkBO6DjLFd7d9lIrxjZyaZ93flP4XY90H3U aPqSawycIs0b4CvYy0VLU1yVQB8rAb2NjMGu21cAW96mfkjILf3N+SyhiLZRexg6hO GbmbeUK2YqBNg== Date: Wed, 3 Jan 2024 17:45:32 +0000 From: Will Deacon To: Elad Nachman Cc: catalin.marinas@arm.com, thunder.leizhen@huawei.com, bhe@redhat.com, akpm@linux-foundation.org, yajun.deng@linux.dev, chris.zjh@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm64: mm: Fix SOCs with DDR starting above zero Message-ID: <20240103174531.GE5954@willie-the-truck> References: <20240103170002.1793197-1-enachman@marvell.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103170002.1793197-1-enachman@marvell.com> User-Agent: Mutt/1.10.1 (2018-07-13) On Wed, Jan 03, 2024 at 07:00:02PM +0200, Elad Nachman wrote: > From: Elad Nachman > > Some SOCs, like the Marvell AC5/X/IM, have a combination > of DDR starting at 0x2_0000_0000 coupled with DMA controllers > limited to 31 and 32 bit of addressing. > This requires to properly arrange ZONE_DMA and ZONE_DMA32 for > these SOCs, so swiotlb and coherent DMA allocation would work > properly. > Change initialization so device tree dma zone bits are taken as > function of offset from DRAM start, and when calculating the > maximal zone physical RAM address for physical DDR starting above > 32-bit, combine the physical address start plus the zone mask > passed as parameter. > This creates the proper zone splitting for these SOCs: > 0..2GB for ZONE_DMA > 2GB..4GB for ZONE_DMA32 > 4GB..8GB for ZONE_NORMAL > > Signed-off-by: Elad Nachman > --- > arch/arm64/mm/init.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 74c1db8ce271..8288c778916e 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -115,20 +115,21 @@ static void __init arch_reserve_crashkernel(void) > > /* > * Return the maximum physical address for a zone accessible by the given bits > - * limit. If DRAM starts above 32-bit, expand the zone to the maximum > - * available memory, otherwise cap it at 32-bit. > + * limit. If DRAM starts above 32-bit, expand the zone to the available memory > + * start limited by the zone bits mask, otherwise cap it at 32-bit. > */ > static phys_addr_t __init max_zone_phys(unsigned int zone_bits) > { > phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits); > phys_addr_t phys_start = memblock_start_of_DRAM(); > + phys_addr_t phys_end = memblock_end_of_DRAM(); > > if (phys_start > U32_MAX) > - zone_mask = PHYS_ADDR_MAX; > + zone_mask = phys_start | zone_mask; > else if (phys_start > zone_mask) > zone_mask = U32_MAX; > > - return min(zone_mask, memblock_end_of_DRAM() - 1) + 1; > + return min(zone_mask, phys_end - 1) + 1; > } > > static void __init zone_sizes_init(void) > @@ -140,7 +141,16 @@ static void __init zone_sizes_init(void) > > #ifdef CONFIG_ZONE_DMA > acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address()); > - dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL)); > + /* > + * When calculating the dma zone bits from the device tree, subtract > + * the DRAM start address, in case it does not start from address > + * zero. This way. we pass only the zone size related bits to > + * max_zone_phys(), which will add them to the base of the DRAM. > + * This prevents miscalculations on arm64 SOCs which combines > + * DDR starting above 4GB with memory controllers limited to > + * 32-bits or less: > + */ > + dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL) - memblock_start_of_DRAM()); > zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); > arm64_dma_phys_limit = max_zone_phys(zone_dma_bits); > max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); Hmm, I'm a bit worried this could regress other platforms since you seem to be assuming that DMA address 0 corresponds to the physical start of DRAM. What if that isn't the case? In any case, we should try hard to avoid different behaviour between DT and ACPI here. Will