hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/include/linux/kexec.h
....@@ -125,7 +125,7 @@
125125 unsigned long cmdline_len);
126126 typedef int (kexec_cleanup_t)(void *loader_data);
127127
128
-#ifdef CONFIG_KEXEC_VERIFY_SIG
128
+#ifdef CONFIG_KEXEC_SIG
129129 typedef int (kexec_verify_sig_t)(const char *kernel_buf,
130130 unsigned long kernel_len);
131131 #endif
....@@ -134,7 +134,7 @@
134134 kexec_probe_t *probe;
135135 kexec_load_t *load;
136136 kexec_cleanup_t *cleanup;
137
-#ifdef CONFIG_KEXEC_VERIFY_SIG
137
+#ifdef CONFIG_KEXEC_SIG
138138 kexec_verify_sig_t *verify_sig;
139139 #endif
140140 };
....@@ -143,6 +143,15 @@
143143
144144 int kexec_image_probe_default(struct kimage *image, void *buf,
145145 unsigned long buf_len);
146
+int kexec_image_post_load_cleanup_default(struct kimage *image);
147
+
148
+/*
149
+ * If kexec_buf.mem is set to this value, kexec_locate_mem_hole()
150
+ * will try to allocate free memory. Arch may overwrite it.
151
+ */
152
+#ifndef KEXEC_BUF_MEM_UNKNOWN
153
+#define KEXEC_BUF_MEM_UNKNOWN 0
154
+#endif
146155
147156 /**
148157 * struct kexec_buf - parameters for finding a place for a buffer in memory
....@@ -174,17 +183,17 @@
174183 bool get_value);
175184 void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
176185
177
-int __weak arch_kexec_apply_relocations_add(struct purgatory_info *pi,
178
- Elf_Shdr *section,
179
- const Elf_Shdr *relsec,
180
- const Elf_Shdr *symtab);
181
-int __weak arch_kexec_apply_relocations(struct purgatory_info *pi,
182
- Elf_Shdr *section,
183
- const Elf_Shdr *relsec,
184
- 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_kimage_file_post_load_cleanup(struct kimage *image);
191
+#ifdef CONFIG_KEXEC_SIG
192
+int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
193
+ unsigned long buf_len);
194
+#endif
195
+int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf);
185196
186
-int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
187
- int (*func)(struct resource *, void *));
188197 extern int kexec_add_buffer(struct kexec_buf *kbuf);
189198 int kexec_locate_mem_hole(struct kexec_buf *kbuf);
190199
....@@ -198,7 +207,7 @@
198207 struct crash_mem {
199208 unsigned int max_nr_ranges;
200209 unsigned int nr_ranges;
201
- struct crash_mem_range ranges[0];
210
+ struct crash_mem_range ranges[];
202211 };
203212
204213 extern int crash_exclude_mem_range(struct crash_mem *mem,
....@@ -206,8 +215,69 @@
206215 unsigned long long mend);
207216 extern int crash_prepare_elf64_headers(struct crash_mem *mem, int kernel_map,
208217 void **addr, unsigned long *sz);
218
+
219
+#ifndef arch_kexec_apply_relocations_add
220
+/*
221
+ * arch_kexec_apply_relocations_add - apply relocations of type RELA
222
+ * @pi: Purgatory to be relocated.
223
+ * @section: Section relocations applying to.
224
+ * @relsec: Section containing RELAs.
225
+ * @symtab: Corresponding symtab.
226
+ *
227
+ * Return: 0 on success, negative errno on error.
228
+ */
229
+static inline int
230
+arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
231
+ const Elf_Shdr *relsec, const Elf_Shdr *symtab)
232
+{
233
+ pr_err("RELA relocation unsupported.\n");
234
+ return -ENOEXEC;
235
+}
236
+#endif
237
+
238
+#ifndef arch_kexec_apply_relocations
239
+/*
240
+ * arch_kexec_apply_relocations - apply relocations of type REL
241
+ * @pi: Purgatory to be relocated.
242
+ * @section: Section relocations applying to.
243
+ * @relsec: Section containing RELs.
244
+ * @symtab: Corresponding symtab.
245
+ *
246
+ * Return: 0 on success, negative errno on error.
247
+ */
248
+static inline int
249
+arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
250
+ const Elf_Shdr *relsec, const Elf_Shdr *symtab)
251
+{
252
+ pr_err("REL relocation unsupported.\n");
253
+ return -ENOEXEC;
254
+}
255
+#endif
209256 #endif /* CONFIG_KEXEC_FILE */
210257
258
+#ifdef CONFIG_KEXEC_ELF
259
+struct kexec_elf_info {
260
+ /*
261
+ * Where the ELF binary contents are kept.
262
+ * Memory managed by the user of the struct.
263
+ */
264
+ const char *buffer;
265
+
266
+ const struct elfhdr *ehdr;
267
+ const struct elf_phdr *proghdrs;
268
+};
269
+
270
+int kexec_build_elf_info(const char *buf, size_t len, struct elfhdr *ehdr,
271
+ struct kexec_elf_info *elf_info);
272
+
273
+int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
274
+ struct kexec_elf_info *elf_info,
275
+ struct kexec_buf *kbuf,
276
+ unsigned long *lowest_load_addr);
277
+
278
+void kexec_free_elf_info(struct kexec_elf_info *elf_info);
279
+int kexec_elf_probe(const char *buf, unsigned long len);
280
+#endif
211281 struct kimage {
212282 kimage_entry_t head;
213283 kimage_entry_t *entry;
....@@ -310,8 +380,8 @@
310380 extern bool kexec_in_progress;
311381
312382 int crash_shrink_memory(unsigned long new_size);
313
-size_t crash_get_memory_size(void);
314383 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
384
+ssize_t crash_get_memory_size(void);
315385
316386 void arch_kexec_protect_crashkres(void);
317387 void arch_kexec_unprotect_crashkres(void);
....@@ -372,6 +442,12 @@
372442 #define kexec_in_progress false
373443 #endif /* CONFIG_KEXEC_CORE */
374444
445
+#ifdef CONFIG_KEXEC_SIG
446
+void set_kexec_sig_enforced(void);
447
+#else
448
+static inline void set_kexec_sig_enforced(void) {}
449
+#endif
450
+
375451 #endif /* !defined(__ASSEBMLY__) */
376452
377453 #endif /* LINUX_KEXEC_H */