From: Pingfan Liu <kernelfans@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
kexec@lists.infradead.org
Subject: Re: [PATCH 0/6] arm64: make kexec_file able to load zboot image
Date: Fri, 10 Mar 2023 12:17:19 +0800 [thread overview]
Message-ID: <ZAqvTyv3C+Hvl9cR@piliu.users.ipa.redhat.com> (raw)
In-Reply-To: <ZAbxF+4ekAfSmoUE@piliu.users.ipa.redhat.com>
On Tue, Mar 07, 2023 at 04:08:55PM +0800, Pingfan Liu wrote:
> Hi Ard,
>
> Thanks for sharing your idea. Please see the comment.
>
> On Mon, Mar 06, 2023 at 09:08:03AM +0100, Ard Biesheuvel wrote:
> > (cc Mark)
> >
> > Hello Pingfan,
> >
> > Thanks for working on this.
> >
> > On Mon, 6 Mar 2023 at 04:03, Pingfan Liu <kernelfans@gmail.com> wrote:
> > >
> > > After introducing zboot image, kexec_file can not load and jump to the
> > > new style image. Hence it demands a method to load the new kernel.
> > >
> > > The crux of the problem lies in when and how to decompress the Image.gz.
> > > There are three possible courses to take: -1. in user space, but hard to
> > > achieve due to the signature verification inside the kernel.
> >
> > That depends. The EFI zboot image encapsulates another PE/COFF image,
> > which could be signed as well.
> >
> > So there are at least three other options here:
> > - sign the encapsulated image with the same key as the zboot image
> > - sign the encapsulated image with a key that is only valid for kexec boot
> > - sign the encapsulated image with an ephemeral key that is only valid
> > for a kexec'ing an image that was produced by the same kernel build
> >
> > > -2. at the
> > > boot time, let the efi_zboot_entry() handles it, which means a simulated
> > > EFI service should be provided to that entry, especially about how to be
> > > aware of the memory layout.
> >
> > This is actually an idea I intend to explore: with the EFI runtime
> > services regions mapped 1:1, it wouldn't be too hard to implement a
> > minimal environment that can run the zboot image under the previous
>
> The idea of the minimal environment lools amazing. After digging
> more deeply into it, I think it means to implement most of the function
> members in efi_boot_services, besides that, some UEFI protocols due to
> the reference of efi_call_proto(). So a clear boundary between zboot and
> its dependent EFI service is demanded before the work.
>
Looking deeper into it. This approach may be splitted into the following
chunks:
-1. Estimation the memory demanded by the decompression of zboot, which
roughly includes the size of Image, the size of the emulated service and
the stack used by zboot. Finally we need a kexec_add_buffer() for this
range.
-2. The emulated EFI services and some initial data such as the physical
address of dtb, the usable memory start address and size should be set
by kexec_purgatory_get_set_symbol()
-3. Set up an identity mapping of the usable memory by zboot, prepare
stack and turn on MMU at the last point just before 'br efi_zboot_entry'
in relocate_kernel.S, which means relocate_kernel.S should support two
kinds of payload.
-4. For efi_zboot_entry(), if jumping from kexec, limit its requirement
to only a few boot services: e.g. allocate_pages, allocate_pool. So the
emulated services can be deduced.
> > kernel up to the point where it call ExitBootServices(), after which
> > kexec() would take over.
> >
>
> IIUC, after kexec switches to efi_zboot_entry(), it will not return,
> right?
>
I have this assumption because letting the control path switch between
kernel and non-kernel code is not a good idea.
Thanks,
Pingfan
> > > -3. in kernel space, during the file load
> > > of the zboot image. At that point, the kernel masters the whole memory
> > > information, and easily allocates a suitable memory for the decompressed
> > > kernel image. (I think this is similar to what grub does today).
> > >
> >
> > GRUB just calls LoadImage(), and the decompression code runs in the EFI context.
> >
>
> Ah, thanks for the correcting. I had made an wrong assumption of grub
> based on [1], from which, I thought that grub is the case "For
> compatibility with non-EFI loaders, the payload can be decompressed and
> executed by the loader as well, provided that the loader implements the
> decompression algorithm and that non-EFI boot is supported by the
> encapsulated image"
>
>
> [1]: https://www.phoronix.com/news/Linux-6.1-Generic-EFI-Zboot
>
>
> Eager to find a solution to kexec a zboot image. Hope it will come soon.
>
>
> Thanks,
>
> Pingfan
> > > The core of this series is [5/6]. [3,6/6] handles the config option.
> > > The assumption of [3/6] is kexec_file_load is independent of zboot,
> > > especially it can load kernel images compressed with different
> > > compression method. [6/6] is if EFI_ZBOOT, the corresponding
> > > decompression method should be included.
> > >
> > >
> > > Cc: Catalin Marinas <catalin.marinas@arm.com>
> > > Cc: Will Deacon <will@kernel.org>
> > > Cc: Andrew Morton <akpm@linux-foundation.org>
> > > Cc: Ard Biesheuvel <ardb@kernel.org>
> > > Cc: kexec@lists.infradead.org
> > > To: linux-arm-kernel@lists.infradead.org
> > > To: linux-kernel@vger.kernel.org
> > >
> > > Pingfan Liu (6):
> > > arm64: kexec: Rename kexec_image.c to kexec_raw_image.c
> > > lib/decompress: Introduce decompress_method_by_name()
> > > arm64: Kconfig: Pick decompressing method for kexec file load
> > > lib/decompress: Keep decompress routines based on selection
> > > arm64: kexec: Introduce zboot image loader
> > > init/Kconfig: Select decompressing method if compressing kernel
> > >
> > > arch/arm64/Kconfig | 59 ++++++
> > > arch/arm64/include/asm/kexec.h | 4 +-
> > > arch/arm64/kernel/Makefile | 2 +-
> > > .../{kexec_image.c => kexec_raw_image.c} | 2 +-
> > > arch/arm64/kernel/kexec_zboot_image.c | 186 ++++++++++++++++++
> > > arch/arm64/kernel/machine_kexec.c | 1 +
> > > arch/arm64/kernel/machine_kexec_file.c | 3 +-
> > > include/linux/decompress/generic.h | 2 +
> > > include/linux/decompress/mm.h | 9 +-
> > > include/linux/zboot.h | 26 +++
> > > init/Kconfig | 7 +
> > > lib/Kconfig | 3 +
> > > lib/decompress.c | 17 +-
> > > 13 files changed, 314 insertions(+), 7 deletions(-)
> > > rename arch/arm64/kernel/{kexec_image.c => kexec_raw_image.c} (98%)
> > > create mode 100644 arch/arm64/kernel/kexec_zboot_image.c
> > > create mode 100644 include/linux/zboot.h
> > >
> > > --
> > > 2.31.1
> > >
next prev parent reply other threads:[~2023-03-10 4:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-06 3:02 Pingfan Liu
2023-03-06 3:03 ` [PATCH 2/6] lib/decompress: Introduce decompress_method_by_name() Pingfan Liu
2023-03-06 3:03 ` [PATCH 4/6] lib/decompress: Keep decompress routines based on selection Pingfan Liu
2023-03-06 3:03 ` [PATCH 6/6] init/Kconfig: Select decompressing method if compressing kernel Pingfan Liu
2023-03-06 8:08 ` [PATCH 0/6] arm64: make kexec_file able to load zboot image Ard Biesheuvel
2023-03-07 8:08 ` Pingfan Liu
2023-03-10 4:17 ` Pingfan Liu [this message]
2023-03-22 3:44 ` Dave Young
2023-03-23 3:40 ` Pingfan Liu
2023-03-10 8:57 ` Naresh Kamboju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZAqvTyv3C+Hvl9cR@piliu.users.ipa.redhat.com \
--to=kernelfans@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=kexec@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®