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=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 0F287C2D0A3 for ; Wed, 4 Nov 2020 11:31:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 79A392072E for ; Wed, 4 Nov 2020 11:31:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eXpLWem+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79A392072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+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=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0F7oBW+DL8Iz+pidMJUjcSTPBQC8JRVVMao4weoTZwU=; b=eXpLWem+p8FR3dlhpiKU+JtJZ lMgE0Wrcg+q53eMX/IDq2k2oSDTqQhpvClrP1KvsobEfmhHa9poiUC97DQeLap2NiAymXpHIEshh8 rcQIVJV8coNXbK3RWrztfCSSnowsn+gZ+usG24ZTSwiQt9FecL5+8jytbpFPOglHVMlCn9T+LmlpU +Nbu0PZEQG2L0OoX9Ylfb7mm7aFBrH5JqdQEDbMu/kGm9nWol5hkKl9jKB2HJge33C27m9bWr2Ine nKN0XAIYqK9EHCjUAhnVR+yVGKmEBonEtSFG6nBSCnBM+mtbpXCeKauJHkvVhqdSViHIniU4MR9C0 i+ES3po3A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaGzP-00082c-0q; Wed, 04 Nov 2020 11:30:07 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaGzL-00082F-HM for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 11:30:05 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 153D91474; Wed, 4 Nov 2020 03:30:01 -0800 (PST) Received: from [10.57.54.223] (unknown [10.57.54.223]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 10F433F718; Wed, 4 Nov 2020 03:29:59 -0800 (PST) Subject: Re: [PATCH 4/4] arm64: head: tidy up the Image header definition To: Ard Biesheuvel References: <20201027073209.2897-1-ardb@kernel.org> <20201027073209.2897-5-ardb@kernel.org> <20201028141726.GE28554@willie-the-truck> <74f37b57-e5c0-14ac-5b25-125fc5139112@arm.com> From: Robin Murphy Message-ID: Date: Wed, 4 Nov 2020 11:29:59 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_063004_261102_A1C2EFF0 X-CRM114-Status: GOOD ( 28.66 ) 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 , Will Deacon , James Morse , Linux ARM Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2020-11-03 07:13, Ard Biesheuvel wrote: > On Thu, 29 Oct 2020 at 14:07, Robin Murphy wrote: >> >> On 2020-10-29 07:30, Ard Biesheuvel wrote: >>> On Wed, 28 Oct 2020 at 18:56, Robin Murphy wrote: >>>> >>>> On 2020-10-28 14:17, Will Deacon wrote: >>>>> On Tue, Oct 27, 2020 at 08:32:09AM +0100, Ard Biesheuvel wrote: >>>>>> Even though support for EFI boot remains entirely optional for arm64, >>>>>> it is unlikely that we will ever be able to repurpose the image header >>>>>> fields that the EFI loader relies on, i.e., the magic NOP at offset >>>>>> 0x0 and the PE header address at offset 0x3c. >>>>>> >>>>>> So let's factor out the differences into a 'magic_nop' macro and a local >>>>>> symbol representing the PE header address, and move the conditional >>>>>> definitions into efi-header.S, taking into account whether CONFIG_EFI is >>>>>> enabled or not. >>>>> >>>>> How many architectures can claim to have both a "magic nop" and a >>>>> "mysterious nop", hey? >>>> >>>> It's fun 'n'all, but putting my serious hat on for a moment, if the name >>>> still requires a comment to explain it at point of use, it's not a very >>>> good name :( >>>> >>>> At worst magic_nop is even potentially misleading, since it's not >>>> necessarily a nop; there's no mention of the implicit dependency on a >>>> context where the side-effect of executing it wouldn't affect anything >>>> important. >>>> >>>> Could we call the macro itself something clear and self-explanatory like >>>> efi_signature_insn please? I'm happy for it to be *commented* as "Magic >>>> NOP" if you want parity with the VDSO :D >>>> >>> >>> Will efi_pseudo_nop do? >> >> Again, what's the defining significance of the instruction that this >> macro stands for - that it does nothing; that it does pseudo-nothing; or >> that it has a specific signature encoding? I know this probably sounds >> like bikeshedding to most, but I firmly believe that good, accurate >> names really do matter :) >> > > Fair enough. But by that reasoning, putting NOP in the name is > important, given that efi_signature_insn does not explain what the > instruction does. > > So, efi_signature_nop then? Sure; I think arguing semantics beyond that point *would* be bikeshedding :) >>> Also, do you think it would be better to use an opcode here that has >>> no architectural side effects, such as a PRFM (literal) instruction? >>> It is obviously not going to make a difference in practice, but it >>> always annoyed me that the pseudo NOP is not a NOP. >> >> Yeah, it's a shame there's no way to get a guaranteed non-taken >> conditional branch in A64, and nearly every good candidate for a >> non-destructive operation with an arbitrary immediate seems to rely on >> an rt=31 encoding... 'prfm PLIL3STRM, . + 2888' is utterly impenetrable, >> but should indeed work; 'ccmp x18, #0, #0xd, pl' is probably the least >> destructive ALU option (only a chance of changing the flags). >> > > I think ccmp is probably a better choice, given that PRFM PLI > instructions issued with the MMU off are more likely to trigger > something unexpected. At least it happened to be PLI rather than PLD - the latter I'd definitely be scared of... Robin. >>>>>> Signed-off-by: Ard Biesheuvel >>>>>> --- >>>>>> arch/arm64/kernel/efi-header.S | 43 +++++++++++++++----- >>>>>> arch/arm64/kernel/head.S | 19 +-------- >>>>>> 2 files changed, 35 insertions(+), 27 deletions(-) >>>>>> >>>>>> diff --git a/arch/arm64/kernel/efi-header.S b/arch/arm64/kernel/efi-header.S >>>>>> index ddaf57d825b5..7b7ac4316d95 100644 >>>>>> --- a/arch/arm64/kernel/efi-header.S >>>>>> +++ b/arch/arm64/kernel/efi-header.S >>>>>> @@ -7,7 +7,27 @@ >>>>>> #include >>>>>> #include >>>>>> >>>>>> + .macro magic_nop >>>>>> +#ifdef CONFIG_EFI >>>>>> +.L_head: >>>>>> + /* >>>>>> + * This add instruction has no meaningful effect except that >>>>>> + * its opcode forms the magic "MZ" signature required by UEFI. >>>>>> + */ >>>>>> + add x13, x18, #0x16 >>>>> >>>>> It's probably faster too ;) >>>>> >>>>>> +#else >>>>>> + /* >>>>>> + * Bootloaders may inspect the opcode at the start of the kernel >>>>>> + * image to decide if the kernel is capable of booting via UEFI. >>>>>> + * So put an ordinary NOP here, not the "MZ.." pseudo-nop above. >>>>>> + */ >>>>>> + nop >>>>> >>>>> Let's just hope nobody was decoding the branch instruction... >>>>> >>>>> Acked-by: Will Deacon >will@kernel.org> >>>>> >>>>> Will >>>>> >>>>> _______________________________________________ >>>>> linux-arm-kernel mailing list >>>>> linux-arm-kernel@lists.infradead.org >>>>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel >>>>> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel