From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4DEE28EA for ; Mon, 5 Sep 2022 07:02:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 769C1C4347C for ; Mon, 5 Sep 2022 07:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662361348; bh=xPHMxMP3aSknTLgdVfrm34dwYqRWEtWvr2jH89OLnJU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZJEM4GOzu0ocxh2i6hJiBY6acbCrF+8qJ2TOPTObZavvpYCVTwbuT3GDXEpJb39f1 5WIKWgvGS/AmNknOwruR0s0rrbDC7z/JqbivtC89qthLwI3ki/5kBL3jdI4yNXQWVW JxSUmH0IW+wiSFOZrzxmDnx81wRjeZs4+by5J5T0BhM/+RAsr6ukjljrtiFiNAdCtS 4wv1QuafBHYOUa3Vb/TH+IFXd4l72hC/qXSOaUlxfVibqSDtrArgzBgRlt15KvO2pA t2UOavUqdHUwwJLI/bipkxWhTtkbBvEh5Vv5yWlLNRGTwMMV7SSSQd0En1/m2FxEYL +uvZcdpC0SBzg== Received: by mail-lj1-f172.google.com with SMTP id b26so8210539ljk.12 for ; Mon, 05 Sep 2022 00:02:28 -0700 (PDT) X-Gm-Message-State: ACgBeo3Xd1+WW8oLzQLv3YuvsXr0LEaNZEW9Uk7UczDZE4yW4AO5YaJc zqOyw/ty9rdLlyLPyohxFruL9Ax+kdGBqRUQhh0= X-Google-Smtp-Source: AA6agR5JH/+ocHX6Q4aKNm6hqdb8IiyaWzai+jlk8QgzXz1zVTLs2c02qT3yI2yOVcsx1a7RR/ZbLR6lQm+btG742Tw= X-Received: by 2002:a05:651c:1a0e:b0:268:94ad:85f8 with SMTP id by14-20020a05651c1a0e00b0026894ad85f8mr6145342ljb.415.1662361346388; Mon, 05 Sep 2022 00:02:26 -0700 (PDT) Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20220819102037.2697798-1-chenhuacai@loongson.cn> <9b6f0aeaebbd36882b5b40d655f9ccd20c7be496.camel@xry111.site> In-Reply-To: From: Ard Biesheuvel Date: Mon, 5 Sep 2022 09:02:15 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V3] LoongArch: Add efistub booting support To: Huacai Chen 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" 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 > > Huacai