From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C938C2D0E5 for ; Sat, 28 Mar 2020 14:10:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CE781206E6 for ; Sat, 28 Mar 2020 14:10:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UDkoep+F"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="zMEHFmCc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE781206E6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2ANTS+HgIE6cRgxT0PkLkRJJCouSGAHQLZRJaJ1fv5Q=; b=UDkoep+FVIXul5 4SuYHomr00153jOoE+IHQgSr1hokx3AR0Q+0EQOeMSYrA54Uf1scYT2+4wCUvI78c3U3mM7GucNsw Gxx5nrN8+zEgrtf1PBKn+VWhU0F03Ceq5JaM2ueO0XEOKKEM08aBtaw/XWEXOOfc1mCKYgnVXd4fC A3GWkQQI5DSrRhD9qGWaIjDHpjhC+YjgNQjY+3G2nRTY4yjp8FBEFVWZjkTatlB78msvlS9PTbqxh D+4v46Lhe3TtJ+Y0KzS+KtHQu8vyd8Pya68GWjHRituXqb9yHp36at6smcZfP07CtZCRbbxSOlgzs 4Av3GixuRixLr//THykw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jICAa-0004Zv-0G; Sat, 28 Mar 2020 14:10:40 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jICAX-0004Zc-M4 for linux-arm-kernel@lists.infradead.org; Sat, 28 Mar 2020 14:10:39 +0000 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6D66207FF for ; Sat, 28 Mar 2020 14:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585404636; bh=VZQs1gVf2IDvqb7BYuqbkw5L8XebB0Z1pH9jbPoh7V4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=zMEHFmCcv4skXGyPp3q9oQCV5QtzPbbi4zxNJSe0qmF811PIiKr1y8OPdo96GdWZR qWQE+FJbwr5/LV5rTVaHRyVcrJf+bANb+qNZHqwjsz7gMh6l22xSsM6RSYYICAGyZL LfMdjuQIFIdC2XVfLKoSNWC3RrwVLwQnZiR503Zc= Received: by mail-il1-f179.google.com with SMTP id 7so11493715ill.2 for ; Sat, 28 Mar 2020 07:10:36 -0700 (PDT) X-Gm-Message-State: ANhLgQ3wUNIijyClBH9OvEUQ91RzJC2OO4p9oftVs8DcqLrKTvlRN2Z2 LkXOX+4bzLb1GNIx0eBJ7QrcnSQRNy9jsT+HhDk= X-Google-Smtp-Source: ADFU+vtUUV8KCdGbs2VMIFXaD36NbeZJ9wf0loihOXgvnZLn5Z+77lVV0SV0f1j/SLKGcgPBnbxm2yHStIABPZ4Qtfg= X-Received: by 2002:a92:dcd1:: with SMTP id b17mr3891182ilr.80.1585404636052; Sat, 28 Mar 2020 07:10:36 -0700 (PDT) MIME-Version: 1.0 References: <20200326165905.2240-1-ardb@kernel.org> <20200326165905.2240-3-ardb@kernel.org> <20200328140648.GA234129@rani.riverdale.lan> In-Reply-To: <20200328140648.GA234129@rani.riverdale.lan> From: Ard Biesheuvel Date: Sat, 28 Mar 2020 15:10:25 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] efi/arm64: increase the PE/COFF alignment so the kernel can run in place To: Arvind Sankar X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200328_071037_763458_2FBAFEA8 X-CRM114-Status: GOOD ( 18.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Catalin Marinas , linux-efi , Will Deacon , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Arvind, Thanks for taking a look. On Sat, 28 Mar 2020 at 15:06, Arvind Sankar wrote: > > On Thu, Mar 26, 2020 at 05:59:05PM +0100, Ard Biesheuvel wrote: > > Update the PE/COFF metadata so that the UEFI image loader will load the > > kernel image at an offset that allows it to execute in place. > > > > Signed-off-by: Ard Biesheuvel > > --- > > arch/arm64/kernel/efi-header.S | 2 +- > > arch/arm64/kernel/image-vars.h | 7 +++++++ > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kernel/efi-header.S b/arch/arm64/kernel/efi-header.S > > index 914999ccaf8a..f9ee1c2a5fd6 100644 > > --- a/arch/arm64/kernel/efi-header.S > > +++ b/arch/arm64/kernel/efi-header.S > > @@ -32,7 +32,7 @@ optional_header: > > > > extra_header_fields: > > .quad 0 // ImageBase > > - .long SZ_4K // SectionAlignment > > + .long PECOFF_SECTION_ALIGNMENT // SectionAlignment > > .long PECOFF_FILE_ALIGNMENT // FileAlignment > > .short 0 // MajorOperatingSystemVersion > > .short 0 // MinorOperatingSystemVersion > > diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h > > index be0a63ffed23..7a7fa3ba7b2f 100644 > > --- a/arch/arm64/kernel/image-vars.h > > +++ b/arch/arm64/kernel/image-vars.h > > @@ -15,6 +15,13 @@ > > __efistub_kernel_size = _edata - _text; > > __efistub_primary_entry_offset = primary_entry - _text; > > > > +#ifndef CONFIG_RELOCATABLE > > +PECOFF_SECTION_ALIGNMENT = SZ_4K; > > +#elif THREAD_ALIGN > SEGMENT_ALIGN > > +PECOFF_SECTION_ALIGNMENT = THREAD_ALIGN; > > +#else > > +PECOFF_SECTION_ALIGNMENT = SEGMENT_ALIGN; > > +#endif > > > > /* > > * The EFI stub has its own symbol namespace prefixed by __efistub_, to > > -- > > 2.17.1 > > > > The section virtual addresses and (possibly) size of image need to be > updated to be a multiple of PECOFF_SECTION_ALIGNMENT, no? Indeed. I spotted that after sending this patch - both _end and _initdata_begin need to be aligned to this value. I also noticed that it is unclear whether values over 64 KB are permitted: the PE/COFF spec mentions that 64 KB is the max for FileAlignment, and that SectionAlignment should be larger or equal to that. So I think it would be better to set this value to 64 KB unconditionally, and round up the sections to 64 KB. This means 64k pagesize kernels with vmap'ed stack have a 50% chance of ending up at an offset that requires moving the image, but this is still an improvement over doing it all the time. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel