From patchwork Tue Oct 24 19:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13435216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 43544C07545 for ; Tue, 24 Oct 2023 19:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=t4E4qxDAd3wFszP4qtetvBtbFg3HJ1/lGDgsA0QpXvE=; b=DqnokQUZXjwmjD cfYxMveJ8K6LBfidaZOTKRwkFsu7dxRmYUpIDtYFYER9rInJcroum/mKRS/V7S5bpA21Ru1rsjRBw KxYvOaCKvoXATv2WIIJz3Wf8BVRV1gSnJ6jBoj4XvySwk8g4kXyjlgmmwmoOqDE1RuCQjHsnvFwZZ dXiqMbnAtjir9tOuwghxPlO5LcX+ld97fLYMonIpiHYZleo89U2TE8UKI5N6e7J+tcreOan9o9yID owQlATcX1IdcELIo1NHS7BPvbf5HccoCHis0Fk9VqmJD1MaaFakuhskUxincDcDWV3Ht9wviF+Umu uDMqQpOnov1yEz2XZPtw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvN3O-00AkSE-09; Tue, 24 Oct 2023 19:27:02 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvN3K-00AkRd-27 for linux-riscv@lists.infradead.org; Tue, 24 Oct 2023 19:27:00 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5EEB161D09; Tue, 24 Oct 2023 19:26:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73354C433C7; Tue, 24 Oct 2023 19:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698175617; bh=+anck+iVi4/9AxBaPBVSONihMc3/xRqjTE3i12vRea4=; h=From:To:Cc:Subject:Date:From; b=pu5np2xifqVw00cZ9Z6nwP8ziNGZoZtGj7PA+aR0d4yzvZy/BMB0PUuBb632APfEa 1ZDWDFJBamzVFMHuii8b0pviocPYN4pumq8L7lE1N3btV7b4N5vQs+v0gZYW7rWUNI 0DNFbZput21S/Ccoh+53Z5hatA9Xp5zw+ORQRPUve9tdxmQXUvycyAkkgGU1IP9QcW 91/e5KgIkF8hDog4o8/Zw/FtyugJzHGQqMFQImtfF8frOLiHo0i3jNUbrfrJaL/DDS UfUtgR1vmE9jypMyNpN77f1zO7GT6nVKK/ziBA+69Lpb/n3kpzlTjJQd3+5wLIa1+A lZgiUIuyaqyQA== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Albert Ou , Anup Patel , Atish Patra , Atish Patra , Palmer Dabbelt , Paul Walmsley Subject: [PATCH] riscv: CONFIG_EFI should not depend on CONFIG_RISCV_ISA_C Date: Tue, 24 Oct 2023 21:26:48 +0200 Message-Id: <20231024192648.25527-1-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231024_122658_781033_FD61042A X-CRM114-Status: GOOD ( 14.22 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Ard Biesheuvel Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Björn Töpel UEFI/PE mandates that the kernel Image starts with "MZ" ASCII (0x5A4D). Convenient enough, "MZ" is a valid compressed RISC-V instruction. This means that a non-UEFI loader can simply jump to "code0" in the Image header [1] and start executing. The Image specification [1] says the following about "code0": | This header is also reused to support EFI stub for RISC-V. EFI | specification needs PE/COFF image header in the beginning of the | kernel image in order to load it as an EFI application. In order | to support EFI stub, code0 is replaced with "MZ" magic string | and res3(at offset 0x3c) points to the rest of the PE/COFF | header. "MZ" is not a valid instruction for implementations without the C extension. A non-UEFI loader, loading a non-C UEFI image have the following options: 1. Trap and emulate "code0" 2. Avoid "code0" if it is "MZ", and have the kernel entry at "code1". Replace the compressed instruction with a hex code variant, that works for CONFIG_RISCV_ISA_C=n builds. Further, this change also make sure that the "code0" instruction is 32b aligned. [1] Documentation/riscv/boot-image-header.rst Signed-off-by: Björn Töpel Signed-off-by: Björn Töpel --- arch/riscv/Kconfig | 1 - arch/riscv/kernel/head.S | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) base-commit: d88520ad73b79e71e3ddf08de335b8520ae41c5c diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index d607ab0f7c6d..9c5bbbc93951 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -799,7 +799,6 @@ config EFI select EFI_RUNTIME_WRAPPERS select EFI_STUB select LIBFDT - select RISCV_ISA_C select UCS2_STRING help This option provides support for runtime services provided diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 3710ea5d160f..33d69b569843 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -27,9 +27,13 @@ ENTRY(_start) */ #ifdef CONFIG_EFI /* - * This instruction decodes to "MZ" ASCII required by UEFI. + * The compressed (C extension) "c.li s4,-13" instruction + * decodes to 0x5a4d/"MZ" (ASCII), which is required by UEFI. + * + * In order to support non-compressed EFI kernels, the + * instruction is written in hex. */ - c.li s4,-13 + .word 0x5a4d5a4d j _start_kernel #else /* jump to start kernel */