Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2788076rwb; Mon, 5 Sep 2022 01:11:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR6RaKMsiD+H8Izk0DfIDepflkYsuuX4gahuAfJAT6+WcVq2awmjsM+IUP5Offb4infunXgL X-Received: by 2002:a17:907:781a:b0:730:ccea:7c29 with SMTP id la26-20020a170907781a00b00730ccea7c29mr35039897ejc.85.1662365471105; Mon, 05 Sep 2022 01:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662365471; cv=none; d=google.com; s=arc-20160816; b=g6+xudFxqt96bcZkUINkcqOfcZFkr1gIJyA7PGEbjLYYQzxZTdMKP8M3bAZlUi18Td QLvaySOONBwyrDJG/kgjzqS6djWMM00MZpdXGB1uE5T1CqPqDNuiST8aKLRxTye2Bbq8 +xzbm10tdfkzwJFV3SyUk2ACHBe0Ehos5d2MzZTr9Y2lgIQJIa0qYzuoJ/krXsi+KyK9 zvuMYb6Fev90w8XPJdW1XKiT12FBOE1jUSbKwrp+JfZDw35d8A2I2R5roFDnA4pMYa9t 4JTOVc6uYyUd9adcLmpDryf4GbhahsC28YK6Xn2J9tnlnShAGTxYfIPQmPcZd1ZzFcmq FAAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WGSBnOIx9kcCYITsFa6ajATBF+Q+CYVLIEsHuq0MjBw=; b=UTPC93fV1FIQreCpPG4ZWbBiP+UfbbKwUCj5M/5IEJUqIVJuSvEn1fsGsyZ1KfoG9Y +XG3GjUqD6nBHkPs10lD4GRRxaN4DL+Pws01ov1Y1mY/bBP+7prXwFzurM8yXPGOjY4g 1M86kOCngfV8JYt6LG7TO4CR/ZTYWTCM3zlGfN2ffr0Y7urupPzMYbKM09O02136HRb5 5kFuJ6lcavdv04PMjFYcDqNehPsqtTC7D1h6iw/uZIqsHb69uaE6C2oMI3IGbebdpiKG WQVLW2+KonspNUoRQiqqsr8S0WH8AfBzi+Oyni9CbyNjIRH92cHXR2PA/utpkWocLKST khNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bQRKoYbL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g21-20020a1709065d1500b0072f42bb813csi7127651ejt.134.2022.09.05.01.10.43; Mon, 05 Sep 2022 01:11: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=@kernel.org header.s=k20201202 header.b=bQRKoYbL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236320AbiIEH1f (ORCPT + 99 others); Mon, 5 Sep 2022 03:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236344AbiIEH1I (ORCPT ); Mon, 5 Sep 2022 03:27:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2515201B8; Mon, 5 Sep 2022 00:25:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6DAB3B80EDC; Mon, 5 Sep 2022 07:25:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12CF7C4347C; Mon, 5 Sep 2022 07:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662362709; bh=vY4vq64x3sm91J5HEru2t38GofMgSHl9txyb3EdJg9M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bQRKoYbLhLYzLufThR1SHnX4SRYwa/y8F5UwG9RFsxyH924JDHb8H8KDr3qpJQUPn 5WXdwNP3KdZpNfq2GfwIE4swJEQkf5QxUjBaHJoQM50n7bIVJdv1jiEcGkCLTUGnUK ufYkOiAZM9NMaWibH7AmI99/j0GbZ2TB0rG8J3VVV9mlNLfuCcQZ/nxw5sp71MRCgG 19s2lgYCr/q0WPQP25fKMbxcc+WzDILpGZjPSMuohNkP0j0DwMulDOs3t5c3Nuc/7r UNieoEfiiiAoyzCuSpKRL7IQgmKHxM5eGi9FFgD3XQ7NFEKc29U6yF4y8pd7HTPeiq vMN6X1Cj8DVIA== Received: by mail-vs1-f42.google.com with SMTP id i1so7993809vsc.9; Mon, 05 Sep 2022 00:25:09 -0700 (PDT) X-Gm-Message-State: ACgBeo3Vt0ThXNjkm2zha4KSVwY+LLqocA2yke0NpfeqhqxZWHcq1yBM maLMyQtowVojRmHuDn9sjcP8pUQi8tQsaPUjoUo= X-Received: by 2002:a67:d49e:0:b0:390:dccf:23c8 with SMTP id g30-20020a67d49e000000b00390dccf23c8mr11950564vsj.59.1662362707979; Mon, 05 Sep 2022 00:25:07 -0700 (PDT) MIME-Version: 1.0 References: <20220819102037.2697798-1-chenhuacai@loongson.cn> <9b6f0aeaebbd36882b5b40d655f9ccd20c7be496.camel@xry111.site> In-Reply-To: From: Huacai Chen Date: Mon, 5 Sep 2022 15:24:56 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V3] LoongArch: Add efistub booting support To: Ard Biesheuvel Cc: Xi Ruoyao , Huacai Chen , Arnd Bergmann , loongarch@lists.linux.dev, linux-arch , Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-efi , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Hi, Ard and Youling, On Mon, Sep 5, 2022 at 3:02 PM Ard Biesheuvel wrote: > > On Mon, 5 Sept 2022 at 05:51, Huacai Chen wrote: > > > > Hi, Ard, > > > > On Mon, Sep 5, 2022 at 5:59 AM Ard Biesheuvel wrote: > > > > > > On Sun, 4 Sept 2022 at 15:24, Huacai Chen wrote: > > > > > > > > Hi, Ard, > > > > > > > > On Thu, Sep 1, 2022 at 6:40 PM Huacai Chen wrote: > > > > > > > > > > Hi, Ard, > > > > > > > > > > On Sat, Aug 27, 2022 at 3:14 PM Ard Biesheuvel wrote: > > > > > > > > > > > > On Sat, 27 Aug 2022 at 06:41, Xi Ruoyao wrote: > > > > > > > > > > > > > > Tested V3 with the magic number check manually removed in my GRUB build. > > > > > > > The system boots successfully. I've not tested Arnd's zBoot patch yet. > > > > > > > > > > > > I am Ard not Arnd :-) > > > > > > > > > > > > Please use this branch when testing the EFI decompressor: > > > > > > https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efi-decompressor-v4 > > > > > The root cause of LoongArch zboot boot failure has been found, it is a > > > > > binutils bug, latest toolchain with the below patch can solve the > > > > > problem. > > > > > > > > > > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > > > > > index 5b44901b9e0..fafdc7c7458 100644 > > > > > --- a/bfd/elfnn-loongarch.c > > > > > +++ b/bfd/elfnn-loongarch.c > > > > > @@ -2341,9 +2341,10 @@ loongarch_elf_relocate_section (bfd > > > > > *output_bfd, struct bfd_link_info *info, > > > > > case R_LARCH_SOP_PUSH_PLT_PCREL: > > > > > unresolved_reloc = false; > > > > > > > > > > - if (resolved_to_const) > > > > > + if (!is_undefweak && resolved_to_const) > > > > > { > > > > > relocation += rel->r_addend; > > > > > + relocation -= pc; > > > > > break; > > > > > } > > > > > else if (is_undefweak) > > > > > > > > > > > > > > > Huacai > > > > Now the patch is submitted here: > > > > https://sourceware.org/pipermail/binutils/2022-September/122713.html > > > > > > > > > > Great. Given the severity of this bug, I imagine that building the > > > LoongArch kernel will require a version of binutils that carries this > > > fix. > > > > > > Therefore, i will revert back to the original approach for accessing > > > uncompressed_size, using an extern declaration with an __aligned(1) > > > attribute. > > > > > > > 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. :) Huacai > > > > Huacai