crash.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
  3. *
  4. * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
  5. *
  6. * Copyright (C) IBM Corporation, 2004. All rights reserved.
  7. * Copyright (C) Red Hat Inc., 2014. All rights reserved.
  8. * Authors:
  9. * Vivek Goyal <vgoyal@redhat.com>
  10. *
  11. */
  12. #define pr_fmt(fmt) "kexec: " fmt
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/smp.h>
  16. #include <linux/reboot.h>
  17. #include <linux/kexec.h>
  18. #include <linux/delay.h>
  19. #include <linux/elf.h>
  20. #include <linux/elfcore.h>
  21. #include <linux/export.h>
  22. #include <linux/slab.h>
  23. #include <linux/vmalloc.h>
  24. #include <asm/processor.h>
  25. #include <asm/hardirq.h>
  26. #include <asm/nmi.h>
  27. #include <asm/hw_irq.h>
  28. #include <asm/apic.h>
  29. #include <asm/io_apic.h>
  30. #include <asm/hpet.h>
  31. #include <linux/kdebug.h>
  32. #include <asm/cpu.h>
  33. #include <asm/reboot.h>
  34. #include <asm/virtext.h>
  35. #include <asm/intel_pt.h>
  36. /* Alignment required for elf header segment */
  37. #define ELF_CORE_HEADER_ALIGN 4096
  38. /* This primarily represents number of split ranges due to exclusion */
  39. #define CRASH_MAX_RANGES 16
  40. struct crash_mem_range {
  41. u64 start, end;
  42. };
  43. struct crash_mem {
  44. unsigned int nr_ranges;
  45. struct crash_mem_range ranges[CRASH_MAX_RANGES];
  46. };
  47. /* Misc data about ram ranges needed to prepare elf headers */
  48. struct crash_elf_data {
  49. struct kimage *image;
  50. /*
  51. * Total number of ram ranges we have after various adjustments for
  52. * crash reserved region, etc.
  53. */
  54. unsigned int max_nr_ranges;
  55. /* Pointer to elf header */
  56. void *ehdr;
  57. /* Pointer to next phdr */
  58. void *bufp;
  59. struct crash_mem mem;
  60. };
  61. /* Used while preparing memory map entries for second kernel */
  62. struct crash_memmap_data {
  63. struct boot_params *params;
  64. /* Type of memory */
  65. unsigned int type;
  66. };
  67. /*
  68. * This is used to VMCLEAR all VMCSs loaded on the
  69. * processor. And when loading kvm_intel module, the
  70. * callback function pointer will be assigned.
  71. *
  72. * protected by rcu.
  73. */
  74. crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss = NULL;
  75. EXPORT_SYMBOL_GPL(crash_vmclear_loaded_vmcss);
  76. unsigned long crash_zero_bytes;
  77. static inline void cpu_crash_vmclear_loaded_vmcss(void)
  78. {
  79. crash_vmclear_fn *do_vmclear_operation = NULL;
  80. rcu_read_lock();
  81. do_vmclear_operation = rcu_dereference(crash_vmclear_loaded_vmcss);
  82. if (do_vmclear_operation)
  83. do_vmclear_operation();
  84. rcu_read_unlock();
  85. }
  86. #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
  87. static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
  88. {
  89. #ifdef CONFIG_X86_32
  90. struct pt_regs fixed_regs;
  91. if (!user_mode(regs)) {
  92. crash_fixup_ss_esp(&fixed_regs, regs);
  93. regs = &fixed_regs;
  94. }
  95. #endif
  96. crash_save_cpu(regs, cpu);
  97. /*
  98. * VMCLEAR VMCSs loaded on all cpus if needed.
  99. */
  100. cpu_crash_vmclear_loaded_vmcss();
  101. /* Disable VMX or SVM if needed.
  102. *
  103. * We need to disable virtualization on all CPUs.
  104. * Having VMX or SVM enabled on any CPU may break rebooting
  105. * after the kdump kernel has finished its task.
  106. */
  107. cpu_emergency_vmxoff();
  108. cpu_emergency_svm_disable();
  109. /*
  110. * Disable Intel PT to stop its logging
  111. */
  112. cpu_emergency_stop_pt();
  113. disable_local_APIC();
  114. }
  115. static void kdump_nmi_shootdown_cpus(void)
  116. {
  117. nmi_shootdown_cpus(kdump_nmi_callback);
  118. disable_local_APIC();
  119. }
  120. #else
  121. static void kdump_nmi_shootdown_cpus(void)
  122. {
  123. /* There are no cpus to shootdown */
  124. }
  125. #endif
  126. void native_machine_crash_shutdown(struct pt_regs *regs)
  127. {
  128. /* This function is only called after the system
  129. * has panicked or is otherwise in a critical state.
  130. * The minimum amount of code to allow a kexec'd kernel
  131. * to run successfully needs to happen here.
  132. *
  133. * In practice this means shooting down the other cpus in
  134. * an SMP system.
  135. */
  136. /* The kernel is broken so disable interrupts */
  137. local_irq_disable();
  138. kdump_nmi_shootdown_cpus();
  139. /*
  140. * VMCLEAR VMCSs loaded on this cpu if needed.
  141. */
  142. cpu_crash_vmclear_loaded_vmcss();
  143. /* Booting kdump kernel with VMX or SVM enabled won't work,
  144. * because (among other limitations) we can't disable paging
  145. * with the virt flags.
  146. */
  147. cpu_emergency_vmxoff();
  148. cpu_emergency_svm_disable();
  149. /*
  150. * Disable Intel PT to stop its logging
  151. */
  152. cpu_emergency_stop_pt();
  153. #ifdef CONFIG_X86_IO_APIC
  154. /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
  155. ioapic_zap_locks();
  156. disable_IO_APIC();
  157. #endif
  158. lapic_shutdown();
  159. #ifdef CONFIG_HPET_TIMER
  160. hpet_disable();
  161. #endif
  162. crash_save_cpu(regs, safe_smp_processor_id());
  163. }
  164. #ifdef CONFIG_KEXEC_FILE
  165. static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg)
  166. {
  167. unsigned int *nr_ranges = arg;
  168. (*nr_ranges)++;
  169. return 0;
  170. }
  171. /* Gather all the required information to prepare elf headers for ram regions */
  172. static void fill_up_crash_elf_data(struct crash_elf_data *ced,
  173. struct kimage *image)
  174. {
  175. unsigned int nr_ranges = 0;
  176. ced->image = image;
  177. walk_system_ram_res(0, -1, &nr_ranges,
  178. get_nr_ram_ranges_callback);
  179. ced->max_nr_ranges = nr_ranges;
  180. /* Exclusion of crash region could split memory ranges */
  181. ced->max_nr_ranges++;
  182. /* If crashk_low_res is not 0, another range split possible */
  183. if (crashk_low_res.end)
  184. ced->max_nr_ranges++;
  185. }
  186. static int exclude_mem_range(struct crash_mem *mem,
  187. unsigned long long mstart, unsigned long long mend)
  188. {
  189. int i, j;
  190. unsigned long long start, end;
  191. struct crash_mem_range temp_range = {0, 0};
  192. for (i = 0; i < mem->nr_ranges; i++) {
  193. start = mem->ranges[i].start;
  194. end = mem->ranges[i].end;
  195. if (mstart > end || mend < start)
  196. continue;
  197. /* Truncate any area outside of range */
  198. if (mstart < start)
  199. mstart = start;
  200. if (mend > end)
  201. mend = end;
  202. /* Found completely overlapping range */
  203. if (mstart == start && mend == end) {
  204. mem->ranges[i].start = 0;
  205. mem->ranges[i].end = 0;
  206. if (i < mem->nr_ranges - 1) {
  207. /* Shift rest of the ranges to left */
  208. for (j = i; j < mem->nr_ranges - 1; j++) {
  209. mem->ranges[j].start =
  210. mem->ranges[j+1].start;
  211. mem->ranges[j].end =
  212. mem->ranges[j+1].end;
  213. }
  214. }
  215. mem->nr_ranges--;
  216. return 0;
  217. }
  218. if (mstart > start && mend < end) {
  219. /* Split original range */
  220. mem->ranges[i].end = mstart - 1;
  221. temp_range.start = mend + 1;
  222. temp_range.end = end;
  223. } else if (mstart != start)
  224. mem->ranges[i].end = mstart - 1;
  225. else
  226. mem->ranges[i].start = mend + 1;
  227. break;
  228. }
  229. /* If a split happend, add the split to array */
  230. if (!temp_range.end)
  231. return 0;
  232. /* Split happened */
  233. if (i == CRASH_MAX_RANGES - 1) {
  234. pr_err("Too many crash ranges after split\n");
  235. return -ENOMEM;
  236. }
  237. /* Location where new range should go */
  238. j = i + 1;
  239. if (j < mem->nr_ranges) {
  240. /* Move over all ranges one slot towards the end */
  241. for (i = mem->nr_ranges - 1; i >= j; i--)
  242. mem->ranges[i + 1] = mem->ranges[i];
  243. }
  244. mem->ranges[j].start = temp_range.start;
  245. mem->ranges[j].end = temp_range.end;
  246. mem->nr_ranges++;
  247. return 0;
  248. }
  249. /*
  250. * Look for any unwanted ranges between mstart, mend and remove them. This
  251. * might lead to split and split ranges are put in ced->mem.ranges[] array
  252. */
  253. static int elf_header_exclude_ranges(struct crash_elf_data *ced,
  254. unsigned long long mstart, unsigned long long mend)
  255. {
  256. struct crash_mem *cmem = &ced->mem;
  257. int ret = 0;
  258. memset(cmem->ranges, 0, sizeof(cmem->ranges));
  259. cmem->ranges[0].start = mstart;
  260. cmem->ranges[0].end = mend;
  261. cmem->nr_ranges = 1;
  262. /* Exclude crashkernel region */
  263. ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
  264. if (ret)
  265. return ret;
  266. if (crashk_low_res.end) {
  267. ret = exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
  268. if (ret)
  269. return ret;
  270. }
  271. return ret;
  272. }
  273. static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg)
  274. {
  275. struct crash_elf_data *ced = arg;
  276. Elf64_Ehdr *ehdr;
  277. Elf64_Phdr *phdr;
  278. unsigned long mstart, mend;
  279. struct kimage *image = ced->image;
  280. struct crash_mem *cmem;
  281. int ret, i;
  282. ehdr = ced->ehdr;
  283. /* Exclude unwanted mem ranges */
  284. ret = elf_header_exclude_ranges(ced, start, end);
  285. if (ret)
  286. return ret;
  287. /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */
  288. cmem = &ced->mem;
  289. for (i = 0; i < cmem->nr_ranges; i++) {
  290. mstart = cmem->ranges[i].start;
  291. mend = cmem->ranges[i].end;
  292. phdr = ced->bufp;
  293. ced->bufp += sizeof(Elf64_Phdr);
  294. phdr->p_type = PT_LOAD;
  295. phdr->p_flags = PF_R|PF_W|PF_X;
  296. phdr->p_offset = mstart;
  297. /*
  298. * If a range matches backup region, adjust offset to backup
  299. * segment.
  300. */
  301. if (mstart == image->arch.backup_src_start &&
  302. (mend - mstart + 1) == image->arch.backup_src_sz)
  303. phdr->p_offset = image->arch.backup_load_addr;
  304. phdr->p_paddr = mstart;
  305. phdr->p_vaddr = (unsigned long long) __va(mstart);
  306. phdr->p_filesz = phdr->p_memsz = mend - mstart + 1;
  307. phdr->p_align = 0;
  308. ehdr->e_phnum++;
  309. pr_debug("Crash PT_LOAD elf header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n",
  310. phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
  311. ehdr->e_phnum, phdr->p_offset);
  312. }
  313. return ret;
  314. }
  315. static int prepare_elf64_headers(struct crash_elf_data *ced,
  316. void **addr, unsigned long *sz)
  317. {
  318. Elf64_Ehdr *ehdr;
  319. Elf64_Phdr *phdr;
  320. unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz;
  321. unsigned char *buf, *bufp;
  322. unsigned int cpu;
  323. unsigned long long notes_addr;
  324. int ret;
  325. /* extra phdr for vmcoreinfo elf note */
  326. nr_phdr = nr_cpus + 1;
  327. nr_phdr += ced->max_nr_ranges;
  328. /*
  329. * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping
  330. * area on x86_64 (ffffffff80000000 - ffffffffa0000000).
  331. * I think this is required by tools like gdb. So same physical
  332. * memory will be mapped in two elf headers. One will contain kernel
  333. * text virtual addresses and other will have __va(physical) addresses.
  334. */
  335. nr_phdr++;
  336. elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr);
  337. elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN);
  338. buf = vzalloc(elf_sz);
  339. if (!buf)
  340. return -ENOMEM;
  341. bufp = buf;
  342. ehdr = (Elf64_Ehdr *)bufp;
  343. bufp += sizeof(Elf64_Ehdr);
  344. memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
  345. ehdr->e_ident[EI_CLASS] = ELFCLASS64;
  346. ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
  347. ehdr->e_ident[EI_VERSION] = EV_CURRENT;
  348. ehdr->e_ident[EI_OSABI] = ELF_OSABI;
  349. memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
  350. ehdr->e_type = ET_CORE;
  351. ehdr->e_machine = ELF_ARCH;
  352. ehdr->e_version = EV_CURRENT;
  353. ehdr->e_phoff = sizeof(Elf64_Ehdr);
  354. ehdr->e_ehsize = sizeof(Elf64_Ehdr);
  355. ehdr->e_phentsize = sizeof(Elf64_Phdr);
  356. /* Prepare one phdr of type PT_NOTE for each present cpu */
  357. for_each_present_cpu(cpu) {
  358. phdr = (Elf64_Phdr *)bufp;
  359. bufp += sizeof(Elf64_Phdr);
  360. phdr->p_type = PT_NOTE;
  361. notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
  362. phdr->p_offset = phdr->p_paddr = notes_addr;
  363. phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
  364. (ehdr->e_phnum)++;
  365. }
  366. /* Prepare one PT_NOTE header for vmcoreinfo */
  367. phdr = (Elf64_Phdr *)bufp;
  368. bufp += sizeof(Elf64_Phdr);
  369. phdr->p_type = PT_NOTE;
  370. phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note();
  371. phdr->p_filesz = phdr->p_memsz = sizeof(vmcoreinfo_note);
  372. (ehdr->e_phnum)++;
  373. #ifdef CONFIG_X86_64
  374. /* Prepare PT_LOAD type program header for kernel text region */
  375. phdr = (Elf64_Phdr *)bufp;
  376. bufp += sizeof(Elf64_Phdr);
  377. phdr->p_type = PT_LOAD;
  378. phdr->p_flags = PF_R|PF_W|PF_X;
  379. phdr->p_vaddr = (Elf64_Addr)_text;
  380. phdr->p_filesz = phdr->p_memsz = _end - _text;
  381. phdr->p_offset = phdr->p_paddr = __pa_symbol(_text);
  382. (ehdr->e_phnum)++;
  383. #endif
  384. /* Prepare PT_LOAD headers for system ram chunks. */
  385. ced->ehdr = ehdr;
  386. ced->bufp = bufp;
  387. ret = walk_system_ram_res(0, -1, ced,
  388. prepare_elf64_ram_headers_callback);
  389. if (ret < 0)
  390. return ret;
  391. *addr = buf;
  392. *sz = elf_sz;
  393. return 0;
  394. }
  395. /* Prepare elf headers. Return addr and size */
  396. static int prepare_elf_headers(struct kimage *image, void **addr,
  397. unsigned long *sz)
  398. {
  399. struct crash_elf_data *ced;
  400. int ret;
  401. ced = kzalloc(sizeof(*ced), GFP_KERNEL);
  402. if (!ced)
  403. return -ENOMEM;
  404. fill_up_crash_elf_data(ced, image);
  405. /* By default prepare 64bit headers */
  406. ret = prepare_elf64_headers(ced, addr, sz);
  407. kfree(ced);
  408. return ret;
  409. }
  410. static int add_e820_entry(struct boot_params *params, struct e820entry *entry)
  411. {
  412. unsigned int nr_e820_entries;
  413. nr_e820_entries = params->e820_entries;
  414. if (nr_e820_entries >= E820MAX)
  415. return 1;
  416. memcpy(&params->e820_map[nr_e820_entries], entry,
  417. sizeof(struct e820entry));
  418. params->e820_entries++;
  419. return 0;
  420. }
  421. static int memmap_entry_callback(u64 start, u64 end, void *arg)
  422. {
  423. struct crash_memmap_data *cmd = arg;
  424. struct boot_params *params = cmd->params;
  425. struct e820entry ei;
  426. ei.addr = start;
  427. ei.size = end - start + 1;
  428. ei.type = cmd->type;
  429. add_e820_entry(params, &ei);
  430. return 0;
  431. }
  432. static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem,
  433. unsigned long long mstart,
  434. unsigned long long mend)
  435. {
  436. unsigned long start, end;
  437. int ret = 0;
  438. cmem->ranges[0].start = mstart;
  439. cmem->ranges[0].end = mend;
  440. cmem->nr_ranges = 1;
  441. /* Exclude Backup region */
  442. start = image->arch.backup_load_addr;
  443. end = start + image->arch.backup_src_sz - 1;
  444. ret = exclude_mem_range(cmem, start, end);
  445. if (ret)
  446. return ret;
  447. /* Exclude elf header region */
  448. start = image->arch.elf_load_addr;
  449. end = start + image->arch.elf_headers_sz - 1;
  450. return exclude_mem_range(cmem, start, end);
  451. }
  452. /* Prepare memory map for crash dump kernel */
  453. int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
  454. {
  455. int i, ret = 0;
  456. unsigned long flags;
  457. struct e820entry ei;
  458. struct crash_memmap_data cmd;
  459. struct crash_mem *cmem;
  460. cmem = vzalloc(sizeof(struct crash_mem));
  461. if (!cmem)
  462. return -ENOMEM;
  463. memset(&cmd, 0, sizeof(struct crash_memmap_data));
  464. cmd.params = params;
  465. /* Add first 640K segment */
  466. ei.addr = image->arch.backup_src_start;
  467. ei.size = image->arch.backup_src_sz;
  468. ei.type = E820_RAM;
  469. add_e820_entry(params, &ei);
  470. /* Add ACPI tables */
  471. cmd.type = E820_ACPI;
  472. flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  473. walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1, &cmd,
  474. memmap_entry_callback);
  475. /* Add ACPI Non-volatile Storage */
  476. cmd.type = E820_NVS;
  477. walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1, &cmd,
  478. memmap_entry_callback);
  479. /* Add crashk_low_res region */
  480. if (crashk_low_res.end) {
  481. ei.addr = crashk_low_res.start;
  482. ei.size = crashk_low_res.end - crashk_low_res.start + 1;
  483. ei.type = E820_RAM;
  484. add_e820_entry(params, &ei);
  485. }
  486. /* Exclude some ranges from crashk_res and add rest to memmap */
  487. ret = memmap_exclude_ranges(image, cmem, crashk_res.start,
  488. crashk_res.end);
  489. if (ret)
  490. goto out;
  491. for (i = 0; i < cmem->nr_ranges; i++) {
  492. ei.size = cmem->ranges[i].end - cmem->ranges[i].start + 1;
  493. /* If entry is less than a page, skip it */
  494. if (ei.size < PAGE_SIZE)
  495. continue;
  496. ei.addr = cmem->ranges[i].start;
  497. ei.type = E820_RAM;
  498. add_e820_entry(params, &ei);
  499. }
  500. out:
  501. vfree(cmem);
  502. return ret;
  503. }
  504. static int determine_backup_region(u64 start, u64 end, void *arg)
  505. {
  506. struct kimage *image = arg;
  507. image->arch.backup_src_start = start;
  508. image->arch.backup_src_sz = end - start + 1;
  509. /* Expecting only one range for backup region */
  510. return 1;
  511. }
  512. int crash_load_segments(struct kimage *image)
  513. {
  514. unsigned long src_start, src_sz, elf_sz;
  515. void *elf_addr;
  516. int ret;
  517. /*
  518. * Determine and load a segment for backup area. First 640K RAM
  519. * region is backup source
  520. */
  521. ret = walk_system_ram_res(KEXEC_BACKUP_SRC_START, KEXEC_BACKUP_SRC_END,
  522. image, determine_backup_region);
  523. /* Zero or postive return values are ok */
  524. if (ret < 0)
  525. return ret;
  526. src_start = image->arch.backup_src_start;
  527. src_sz = image->arch.backup_src_sz;
  528. /* Add backup segment. */
  529. if (src_sz) {
  530. /*
  531. * Ideally there is no source for backup segment. This is
  532. * copied in purgatory after crash. Just add a zero filled
  533. * segment for now to make sure checksum logic works fine.
  534. */
  535. ret = kexec_add_buffer(image, (char *)&crash_zero_bytes,
  536. sizeof(crash_zero_bytes), src_sz,
  537. PAGE_SIZE, 0, -1, 0,
  538. &image->arch.backup_load_addr);
  539. if (ret)
  540. return ret;
  541. pr_debug("Loaded backup region at 0x%lx backup_start=0x%lx memsz=0x%lx\n",
  542. image->arch.backup_load_addr, src_start, src_sz);
  543. }
  544. /* Prepare elf headers and add a segment */
  545. ret = prepare_elf_headers(image, &elf_addr, &elf_sz);
  546. if (ret)
  547. return ret;
  548. image->arch.elf_headers = elf_addr;
  549. image->arch.elf_headers_sz = elf_sz;
  550. ret = kexec_add_buffer(image, (char *)elf_addr, elf_sz, elf_sz,
  551. ELF_CORE_HEADER_ALIGN, 0, -1, 0,
  552. &image->arch.elf_load_addr);
  553. if (ret) {
  554. vfree((void *)image->arch.elf_headers);
  555. return ret;
  556. }
  557. pr_debug("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
  558. image->arch.elf_load_addr, elf_sz, elf_sz);
  559. return ret;
  560. }
  561. #endif /* CONFIG_KEXEC_FILE */