From patchwork Mon Jul 9 17:33:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 141480 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2924863ljj; Mon, 9 Jul 2018 10:35:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdTzLBVNlxA+Gj0mjDqMRJAGb2xvc3crdnKIx/LvZPuraaU0tWNkbLMsc4Pzx0vrETAXGtK X-Received: by 2002:ac8:3094:: with SMTP id v20-v6mr8753682qta.313.1531157742942; Mon, 09 Jul 2018 10:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531157742; cv=none; d=google.com; s=arc-20160816; b=JfczcxBkv1Wi6lNzO2jPHRSSpGDQ68BP3ESp16lgNz7LpP/RbvLNr6ntO6suaBk/O+ 4TRScydRdeQKXFLn1L8E1sbE0O/YMN+6L9UABG9eQp1Gne6olVJTdJCQrzUrPIl+/rS6 qlbZBWbSgb3xeor1sAr/xGleloW14J4/0dRq54/dJQGywDsT0b5wwZ1RigfkogFE+Xw9 f+EzcRACCkG0IAdkVljKz03UG/vAJoKOR+Lqwos/72xt1cLCM1cBpkdrYo8ssT/iKEmu 8qyS18xz0A17u/J1ZH23bUxzuCSw66a64z+fMXQny5vJANDgouNSNBphY8BwCtNWi3lY hmNw== 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=6st4UNQ0DaiCPD06wGOo+dUyb26eTvpMce+A/9AUopw=; b=jmtZJRUQdH5RMwhHfV4FNiFRAl2OWj2bTb9cBeQiuFZ1Z8rtDQosbQBcznxYu1GSeZ /1icf2ZmeC2llIF3T9KAfB7XJMhGrHTcGaDGqMXavpziGo0TMrZ2QGzZrDoRHf0t2lhV AxiXTT4AjmvJqPfovhc7WM7WqQTX0rO8Av0fd5dptX4EMJvn3saghaRpIA4cffSrbO20 l75HrcHsA54HWUq3DFXrICGADtGZevuosj/xQXa5vp7j1YG0RHgddCe6CFl9X9Dvipi0 XruGRZJl0oV39WHCoyf0fbb1qWUYz9tKIZYZ9dswrga2dNvdzIspZWUnKqKUHd0+cTDY wVeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fw49ikRh; 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 y39-v6si8467417qtc.351.2018.07.09.10.35.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 09 Jul 2018 10:35:42 -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.s=google header.b=fw49ikRh; 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]:43614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fca4c-0001N3-9p for patch@linaro.org; Mon, 09 Jul 2018 13:35:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fca2I-0000NF-MB for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fca2H-0002iP-Ta for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:18 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:39534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fca2H-0002i9-Nq for grub-devel@gnu.org; Mon, 09 Jul 2018 13:33:17 -0400 Received: by mail-wm0-x241.google.com with SMTP id h20-v6so5691515wmb.4 for ; Mon, 09 Jul 2018 10:33:17 -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=s1mAK/H4O2CP9yZ1VWcq1G/Unhl4fp5+B1fp0SeCbN8=; b=fw49ikRhRkvhebudL7fU65N+f1AOqpjj0ctzUc1gb5MWO3dhV1GhYdqeSUNC8NYpSM xDGyGcBLu+MdhAMnKdJD2rYqhChETFXe2wWfMohUuA1QCCxboHPQZp2m7DzNRO/4Boar 5Zi+Td6wWCLHtAcvxyT5z4/4etexQmkF5zbDk= 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=s1mAK/H4O2CP9yZ1VWcq1G/Unhl4fp5+B1fp0SeCbN8=; b=WcsQ9LJU3EIMb3paKu8gJtFlrHFl7UlEnQkzfdboSHJXLCr6WQOJYf19x+couyrGhx gek4inRBfC84nbUrJK2DoucpD4O5/1AwMFc+5tRPB4SqaORdSpxzLHCgshKFrScFNAUT 5PRK1Dxap2WPUQXEryyUNouUp6uKvKcCsQnf2wYgEEgjGQ6zP+xGtU5hpkroQ/gGAnN6 vu185R8/0USrXDY0vZoxEvrsnpSjZUTPKOuEfUu8AbLaNXKpamFHZIKZOBt6J7spR7DN 8OsPLMpuh1QWQl4gmyO0mjgvcCTtmvwDshekRQtkRWexkjntpO0wSuNsg97Yn0TtEfj1 q1iA== X-Gm-Message-State: APt69E2oLEDKBOJTDS0eCemu+0Ejrv0iWim+HdiaZRZxydK9eri0VM1/ s/F4+4UUKOxAnZOiAFqN+lZ8sYpFiJo= X-Received: by 2002:a1c:ce0c:: with SMTP id e12-v6mr11906250wmg.86.1531157596471; Mon, 09 Jul 2018 10:33:16 -0700 (PDT) Received: from vanye.hemma.eciton.net (cpc92302-cmbg19-2-0-cust304.5-4.cable.virginm.net. [82.1.209.49]) by smtp.gmail.com with ESMTPSA id p3-v6sm27742988wrg.47.2018.07.09.10.33.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 10:33:15 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v4 6/6] efi: restrict arm/arm64 linux loader initrd placement Date: Mon, 9 Jul 2018 18:33:05 +0100 Message-Id: <20180709173305.17588-7-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180709173305.17588-1-leif.lindholm@linaro.org> References: <20180709173305.17588-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::241 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 f90c5f926..1f86229f8 100644 --- a/grub-core/loader/arm64/linux.c +++ b/grub-core/loader/arm64/linux.c @@ -193,6 +193,42 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } +/* + * 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 + +/* + * 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; + + 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[]) @@ -221,7 +257,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_any_pages (initrd_pages); + initrd_mem = allocate_initrd_mem (initrd_pages); + if (!initrd_mem) { grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));