-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCHv3 0/6] arm64: zboot support #4
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As more complicated kernel format occurs such as zboot, where the compressed kernel is stored as a payload. The straight forward decompression can not meet the demand. A new image probe method is expected to read in the kernel file and decide how to unfold the content by itself. This patch aims to change the image probe's prototype from typedef int (probe_t)(const char *kernel_buf, off_t kernel_size); to typedef int (probe_t)(const char *kernel_buf, off_t kernel_size, struct kexec_info *info); Later, info can be used to return both the file descriptor and the parsed kernel buffer. In case your are curious, the remaing part of the log describes the process of the substitution of the new prototype, which can be divided into three groups. 1. change function pointer and its callsites: sed -i 's/(probe_t)(const char \*kernel_buf, off_t kernel_size);/(probe_t)(const char \*kernel, off_t kernel_size, struct kexec_info \*info);/g' kexec/kexec.h sed -i 's/\.probe(\([^,]*\), \([^)]*\))/\.probe(\1, \2, NULL)/g' kexec/kexec.c 2. change the function declaration and definition of each 'probe' instance by coccinelle because they may cross lines The cocci file looks like: @ rule1 @ identifier fn =~ "_probe"; identifier buf, size; typedef off_t; @@ -int fn(const char *buf, off_t size) +int fn(const char *buf, off_t size, struct kexec_info *info) { ... } @ rule2 @ identifier fn =~ "_probe"; identifier buf, size; typedef off_t; @@ +int fn(const char *buf, off_t size, struct kexec_info *info); -int fn(const char *buf, off_t size); Then running the command spatch --sp-file cocci/define.cocci --dir kexec --include-headers > ../define.patch git apply --directory=kexec ../define.patch 3. change the direct calls to the probe instances Originally I planned to achieve this by coccinelle, but failed similar to [1]. I have tried using "-I and --include" option for coccinelle, but it still did not work. Checking the direct callsite by "git grep "_probe(" | grep -v const" Fortunatelly, it turns out that only a few direct callsites exist, which lies in i386, and easy to be amended manually. Anyway, just FYI, the cocci file looks like: @ rule1 @ identifier fn =~ "_probe"; identifier buf, size; identifier info; typedef off_t; @@ int fn(const char *buf, off_t size, struct kexec_info *info); /* change the direct callsite of any probe */ @ rule2 @ identifier rule1.fn; expression E1, E2; @@ fn(E1, E2 + ,NULL ) Then running the command: spatch --sp-file cocci/direct.cocci --dir kexec --include-headers [1]: https://lore.kernel.org/all/alpine.DEB.2.22.394.2202280705080.3112@hadrien/T/ Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
Current compilers note that fname will be null while attempting to print failures from strdup(). Further fix a memory leak caused by kernel_uncompressed_buf never being used/freed before the allocated block is replaced by the one returned by slurp_decompress_file(). Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
As more complicated capsule kernel format ,such as zboot, emerge, where the compressed kernel is stored as a payload. The straight forward decompression can not meet the demand. Therefore, let a probe method read in the kernel file and decide how to unfold the content by the method itself. Since other arches still read the kernel image before probe method, the purpose of the first argument differs from that in aarch64. Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
The linux kernel CONFIG_ZBOOT option creates self decompressing PE kernel images. So this means that kexec should have a generic understanding of the format which may be used by multiple arches. So lets add an arch independent validation and decompression routine. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> [Modified by Pingfan to adapt the new probe interface] Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
The kernel EFI stub ZBOOT feature creates a PE that contains a compressed linux kernel image. The stub when run in a valid UEFI environment then decompresses the resulting image and executes it. Support these image formats with kexec as well to avoid having to keep an alternate kernel image around. This patch adds a the _probe() and usage() routines needed for kexec to understand this format. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> [Modified by Pingfan to adapt the new probe interface] Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
Add the previously defined _probe() and _usage() routines to the kexec file types table, and build the new module. It should be noted that this "vmlinuz" support reuses the "Image" support to actually load the resulting image after it has been decompressed to a temporary file. Signed-off-by: Jeremy Linton <jeremy.linton@arm.com> Signed-off-by: Pingfan Liu <piliu@redhat.com> To: kexec@lists.infradead.org Cc: horms@verge.net.au Cc: ardb@kernel.org Cc: jeremy.linton@arm.com
I have sent out V4 in mailing list, so close this v3 pull request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As more complicated capsule kernel format occurs like zboot, where the
compressed kernel is stored as a payload. The straight forward
decompression can not meet the demand.
As the first step, on aarch64, reading in the kernel file in a probe
method and decide how to unfold the content by the method itself.
The new designed probe interface returns two factors:
the image load method later.
only work with Image format, the outer payload should be stripped and a
temporary file of Image should be created.
After substitution, although each probe mehod seems to have the same
prototype, they have differenct purpose on the first argument.
On aarch64, the argument is used to pass the kernel file name, while on
the other arches, it is used to passs the decompressed kernel.
This can be cured by scattering out the logic of reading the kernel file
into each probe. (This should be done by coccinelle. But let us keep a
small step for the time being)
v2 -> v3:
Fix some missing replacement by Coccinelle in [1/6], due to UNUSED() macro
v1 -> v2:
take in Jeremy's patches to implement zboot format support
use coccinelle and sed to substitue the image probe method prototype.