Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp335857rdb; Fri, 5 Jan 2024 11:22:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGcHcVJRExOp4XV2Zaw5mJbfbaVNaYwPgrB3iY69UzkK2tSKSmmG4hJhi5XdIiMlZizsfu X-Received: by 2002:aa7:9151:0:b0:6d9:a0b2:7aa6 with SMTP id 17-20020aa79151000000b006d9a0b27aa6mr2185323pfi.41.1704482520956; Fri, 05 Jan 2024 11:22:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704482520; cv=none; d=google.com; s=arc-20160816; b=W6iUDlq4ToAU3GvDP5Hxfm3cI5HD/1NwupLnK+8D+xBJBAPFv9rzEvWbO5EHaKFneE aJVlmGMCQ5fTYZ0GS3F3BHF1OmYHLVEsZbZG4WWZ3lz3tUw5h4w9XdKXQ1bDFQzgMvDW Jb2rBUmSccSHKjCHnjW1vgmTsVRw2ULTbqoxWBcTKZBLYXz4cmNP38G+at9Ly55xbzyV 7KO2uXJn0KvjQCtxboaFGT8UP2agVLicjADxTtySnFmQKNnFv3Uwf1nOn8V/4q8YlUwx Wr2BLToyC0ON/5hfVMRpXKPLOd1ifutv36k/qxmls1JLxkO1SlFYFA/J0/PaMq+6QtQK 5tvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=IpeShd++zzYFdrMkxqXIPIA/T8W+zMPfpJtHAmbzULg=; fh=EKeE7buM+EXiFBeYcZISV9YOrb2Qy7u9knovR6UGO5o=; b=uUVuXPXUK4TGsMalrXJNLPSVMW969drfdO48LXZH4WAWvV2T4TfWQm1HgtewQsM4j1 68pVfdVPQ1N3JeHLDJB6bpYNxlQ50IIXtpHvqBV94Ic2wdZdfhoJ76gP9UaAIgGRvhcU oS+hjFM5wKsHEfIVtUW7rVfQqcdTlPj2WbUu8xQ8TaDJi6VwHql+yWAmBNHlDS2Kqbpf YKf8vzMPyPb4EJNveNiW6tKVFqFfgNQctSE+h0PrXHS0udnvUlvK3PKBdGkquxTVjUIa 0Ei1qtNun/1AzM28XbVFC0ojnYrMmhDlQqfB/RzowouKXw+CY46T6abdjP39Nfj9PwKQ cKuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b10-20020a630c0a000000b005ce4b19c30csi1693189pgl.519.2024.01.05.11.22.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 11:22:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-18295-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18295-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9FC1E285622 for ; Fri, 5 Jan 2024 19:22:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 490AB35F12; Fri, 5 Jan 2024 19:21:50 +0000 (UTC) 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 D626A35291 for ; Fri, 5 Jan 2024 19:21:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A6F9C433C7; Fri, 5 Jan 2024 19:21:47 +0000 (UTC) Date: Fri, 5 Jan 2024 19:21:45 +0000 From: Catalin Marinas To: Elad Nachman Cc: will@kernel.org, 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: 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> 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 Please see this discussion: https://lore.kernel.org/all/ZU0QEL9ByWNYVki1@arm.com/ and follow-up patches from Baruch, though I haven't reviewed them yet: https://lore.kernel.org/all/fae5b1180161a7d8cd626a96f5df80b0a0796b8b.1703683642.git.baruch@tkos.co.il/ The problem is that the core code pretty much assumes that DRAM starts from 0. No matter how you massage the zones in the arm64 kernel for your case, memblock_start_of_DRAM() + (2 << zone_dma_bits) won't be a power of two and therefore zone_dma_bits in the core code cannot describe what you need. I can see Baruch added a zone_dma_off assuming it's the same for all DMA-capable devices on that SoC (well, those with a coherent mask smaller than 64-bit). I need to think a bit more about this. Anyway, we first need to address the mask/bits comparisons in the core code, maybe changing bits to a physical limit instead and take the device DMA offset into account. After that we can look at how to correctly set up the DMA zones on arm64. -- Catalin