From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20115C43215 for ; Tue, 3 Dec 2019 11:19:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DEECE206EC for ; Tue, 3 Dec 2019 11:19:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DEECE206EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 690C16B04A3; Tue, 3 Dec 2019 06:19:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 643846B04A4; Tue, 3 Dec 2019 06:19:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 557E36B04A5; Tue, 3 Dec 2019 06:19:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 413326B04A3 for ; Tue, 3 Dec 2019 06:19:07 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id D591C629 for ; Tue, 3 Dec 2019 11:19:06 +0000 (UTC) X-FDA: 76223583492.08.music43_89a6ed7ea3c07 X-HE-Tag: music43_89a6ed7ea3c07 X-Filterd-Recvd-Size: 5170 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Dec 2019 11:19:05 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C1D9430E; Tue, 3 Dec 2019 03:19:04 -0800 (PST) Received: from arrakis.emea.arm.com (arrakis.cambridge.arm.com [10.1.197.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 916673F68E; Tue, 3 Dec 2019 03:19:02 -0800 (PST) Date: Tue, 3 Dec 2019 11:19:00 +0000 From: Catalin Marinas To: Will Deacon Cc: John Stultz , Nicolas Saenz Julienne , Christoph Hellwig , wahrenst@gmx.net, Marc Zyngier , Rob Herring , linux-arm-kernel , Florian Fainelli , Robin Murphy , lkml , linux-mm , mbrugger@suse.com, linux-rpi-kernel@lists.infradead.org, Marek Szyprowski , Bjorn Andersson , Amit Pundir , Nicolas Dechense Subject: Re: [PATCH v6 3/4] arm64: use both ZONE_DMA and ZONE_DMA32 Message-ID: <20191203111900.GA23522@arrakis.emea.arm.com> References: <20190911182546.17094-1-nsaenzjulienne@suse.de> <20190911182546.17094-4-nsaenzjulienne@suse.de> <20191203101249.GC6815@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191203101249.GC6815@willie-the-truck> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Dec 03, 2019 at 10:12:50AM +0000, Will Deacon wrote: > On Mon, Dec 02, 2019 at 10:03:17PM -0800, John Stultz wrote: > > Ok, narrowing it down further, it seems its the following bit from the > > patch: > > > > > @@ -201,13 +212,18 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) > > > struct memblock_region *reg; > > > unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES]; > > > unsigned long max_dma32 = min; > > > + unsigned long max_dma = min; > > > > > > memset(zone_size, 0, sizeof(zone_size)); > > > > > > - /* 4GB maximum for 32-bit only capable devices */ > > > +#ifdef CONFIG_ZONE_DMA > > > + max_dma = PFN_DOWN(arm64_dma_phys_limit); > > > + zone_size[ZONE_DMA] = max_dma - min; > > > + max_dma32 = max_dma; > > > +#endif > > > #ifdef CONFIG_ZONE_DMA32 > > > max_dma32 = PFN_DOWN(arm64_dma32_phys_limit); > > > - zone_size[ZONE_DMA32] = max_dma32 - min; > > > + zone_size[ZONE_DMA32] = max_dma32 - max_dma; > > > #endif > > > zone_size[ZONE_NORMAL] = max - max_dma32; > > > > > > @@ -219,11 +235,17 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) > > > > > > if (start >= max) > > > continue; > > > - > > > +#ifdef CONFIG_ZONE_DMA > > > + if (start < max_dma) { > > > + unsigned long dma_end = min_not_zero(end, max_dma); > > > + zhole_size[ZONE_DMA] -= dma_end - start; > > > + } > > > +#endif > > > #ifdef CONFIG_ZONE_DMA32 > > > if (start < max_dma32) { > > > - unsigned long dma_end = min(end, max_dma32); > > > - zhole_size[ZONE_DMA32] -= dma_end - start; > > > + unsigned long dma32_end = min(end, max_dma32); > > > + unsigned long dma32_start = max(start, max_dma); > > > + zhole_size[ZONE_DMA32] -= dma32_end - dma32_start; > > > } > > > #endif > > > if (end > max_dma32) { > > > > The zhole_sizes end up being: > > zhole_size: DMA: 67671, DMA32: 1145664 NORMAL: 0 > > > > This seems to be due to dma32_start being calculated as 786432 each > > time - I'm guessing that's the max_dma value. > > Where dma32_end is around 548800, but changes each iteration (so we > > end up subtracting a negative value each pass, growing the size). [...] > Anyway, I've had a go at fixing it below but it's 100% untested. I think > the issue is that your SoC has memblocks contained entirely within the > ZONE_DMA region and we don't cater for that at all when processing the > ZONE_DMA32 region. This seems to be issue, the SoC memory contained withing ZONE_DMA. I managed to reproduce it under KVM/Qemu by reducing the amount of memory given to the guest. You'd also need NUMA disabled to hit this code path. Your proposed change fixes it but I'll send a tested-by on the full patch when it hits the list. -- Catalin