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

powerpc/kexec_file: Mark PPC64 specific code

Some of the kexec_file_load code isn't PPC64 specific. Move PPC64
specific code from kexec/file_load.c to kexec/file_load_64.c. Also,
rename purgatory/trampoline.S to purgatory/trampoline_64.S in the same
spirit. No functional changes.

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

authored by

Hari Bathini and committed by
Michael Ellerman
19031275 f891f197

+105 -23
+9
arch/powerpc/include/asm/kexec.h
··· 116 116 unsigned long initrd_load_addr, unsigned long initrd_len, 117 117 const char *cmdline); 118 118 int delete_fdt_mem_rsv(void *fdt, unsigned long start, unsigned long size); 119 + 120 + #ifdef CONFIG_PPC64 121 + int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, 122 + const void *fdt, unsigned long kernel_load_addr, 123 + unsigned long fdt_load_addr); 124 + int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, 125 + unsigned long initrd_load_addr, 126 + unsigned long initrd_len, const char *cmdline); 127 + #endif /* CONFIG_PPC64 */ 119 128 #endif /* CONFIG_KEXEC_FILE */ 120 129 121 130 #else /* !CONFIG_KEXEC_CORE */
+1 -1
arch/powerpc/kexec/Makefile
··· 7 7 8 8 obj-$(CONFIG_PPC32) += relocate_32.o 9 9 10 - obj-$(CONFIG_KEXEC_FILE) += file_load.o elf_$(BITS).o 10 + obj-$(CONFIG_KEXEC_FILE) += file_load.o file_load_$(BITS).o elf_$(BITS).o 11 11 12 12 ifdef CONFIG_HAVE_IMA_KEXEC 13 13 ifdef CONFIG_IMA
+4 -3
arch/powerpc/kexec/elf_64.c
··· 88 88 goto out; 89 89 } 90 90 91 - ret = setup_new_fdt(image, fdt, initrd_load_addr, initrd_len, cmdline); 91 + ret = setup_new_fdt_ppc64(image, fdt, initrd_load_addr, 92 + initrd_len, cmdline); 92 93 if (ret) 93 94 goto out; 94 95 ··· 108 107 pr_debug("Loaded device tree at 0x%lx\n", fdt_load_addr); 109 108 110 109 slave_code = elf_info.buffer + elf_info.proghdrs[0].p_offset; 111 - ret = setup_purgatory(image, slave_code, fdt, kernel_load_addr, 112 - fdt_load_addr); 110 + ret = setup_purgatory_ppc64(image, slave_code, fdt, kernel_load_addr, 111 + fdt_load_addr); 113 112 if (ret) 114 113 pr_err("Error setting up the purgatory.\n"); 115 114
+2 -17
arch/powerpc/kexec/file_load.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 /* 3 - * ppc64 code to implement the kexec_file_load syscall 3 + * powerpc code to implement the kexec_file_load syscall 4 4 * 5 5 * Copyright (C) 2004 Adam Litke (agl@us.ibm.com) 6 6 * Copyright (C) 2004 IBM Corp. ··· 20 20 #include <linux/libfdt.h> 21 21 #include <asm/ima.h> 22 22 23 - #define SLAVE_CODE_SIZE 256 24 - 25 - const struct kexec_file_ops * const kexec_file_loaders[] = { 26 - &kexec_elf64_ops, 27 - NULL 28 - }; 29 - 30 - int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, 31 - unsigned long buf_len) 32 - { 33 - /* We don't support crash kernels yet. */ 34 - if (image->type == KEXEC_TYPE_CRASH) 35 - return -EOPNOTSUPP; 36 - 37 - return kexec_image_probe_default(image, buf, buf_len); 38 - } 23 + #define SLAVE_CODE_SIZE 256 /* First 0x100 bytes */ 39 24 40 25 /** 41 26 * setup_purgatory - initialize the purgatory's global variables
+87
arch/powerpc/kexec/file_load_64.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * ppc64 code to implement the kexec_file_load syscall 4 + * 5 + * Copyright (C) 2004 Adam Litke (agl@us.ibm.com) 6 + * Copyright (C) 2004 IBM Corp. 7 + * Copyright (C) 2004,2005 Milton D Miller II, IBM Corporation 8 + * Copyright (C) 2005 R Sharada (sharada@in.ibm.com) 9 + * Copyright (C) 2006 Mohan Kumar M (mohan@in.ibm.com) 10 + * Copyright (C) 2020 IBM Corporation 11 + * 12 + * Based on kexec-tools' kexec-ppc64.c, kexec-elf-rel-ppc64.c, fs2dt.c. 13 + * Heavily modified for the kernel by 14 + * Hari Bathini, IBM Corporation. 15 + */ 16 + 17 + #include <linux/kexec.h> 18 + #include <linux/of_fdt.h> 19 + #include <linux/libfdt.h> 20 + 21 + const struct kexec_file_ops * const kexec_file_loaders[] = { 22 + &kexec_elf64_ops, 23 + NULL 24 + }; 25 + 26 + /** 27 + * setup_purgatory_ppc64 - initialize PPC64 specific purgatory's global 28 + * variables and call setup_purgatory() to initialize 29 + * common global variable. 30 + * @image: kexec image. 31 + * @slave_code: Slave code for the purgatory. 32 + * @fdt: Flattened device tree for the next kernel. 33 + * @kernel_load_addr: Address where the kernel is loaded. 34 + * @fdt_load_addr: Address where the flattened device tree is loaded. 35 + * 36 + * Returns 0 on success, negative errno on error. 37 + */ 38 + int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, 39 + const void *fdt, unsigned long kernel_load_addr, 40 + unsigned long fdt_load_addr) 41 + { 42 + int ret; 43 + 44 + ret = setup_purgatory(image, slave_code, fdt, kernel_load_addr, 45 + fdt_load_addr); 46 + if (ret) 47 + pr_err("Failed to setup purgatory symbols"); 48 + return ret; 49 + } 50 + 51 + /** 52 + * setup_new_fdt_ppc64 - Update the flattend device-tree of the kernel 53 + * being loaded. 54 + * @image: kexec image being loaded. 55 + * @fdt: Flattened device tree for the next kernel. 56 + * @initrd_load_addr: Address where the next initrd will be loaded. 57 + * @initrd_len: Size of the next initrd, or 0 if there will be none. 58 + * @cmdline: Command line for the next kernel, or NULL if there will 59 + * be none. 60 + * 61 + * Returns 0 on success, negative errno on error. 62 + */ 63 + int setup_new_fdt_ppc64(const struct kimage *image, void *fdt, 64 + unsigned long initrd_load_addr, 65 + unsigned long initrd_len, const char *cmdline) 66 + { 67 + return setup_new_fdt(image, fdt, initrd_load_addr, initrd_len, cmdline); 68 + } 69 + 70 + /** 71 + * arch_kexec_kernel_image_probe - Does additional handling needed to setup 72 + * kexec segments. 73 + * @image: kexec image being loaded. 74 + * @buf: Buffer pointing to elf data. 75 + * @buf_len: Length of the buffer. 76 + * 77 + * Returns 0 on success, negative errno on error. 78 + */ 79 + int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, 80 + unsigned long buf_len) 81 + { 82 + /* We don't support crash kernels yet. */ 83 + if (image->type == KEXEC_TYPE_CRASH) 84 + return -EOPNOTSUPP; 85 + 86 + return kexec_image_probe_default(image, buf, buf_len); 87 + }
+2 -2
arch/powerpc/purgatory/Makefile
··· 2 2 3 3 KASAN_SANITIZE := n 4 4 5 - targets += trampoline.o purgatory.ro kexec-purgatory.c 5 + targets += trampoline_$(BITS).o purgatory.ro kexec-purgatory.c 6 6 7 7 LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined 8 8 9 - $(obj)/purgatory.ro: $(obj)/trampoline.o FORCE 9 + $(obj)/purgatory.ro: $(obj)/trampoline_$(BITS).o FORCE 10 10 $(call if_changed,ld) 11 11 12 12 quiet_cmd_bin2c = BIN2C $@
arch/powerpc/purgatory/trampoline.S arch/powerpc/purgatory/trampoline_64.S