From patchwork Wed Mar 30 13:18:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 64701 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2593180lbc; Wed, 30 Mar 2016 06:20:37 -0700 (PDT) X-Received: by 10.98.19.2 with SMTP id b2mr13103247pfj.93.1459344037150; Wed, 30 Mar 2016 06:20:37 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id j3si6529016pap.58.2016.03.30.06.20.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Mar 2016 06:20:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1alG20-0006dB-He; Wed, 30 Mar 2016 13:19:32 +0000 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1alG1j-0006Vq-0S for linux-arm-kernel@lists.infradead.org; Wed, 30 Mar 2016 13:19:15 +0000 Received: by mail-wm0-x230.google.com with SMTP id p65so182983095wmp.1 for ; Wed, 30 Mar 2016 06:18: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=0yIww9z/NtMwwftRWyowm8xoE9/ZfmgVv2n2BtwE8CY=; b=eyvGu9ICbUNy3YPn8U/2tRovU1R3lWitrTZ0W5PAMSuMPK8BaSSvlIOOc2cZENjecW XSbqjw08l1YBHRh0ZlqzK8Nv1b454ZEHg4AkfMxxBzts2wfDNB8aGZjYtHWM7os5zIBM I5INQMian7oA3f8245Wq5brzUpPIF7KHL+dfs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0yIww9z/NtMwwftRWyowm8xoE9/ZfmgVv2n2BtwE8CY=; b=bWT/yXQCoDkw+EqKybGfjOHTS6H/yk+mmgEsZXL3fQ4lhwqgp6AV5xDWOKFI58tV/T N+mwJRW7ml6U7H1mhDZVX1yKcGpSlvlW/GYCIwDubOf1ZyZiD/54CoU/3jDF5eAFK+YT 9V+MZZ6UQLu2Q4ymZ3n4ZGpE0WstsFKzMWi6cRE6+0GUQXmhqI8caRhn0x8+Cc7hb3Bx Rj5HFQPDayIRu9ygac79wVwuA2apUKYwwoDuWUQgQZAhz3k6bi7cBTatauxxAIlW4yWI Z5ROHrnRP7HqnESzN0SkNwj8DLep/+bOk7AWX0Qo3MwUjpG9YiyXGLQcSNBMPamifvf8 KsWA== X-Gm-Message-State: AD7BkJLajZJpZpuH++RUhA8fTiQMRXo40wvD371CrOZ23UChG1VpTOAMOsbxno3i0L6tMSPL X-Received: by 10.28.48.147 with SMTP id w141mr7219913wmw.85.1459343933299; Wed, 30 Mar 2016 06:18:53 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id js8sm3913786wjc.37.2016.03.30.06.18.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Mar 2016 06:18:52 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com Subject: [PATCH 1/2] arm64: add the initrd region to the linear mapping explicitly Date: Wed, 30 Mar 2016 15:18:42 +0200 Message-Id: <1459343923-16283-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459343923-16283-1-git-send-email-ard.biesheuvel@linaro.org> References: <1459343923-16283-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160330_061915_218587_CCFE2540 X-CRM114-Status: GOOD ( 21.28 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:230 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , mlangsdo@redhat.com, jeremy.linton@arm.com, msalter@redhat.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Instead of going out of our way to relocate the initrd if it turns out to occupy memory that is not covered by the linear mapping, just add the initrd to the linear mapping. This puts the burden on the bootloader to pass initrd= and mem= options that are mutually consistent. Note that, since the placement of the linear region in the PA space is also dependent on the placement of the kernel Image, which may reside anywhere in memory, we may still end up with a situation where the initrd and the kernel Image are simply too far apart to be covered by the linear region. Since we now leave it up to the bootloader to pass the initrd in memory that is guaranteed to be accessible by the kernel, add a mention of this to the arm64 boot protocol specification as well. Signed-off-by: Ard Biesheuvel --- Documentation/arm64/booting.txt | 4 +++ arch/arm64/mm/init.c | 29 ++++++++++++++++++++ 2 files changed, 33 insertions(+) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/Documentation/arm64/booting.txt b/Documentation/arm64/booting.txt index 56d6d8b796db..8d0df62c3fe0 100644 --- a/Documentation/arm64/booting.txt +++ b/Documentation/arm64/booting.txt @@ -132,6 +132,10 @@ NOTE: versions prior to v4.6 cannot make use of memory below the physical offset of the Image so it is recommended that the Image be placed as close as possible to the start of system RAM. +If an initrd/initramfs is passed to the kernel at boot, it must reside +entirely within a 1 GB aligned physical memory window of up to 32 GB in +size that fully covers the kernel Image as well. + Any memory described to the kernel (even that below the start of the image) which is not marked as reserved from the kernel (e.g., with a memreserve region in the device tree) will be considered as available to diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 83ae8b5e5666..82ced5fa1e66 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -207,6 +207,35 @@ void __init arm64_memblock_init(void) memblock_add(__pa(_text), (u64)(_end - _text)); } + if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) && initrd_start) { + /* + * Add back the memory we just removed if it results in the + * initrd to become inaccessible via the linear mapping. + * Otherwise, this is a no-op + */ + u64 base = initrd_start & PAGE_MASK; + u64 size = PAGE_ALIGN(initrd_end) - base; + + /* + * We can only add back the initrd memory if we don't end up + * with more memory than we can address via the linear mapping. + * It is up to the bootloader to position the kernel and the + * initrd reasonably close to each other (i.e., within 32 GB of + * each other) so that all granule/#levels combinations can + * always access both. + */ + if (WARN(base < memblock_start_of_DRAM() || + base + size > memblock_start_of_DRAM() + + linear_region_size, + "initrd not fully accessible via the linear mapping -- please check your bootloader ...\n")) { + initrd_start = 0; + } else { + memblock_remove(base, size); /* clear MEMBLOCK_ flags */ + memblock_add(base, size); + memblock_reserve(base, size); + } + } + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { extern u16 memstart_offset_seed; u64 range = linear_region_size -