From patchwork Wed Jun 27 17:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 140372 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1152257ljj; Wed, 27 Jun 2018 10:19:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8fsyrk9c3WDbXQhtE5g9qUzZWuGhpw3bY9QtzhP9n16cmRY2FeGSowULJHK6aMZh5U2nU X-Received: by 2002:aed:2317:: with SMTP id h23-v6mr5712831qtc.85.1530119945667; Wed, 27 Jun 2018 10:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530119945; cv=none; d=google.com; s=arc-20160816; b=PD+SQ9aw2CcKyyYvFQgM3ET8IxDAItnnOLg3JbUmq9HN1oFBr7QuMkwrdFfC4SzoNR rNOVnunZbzpkMoPAzPLV6RaqoU6rodeHlu5hikXa9DZqRnM3Si1CljhkkHZuy5YkcFI/ lA4PajYbnlreuMDT4vK7lTASxP2z6lDTUTCaHTmjnTDCQU2pxifZ7hLeeL8Ag/iSEI0V A/O6LMatMYhrtbrng0fWn8pyJ07OwXWiC55F0h8SvnjQEAHrUDQoK95MwQKNxNoIexTq WAU1ahiZLBv/z2jtV5Dg4Wi0i1wszGbymCJRj/D1V1Gp2+BZNxh39AisUPxG/itADUm9 yqIw== 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=Z4fa3yjbEmziHOCxKTQLig5a7J51yJiPU10ubc/s018=; b=o7xRXazI/WX8yY2nE/KS6/NwenL3m4VulounUvcampjRjNsqUGqH3upTUF9j9Ewfo5 aVXQLcnO1/6b7BOseyvEpxufcKBZQ7tP0BbGDgp7rR27v+CEUIJTQjDjl7SY/HvsLWR5 Rd8kf4LzmqXWZnENufbiYOmSnwD39S8WA5Do96YbrLAjm6ZvAYsSRaniB6z8XRFCdGl8 nzdubK4QHWhwUcItVmIcFdnhEgp/GNjkUbcVFVSPTg2EZzVD20c55lrN4qomtYJPiJdS gwYJy7CdtpTIe1HKyhEuzr9MuDhawaJ9PGDxjKraZSSiZdwv7Bn8pRLC1LmUW6ZHDZ5f TSzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=B9+LE0sX; 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 s8-v6si4560805qvc.77.2018.06.27.10.19.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 27 Jun 2018 10:19:05 -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=B9+LE0sX; 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]:60574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYE5w-0005Xd-So for patch@linaro.org; Wed, 27 Jun 2018 13:19:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYE4b-0004gV-8r for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYE4W-0006Wu-1D for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:40 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:38663) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYE4V-0006Vw-Pa for grub-devel@gnu.org; Wed, 27 Jun 2018 13:17:35 -0400 Received: by mail-wr0-x242.google.com with SMTP id e18-v6so2812593wrs.5 for ; Wed, 27 Jun 2018 10:17:35 -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=Qy4I2sp/I/OB+4EB/ycGuC7SztEI3vJjew2QqPp3/A0=; b=B9+LE0sXIrbCrIh/0kUqE5tcoZebx5PhpVPPQ5PLI/WVbow9rXxTLHfRajWdk7vmrC 3LgLfPK74ldnGV+pg1TJStYVwAA51u4YLuENXwfQ5dyiv8a8UqIasm1GdLluc03T54uQ fUEi8pzl11JjUU/Lr45435piQoGar5A2cGbio= 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=Qy4I2sp/I/OB+4EB/ycGuC7SztEI3vJjew2QqPp3/A0=; b=WjCiN4YACGJbU56HALaRVHmGU+6qMEIVtjvHe6xxXF5dhcmzyH4dlUYp/Ss0F8KzaS keD0xZS76YMcRhi1lSBdjqoGMdZD6w6A2dU6AwK6cboCSt9G8JcYz9xoSZh3gcb4caZr S/CzaVeAJ0A0BvxTI57OHGi8D6wHAXUQNe6TYy+PTitMZO8/lQKUotLroi2YxGsQMEz5 t9ykDwV8mT4WguUKI4TWTumFlnG1OoTTcJromntZYY9mEGj4umpqd+XACA+/x0rZVuP+ tZuiN2A/Xs0Siq+gZ+RPQPGKHos4ukm3l3FTxavDG6MW3sq6CFW3S3ARMO6ZWUk+mv6E utsQ== X-Gm-Message-State: APt69E2RFC7dv+ut6bq0jFq4S/7oE+2g+iuNceqU++J0MBLFmNVe0GpT OITFjuU2i6HCgQjLHVJZuNhogMljZoY= X-Received: by 2002:adf:ec4d:: with SMTP id w13-v6mr5765084wrn.222.1530119854476; Wed, 27 Jun 2018 10:17:34 -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 a2-v6sm3406572wmb.6.2018.06.27.10.17.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 10:17:32 -0700 (PDT) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH v3 6/6] efi: restrict arm/arm64 linux loader initrd placement Date: Wed, 27 Jun 2018 18:17:20 +0100 Message-Id: <20180627171720.27028-7-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180627171720.27028-1-leif.lindholm@linaro.org> References: <20180627171720.27028-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::242 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 577fbda54..0d550182f 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; } +/* + * 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[]) @@ -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"));