From patchwork Tue Feb 28 22:35:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 94668 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1528911qgi; Tue, 28 Feb 2017 14:39:25 -0800 (PST) X-Received: by 10.55.66.68 with SMTP id p65mr5428090qka.187.1488321565818; Tue, 28 Feb 2017 14:39:25 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c50si2631167qtc.208.2017.02.28.14.39.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:39:25 -0800 (PST) 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]:37455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqQV-0008Bx-Bb for patch@linaro.org; Tue, 28 Feb 2017 17:39:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciqN0-0004ts-LG for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciqMz-0004aW-Oh for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:46 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciqMz-0004ZZ-Io for grub-devel@gnu.org; Tue, 28 Feb 2017 17:35:45 -0500 Received: by mail-wm0-x22f.google.com with SMTP id v77so22995343wmv.0 for ; Tue, 28 Feb 2017 14:35:45 -0800 (PST) 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=O6HHy6/htsEbLN7rpdmqy7+INOJzMX+ImQ8jn5i4/JM=; b=Mm5ZqCvpIXRRcmAHGLbzEb8v/sfhf732h9Hg5m10wNMM4y0keWYKuMz2VUjvaJzafR 7/sqCcYhmp1LHrWzSPGpp17j0yGYfal21yuAzvKfJ5Tw6lDrc1ykG5NTK8AKaLx0H0dN 3iK2fW2RII+XbS0fiCrcLDQJxzvpF4MAABc78= 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=O6HHy6/htsEbLN7rpdmqy7+INOJzMX+ImQ8jn5i4/JM=; b=Z1wdhyW82bF6Bvy+huWlHqSmG/gXdFBblnKnOYkAziGdGL3fTpcHlWmFQwSWQL1fMr 6BS1DbwOhGkFB5Jq44CriEzAf9gOJB7iXUIGv073zrBSVfO9HkIrPpV/NbZB5oDLdOv0 W4iB9mewpfdR3KE9REe49rlufXHxVnQjLZLMRTDSU2mpcwrTby8ygeg7rRIcKVIOC0RM ItQEsjHwhqhKJz2i42NTI7mbZZNsZY8TLQRoPWNG2OQ17cXspF9OKBfjYxuw1taq21db ooP+1TU+wO3s90j5dx+FYDWBdVGZagLAGSAQH3Ks4L6rcY7zqAQtUHfO3e9KRWq7Dzfc uXRg== X-Gm-Message-State: AMke39kzphlWL4plXHQg+Ws9uh/TqLoTxmn6GQPk9RUI5dbBs5FraTSfHRDX4vx2kSz0S9O7 X-Received: by 10.28.71.21 with SMTP id u21mr640397wma.1.1488321344510; Tue, 28 Feb 2017 14:35:44 -0800 (PST) Received: from mohikan.hemma.eciton.net ([2a01:348:6:8735:e23f:49ff:fe6d:9d26]) by smtp.gmail.com with ESMTPSA id 40sm4043391wry.22.2017.02.28.14.35.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:35:43 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 6/7] efi: restrict arm/arm64 linux loader initrd placement Date: Tue, 28 Feb 2017 22:35:36 +0000 Message-Id: <20170228223537.9685-7-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228223537.9685-1-leif.lindholm@linaro.org> References: <20170228223537.9685-1-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f 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: Laszlo Ersek , Gerd Hoffmann , Alexander Graf , ard.biesheuvel@linaro.org 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 37de3ed05..c67c1316c 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"));