From patchwork Thu Oct 29 14:07:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 55776 Delivered-To: patch@linaro.org Received: by 10.202.175.130 with SMTP id y124csp443835oie; Thu, 29 Oct 2015 07:09:35 -0700 (PDT) X-Received: by 10.107.131.147 with SMTP id n19mr3672696ioi.192.1446127775199; Thu, 29 Oct 2015 07:09:35 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id y28si3259332ioi.124.2015.10.29.07.09.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Oct 2015 07:09:35 -0700 (PDT) Received-SPF: pass (google.com: 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; spf=pass (google.com: 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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com 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 1Zrns5-0006fX-Td; Thu, 29 Oct 2015 14:08:05 +0000 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zrns1-0006aw-KM for linux-arm-kernel@lists.infradead.org; Thu, 29 Oct 2015 14:08:02 +0000 Received: by wicll6 with SMTP id ll6so43580487wic.1 for ; Thu, 29 Oct 2015 07:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=b+yKu7hAknaplCwKZVi+/4RNKy6sXE6Ixqc4jFGaw8k=; b=YJ6X1+7+GPwEJya0YhGXF7QZxjB5wd1tAs0nx0/zxHEi3Ns161dhZslaq+UkPbKSBj i/E3Mi2MwRvRpkyfFq86JaueZ5boAofIffV8rJyGE9efKgCoKRwq47YFDoqhwOLvYRyQ 5DJOYyIs5HOIFa2bDWA3IXOOm84kUAWKF/ti7gq7ekznjG9MDrodsDyQVvrkVq3lg30s MPB5D4a7kRk8V6WgUjCFXpoWxwE3qyrkN8nkcAX4sOYcyfVtslPtk/mq/qcq5do6UIQr wk8akGuV7FwzXn/GN8B2jMfptKoECheHDsKXgSLhFnKn6V+0lbIa5/3XWVj2c9GhI8uW +vnQ== 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; bh=b+yKu7hAknaplCwKZVi+/4RNKy6sXE6Ixqc4jFGaw8k=; b=PaRQvu8NI/2kPLb2kKzk+wvtqFVUTnA40To35ip17ZtD9jzZ3HfJu9kecTmUdIq1WS wmV9HOQqxvZe/9aPJf5XWNgy/0sh+Kt9eIpsJr+mfsfov+KOtbgxz1fzeshK+RYmcnbp 3kLAQcj4JmLKzzDVR9/z92ttiDzEl+GsCoSWFk6FUuchYJ+I/oDvif/6v4T1kgO+Eyq4 7yLrmGsveTvPWGjCdazg2eRE46zv9xJyvoHk1GFKxczOpp6XWyRh3TCTB0LmLzT9c94X EjY+BOXKWsD3RAGvgZLtaAUeJimdBYp42iDxnKzjeBcduw8JMRet4oASyamSyt59SP2d 2a1g== X-Gm-Message-State: ALoCoQnLv3uyijYhxUvD9I3UeOfMhQ9u6MqZGhzP9awSJhxLpOw6Wm/MiU1tNR5VNQYCGngP0TfY X-Received: by 10.194.192.6 with SMTP id hc6mr2416008wjc.33.1446127659338; Thu, 29 Oct 2015 07:07:39 -0700 (PDT) Received: from jessie.localdomain ([85.119.43.29]) by smtp.gmail.com with ESMTPSA id p2sm1994753wjb.21.2015.10.29.07.07.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Oct 2015 07:07:38 -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] arm64/efi: do not assume DRAM base is aligned to 2 MB Date: Thu, 29 Oct 2015 15:07:25 +0100 Message-Id: <1446127645-4115-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151029_070801_943459_82D02CC4 X-CRM114-Status: GOOD ( 17.50 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c05:0:0:0:236 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 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: timur@codeaurora.org, Ard Biesheuvel , leif.lindholm@linaro.org, msalter@redhat.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org The current arm64 Image relocation code in the UEFI stub assumes that the dram_base argument it receives is always a multiple of 2 MB. In reality, it is simply the lowest start address of all RAM entries in the UEFI memory map, which means it could be any multiple of 4 KB. Since the arm64 kernel Image needs to reside TEXT_OFFSET bytes beyond a 2 MB aligned base, or it will fail to boot, make sure we round dram_base to 2 MB before using it to calculate the relocation address. Reported-by: Timur Tabi Acked-by: Mark Rutland Signed-off-by: Ard Biesheuvel --- If deemed acceptable, could we either get this into v4.3 or tag it for stable (v4.3 only) please? arch/arm64/kernel/efi-stub.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) -- 2.1.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index 816120ece6bc..78dfbd34b6bf 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -25,10 +25,20 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg, unsigned long kernel_size, kernel_memsize = 0; unsigned long nr_pages; void *old_image_addr = (void *)*image_addr; + unsigned long preferred_offset; + + /* + * The preferred offset of the kernel Image is TEXT_OFFSET bytes beyond + * a 2 MB aligned base, which itself may be lower than dram_base, as + * long as the resulting offset equals or exceeds it. + */ + preferred_offset = round_down(dram_base, SZ_2M) + TEXT_OFFSET; + if (preferred_offset < dram_base) + preferred_offset += SZ_2M; /* Relocate the image, if required. */ kernel_size = _edata - _text; - if (*image_addr != (dram_base + TEXT_OFFSET)) { + if (*image_addr != preferred_offset) { kernel_memsize = kernel_size + (_end - _edata); /* @@ -42,7 +52,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg, * Mustang), we can still place the kernel at the address * 'dram_base + TEXT_OFFSET'. */ - *image_addr = *reserve_addr = dram_base + TEXT_OFFSET; + *image_addr = *reserve_addr = preferred_offset; nr_pages = round_up(kernel_memsize, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; status = efi_call_early(allocate_pages, EFI_ALLOCATE_ADDRESS,