From patchwork Thu Aug 3 10:04:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 109315 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp682593obm; Thu, 3 Aug 2017 03:15:21 -0700 (PDT) X-Received: by 10.200.50.151 with SMTP id z23mr1355687qta.140.1501755321542; Thu, 03 Aug 2017 03:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501755321; cv=none; d=google.com; s=arc-20160816; b=rGaQUh2EfuwwtvTdPE8gkAYcgRYCCCeSH5hOUQ1fghCyt7cyNjrlP/n/AokcUU6pHI OjYgKpNvRuWCmd+WYG0KPfS6QIVBLPl3Q/cmztKXnRa6MV+qKEB+cxt+c9k/2nmWQ5LJ tJyJVyfHVg1coDto3Lyz1PbFRcbqPwRy7Eqg8yf4sLrov/NglhhTs0uv5r/8NUDMUejY 1g38dogZgmDb/2aST/PjJU2alyPhfN92E9vvqXQA44bDC0sK7czy6Q6nDwVoC4ja3uT3 oD8vs+i72OadE9JvOwWfNrfo1F18QzB5r1Ipk7J39JB15EAYCoT5DViK9KoJX7Z7IpRe DgqA== 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=vUz2rC5EA7bYOPoAxPN/54AwqHxs3DXlHp9EiAlWkuk=; b=QIUouiEK9EjNZEpCA4o8CGdhEHdT2Vy5I3ImFICSfoGKNjeZtwMxLRQn5SwgGXYcH2 kHOtF3iASH8wlo9wTTWsTUff3D5gzSUx9PhY1GHwpuH4MFuGwxObOn/FwPiFte8J9dsd Z3E9X2cGPo9OeNKhZjMdJrWtDdAzJx7LT1r0mGykLCn05oZAGeBlAiUjv+cMZmljbWA2 gBJiQx2w7stJ0bFwkXE/o3ASH48UzrYg+XncJKJGIPNOluMtXRQrM9XEUoQrtJ2fjUHa v2DzqWP2eXrrzklER4PjLqtLEyckmoIlsyZ4vBDeiYwH1s0NnvofSVlwrLblDd1RLEkA 6I2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=BNULt0Gy; 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 j62si22075080qkd.539.2017.08.03.03.15.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 Aug 2017 03:15:21 -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 header.b=BNULt0Gy; 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]:53793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD9y-0007NE-VB for patch@linaro.org; Thu, 03 Aug 2017 06:15:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddD1m-0000OX-P5 for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddD1l-0004IZ-OX for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:50 -0400 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:33516) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddD1l-0004Hh-Hw for grub-devel@gnu.org; Thu, 03 Aug 2017 06:06:49 -0400 Received: by mail-wm0-x22e.google.com with SMTP id k20so3355858wmg.0 for ; Thu, 03 Aug 2017 03:06:49 -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=ckTreSR6iDYDUDIVWewLS0lTVTiop8S3dutqHJfhtCo=; b=BNULt0GymvU3SLL5KqBpkoo1So7edmLU7grvCLaKVswp7UrzJDlj7VdQ5XfzAqx64b ciVdy8J6jjF6ciyt3uwa3xXRe+vwIg2B60QKKONkKctsBrsOE/svnM3bPiUHniQe/aiH YXsRV8wDMHMiHFLEcm5niT0eVvhDbwxdR3AJ8= 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=ckTreSR6iDYDUDIVWewLS0lTVTiop8S3dutqHJfhtCo=; b=LDo/Cbr/Fmckpp2wztDZEffIoogjfF65kNc5+9h2YZg6ll71uIhDfQAJvcdhj+elEm jPw9tn2LtGMMLDmdtr2+Vz41mRU8cH3HR67rWtQqR2T0zT5nv64MPwkkUsrGI/gE35aN 4OCaVy4vn8GaI9SRBeJsVbFFYNHXIVaupI3w7YnDlmUUfgHp0ecQJQtyndDJth+jcn5b k5CB2XDUxufalvxN912fGP0YcLfTJ+T2RiwVAilGlI76nJGv0uRaV2itBp8Q2Lkq54Ed 0SfILLDUKvf0qgqghfnvh66Cs/bK+9ZEvdLxy9Avip853lbzMAuNB8ktC6FEvTxu91Ei WJQw== X-Gm-Message-State: AIVw11029Dey5UOpNqutvmuo5BtbIEniIVwGPr9rE7eDtQ/JM+ADOV8J LqvyiKqLg+eDD8AABxM1cA== X-Received: by 10.28.199.207 with SMTP id x198mr761456wmf.156.1501754808302; Thu, 03 Aug 2017 03:06:48 -0700 (PDT) Received: from vanye.hemma.eciton.net (cpc92316-cmbg19-2-0-cust118.5-4.cable.virginm.net. [82.12.0.119]) by smtp.gmail.com with ESMTPSA id e5sm2274543wre.24.2017.08.03.03.06.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 03:06:46 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v2 13/14] efi: restrict arm/arm64 linux loader initrd placement Date: Thu, 3 Aug 2017 11:04:31 +0100 Message-Id: <20170803100432.29913-14-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170803100432.29913-1-leif.lindholm@linaro.org> References: <20170803100432.29913-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:c09::22e 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: Daniel Kiper 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..a96019a3b 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -194,6 +194,42 @@ 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_ram_base (&max_addr) != GRUB_ERR_NONE) + return NULL; + + /* + * 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 + + 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"));