Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3893560ybl; Tue, 20 Aug 2019 04:02:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzL4mniwtn9ui5OU7D/nmdOC2kOjL3WroL2kx/pJJZAd/xCcjfiv9Wc/guRAm2IKeezXYiQ X-Received: by 2002:a63:5d54:: with SMTP id o20mr24435170pgm.413.1566298940083; Tue, 20 Aug 2019 04:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566298940; cv=none; d=google.com; s=arc-20160816; b=mydH7bsA86Y1eY4aKbEgY7INeYSq2uXHkMLAWVoeEVJX/1K9T41aePFkxe1h7t7vDy MXowCgvwF+iIY7K/ABWIIbMcQMBAeiPlHEV39kyurkNfn1DknKhKvqkEEuXyO+8MN/bC 0dO7gCOhkFTEwcTHu3gyka0H66JmYwcvdG+VmExyZ4ABENQyeJSgpzkN7IbsO0esgeCq K2LThPW6VE6qWm/ljT19d+X5hhO1XhQeQAui3twuxkaMqa7yfN+cZoO6L1v2hQ0LjLY5 WebiFzWhIsbMYSCaju44YsMb/rFeOfhHdFFLbj+lvdF3cKHsrUkT57ks/vuJ10ROMrUw /eTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=c2BZOupmPdmcZlLBqrfSN7ZTEPpOmtLck5V3tPbIa6o=; b=ydAnXWji+URoOX9RckLPgrWm5dC6k/htj0fHr1ar1ZseuDDevRO10xkq3ErHFTM4VK eLrxhmrZI6GyFgfbpdANSq5bwdpRZL9wBumZJy3d6NPvRp4Hxub4ZcXBUTqIw3PYtiO9 MioVPbnVStGUIr3hj7GUmAiTloioxwG/LqlUwa5vQ5h0D/MzPOlZoJ5xHY15DkuQFp/U XsZPaeutQvHX26WnGfsL2AjfscDukSIFVRj1LR99EaXVX/iz1oJSXOf+N0QnXEA3ky0S xRBXXpGbs2FYgrWHGzYnF6TA2dOecg4/ZJUtvE9Ov7XcsG47aOqKdKtLxlTOFLM9+e4k fSaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pTSFJ+DJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si10749562pjt.51.2019.08.20.04.02.04; Tue, 20 Aug 2019 04:02:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pTSFJ+DJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729428AbfHTLBC (ORCPT + 99 others); Tue, 20 Aug 2019 07:01:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41213 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728545AbfHTLBB (ORCPT ); Tue, 20 Aug 2019 07:01:01 -0400 Received: by mail-wr1-f66.google.com with SMTP id j16so11910878wrr.8 for ; Tue, 20 Aug 2019 04:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c2BZOupmPdmcZlLBqrfSN7ZTEPpOmtLck5V3tPbIa6o=; b=pTSFJ+DJjQeD4zLrIjwB1OWBwTiVCGijk0DCA1ksahHdaEFVP4Q/bVQbUkwetcH4Nh QfOmdXPmamPnY3J3/ATMwJxsggn5gl6804SXb4E4z6Hwgi32zN4de8ihO39HLnDb+hNI Ujp9Em/SJiUh8vyQSfyR/AJ+qk4iGJCL7OvGoYBBSTYDnnlhXTZjCPRzI+bkC9bhRT9Q wZH8+wx0t3QJDEdXbu5IWAQzw92Qx/rm90evuQBJZCpZn7w6ZYg4bjmrF/TpU+w5v4r5 2iuft/USAu4gdMwu2bau4VT8FEnx57QtgP4nwB4PcuT6vNq2VIyBMp0c++4KUv+ez7Ff qCCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c2BZOupmPdmcZlLBqrfSN7ZTEPpOmtLck5V3tPbIa6o=; b=WXrX3ERCn0iKvG65LEl87tMgay/5mEVtc8UDxqcjhBKLvbFBnSJWpVGHb60RtZl03+ GxwqboCuXvDHU6m8/ulPMIK+uIg34ASVgx1Q6oc1t/dhvw9fxIKsuKYyvQC2itclOSk5 IUPccgM4rnY+xaR0HZDThCGZn3ijSmj4yq0t7jdCfKzRzuSc93Bh27hCKkaFVgvBR+GD S5HTPTWsorNFk9gP9xHUnWdGFQeOx4eqURx3n+DhVTUUOVcwNURSs5xVFbVS6s+k48BG tWpVatIIqGRmt8cCGaYnBJfO8m1RjKLY5iOcz8fUFtZ6io/sA53rNNCMUVgQs5FkVqkM 2nXw== X-Gm-Message-State: APjAAAV/x/LCF8JJV/GphZ/DbVjAuqbw6QpZPktIE56pvO7ME6GVs3uu kvEXhb+Y+1X4PeC4xK1mXbawYbMGJM9zoLwdX7ixOg== X-Received: by 2002:a5d:5450:: with SMTP id w16mr20113864wrv.174.1566298859893; Tue, 20 Aug 2019 04:00:59 -0700 (PDT) MIME-Version: 1.0 References: <20190802053744.5519-1-clin@suse.com> <20190815111543.GA4728@linux-8mug> <20190815133738.GA2483@rapoport-lnx> <20190819075621.GA20595@linux-8mug> <20190820074930.GC5989@rapoport-lnx> In-Reply-To: <20190820074930.GC5989@rapoport-lnx> From: Ard Biesheuvel Date: Tue, 20 Aug 2019 14:00:48 +0300 Message-ID: Subject: Re: [PATCH] efi/arm: fix allocation failure when reserving the kernel base To: Mike Rapoport Cc: Chester Lin , "guillaume.gardet@arm.com" , "linux@armlinux.org.uk" , "ren_guo@c-sky.com" , "mingo@kernel.org" , "akpm@linux-foundation.org" , "geert@linux-m68k.org" , "linux-arm-kernel@lists.infradead.org" , Gary Lin , Juergen Gross , Joey Lee , "linux-efi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 20 Aug 2019 at 10:49, Mike Rapoport wrote: > > On Mon, Aug 19, 2019 at 05:56:51PM +0300, Ard Biesheuvel wrote: > > On Mon, 19 Aug 2019 at 11:01, Chester Lin wrote: > > > > > > Hi Mike and Ard, > > > > > > On Thu, Aug 15, 2019 at 04:37:39PM +0300, Mike Rapoport wrote: > > > > On Thu, Aug 15, 2019 at 02:32:50PM +0300, Ard Biesheuvel wrote: > > > > > (adding Mike) > > > > > > > ... > > > > > > > In this case the kernel failed to reserve cma, which should hit the issue of > > > > > > memblock_limit=0x1000 as I had mentioned in my patch description. The first > > > > > > block [0-0xfff] was scanned in adjust_lowmem_bounds(), but it did not align > > > > > > with PMD_SIZE so the cma reservation failed because the memblock.current_limit > > > > > > was extremely low. That's why I expand the first reservation from 1 PAGESIZE to > > > > > > 1 PMD_SIZE in my patch in order to avoid this issue. Please kindly let me know > > > > > > if any suggestion, thank you. > > > > > > > > > > > > > This looks like it is a separate issue. The memblock/cma code should > > > > > not choke on a reserved page of memory at 0x0. > > > > > > > > > > Perhaps Russell or Mike (cc'ed) have an idea how to address this? > > > > > > > > Presuming that the last memblock dump comes from the end of > > > > arm_memblock_init() with the this memory map > > > > > > > > memory[0x0] [0x0000000000000000-0x0000000000000fff], 0x0000000000001000 bytes flags: 0x4 > > > > memory[0x1] [0x0000000000001000-0x0000000007ef5fff], 0x0000000007ef5000 bytes flags: 0x0 > > > > memory[0x2] [0x0000000007ef6000-0x0000000007f09fff], 0x0000000000014000 bytes flags: 0x4 > > > > memory[0x3] [0x0000000007f0a000-0x000000003cb3efff], 0x0000000034c35000 bytes flags: 0x0 > > > > > > > > adjust_lowmem_bounds() will set the memblock_limit (and respectively global > > > > memblock.current_limit) to 0x1000 and any further memblock_alloc*() will > > > > happily fail. > > > > > > > > I believe that the assumption for memblock_limit calculations was that the > > > > first bank has several megs at least. > > > > > > > > I wonder if this hack would help: > > > > > > > > diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c > > > > index d9a0038..948e5b9 100644 > > > > --- a/arch/arm/mm/mmu.c > > > > +++ b/arch/arm/mm/mmu.c > > > > @@ -1206,7 +1206,7 @@ void __init adjust_lowmem_bounds(void) > > > > * allocated when mapping the start of bank 0, which > > > > * occurs before any free memory is mapped. > > > > */ > > > > - if (!memblock_limit) { > > > > + if (memblock_limit < PMD_SIZE) { > > > > if (!IS_ALIGNED(block_start, PMD_SIZE)) > > > > memblock_limit = block_start; > > > > else if (!IS_ALIGNED(block_end, PMD_SIZE)) > > > > > > > > > > I applied this patch as well and it works well on rpi-2 model B. > > > > > > > Thanks, Chester, that is good to know. > > > > However, afaict, this only affects systems where physical memory > > starts at address 0x0, so I think we need a better fix. > > This hack can be easily extended to handle systems with arbitrary start > address, but it's still a hack... > > > I know Mike has been looking into the NOMAP stuff lately, and your > > original patch contains a hunk that makes this code (?) disregard > > nomap memblocks. That might be a better approach. > > I was actually looking how to replace NOMAP with something else to make > memblock.memory consistent with actual physical memory banks. But this work > is stashed for now. > > I'm not sure that skipping NOMAP regions would be good enough. > If I understand corrrectly, with Chester's original patch the reservation > of PMD aligned chunk of 32M for the kernel made the first conv-mem region > PMD aligned and then memblock_limit will be set to the end of this region. > > Is there a reason for marking EFI_RESERVED_TYPE as NOMAP rather than simply > reserve them with memblock_reserve()? > Yes. On ARM systems, reserved memory regions should never be mapped by default, since the cacheable mappings we use in the linear region may conflict with the mapping attributes used by the firmware or driver components that are using this memory. In this particular case, we are talking about things like spin tables and pens for secondaries that boot up with their caches disabled, and having a cacheable mapping on the primary CPU might cause a loss of coherency.