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=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 E422BC07E94 for ; Fri, 4 Jun 2021 15:41:14 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A101561405 for ; Fri, 4 Jun 2021 15:41:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A101561405 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4A65C82AD8; Fri, 4 Jun 2021 17:41:07 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="a9UzA8Ip"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BA0E082ADA; Fri, 4 Jun 2021 17:41:05 +0200 (CEST) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AFC0F81895 for ; Fri, 4 Jun 2021 17:41:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=07892f41cf=patrick.delaunay@foss.st.com Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 154FWVJV012527; Fri, 4 Jun 2021 17:40:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=pgI+ab3pZX6pJ5JCqiPf6D6rXzpkbXQhVOJ7gCGa5Iw=; b=a9UzA8Ip+VCBtM8mXSAdYLd5O7FMrMkS1fSnI5dhcGbhxOoKv2HIwUs27jOzcae0VOmP ZrR0Nfz1dpFwybFQfMFFY+UGiyuJoM4VFuj33f7b6ZEeS72Hj4XGHmB7hDnWfj0PtKVW I5gOxH1CTBZ5gMkgV8j3nENtPLwgK6vgd5qNLfTT2fa9vM+iw1slgjPEk4ZOSWag85hW HxJTQZ3IkdFlbW92GaedOYIyMTjg9v1xjje9fKAuspTV9IwLlofRq+cfvPW1IT+ly/2d FfTrpqKf4hP5oiqyJjPJ6RJWl3TYr5VzoRFJPT9O2wi1WVD6gErJsIes33FMEhHRbnU5 OA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38xwmhyvwr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 04 Jun 2021 17:40:55 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 6250410002A; Fri, 4 Jun 2021 17:40:54 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 55A08221763; Fri, 4 Jun 2021 17:40:54 +0200 (CEST) Received: from lmecxl0994.lme.st.com (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 4 Jun 2021 17:40:53 +0200 Subject: Re: [PATCH] arm: bootm: wrong lmb region reservation when PRAM is used To: Aleksandar Gerasimovski , Tom Rini , Michal Simek , ". Simon Goldschmidt" CC: "u-boot@lists.denx.de" References: <20210430115242.GL17669@bill-the-cat> From: Patrick DELAUNAY Message-ID: Date: Fri, 4 Jun 2021 17:40:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG3NODE1.st.com (10.75.127.7) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-06-04_08:2021-06-04, 2021-06-04 signatures=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean Hi Aleksandar, On 6/3/21 6:40 AM, Aleksandar Gerasimovski wrote: > Hi Folks, > > I hope you are all doing well! > Is it possible this patch to get some attention? > > Thanks! > > Regards, > Aleksandar > > -----Original Message----- > From: Tom Rini > Sent: Freitag, 30. April 2021 13:53 > To: Aleksandar Gerasimovski ; Patrick Delaunay ; Michal Simek ; . Simon Goldschmidt > Cc: u-boot@lists.denx.de > Subject: Re: [PATCH] arm: bootm: wrong lmb region reservation when PRAM is used > > On Fri, Feb 19, 2021 at 09:46:49PM +0000, Aleksandar Gerasimovski wrote: > >> This is a draft patch to describe the problem and to initiate a >> discussion for solution. >> >> PRAM usage is not taken into account when reserving lmb for ARM >> architecture, this means that predefined PRAM region is reserved by >> the u-boot and cannot be used by the u-boot users. >> >> In our case this bug leads to non functional ramfs boot, as the PRAM >> and ram rootfs address ranges are getting reserved by the u-boot. >> >> It is obvious that here PRAM region is ignored, but my question is is >> this clear to everyone and expected? >> >> Taking  board_f.c as reference, when calculating relocation address >> PRAM area is taken into account so I would expect that to be case here. >> Here the intention is to reserve unused space at the end of the >> effective RAM but PRAM is not part of that. >> >> Possible solution would be to introduce something like >> get_effective_memsize here e.g powerpc/lib/bootm.c but then also >> NR_DRAM_BANKS has to be considered? >> >> Signed-off-by: Aleksandar Gerasimovski >> >> --- >> arch/arm/lib/bootm.c | 10 ++++++++-- >> 1 file changed, 8 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index >> 11af9e2..4b06d25 100644 >> --- a/arch/arm/lib/bootm.c >> +++ b/arch/arm/lib/bootm.c >> @@ -54,7 +54,7 @@ static ulong get_sp(void) >> >> void arch_lmb_reserve(struct lmb *lmb) { >> - ulong sp, bank_end; >> + ulong sp, bank_end, pram = 0; >> int bank; >> >> /* >> @@ -69,6 +69,11 @@ void arch_lmb_reserve(struct lmb *lmb) >> sp = get_sp(); >> debug("## Current stack ends at 0x%08lx ", sp); >> >> +#ifdef CONFIG_PRAM >> + pram = env_get_ulong("pram", 10, CONFIG_PRAM); >> + pram = pram << 10; /* size is in kB */ >> +#endif >> + >> /* adjust sp by 4K to be safe */ >> sp -= 4096; >> for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { @@ -76,8 +81,9 >> @@ void arch_lmb_reserve(struct lmb *lmb) >> sp < gd->bd->bi_dram[bank].start) >> continue; >> /* Watch out for RAM at end of address space! */ >> + /* @todo: pram obviously wrong if NR_DRAM_BANKS > 1 */ >> bank_end = gd->bd->bi_dram[bank].start + >> - gd->bd->bi_dram[bank].size - 1; >> + gd->bd->bi_dram[bank].size - pram - 1; >> if (sp > bank_end) >> continue; >> if (bank_end > gd->ram_top) > Adding a few folks who have touched lmb code relatively recently for their thoughts. Thanks! > > -- > Tom My first felling it is not a good location for the correction => it is not a ARM specific issue And you already point the NR_DRAM_BANKS issue Even if this option CONFIG_PRAM seems fewly used... The expect behavior is described in README - Protected RAM:         CONFIG_PRAM         Define this variable to enable the reservation of         "protected RAM", i. e. RAM which is not overwritten         by U-Boot. Define CONFIG_PRAM to hold the number of         kB you want to reserve for pRAM. You can overwrite         this default value by defining an environment         variable "pram" to the number of kB you want to         reserve. Note that the board info structure will         still show the full amount of RAM. If pRAM is         reserved, a new environment variable "mem" will         automatically be defined to hold the amount of         remaining RAM in a form that can be passed as boot         argument to Linux, for instance like that:             setenv bootargs ... mem=\${mem}             saveenv         This way you can tell Linux not to use this memory,         either, which results in a memory region that will         not be affected by reboots.         *WARNING* If your board configuration uses automatic         detection of the RAM size, you must make sure that         this memory test is non-destructive. So far, the         following board configurations are known to be         "pRAM-clean":             IVMS8, IVML24, SPD8xx,             HERMES, IP860, RPXlite, LWMON,             FLAGADM But I don't found the ${mem} usage.... I think  you can directly add a lmb reserved memory region in a lmb_reserve_common() just after boot_fdt_add_mem_rsv_regions() I the propsal, I use gd->ram_top to avoid issue with NR_DRAM_BANKS > 1 it is alligned with board_f.c::setup_dest_addr() staticvoidlmb_reserve_common(structlmb*lmb, void*fdt_blob) { arch_lmb_reserve(lmb); board_lmb_reserve(lmb); if(IMAGE_ENABLE_OF_LIBFDT && fdt_blob) boot_fdt_add_mem_rsv_regions(lmb, fdt_blob); +    if(IS_ENABLED(CONFIG_PRAM)){ +      pram = env_get_ulong("pram", 10, CONFIG_PRAM); +        lmb_reserve(lmb,gd->ram_top - pram, param); +    } } but I see potential issue here if the lmb init function is called when ENV is not ready. perhaps it should be done in your board_lmb_reserve() to avoid to impact other board /arch PS: I think that is done in arch/arm/mach-imx/misc.c => reserved memory after the sp !? For information, the "reserved-memory" can also be defined in device tree of U-Boot and kernel (that avoid the CONFIG_PRAM in U-Boot and mem='' in kernel cmd line) U-Boot need to use the device tree information to avoid the reserved memory for relocation. it is done in stm32mp platform: using lmb to parse the DT and found the correct usable ram top arch/arm/mach-stm32mp/dram_init.c::board_get_usable_ram_top() ulong board_get_usable_ram_top(ulong total_size) {     phys_size_t size;     phys_addr_t reg;     struct lmb lmb;     /* found enough not-reserved memory to relocated U-Boot */     lmb_init(&lmb);     lmb_add(&lmb, gd->ram_base, gd->ram_size);     boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob);     size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE),     reg = lmb_alloc(&lmb, size, MMU_SECTION_SIZE); ....    return reg + size; } The OP-TEE reserved memory is dynamically added by the secure OS in U-Boot device tree. Drawback: huge DT parsing cost if data cache is not activated then the function is called Regards Patrick