From patchwork Fri Jan 4 09:10:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Li X-Patchwork-Id: 1020650 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="uBjjOFFJ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43WJsc69YGz9s3l for ; Fri, 4 Jan 2019 20:10:28 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 80AE8C21DA2; Fri, 4 Jan 2019 09:10:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 36E31C21C8B; Fri, 4 Jan 2019 09:10:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 567FAC21C8B; Fri, 4 Jan 2019 09:10:22 +0000 (UTC) Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30060.outbound.protection.outlook.com [40.107.3.60]) by lists.denx.de (Postfix) with ESMTPS id 0252BC21C4A for ; Fri, 4 Jan 2019 09:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=g0uZyGCElhr0EdPgknh8nxQ65JKkNcrGcvPNjcsiQig=; b=uBjjOFFJoEb8XdZ44nL4s2kRy5JVV1qsPgrCdcOnA8C5/rFPkhX5JW405fiyktqZlFrJw6+3QZfshJXhwMNd3FWjEyMicUFE5wdg+nfrdYgUsMEVz1g1E3zHzOG6ad+jaEmnaBuL/2D3sGxXxHQa3+JlXY3XGML1OB4AN9u2PDA= Received: from VI1PR04MB4414.eurprd04.prod.outlook.com (20.177.55.153) by VI1PR04MB1630.eurprd04.prod.outlook.com (10.164.84.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1471.20; Fri, 4 Jan 2019 09:10:20 +0000 Received: from VI1PR04MB4414.eurprd04.prod.outlook.com ([fe80::f1e0:df54:f9c:b4b9]) by VI1PR04MB4414.eurprd04.prod.outlook.com ([fe80::f1e0:df54:f9c:b4b9%3]) with mapi id 15.20.1495.005; Fri, 4 Jan 2019 09:10:20 +0000 From: Ye Li To: "sbabic@denx.de" , "u-boot@lists.denx.de" Thread-Topic: [PATCH] imx: Fix potential lmb memory overwritten by stack Thread-Index: AQHUpA1R4zPzuRRoZkeA8ATdDi91lQ== Date: Fri, 4 Jan 2019 09:10:20 +0000 Message-ID: <1546593003-41166-1-git-send-email-ye.li@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK2PR0302CA0007.apcprd03.prod.outlook.com (2603:1096:202::17) To VI1PR04MB4414.eurprd04.prod.outlook.com (2603:10a6:803:6e::25) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ye.li@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.68] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR04MB1630; 6:TI6YouzohL107E8pLukHXkvUuQKq0EkWkk0e27aKwruJqghV8OXprShme9pQzv9nvY6VKf58JFEqAKhuIgcIQTt1e1kn5v49uEpToblZM/CLNAKw0UZXH3LFAK3IRszP6Pw1czhWp6AdrjYM1fIp6cq+ROzvYl7B0D7mBCZlzG+HZYVV2M3Oaw488Xk+Z05g/B4dJRpV7ytzSjCe+ejCQEzwV4+Sfs2lRa9mG3xNH9rn4mIXCIVI+6ypbgoClIvdl6dS09HsgYeac5O0YQAd9tLggAu6fM8Tcb6CA9Its4k8Nl38gOxJ+rczb+KPEJY6dbO/22ZWwPKQrz0kjlWG2ptigHjt0ew4bSgOWBfOPYwN5fLNA5fg16Io+z23GRSs4qG82cLdRyTQ3B0sP/mPLEeC/VkGXXIaQ0M8qrLcr/EB5KN2cDYLVNWPNyk+D75nIrZavpJtHNH9BMfKMrWMJA==; 5:Hhs8IEp5lcxqAiWCB/A3o6sK6S8+KgfbHrC4ETznOOMMMM7HRj0SCKIvhLnLJwHyrZrTvXI27DlhUVmRefLLQG1CKkH5T3TDT0VnJS/LeV/+VwOohIhxAq7s6KDuL4NMJzWu4mwpzr5iTdH3bIL8WHViDzF7hqDIKhXsTxyevF4=; 7:RjGTC5JdUUOUha4oyyBYAy3EGU0OIuCrnNhtmKzcwmS8O+Zt8Sr+5SoCYxBL5WtmU9UIXEfRWGOBsVXSldd5Kg51y/Ln+PJ5P6h97X9tBo8GAQyhGJtLio106OezzYHI4ISeWHBBvzlPbY9BC3S/Sg== x-ms-office365-filtering-correlation-id: 45cc3f55-09d0-4b60-61c4-08d672247353 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB1630; x-ms-traffictypediagnostic: VI1PR04MB1630: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:VI1PR04MB1630; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB1630; x-forefront-prvs: 0907F58A24 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(366004)(376002)(136003)(39860400002)(396003)(199004)(189003)(6436002)(71200400001)(316002)(71190400001)(53936002)(4326008)(6512007)(110136005)(54906003)(186003)(26005)(68736007)(5660300001)(97736004)(2616005)(2501003)(14454004)(66066001)(6486002)(6116002)(8936002)(3846002)(50226002)(81156014)(2906002)(8676002)(81166006)(52116002)(486006)(44832011)(105586002)(106356001)(478600001)(7736002)(86362001)(386003)(6506007)(99286004)(25786009)(36756003)(256004)(305945005)(476003)(102836004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB1630; H:VI1PR04MB4414.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: sZJdOS4MMhIINE/IautCj6rnDb860OUSKkDJhchCIqiTHjN/W2E6DjTPDt9rphDA3D+xjKwZhW+Nw7eVfUpw8sK/IthXbZXRfvu409nf3ha+JuPT1OCb3gOxP1OG8Nby/zoZTBpu/WChc3iR2XCvfPM0LEdp/IublZzjOgdnA3dECaQywxRdU9iFFnzaLLdSG2I3tzbcwGy7nJIyyuSti6Z7q/wFxu7BAvuS56/taeIgDFknzxqttLGrR8EAs5YBXt8ESg2eN1vBGJ3L86JulrEZq4mFpkavx8lbV/dUwJDpdqPBpfgR1kyV95wVu4Rk spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45cc3f55-09d0-4b60-61c4-08d672247353 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Jan 2019 09:10:17.3112 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1630 Cc: Fabio Estevam , dl-uboot-imx Subject: [U-Boot] [PATCH] imx: Fix potential lmb memory overwritten by stack X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" At default, u-boot reserves the memory from SP - 4KB to DRAM end for lmb in arch_lmb_reserve. So lmb won't allocate any memory from it. But we found the 4K gap for SP is not enough now, because some FDT updating operations are added in our u-boot before jumping to kernel, which needs larger stack. This causes the lmb allocated memory is overwritten by stack. Fix the issue by implementing the board_lmb_reserve to reserve from SP - 16KB to memory end for lmb. Signed-off-by: Ye Li --- arch/arm/mach-imx/misc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/arm/mach-imx/misc.c b/arch/arm/mach-imx/misc.c index 1bb8c50..31e95a9 100644 --- a/arch/arm/mach-imx/misc.c +++ b/arch/arm/mach-imx/misc.c @@ -9,6 +9,8 @@ #include #include +DECLARE_GLOBAL_DATA_PTR; + /* 1 second delay should be plenty of time for block reset. */ #define RESET_MAX_TIMEOUT 1000000 @@ -71,3 +73,33 @@ int mxs_reset_block(struct mxs_register_32 *reg) return 0; } + +static ulong get_sp(void) +{ + ulong ret; + + asm("mov %0, sp" : "=r"(ret) : ); + return ret; +} + +void board_lmb_reserve(struct lmb *lmb) +{ + ulong sp, bank_end; + int bank; + + sp = get_sp(); + debug("## Current stack ends at 0x%08lx ", sp); + + /* adjust sp by 16K to be safe */ + sp -= 4096 << 2; + for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { + if (sp < gd->bd->bi_dram[bank].start) + continue; + bank_end = gd->bd->bi_dram[bank].start + + gd->bd->bi_dram[bank].size; + if (sp >= bank_end) + continue; + lmb_reserve(lmb, sp, bank_end - sp); + break; + } +}