Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3442535rwb; Mon, 5 Sep 2022 11:44:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR6XdZOrMtIgI8NUBp5dr9+JU/1k2TD1Di/gPeo4zQogZJvqcGmvzCOtRUoI9HDqHiZcyDJc X-Received: by 2002:a17:902:9341:b0:172:775e:9573 with SMTP id g1-20020a170902934100b00172775e9573mr51246964plp.128.1662403451615; Mon, 05 Sep 2022 11:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662403451; cv=none; d=google.com; s=arc-20160816; b=sxJYw1IVBpuLH26U5+pU9jqlefx7GF9LsYlCD9q586I+Opj+tVvnltCENYWXEYX8vp 3IduNcLzjF5uqq+XrfR+cSBTWlZ9YeF3Qxi56/PLlJTFbCNg28+lssccGvLqTbRnXQTd g2gs3y3kSFVSQFROn+qNJhp1VK9MviNO2zqn75k3apYQMQAGuj+MKzlAWBZcMTa2Pcz1 8YYRazZW+5H/8FBqGEyEQhUREJnku7WlYjTcU0LZ8+2y4ziGgNvwQdMXcRKER8rkadxJ LxJj7bxxC5+/ucecY7AIFAIdCAeruwlPPxxRWl4KIAQbbDwZn62athhaXqZzLncKqdN3 m0bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=sYYY2D4/n8sAjjgITrWOq5NXj9vlaLQm3DEdhATeAf4=; b=A+CQyLpzFWJppoGRLsf/mf5n94tKBRDXnkqSo0KcUsBj5BTN6XMLkIvZbF3tg4yBB3 HS8HmDPZemKWBHONPgiC4mNUk/gn1jQ/eED0S8OQ8Acet+hYgKGs/0riYusTV1F6KmNJ uNE64U5cR8HfuJN/cPZCeZkfxV5lFAWhxa4gOhgmQnCPjiIWm0tntNTXz4JATsnLdfRF 5jsgT4P8diXITyYKTOu3W425L7/jv+95SWZf7NZQKcJFHyRtwHnEk05CoLVcYnOqWHJm cekqRtheFfekksnTxMWUwgt33xgULimSb2DZZGlKKx/ZMHLgWxc8JTGFvzH2s3LNFF8S nSDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=puIOOBlN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k15-20020aa7820f000000b00535e3dc1519si10266695pfi.64.2022.09.05.11.43.59; Mon, 05 Sep 2022 11:44:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=puIOOBlN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232095AbiIESID (ORCPT + 99 others); Mon, 5 Sep 2022 14:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231162AbiIESH7 (ORCPT ); Mon, 5 Sep 2022 14:07:59 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5705061717; Mon, 5 Sep 2022 11:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1662401271; bh=5+fBIDj/plLFKdhPodt2PuIY5OBgWlvoqpWtbGLNoXM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=puIOOBlNKkdEH2NfqMZ6Dv+IlrIPGhmqaDgp7h/qM2meKfWQ7SIwqeYUkn6dYgczL Q/Iv3vTQglESUW6b+rP5yhnh5leHyveimiFrvxIFlRbpSEDFd6iih6c11OjY3WYVu3 iILqoc9d48XIgD/SbgOagG4+sAU36CsE9BVH2uJ8= Received: from [192.168.9.172] (unknown [101.88.26.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id C40CA6006F; Tue, 6 Sep 2022 02:07:50 +0800 (CST) Message-ID: <3591e532-a6ed-01f1-88fc-77b8637abced@xen0n.name> Date: Tue, 6 Sep 2022 02:07:49 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Thunderbird/106.0a1 Subject: Re: [PATCH V3] LoongArch: Add efistub booting support To: Ard Biesheuvel , Huacai Chen Cc: Xi Ruoyao , Huacai Chen , Arnd Bergmann , loongarch@lists.linux.dev, linux-arch , Xuefeng Li , Guo Ren , Jiaxun Yang , linux-efi , LKML References: <20220819102037.2697798-1-chenhuacai@loongson.cn> <9b6f0aeaebbd36882b5b40d655f9ccd20c7be496.camel@xry111.site> Content-Language: en-US From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/5/22 15:28, Ard Biesheuvel wrote: > [snip] >>>>>> And I have some other questions about kexec: kexec should jump to the >>>>>> elf entry or the pe entry? I think is the elf entry, because if we >>>>>> jump to the pe entry, then SVAM will be executed twice (but it should >>>>>> be executed only once). However, how can we jump to the elf entry if >>>>>> we use zboot? Maybe it is kexec-tool's responsibility to decompress >>>>>> the zboot kernel image? >>>>>> >>>>> Yes, very good point. Kexec kernels cannot boot via the EFI entry >>>>> point, as the boot services will already be shutdown. So the kexec >>>>> kernel needs to boot via the same entrypoint in the core kernel that >>>>> the EFI stub calls when it hands over. >>>>> >>>>> For the EFI zboot image in particular, we will need to teach kexec how >>>>> to decompress them. The zboot image has a header that >>>>> a) describes it as a EFI linux zimg >>>>> b) describes the start and end offset of the compressed payload >>>>> c) describes which compression algorithm was used. >>>>> >>>>> This means that any non-EFI loader (including kexec) should be able to >>>>> extract the inner PE/COFF image and decompress it. For arm64 and >>>>> RISC-V, this is sufficient as the EFI and raw images are the same. For >>>>> LoongArch, I suppose it means we need a way to enter the core kernel >>>>> directly via the entrypoint that the EFI stub uses when handing over >>>>> (and pass the original DT argument so the kexec kernel has access to >>>>> the EFI and ACPI firmware tables) >>>> OK, then is this implementation [1] acceptable? I remember that you >>>> said the MS-DOS header shouldn't contain other information, so I guess >>>> this is unacceptable? >>>> >>> No, this looks reasonable to me. I objected to using magic numbers in >>> the 'pure PE' view of the image, as it does not make sense for a pure >>> PE loader such as GRUB to rely on such metadata. >>> >>> In this case (like on arm64), we are dealing with something else: we >>> need to identify the image to the kernel itself, and here, using the >>> unused space in the MS-DOS header is fine. >>> >>>> [1] https://lore.kernel.org/loongarch/c4dbb14a-5580-1e47-3d15-5d2079e88404@loongson.cn/T/#mb8c1dc44f7fa2d3ef638877f0cd3f958f0be96ad >> OK, then there is no big problem here. And I found that arm64/riscv >> don't need the kernel entry point in the header. I don't know why, but >> I think it implies that a unified layout across architectures is >> unnecessary, and I prefer to put the kernel entry point before >> effective kernel size. :) >> > It is fine to put the entry point offset in the header. arm64 and > RISC-V don't need this because the first instructions are a pseudo-NOP > (an instruction that does nothing but its binary encoding looks like > 'MZ..') and a jump to the actual entry point. FYI the same trick also works for LoongArch: the code "MZ\x00\x00" i.e. 00005a4d is in fact "ext.w.h $t1, $t6", which is going to simply trash one temporary register without any other effect, so a similar jump to the actual entrypoint could follow. This instruction is available for both LA32 and LA64. The only subset without it is the LA32 Primary, which is meant for university courses and probably would never run UEFI, so the instruction is safe to use. P.S. If we'd go the extra mile just for ensuring the instruction works on every possible LoongArch core, due to the prefix construction of LoongArch encoding, we could just change the bytes toward the MSB (so we keep the "MZ" with ease) and still only trash $t1. For example "MZ\x10\x00" or 00105a4d is "add.w $t1, $t6, $fp", which is similarly harmless, but this time it works on even coursework cores! -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/