Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1371110pxa; Fri, 28 Aug 2020 10:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdtKqIMc1EqrUSBBgeJX/RC5heGiwGopOEscwTyTYq+RRWSg3+BfUu2cNRlJKhh+ag9i8Y X-Received: by 2002:a50:fc18:: with SMTP id i24mr3026806edr.176.1598636716154; Fri, 28 Aug 2020 10:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598636716; cv=none; d=google.com; s=arc-20160816; b=AtdGpZ1Pe8GrMgoJQHlQL2Q8Tut+cGzvJZRLwgbeXhnAKjwFv+Y5IBYRlWDXu0Gcwl VK6KTViYAyoDxX0V/y/lb145nBGU72JOEuvhA1BnoR7Yr0MX5BIJPm8vHXJrIkY0lSQf v1nennZlqEXC43xYIHkBauSp+k7J6QSQtfAJggEHNlyBqJGHlFK5vI0yPZmvc3i3iudm lBuUO2JMsQuOyJNAaFjOpsxklb420WVBeh1oZxRih32o/nyJeDxbJApYPcMRv7BUgTub HSQWTxCgPsqSghbTS8054HC/eWUlh9YYoESrHjncB1GdkZ1Inq8FBE/arilAOF52QXWh +GIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=tL+3TYSO4Sm9lEE+ybSQloqXNo0/zspDryE/2yjuIVE=; b=zKOmU8zQC/0TDIJ8S+Xzm3cLU1YodltsShwMD1dd8gavf7nLksNF7wGFDbq/ThqWV8 U0VSKO/PvLSWkcnE1zDHY1O8LRbEQKkAVfykN4w+vFfU+l+7aLQvgriU/4Cd3t1ZWOFK BhQHmCl1YIj4odF+rXENipkIBHRkq7G3+60kGp0X0+2LxpXnTAKei1+M678lcBVEko/B 5dMqA5VNabDFCvojfgoh6CRXIwh8j3CHBxgCptabkl8mO0pT8VujXM4NKhuLnUDCZ7Ss BWGVKxSO4w5azNGCosYY1zhWM9OjYu1lqueOOB0zVaT5XuDzKQGGTw2WSIZFqWreBDZY vLGA== 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 u11si1090950edp.466.2020.08.28.10.44.53; Fri, 28 Aug 2020 10:45:16 -0700 (PDT) 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 S1727051AbgH1Rno (ORCPT + 99 others); Fri, 28 Aug 2020 13:43:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:59584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725814AbgH1Rnn (ORCPT ); Fri, 28 Aug 2020 13:43:43 -0400 Received: from gaia (unknown [46.69.195.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EDB422074A; Fri, 28 Aug 2020 17:43:41 +0000 (UTC) Date: Fri, 28 Aug 2020 18:43:39 +0100 From: Catalin Marinas To: Nicolas Saenz Julienne Cc: linux-kernel@vger.kernel.org, f.fainelli@gmail.com, hch@lst.de, linux-rpi-kernel@lists.infradead.org, Will Deacon , linux-arm-kernel@lists.infradead.org, robh@kernel.org Subject: Re: [RFC] arm64: mm: Do not use both DMA zones when 30-bit address space unavailable Message-ID: <20200828174338.GK3169@gaia> References: <20200819182434.28196-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200819182434.28196-1-nsaenzjulienne@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nicolas, On Wed, Aug 19, 2020 at 08:24:33PM +0200, Nicolas Saenz Julienne wrote: > There is no benefit in splitting the 32-bit address space into two > distinct DMA zones when the 30-bit address space isn't even available on > a device. If that is the case, default to one big ZONE_DMA spanning the > whole 32-bit address space. > > This will help reduce some of the issues we've seen with big crash > kernel allocations. > > Signed-off-by: Nicolas Saenz Julienne > --- > > Whith this patch, on a 8GB RPi4 the setup looks like this: > > DMA [mem 0x0000000000000000-0x000000003fffffff] > DMA32 [mem 0x0000000040000000-0x00000000ffffffff] > Normal [mem 0x0000000100000000-0x00000001ffffffff] > > And stock 8GB virtme/qemu: > > DMA [mem 0x0000000040000000-0x00000000ffffffff] > DMA32 empty > Normal [mem 0x0000000100000000-0x000000023fffffff] > > arch/arm64/mm/init.c | 29 +++++++++++++++++++++++++---- > 1 file changed, 25 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index b6881d61b818..857a62611d7a 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -183,13 +183,20 @@ static void __init reserve_elfcorehdr(void) > > /* > * Return the maximum physical address for a zone with a given address size > - * limit. It currently assumes that for memory starting above 4G, 32-bit > - * devices will use a DMA offset. > + * limit or zero if memory starts from an address higher than the zone targeted. > + * It currently assumes that for memory starting above 4G, 32-bit devices will > + * use a DMA offset. > */ > static phys_addr_t __init max_zone_phys(unsigned int zone_bits) > { > - phys_addr_t offset = memblock_start_of_DRAM() & GENMASK_ULL(63, zone_bits); > - return min(offset + (1ULL << zone_bits), memblock_end_of_DRAM()); > + phys_addr_t base = memblock_start_of_DRAM(); > + phys_addr_t offset = base & GENMASK_ULL(63, 32); > + s64 zone_size = (1ULL << zone_bits) - (base & DMA_BIT_MASK(32)); > + > + if (zone_size <= 0) > + return 0; > + > + return min(base + zone_size + offset, memblock_end_of_DRAM()); > } OK, so we can still get some ZONE_DMA if DRAM starts in the first GB. I don't think it entirely solves the problem. It just happens that the other affected SoCs don't have memory in the first GB. With this patch, we go by the assumption that ZONE_DMA/DMA32 split is only needed if there is memory in the low 1GB and such <32-bit devices don't have a DMA offset. Adding Rob H (it's easier to ask him than grep'ing the DT files ;)), we may be ok with this assumption on current SoCs. An alternative (and I think we had a patch at some point) is to make it generic and parse the dma-range in the DT to identify the minimum mask and set ZONE_DMA accordingly. But this doesn't solve ACPI, so if Linux can boot with ACPI on RPi4 it would still be broken. -- Catalin