Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0AA8FC3DA7D for ; Thu, 5 Jan 2023 10:03:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8E4FA8558F; Thu, 5 Jan 2023 11:03:20 +0100 (CET) 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="fx10djMp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F07C5855A6; Thu, 5 Jan 2023 11:03:18 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (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 6CBF485172 for ; Thu, 5 Jan 2023 11:03:16 +0100 (CET) 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=93696a50ca=patrick.delaunay@foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3057bR0r031651; Thu, 5 Jan 2023 11:03:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=XH0bncgA+5BAorPfgwAmrmB8/b1urC08ucnhhyz7jo4=; b=fx10djMpSikcAmEKlyuNODQWHPjvSpUnwg2SIP6tMdmt4smk5K1K3MpL43cuKh63VoyM W1tR8ptk81KhtN29AplezwLpyfgNaxNSMvUAOcMe2cOxMnbJgK8fT1GMl38Zl/mvFUum iYhgNCqeL5K3/jDNdFlLLdKDgL+4opcthnnYF3k23hpRM7OIsTi3477tV2AgSsploA2t iBwzcShFnp31KwBGoV1qjDQt0/c+gdRCzijAi92L03kdggxXI7a/avG0WT+kgybcLx8i a5ldrc0PiewXlNIKnfSjt0wwaixy3+40bCgOaoTIdc86nd208pt5GygrrgSe66zgA8of Hw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3mwtas96uy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 11:03:10 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B2AC310002A; Thu, 5 Jan 2023 11:03:08 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AA9AE226FBA; Thu, 5 Jan 2023 11:03:08 +0100 (CET) Received: from [10.48.0.157] (10.48.0.157) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.13; Thu, 5 Jan 2023 11:03:07 +0100 Message-ID: <99e68254-e6a1-9653-54fb-61d64d8e02e1@foss.st.com> Date: Thu, 5 Jan 2023 11:03:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] arm: stm32mp: Fix board_get_usable_ram_top() again Content-Language: en-US To: Marek Vasut , , Pali Rohar CC: Patrice Chotard , Simon Glass , Tom Rini References: <20230105012222.238075-1-marex@denx.de> From: Patrick DELAUNAY In-Reply-To: <20230105012222.238075-1-marex@denx.de> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.0.157] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-05_03,2023-01-04_02,2022-06-22_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean Hi, On 1/5/23 02:22, Marek Vasut wrote: > Do not access gd->ram_size and assume this is actual valid RAM size. Since commit > 777aaaa706b ("common/memsize.c: Fix get_effective_memsize() to check for overflow") > the RAM size may be less than gd->ram_size , call get_effective_memsize() to get > the limited value instead. > > The aforementioned commit makes STM32MP15xx boards with 1 GiB of DRAM > at 0xc0000000 hang on boot, which is a grave defect. > > Signed-off-by: Marek Vasut > --- > Cc: Pali Rohar > Cc: Patrice Chotard > Cc: Patrick Delaunay > Cc: Tom Rini > --- > arch/arm/mach-stm32mp/dram_init.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/mach-stm32mp/dram_init.c b/arch/arm/mach-stm32mp/dram_init.c > index 9346fa8546d..80ba5c27741 100644 > --- a/arch/arm/mach-stm32mp/dram_init.c > +++ b/arch/arm/mach-stm32mp/dram_init.c > @@ -51,7 +51,7 @@ phys_size_t board_get_usable_ram_top(phys_size_t total_size) > > /* found enough not-reserved memory to relocated U-Boot */ > lmb_init(&lmb); > - lmb_add(&lmb, gd->ram_base, gd->ram_size); > + lmb_add(&lmb, gd->ram_base, get_effective_memsize()); > boot_fdt_add_mem_rsv_regions(&lmb, (void *)gd->fdt_blob); > /* add 8M for reserved memory for display, fdt, gd,... */ > size = ALIGN(SZ_8M + CONFIG_SYS_MALLOC_LEN + total_size, MMU_SECTION_SIZE), Thanks for the patch Reviewed-by: Patrick Delaunay Even if I don't uderstood where the code blocked here... I need to cros-check it. But I think it is more a regression introduced by 777aaaa706b ("common/memsize.c: Fix get_effective_memsize() to check for overflow") in this patch I don't understood the assumption: * It is required that ram_base + ram_size must be representable by * phys_size_t type and must be aligned by direct access why add now this limitation ? why phys_size_t here and not phys_addr_t or unsigned long, the ram_base type ? why align on 4kB and not on MMU_SECTION_SIZE ? until now on ARM 32bits U-Boot is working with ram_base = 0xC0000000 (unsigned long) ram_size = 0x40000000 (phys_size_t) overflow for ram_top (phys_addr_t) = ram_base + get_effective_memsize() was previously managed in the code as we work only on base address + size (in board_f.c, in lmb library) I correct in the code overflow issues, for example in commit 54be09cd8f6e ("arm: caches: manage phys addr_t overflow in mmu_set_region_dcache_behaviour"). moreover for me it is strange to reduce the size of the DDR banks by default (see resutl of bdinfo command) only just to avoid overflow: common/board_f.c:267: gd->bd->bi_dram[0].size = get_effective_memsize(); For me the real assumption is on the end of RAM: "ram_base + ram_size - 1" must be representable by 'ram_base' type (phys_addr_t or unsigned long ?) + + /* + * Check for overflow and limit ram size. + * It is required that ram_base + ram_size - 1 must be representable + * by ram_base type, unsigned long. + */ + if (gd->ram_base - 1 + ram_size < gd->ram_base) + ram_size = ((unsigned long)~0x0ULL) - gd->ram_base; => no need to remove 4KB is here... base + size can reach the MAX value for the type + 1 Patrick