From patchwork Wed Aug 29 18:53:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 963607 X-Patchwork-Delegate: agraf@suse.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=none (p=none dis=none) header.from=wwwdotorg.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 420vsr10YDz9ryt for ; Thu, 30 Aug 2018 04:53:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9A93AC21DA6; Wed, 29 Aug 2018 18:53:47 +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=none 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 87BB3C21D8E; Wed, 29 Aug 2018 18:53:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1BA3DC21D8A; Wed, 29 Aug 2018 18:53:43 +0000 (UTC) Received: from avon.wwwdotorg.org (avon.wwwdotorg.org [104.237.132.123]) by lists.denx.de (Postfix) with ESMTPS id A1A31C21D8A for ; Wed, 29 Aug 2018 18:53:42 +0000 (UTC) Received: from swarren-lx1.nvidia.com (unknown [216.228.112.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPSA id BF4371C00FD; Wed, 29 Aug 2018 12:53:40 -0600 (MDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.1 at avon.wwwdotorg.org From: Stephen Warren To: Tom Rini Date: Wed, 29 Aug 2018 12:53:29 -0600 Message-Id: <20180829185330.30493-1-swarren@wwwdotorg.org> X-Mailer: git-send-email 2.18.0 X-NVConfidentiality: public Cc: Stephen Warren , xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de, Tom Warren Subject: [U-Boot] [PATCH 1/2] ARM: tegra: reserve unmapped RAM so EFI doesn't use it 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Stephen Warren Tegra U-Boot ensures that board_get_usable_ram_top() never returns a value over 4GB, since some peripherals can't access such addresses. However, on systems with more than 2GB of RAM, RAM bank 1 does describe this extra RAM, so that Linux (or whatever OS) can use it, subject to DMA limitations. Since board_get_usable_ram_top() points at the top of RAM bank 0, the memory locations describes by RAM bank 1 are not mapped by U-Boot's MMU configuration, and so cannot be used for anything. For some completely inexplicable reason, U-Boot's EFI support ignores the value returned by board_get_usable_ram_top(), and EFI memory allocation routines will return values above U-Boot's RAM top. This causes U-Boot to crash when it accesses that RAM, since it isn't mapped by the MMU. One use-case where this happens is TFTP download of a file on Jetson TX1 (p2371-2180). This change explicitly tells the EFI code that this extra RAM should not be used, thus avoiding the crash. A previous attempt to make EFI honor board_get_usable_ram_top() was rejected. So, this patch will need to be replicated for any board that implements board_get_usable_ram_top(). Fixes: aa909462d018 ("efi_loader: efi_allocate_pages is too restrictive") Signed-off-by: Stephen Warren --- arch/arm/mach-tegra/board2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c index 421a71b3014d..869d5d99d2fd 100644 --- a/arch/arm/mach-tegra/board2.c +++ b/arch/arm/mach-tegra/board2.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -210,6 +211,19 @@ int board_early_init_f(void) int board_late_init(void) { +#ifdef CONFIG_EFI_LOADER + if (gd->bd->bi_dram[1].start) { + /* + * Only bank 0 is below board_get_usable_ram_top(), so all of + * bank 1 is not mapped by the U-Boot MMU configuration, and so + * we must prevent EFI from using it. + */ + efi_add_memory_map(gd->bd->bi_dram[1].start, + gd->bd->bi_dram[1].size / 4096, + EFI_RESERVED_MEMORY_TYPE, false); + } +#endif + #if defined(CONFIG_TEGRA_SUPPORT_NON_SECURE) if (tegra_cpu_is_non_secure()) { printf("CPU is in NS mode\n"); From patchwork Wed Aug 29 18:53:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 963608 X-Patchwork-Delegate: agraf@suse.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=none (p=none dis=none) header.from=wwwdotorg.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 420vtD4tdPz9ryt for ; Thu, 30 Aug 2018 04:54:12 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4D573C21DAF; Wed, 29 Aug 2018 18:54:04 +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=none 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 30F3CC21E08; Wed, 29 Aug 2018 18:53:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CE885C21D8E; Wed, 29 Aug 2018 18:53:43 +0000 (UTC) Received: from avon.wwwdotorg.org (avon.wwwdotorg.org [104.237.132.123]) by lists.denx.de (Postfix) with ESMTPS id 6B191C21D8A for ; Wed, 29 Aug 2018 18:53:43 +0000 (UTC) Received: from swarren-lx1.nvidia.com (unknown [216.228.112.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPSA id A01231C010F; Wed, 29 Aug 2018 12:53:41 -0600 (MDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.1 at avon.wwwdotorg.org From: Stephen Warren To: Tom Rini Date: Wed, 29 Aug 2018 12:53:30 -0600 Message-Id: <20180829185330.30493-2-swarren@wwwdotorg.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180829185330.30493-1-swarren@wwwdotorg.org> References: <20180829185330.30493-1-swarren@wwwdotorg.org> X-NVConfidentiality: public Cc: Stephen Warren , xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de, Tom Warren Subject: [U-Boot] [PATCH 2/2] Revert "Revert "efi_loader: efi_allocate_pages is too restrictive"" 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Stephen Warren This reverts commit ccfc78b820e5e431c5bd73b072e7536a972e1710. Now that the underlying issue is fixed, we can revert the revert and hence restore the original EFI code. Signed-off-by: Stephen Warren --- lib/efi_loader/efi_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index e2b40aa85b5a..e902d5a280bb 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -304,7 +304,7 @@ efi_status_t efi_allocate_pages(int type, int memory_type, switch (type) { case EFI_ALLOCATE_ANY_PAGES: /* Any page */ - addr = efi_find_free_memory(len, gd->start_addr_sp); + addr = efi_find_free_memory(len, -1ULL); if (!addr) { r = EFI_NOT_FOUND; break;