From patchwork Mon Jun 12 14:53:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 103643 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp235869qgd; Mon, 12 Jun 2017 08:02:24 -0700 (PDT) X-Received: by 10.237.63.182 with SMTP id s51mr55306907qth.61.1497279744489; Mon, 12 Jun 2017 08:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497279744; cv=none; d=google.com; s=arc-20160816; b=Z9k3PVGt1xrwEYHtAHlnHyEnQJnx8bY0pw67VxMLX+SarRZheU/MWp0Km1+IhMkY+e Lw+iPQWxVK3+ceVR1ef6pVhgrEoXeTKcFTlqMUuH0LYdB96JiKSi6LgUA+x1NeI5BX15 YVPOsbsgx5zQ3GVsQBxFzxxcpVnsse+q9FFtnnRG1GK50D9pvHVtBxTWy+x2fYfSeKJ4 c+a+IutAJIhnzStM0HFJ3Zqhd0p0q6uEK5I11khnkiILchA5uquZYwxMdCIKlUEX3W6z mMr8Nr/x2MN4vz0FPyD5uNEwVgsyryNPU/ro3KDy76PaH/OlsyL6EhbCPwOSDCvO0Nh9 101A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:arc-authentication-results; bh=tX5ldvnd8pXabiGA9TANkHUpNFvwHOucXSqCtPC7vIw=; b=cmMMSLYjge/+PCF+g1jykvnxPuvew/RBRTCwqBhlbJ5aaZ/EnZO+41g3DMRnVHYL2F Bgr2WTRkefUjntHj50vD7JjR6MqYBg9Jt8VZbj9zejlD1rOOT7jj04M3WGGPhDnqTlVt EhZWIrQn2cJaUU1ZaASk1/YUSopBPUlgA8gMGFAC3xzPrfF665A2YJe+Qzcqa2QsoMyQ ljaKZaVdwc4ugV2dKJvrZjkH6KJwG6EXfs2XEAZsWN5mk/Y+CiiJ4ObfnFkVSe5dTHh8 Ojo/sl6rhQ24fhygdy1cwKOb5ePUcDckyMtRN6hC6ccQ5EOtaip4cP9CjeCnneSySaGh QT7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v69si9052612qkb.125.2017.06.12.08.02.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 12 Jun 2017 08:02:24 -0700 (PDT) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQrG-0005nh-48 for patch@linaro.org; Mon, 12 Jun 2017 11:02:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKQl2-0000yP-GP for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKQl1-0000wK-Br for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:56 -0400 Received: from mail-wr0-x236.google.com ([2a00:1450:400c:c0c::236]:32900) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKQl0-0000vv-Vr for grub-devel@gnu.org; Mon, 12 Jun 2017 10:55:55 -0400 Received: by mail-wr0-x236.google.com with SMTP id v104so99062529wrb.0 for ; Mon, 12 Jun 2017 07:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uUMXXzs9lDnMkuvXX0lJdSXJVTvkG20S6kNTA3DIhYE=; b=ShUmsDdbffXoVkK4w2XArH/GZqozgAOKapwxVgKrIPvDfBFqEw9l6DKxI1lIstBCmw UK6Jpmax3FnIY40TEBTjzbFl/e183O8JmQCNzN5jZuCVdKQi2vsLwNckTtTTRzWg8r/Y Fctbujbgj+YpI9sUMHHaT+E2Bwcme8XNmglfI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uUMXXzs9lDnMkuvXX0lJdSXJVTvkG20S6kNTA3DIhYE=; b=M1K5HiIdX8rQA4YPwmc7I06kMT1Kx2lc6w5zv3XqyRoC9Nj5X82W4WAWL0NMZbxk44 e/6BfgaTPa+0ggU+QBWcfg33mn+rm73rX8oxT+VGOzIJz/4EI1XaG7pgpT1waAMGujC4 hHedQhXyl3zluBmHOuA8A8VPSlfV6kBVRf7uBBP9tctEpxy+uHE0MqivVJYI5zXYAkne 67ifm7jdrP/9V1wPz1QbqJCAXygnzQVPelzg7kPm31+pfi31zwHoCztdN4GO0nJNHXrN tJ4hQcxqMZMbSNhyAAaaJJF/+wJp+hgLqti0O2XbCCosWZuk13v5U0GM0lRWFZeH+3yx hNTw== X-Gm-Message-State: AKS2vOw26Ar77TTtcmgJfQUL5OeWyW/DybGvT+bAWu37n+emNCFdWm7y bYiDOVjhYL04INPXJzHXhw== X-Received: by 10.28.13.1 with SMTP id 1mr8401446wmn.12.1497279349268; Mon, 12 Jun 2017 07:55:49 -0700 (PDT) Received: from mohikan.hemma.eciton.net (cpc92316-cmbg19-2-0-cust118.5-4.cable.virginm.net. [82.12.0.119]) by smtp.gmail.com with ESMTPSA id s140sm7722wmd.1.2017.06.12.07.55.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jun 2017 07:55:48 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 6/7] efi: restrict arm/arm64 linux loader initrd placement Date: Mon, 12 Jun 2017 15:53:40 +0100 Message-Id: <20170612145341.3351-7-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170612145341.3351-1-leif.lindholm@linaro.org> References: <20170612145341.3351-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::236 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: ard.biesheuvel@linaro.org, lersek@redhat.com, agraf@suse.de, kraxel@redhat.com MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" The 32-bit arm Linux kernel is built as a zImage, which self-decompresses down to near start of RAM. In order for an initrd/initramfs to be accessible, it needs to be placed within the first ~768MB of RAM. The initrd loader built into the kernel EFI stub restricts this down to 512MB for simplicity - so enable the same restriction in grub. For arm64, the requirement is within a 1GB aligned 32GB window also covering the (runtime) kernel image. Since the EFI stub loader itself will attempt to relocate to near start of RAM, force initrd to be loaded completely within the first 32GB of RAM. Signed-off-by: Leif Lindholm --- grub-core/loader/arm64/linux.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c index 8cd44230d..7e989c2b9 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -35,6 +35,23 @@ GRUB_MOD_LICENSE ("GPLv3+"); +/* + * As per linux/Documentation/arm/Booting + * ARM initrd needs to be covered by kernel linear mapping, + * so place it in the first 512MB of DRAM. + * + * As per linux/Documentation/arm64/booting.txt + * ARM64 initrd needs to be contained entirely within a 1GB aligned window + * of up to 32GB of size that covers the kernel image as well. + * Since the EFI stub loader will attempt to load the kernel near start of + * RAM, place the buffer in the first 32GB of RAM. + */ +#ifdef __arm__ +#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024) +#else /* __aarch64__ */ +#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024) +#endif + static grub_dl_t my_mod; static int loaded; @@ -194,6 +211,25 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } +/* + * This function returns a pointer to a legally allocated initrd buffer, + * or NULL if unsuccessful + */ +static void * +allocate_initrd_mem (int initrd_pages) +{ + grub_addr_t max_addr; + + if (grub_efi_get_dram_base (&max_addr) != GRUB_ERR_NONE) + return NULL; + + max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; + + return grub_efi_allocate_pages_real (max_addr, initrd_pages, + GRUB_EFI_ALLOCATE_MAX_ADDRESS, + GRUB_EFI_LOADER_DATA); +} + static grub_err_t grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) @@ -222,7 +258,8 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), grub_dprintf ("linux", "Loading initrd\n"); initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size)); - initrd_mem = grub_efi_allocate_pages (0, initrd_pages); + initrd_mem = allocate_initrd_mem (initrd_pages); + if (!initrd_mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));