From patchwork Mon Nov 11 18:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 179116 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp7051301ilf; Mon, 11 Nov 2019 10:57:24 -0800 (PST) X-Google-Smtp-Source: APXvYqyvbG26yZqncTq93nj6F2JVYJCzfKrFhMlkVa/0YHWE8aoN6jrez3MKTe1ShkMr1I/BRjoG X-Received: by 2002:a17:906:3053:: with SMTP id d19mr24660886ejd.109.1573498644420; Mon, 11 Nov 2019 10:57:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498644; cv=none; d=google.com; s=arc-20160816; b=W7FaikHUSq3gG+ZC7Jixw3uVsm/q8Kgp7r7AxYCoZP0n0SSQtepVnakCHtxhfavsUm QU6qMz8el/wgUhaBpHPog4yAWAR9/YFSNHB5l4FCI8GiqUSZlMkrvlySSo5y6PGijv47 H42ZdCIxnjRZ3oSap1uA06WARsdGXM2BLMsR4nQIhv2fcfuCqc0DX5epzj7WLeMNBU3H NoPt6ms5zHQtDS0FR0dctRbqjyfOobjlpY/W8EZm1IDHAve3Wk05hyMum0x4Q558Jary NaqpC15QKpwakhC+k5zJvFTovd+RfStivTWjwv3vHJRPGxHs2YtRCaZGJRzPPkddlJW9 bL8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WOv1x4rimo92eC9CZtpMog1XkcAIieI7LabCrENeIe8=; b=kDY87EffDkx9K+TztOM6GVedCQq/pqs3jsCP0KXSpwSaweDbcPS1vuzBskDtLQLvRE ZuT0YEWjVo27erMDAK8jUs//w2mPy1ORiRObb/fYdo/hRTL7p7TMHV149KuHl8WSjgFA 2HtDM2a3RSx7eESCqZeRov6i3kzoOtyDsmrbVzR3fLRUlvm6r29ZAUdphpf1WP+7DACA jTcRsDlyBLnKw/Rrgj2MveolZibYZ3vqMbmcLVooD7V0k6RS8rPjz/zgb2DC35l0HfJJ vcVE3l1gkfd1+zTFycwoLZz4zI37af+DSLF1aoMDL5bsKSNzHrPFdKt/HQ2ew9IuaF4n tD8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dyQYtVuN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si11959499eda.433.2019.11.11.10.57.24; Mon, 11 Nov 2019 10:57:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dyQYtVuN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730820AbfKKS5V (ORCPT + 26 others); Mon, 11 Nov 2019 13:57:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:56468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730493AbfKKS5Q (ORCPT ); Mon, 11 Nov 2019 13:57:16 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 803FB21783; Mon, 11 Nov 2019 18:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498635; bh=9VlzYfDK4xB2zu0xHS/uE7JswxMQCb8hawKUTinRw1c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dyQYtVuNTfoPQ1lQD8BK7Vd6byFvQ3M+4jUm/e3RQbNLwMdYM7mMEg0ssiHwh1KOZ 94BQYWyqgSDCb0bLaEaiBnj0giS2k+yJoiBTROxrqZe7FWhXnjtwhjMfd2JpsEz1U6 Voh3E0GvvECCkYpMD4RtBNRwU7ORxAo0643GjQhI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Gardet , Ard Biesheuvel , Chester Lin , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , linux-efi@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.3 176/193] efi: libstub/arm: Account for firmware reserved memory at the base of RAM Date: Mon, 11 Nov 2019 19:29:18 +0100 Message-Id: <20191111181514.101511069@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel [ Upstream commit 41cd96fa149b29684ebd38759fefb07f9c7d5276 ] The EFI stubloader for ARM starts out by allocating a 32 MB window at the base of RAM, in order to ensure that the decompressor (which blindly copies the uncompressed kernel into that window) does not overwrite other allocations that are made while running in the context of the EFI firmware. In some cases, (e.g., U-Boot running on the Raspberry Pi 2), this is causing boot failures because this initial allocation conflicts with a page of reserved memory at the base of RAM that contains the SMP spin tables and other pieces of firmware data and which was put there by the bootloader under the assumption that the TEXT_OFFSET window right below the kernel is only used partially during early boot, and will be left alone once the memory reservations are processed and taken into account. So let's permit reserved memory regions to exist in the region starting at the base of RAM, and ending at TEXT_OFFSET - 5 * PAGE_SIZE, which is the window below the kernel that is not touched by the early boot code. Tested-by: Guillaume Gardet Signed-off-by: Ard Biesheuvel Acked-by: Chester Lin Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191029173755.27149-5-ardb@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- drivers/firmware/efi/libstub/Makefile | 1 + drivers/firmware/efi/libstub/arm32-stub.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 0460c7581220e..ee0661ddb25bb 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -52,6 +52,7 @@ lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \ lib-$(CONFIG_ARM) += arm32-stub.o lib-$(CONFIG_ARM64) += arm64-stub.o +CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c index e8f7aefb6813d..ffa242ad0a82e 100644 --- a/drivers/firmware/efi/libstub/arm32-stub.c +++ b/drivers/firmware/efi/libstub/arm32-stub.c @@ -195,6 +195,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, unsigned long dram_base, efi_loaded_image_t *image) { + unsigned long kernel_base; efi_status_t status; /* @@ -204,9 +205,18 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, * loaded. These assumptions are made by the decompressor, * before any memory map is available. */ - dram_base = round_up(dram_base, SZ_128M); + kernel_base = round_up(dram_base, SZ_128M); - status = reserve_kernel_base(sys_table, dram_base, reserve_addr, + /* + * Note that some platforms (notably, the Raspberry Pi 2) put + * spin-tables and other pieces of firmware at the base of RAM, + * abusing the fact that the window of TEXT_OFFSET bytes at the + * base of the kernel image is only partially used at the moment. + * (Up to 5 pages are used for the swapper page tables) + */ + kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE; + + status = reserve_kernel_base(sys_table, kernel_base, reserve_addr, reserve_size); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Unable to allocate memory for uncompressed kernel.\n"); @@ -220,7 +230,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table, *image_size = image->image_size; status = efi_relocate_kernel(sys_table, image_addr, *image_size, *image_size, - dram_base + MAX_UNCOMP_KERNEL_SIZE, 0); + kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel.\n"); efi_free(sys_table, *reserve_size, *reserve_addr);