From patchwork Mon Aug 7 18:35:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 109588 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1952753qge; Mon, 7 Aug 2017 11:38:34 -0700 (PDT) X-Received: by 10.84.195.131 with SMTP id j3mr1584805pld.147.1502131114656; Mon, 07 Aug 2017 11:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502131114; cv=none; d=google.com; s=arc-20160816; b=l2vSKiyugb78jVNrLTghWcjj35MaodQSNBteJRzIOQfqf7VS4pyst3gc0YJnq9nje8 VeCouFibFTS5bhn3vFYFHj8UlareNeGHIfFED2Cc0xAq1yUrB+YKzLyrRmM3tzYXhiZs YQa12OfPJom5aYGnjgUEpUpbhQJSssPQXkTLx4F119ROaG9M63ZP2lgoiE2g3Dc5xNss t0mu93mZTc9HD7iMLRhh0gVvJxo8b4mcsgdu8ML2+0iOEzillseRCRV2JEt7UjHTFMwc pWXiSWL1T3oXcypi4PVRNL4edzHmQ4V41zqNhApWeQutYWVfIxtKg/9NrCjafmnznQBz X8Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=f4W+MVt+MWmgN7H5Ph3KbbnDHwzDRKdW0Fw6JePBmSc=; b=GIL/+sWRQYir3J76bzj5l4ww2OGeovKBG7Zrj5a5HhLE/vYdXc8IVnQDPgPmklb3b3 fn0jAy1+xBUJIw7QYaKQWDea6gzQ3bC/j5JmQF3Ii15aVoX7wlix5goHJ6sDXCPwwxJa Wo9Iq7ms1LZ9IWrDSBrv8pHQvC8ZIalIMBOL+1Fl+f2/717OndoCBanKzuklaEsiRJn6 2XuzL7q9tTKYMnRDtrXIVY2luD04gFGXvtSYg+aglf9494QB1QsT6VbVrLn2PZoE6OWG EggvWKJkOIWOSNRTuqZC7b6tYDPk/eE8mmo43gMp7wyaBt4vuGT+bIRokp5iAueEn2/O kBiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si5029386pfi.554.2017.08.07.11.38.34; Mon, 07 Aug 2017 11:38:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752150AbdHGSib (ORCPT + 25 others); Mon, 7 Aug 2017 14:38:31 -0400 Received: from foss.arm.com ([217.140.101.70]:52642 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752069AbdHGSi3 (ORCPT ); Mon, 7 Aug 2017 14:38:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0CD651715; Mon, 7 Aug 2017 11:38:29 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E4F3B3F577; Mon, 7 Aug 2017 11:38:26 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: ard.biesheuvel@linaro.org, catalin.marinas@arm.com, james.morse@arm.com, labbott@redhat.com, linux-kernel@vger.kernel.org, luto@amacapital.net, mark.rutland@arm.com, matt@codeblueprint.co.uk, will.deacon@arm.com, kernel-hardening@lists.openwall.com, keescook@chromium.org Subject: [PATCH 08/14] efi/arm64: add EFI_KIMG_ALIGN Date: Mon, 7 Aug 2017 19:35:59 +0100 Message-Id: <1502130965-18710-9-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502130965-18710-1-git-send-email-mark.rutland@arm.com> References: <1502130965-18710-1-git-send-email-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The EFI stub is intimately coupled with the kernel, and takes advantage of this by relocating the kernel at a weaker alignment than the documented boot protocol mandates. However, it does so by assuming it can align the kernel to the segment alignment, and assumes that this is 64K. In subsequent patches, we'll have to consider other details to determine this de-facto alignment constraint. This patch adds a new EFI_KIMG_ALIGN definition that will track the kernel's de-facto alignment requirements. Subsequent patches will modify this as required. Signed-off-by: Mark Rutland Cc: Ard Biesheuvel Cc: Catalin Marinas Cc: James Morse Cc: Laura Abbott Cc: Matt Fleming Cc: Will Deacon --- arch/arm64/include/asm/efi.h | 3 +++ drivers/firmware/efi/libstub/arm64-stub.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index 8f3043a..0e8cc3b 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,8 @@ */ #define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ +#define EFI_KIMG_ALIGN SEGMENT_ALIGN + /* on arm64, the FDT may be located anywhere in system RAM */ static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base) { diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c index b4c2589..af6ae95 100644 --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -11,6 +11,7 @@ */ #include #include +#include #include #include @@ -81,9 +82,10 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg, /* * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a * displacement in the interval [0, MIN_KIMG_ALIGN) that - * is a multiple of the minimal segment alignment (SZ_64K) + * doesn't violate this kernel's de-facto alignment + * constraints. */ - u32 mask = (MIN_KIMG_ALIGN - 1) & ~(SZ_64K - 1); + u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1); u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ? (phys_seed >> 32) & mask : TEXT_OFFSET;