Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kexec_file: Allow archs to handle special regions while locating memory hole

Some architectures may have special memory regions, within the given
memory range, which can't be used for the buffer in a kexec segment.
Implement weak arch_kexec_locate_mem_hole() definition which arch code
may override, to take care of special regions, while trying to locate
a memory hole.

Also, add the missing declarations for arch overridable functions and
and drop the __weak descriptors in the declarations to avoid non-weak
definitions from becoming weak.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Tested-by: Pingfan Liu <piliu@redhat.com>
Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Acked-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/159602273603.575379.17665852963340380839.stgit@hbathini

authored by

Hari Bathini and committed by
Michael Ellerman
f891f197 fdaa7ce2

+32 -13
+18 -11
include/linux/kexec.h
··· 183 183 bool get_value); 184 184 void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name); 185 185 186 - int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf, 187 - unsigned long buf_len); 188 - void * __weak arch_kexec_kernel_image_load(struct kimage *image); 189 - int __weak arch_kexec_apply_relocations_add(struct purgatory_info *pi, 190 - Elf_Shdr *section, 191 - const Elf_Shdr *relsec, 192 - const Elf_Shdr *symtab); 193 - int __weak arch_kexec_apply_relocations(struct purgatory_info *pi, 194 - Elf_Shdr *section, 195 - const Elf_Shdr *relsec, 196 - const Elf_Shdr *symtab); 186 + /* Architectures may override the below functions */ 187 + int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, 188 + unsigned long buf_len); 189 + void *arch_kexec_kernel_image_load(struct kimage *image); 190 + int arch_kexec_apply_relocations_add(struct purgatory_info *pi, 191 + Elf_Shdr *section, 192 + const Elf_Shdr *relsec, 193 + const Elf_Shdr *symtab); 194 + int arch_kexec_apply_relocations(struct purgatory_info *pi, 195 + Elf_Shdr *section, 196 + const Elf_Shdr *relsec, 197 + const Elf_Shdr *symtab); 198 + int arch_kimage_file_post_load_cleanup(struct kimage *image); 199 + #ifdef CONFIG_KEXEC_SIG 200 + int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, 201 + unsigned long buf_len); 202 + #endif 203 + int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); 197 204 198 205 extern int kexec_add_buffer(struct kexec_buf *kbuf); 199 206 int kexec_locate_mem_hole(struct kexec_buf *kbuf);
+14 -2
kernel/kexec_file.c
··· 658 658 } 659 659 660 660 /** 661 + * arch_kexec_locate_mem_hole - Find free memory to place the segments. 662 + * @kbuf: Parameters for the memory search. 663 + * 664 + * On success, kbuf->mem will have the start address of the memory region found. 665 + * 666 + * Return: 0 on success, negative errno on error. 667 + */ 668 + int __weak arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) 669 + { 670 + return kexec_locate_mem_hole(kbuf); 671 + } 672 + 673 + /** 661 674 * kexec_add_buffer - place a buffer in a kexec segment 662 675 * @kbuf: Buffer contents and memory parameters. 663 676 * ··· 682 669 */ 683 670 int kexec_add_buffer(struct kexec_buf *kbuf) 684 671 { 685 - 686 672 struct kexec_segment *ksegment; 687 673 int ret; 688 674 ··· 709 697 kbuf->buf_align = max(kbuf->buf_align, PAGE_SIZE); 710 698 711 699 /* Walk the RAM ranges and allocate a suitable range for the buffer */ 712 - ret = kexec_locate_mem_hole(kbuf); 700 + ret = arch_kexec_locate_mem_hole(kbuf); 713 701 if (ret) 714 702 return ret; 715 703