From patchwork Mon Dec 2 07:06:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 846594 Delivered-To: patch@linaro.org Received: by 2002:a5d:4cd0:0:b0:385:e875:8a9e with SMTP id c16csp1024973wrt; Sun, 1 Dec 2024 23:07:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU9pOQTwgyBoirl+3AdwhbffUQXh1DnuRQRaxRdusnVpOBEELUwCle0uu8TvaKf872+Rhj+yA==@linaro.org X-Google-Smtp-Source: AGHT+IFMgZtXeePLtsSEmR2dvQ0tewHLm4qV29e5bR66i/z/vY54ldvW3ISoMRS2XzjGrZJLENbs X-Received: by 2002:a17:906:3d29:b0:aa5:63a1:17cf with SMTP id a640c23a62f3a-aa580f23e33mr2243818066b.20.1733123232327; Sun, 01 Dec 2024 23:07:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733123232; cv=none; d=google.com; s=arc-20240605; b=Nhfbok1QRCLfij0/JrycqFfWWF0AM6i8VU5KN/aeSxpN3U2TtYVf6BORqO0fid3Vqq 2h1Q1HC3i0ItGCNeUXGFm2D/dKlqQmb3YfHSTb+jiKB+I2mtLnQdnHflpJMLFdRRiHpM N6rRgsXvYH0ZiAMpTUXJhksAgV6pIfXBy8CJiY+RX28X78GQBz4vSspZ4Ty307axqqnc XGbM3ycbVjKeANGwTKL0XxC2y8ZxcsdwEMyvGbiNDI21gnM+QUd8pRVSTd4AceIb3321 6o4lvF0CGj1WB1NCNEDqMebbxg2Tw4QguQFpWfdjdEPf29lguUAn0zzQki05gJCY02+B KZ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=EyyCZQF8JsN3rUxKvP2LVEy3/5Wis8q4Emq1kJrCieA=; fh=Ktd/XQHJPcMJexL1V7FLDMlYTnDUEoOqVlt4qT32Y6s=; b=flZ+wawIx2doltRJ340/Zg41PZpur9ftZGl5pTuwIc4GmFSB8oIDAiptE+JQo3mBfK F/1jN4teYIMTUF8GLwO3K5k/E5fMRsriGVmwB54mk5/Zqa6j1oQmjrCrx2qKlzdvLTxP TuqsLo59HZDrtLnQ6h9BIDzJUFgI4RgSuo/LpBkTN9srahQJjrikhXl2v5qbXzHPVtK1 BHjZc1pn9lnQrRC/2eJ0npC4YNapaZD1Lp5wvavMfwZwUnQF4cxbinWJGCWWbMus6t8F sjKtorUZsuZJ6WujH/EN+tLM2u8LhNK2CMMiUl9xyFP7es6q7MtkBvcDYq+seSDIeBmk PejA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-aa5999bf5aesi670453766b.960.2024.12.01.23.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2024 23:07:12 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 000AA89323; Mon, 2 Dec 2024 08:07:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id A69BD89385; Mon, 2 Dec 2024 08:07:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 9730689100 for ; Mon, 2 Dec 2024 08:07:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org 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 843F61063; Sun, 1 Dec 2024 23:07:35 -0800 (PST) Received: from a079122.blr.arm.com (a079122.arm.com [10.162.17.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 24EFB3F71E; Sun, 1 Dec 2024 23:07:04 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , E Shattow , Tom Rini , Sughosh Ganu Subject: [PATCH] lmb: prohibit allocations above ram_top even from same bank Date: Mon, 2 Dec 2024 12:36:24 +0530 Message-Id: <20241202070624.1295497-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean There are platforms which set the value of ram_top based on certain restrictions that the platform might have in accessing memory above ram_top, even when the memory region is in the same DRAM bank. So, even though the LMB allocator works as expected, when trying to allocate memory above ram_top, prohibit this by marking all memory above ram_top as reserved, even if the said memory region is from the same bank. Signed-off-by: Sughosh Ganu Tested-by: Andreas Schwab --- lib/lmb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/lmb.c b/lib/lmb.c index 14b9b8466ff..be168dfb8dc 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -615,6 +615,7 @@ static __maybe_unused void lmb_reserve_common_spl(void) void lmb_add_memory(void) { int i; + phys_addr_t bank_end; phys_size_t size; u64 ram_top = gd->ram_top; struct bd_info *bd = gd->bd; @@ -628,6 +629,8 @@ void lmb_add_memory(void) for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { size = bd->bi_dram[i].size; + bank_end = bd->bi_dram[i].start + size; + if (size) { lmb_add(bd->bi_dram[i].start, size); @@ -639,6 +642,9 @@ void lmb_add_memory(void) if (bd->bi_dram[i].start >= ram_top) lmb_reserve_flags(bd->bi_dram[i].start, size, LMB_NOOVERWRITE); + else if (bank_end > ram_top) + lmb_reserve_flags(ram_top, bank_end - ram_top, + LMB_NOOVERWRITE); } } }