crash.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. void kdump_nmi_shootdown_cpus(void)
  116. {
  117. nmi_shootdown_cpus(kdump_nmi_callback);
  118. disable_local_APIC();
  119. }
  120. /* Override the weak function in kernel/panic.c */
  121. void crash_smp_send_stop(void)
  122. {
  123. static int cpus_stopped;
  124. if (cpus_stopped)
  125. return;
  126. if (smp_ops.crash_stop_other_cpus)
  127. smp_ops.crash_stop_other_cpus();
  128. else
  129. smp_send_stop();
  130. cpus_stopped = 1;
  131. }
  132. #else
  133. void crash_smp_send_stop(void)
  134. {
  135. /* There are no cpus to shootdown */
  136. }
  137. #endif
  138. void native_machine_crash_shutdown(struct pt_regs *regs)
  139. {
  140. /* This function is only called after the system
  141. * has panicked or is otherwise in a critical state.
  142. * The minimum amount of code to allow a kexec'd kernel
  143. * to run successfully needs to happen here.
  144. *
  145. * In practice this means shooting down the other cpus in
  146. * an SMP system.
  147. */
  148. /* The kernel is broken so disable interrupts */
  149. local_irq_disable();
  150. crash_smp_send_stop();
  151. /*
  152. * VMCLEAR VMCSs loaded on this cpu if needed.
  153. */
  154. cpu_crash_vmclear_loaded_vmcss();
  155. /* Booting kdump kernel with VMX or SVM enabled won't work,
  156. * because (among other limitations) we can't disable paging
  157. * with the virt flags.
  158. */
  159. cpu_emergency_vmxoff();
  160. cpu_emergency_svm_disable();
  161. /*
  162. * Disable Intel PT to stop its logging
  163. */
  164. cpu_emergency_stop_pt();
  165. #ifdef CONFIG_X86_IO_APIC
  166. /* Prevent crash_kexec() from deadlocking on ioapic_lock. */
  167. ioapic_zap_locks();
  168. disable_IO_APIC();
  169. #endif
  170. lapic_shutdown();
  171. #ifdef CONFIG_HPET_TIMER
  172. hpet_disable();
  173. #endif
  174. crash_save_cpu(regs, safe_smp_processor_id());
  175. }
  176. #ifdef CONFIG_KEXEC_FILE
  177. static int get_nr_ram_ranges_callback(u64 start, u64 end, void *arg)
  178. {
  179. unsigned int *nr_ranges = arg;
  180. (*nr_ranges)++;
  181. return 0;
  182. }
  183. /* Gather all the required information to prepare elf headers for ram regions */
  184. static void fill_up_crash_elf_data(struct crash_elf_data *ced,
  185. struct kimage *image)
  186. {
  187. unsigned int nr_ranges = 0;
  188. ced->image = image;
  189. walk_system_ram_res(0, -1, &nr_ranges,
  190. get_nr_ram_ranges_callback);
  191. ced->max_nr_ranges = nr_ranges;
  192. /* Exclusion of crash region could split memory ranges */
  193. ced->max_nr_ranges++;
  194. /* If crashk_low_res is not 0, another range split possible */
  195. if (crashk_low_res.end)
  196. ced->max_nr_ranges++;
  197. }
  198. static int exclude_mem_range(struct crash_mem *mem,
  199. unsigned long long mstart, unsigned long long mend)
  200. {
  201. int i, j;
  202. unsigned long long start, end;
  203. struct crash_mem_range temp_range = {0, 0};
  204. for (i = 0; i < mem->nr_ranges; i++) {
  205. start = mem->ranges[i].start;
  206. end = mem->ranges[i].end;
  207. if (mstart > end || mend < start)
  208. continue;
  209. /* Truncate any area outside of range */
  210. if (mstart < start)
  211. mstart = start;
  212. if (mend > end)
  213. mend = end;
  214. /* Found completely overlapping range */
  215. if (mstart == start && mend == end) {
  216. mem->ranges[i].start = 0;
  217. mem->ranges[i].end = 0;
  218. if (i < mem->nr_ranges - 1) {
  219. /* Shift rest of the ranges to left */
  220. for (j = i; j < mem->nr_ranges - 1; j++) {
  221. mem->ranges[j].start =
  222. mem->ranges[j+1].start;
  223. mem->ranges[j].end =
  224. mem->ranges[j+1].end;
  225. }
  226. }
  227. mem->nr_ranges--;
  228. return 0;
  229. }
  230. if (mstart > start && mend < end) {
  231. /* Split original range */
  232. mem->ranges[i].end = mstart - 1;
  233. temp_range.start = mend + 1;
  234. temp_range.end = end;
  235. } else if (mstart != start)
  236. mem->ranges[i].end = mstart - 1;
  237. else
  238. mem->ranges[i].start = mend + 1;
  239. break;
  240. }
  241. /* If a split happend, add the split to array */
  242. if (!temp_range.end)
  243. return 0;
  244. /* Split happened */
  245. if (i == CRASH_MAX_RANGES - 1) {
  246. pr_err("Too many crash ranges after split\n");
  247. return -ENOMEM;
  248. }
  249. /* Location where new range should go */
  250. j = i + 1;
  251. if (j < mem->nr_ranges) {
  252. /* Move over all ranges one slot towards the end */
  253. for (i = mem->nr_ranges - 1; i >= j; i--)
  254. mem->ranges[i + 1] = mem->ranges[i];
  255. }
  256. mem->ranges[j].start = temp_range.start;
  257. mem->ranges[j].end = temp_range.end;
  258. mem->nr_ranges++;
  259. return 0;
  260. }
  261. /*
  262. * Look for any unwanted ranges between mstart, mend and remove them. This
  263. * might lead to split and split ranges are put in ced->mem.ranges[] array
  264. */
  265. static int elf_header_exclude_ranges(struct crash_elf_data *ced,
  266. unsigned long long mstart, unsigned long long mend)
  267. {
  268. struct crash_mem *cmem = &ced->mem;
  269. int ret = 0;
  270. memset(cmem->ranges, 0, sizeof(cmem->ranges));
  271. cmem->ranges[0].start = mstart;
  272. cmem->ranges[0].end = mend;
  273. cmem->nr_ranges = 1;
  274. /* Exclude crashkernel region */
  275. ret = exclude_mem_range(cmem, crashk_res.start, crashk_res.end);
  276. if (ret)
  277. return ret;
  278. if (crashk_low_res.end) {
  279. ret = exclude_mem_range(cmem, crashk_low_res.start, crashk_low_res.end);
  280. if (ret)
  281. return ret;
  282. }
  283. return ret;
  284. }
  285. static int prepare_elf64_ram_headers_callback(u64 start, u64 end, void *arg)
  286. {
  287. struct crash_elf_data *ced = arg;
  288. Elf64_Ehdr *ehdr;
  289. Elf64_Phdr *phdr;
  290. unsigned long mstart, mend;
  291. struct kimage *image = ced->image;
  292. struct crash_mem *cmem;
  293. int ret, i;
  294. ehdr = ced->ehdr;
  295. /* Exclude unwanted mem ranges */
  296. ret = elf_header_exclude_ranges(ced, start, end);
  297. if (ret)
  298. return ret;
  299. /* Go through all the ranges in ced->mem.ranges[] and prepare phdr */
  300. cmem = &ced->mem;
  301. for (i = 0; i < cmem->nr_ranges; i++) {
  302. mstart = cmem->ranges[i].start;
  303. mend = cmem->ranges[i].end;
  304. phdr = ced->bufp;
  305. ced->bufp += sizeof(Elf64_Phdr);
  306. phdr->p_type = PT_LOAD;
  307. phdr->p_flags = PF_R|PF_W|PF_X;
  308. phdr->p_offset = mstart;
  309. /*
  310. * If a range matches backup region, adjust offset to backup
  311. * segment.
  312. */
  313. if (mstart == image->arch.backup_src_start &&
  314. (mend - mstart + 1) == image->arch.backup_src_sz)
  315. phdr->p_offset = image->arch.backup_load_addr;
  316. phdr->p_paddr = mstart;
  317. phdr->p_vaddr = (unsigned long long) __va(mstart);
  318. phdr->p_filesz = phdr->p_memsz = mend - mstart + 1;
  319. phdr->p_align = 0;
  320. ehdr->e_phnum++;
  321. 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",
  322. phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
  323. ehdr->e_phnum, phdr->p_offset);
  324. }
  325. return ret;
  326. }
  327. static int prepare_elf64_headers(struct crash_elf_data *ced,
  328. void **addr, unsigned long *sz)
  329. {
  330. Elf64_Ehdr *ehdr;
  331. Elf64_Phdr *phdr;
  332. unsigned long nr_cpus = num_possible_cpus(), nr_phdr, elf_sz;
  333. unsigned char *buf, *bufp;
  334. unsigned int cpu;
  335. unsigned long long notes_addr;
  336. int ret;
  337. /* extra phdr for vmcoreinfo elf note */
  338. nr_phdr = nr_cpus + 1;
  339. nr_phdr += ced->max_nr_ranges;
  340. /*
  341. * kexec-tools creates an extra PT_LOAD phdr for kernel text mapping
  342. * area on x86_64 (ffffffff80000000 - ffffffffa0000000).
  343. * I think this is required by tools like gdb. So same physical
  344. * memory will be mapped in two elf headers. One will contain kernel
  345. * text virtual addresses and other will have __va(physical) addresses.
  346. */
  347. nr_phdr++;
  348. elf_sz = sizeof(Elf64_Ehdr) + nr_phdr * sizeof(Elf64_Phdr);
  349. elf_sz = ALIGN(elf_sz, ELF_CORE_HEADER_ALIGN);
  350. buf = vzalloc(elf_sz);
  351. if (!buf)
  352. return -ENOMEM;
  353. bufp = buf;
  354. ehdr = (Elf64_Ehdr *)bufp;
  355. bufp += sizeof(Elf64_Ehdr);
  356. memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
  357. ehdr->e_ident[EI_CLASS] = ELFCLASS64;
  358. ehdr->e_ident[EI_DATA] = ELFDATA2LSB;
  359. ehdr->e_ident[EI_VERSION] = EV_CURRENT;
  360. ehdr->e_ident[EI_OSABI] = ELF_OSABI;
  361. memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
  362. ehdr->e_type = ET_CORE;
  363. ehdr->e_machine = ELF_ARCH;
  364. ehdr->e_version = EV_CURRENT;
  365. ehdr->e_phoff = sizeof(Elf64_Ehdr);
  366. ehdr->e_ehsize = sizeof(Elf64_Ehdr);
  367. ehdr->e_phentsize = sizeof(Elf64_Phdr);
  368. /* Prepare one phdr of type PT_NOTE for each present cpu */
  369. for_each_present_cpu(cpu) {
  370. phdr = (Elf64_Phdr *)bufp;
  371. bufp += sizeof(Elf64_Phdr);
  372. phdr->p_type = PT_NOTE;
  373. notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
  374. phdr->p_offset = phdr->p_paddr = notes_addr;
  375. phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
  376. (ehdr->e_phnum)++;
  377. }
  378. /* Prepare one PT_NOTE header for vmcoreinfo */
  379. phdr = (Elf64_Phdr *)bufp;
  380. bufp += sizeof(Elf64_Phdr);
  381. phdr->p_type = PT_NOTE;
  382. phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note();
  383. phdr->p_filesz = phdr->p_memsz = sizeof(vmcoreinfo_note);
  384. (ehdr->e_phnum)++;
  385. #ifdef CONFIG_X86_64
  386. /* Prepare PT_LOAD type program header for kernel text region */
  387. phdr = (Elf64_Phdr *)bufp;
  388. bufp += sizeof(Elf64_Phdr);
  389. phdr->p_type = PT_LOAD;
  390. phdr->p_flags = PF_R|PF_W|PF_X;
  391. phdr->p_vaddr = (Elf64_Addr)_text;
  392. phdr->p_filesz = phdr->p_memsz = _end - _text;
  393. phdr->p_offset = phdr->p_paddr = __pa_symbol(_text);
  394. (ehdr->e_phnum)++;
  395. #endif
  396. /* Prepare PT_LOAD headers for system ram chunks. */
  397. ced->ehdr = ehdr;
  398. ced->bufp = bufp;
  399. ret = walk_system_ram_res(0, -1, ced,
  400. prepare_elf64_ram_headers_callback);
  401. if (ret < 0)
  402. return ret;
  403. *addr = buf;
  404. *sz = elf_sz;
  405. return 0;
  406. }
  407. /* Prepare elf headers. Return addr and size */
  408. static int prepare_elf_headers(struct kimage *image, void **addr,
  409. unsigned long *sz)
  410. {
  411. struct crash_elf_data *ced;
  412. int ret;
  413. ced = kzalloc(sizeof(*ced), GFP_KERNEL);
  414. if (!ced)
  415. return -ENOMEM;
  416. fill_up_crash_elf_data(ced, image);
  417. /* By default prepare 64bit headers */
  418. ret = prepare_elf64_headers(ced, addr, sz);
  419. kfree(ced);
  420. return ret;
  421. }
  422. static int add_e820_entry(struct boot_params *params, struct e820entry *entry)
  423. {
  424. unsigned int nr_e820_entries;
  425. nr_e820_entries = params->e820_entries;
  426. if (nr_e820_entries >= E820MAX)
  427. return 1;
  428. memcpy(&params->e820_map[nr_e820_entries], entry,
  429. sizeof(struct e820entry));
  430. params->e820_entries++;
  431. return 0;
  432. }
  433. static int memmap_entry_callback(u64 start, u64 end, void *arg)
  434. {
  435. struct crash_memmap_data *cmd = arg;
  436. struct boot_params *params = cmd->params;
  437. struct e820entry ei;
  438. ei.addr = start;
  439. ei.size = end - start + 1;
  440. ei.type = cmd->type;
  441. add_e820_entry(params, &ei);
  442. return 0;
  443. }
  444. static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem,
  445. unsigned long long mstart,
  446. unsigned long long mend)
  447. {
  448. unsigned long start, end;
  449. int ret = 0;
  450. cmem->ranges[0].start = mstart;
  451. cmem->ranges[0].end = mend;
  452. cmem->nr_ranges = 1;
  453. /* Exclude Backup region */
  454. start = image->arch.backup_load_addr;
  455. end = start + image->arch.backup_src_sz - 1;
  456. ret = exclude_mem_range(cmem, start, end);
  457. if (ret)
  458. return ret;
  459. /* Exclude elf header region */
  460. start = image->arch.elf_load_addr;
  461. end = start + image->arch.elf_headers_sz - 1;
  462. return exclude_mem_range(cmem, start, end);
  463. }
  464. /* Prepare memory map for crash dump kernel */
  465. int crash_setup_memmap_entries(struct kimage *image, struct boot_params *params)
  466. {
  467. int i, ret = 0;
  468. unsigned long flags;
  469. struct e820entry ei;
  470. struct crash_memmap_data cmd;
  471. struct crash_mem *cmem;
  472. cmem = vzalloc(sizeof(struct crash_mem));
  473. if (!cmem)
  474. return -ENOMEM;
  475. memset(&cmd, 0, sizeof(struct crash_memmap_data));
  476. cmd.params = params;
  477. /* Add first 640K segment */
  478. ei.addr = image->arch.backup_src_start;
  479. ei.size = image->arch.backup_src_sz;
  480. ei.type = E820_RAM;
  481. add_e820_entry(params, &ei);
  482. /* Add ACPI tables */
  483. cmd.type = E820_ACPI;
  484. flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  485. walk_iomem_res_desc(IORES_DESC_ACPI_TABLES, flags, 0, -1, &cmd,
  486. memmap_entry_callback);
  487. /* Add ACPI Non-volatile Storage */
  488. cmd.type = E820_NVS;
  489. walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1, &cmd,
  490. memmap_entry_callback);
  491. /* Add crashk_low_res region */
  492. if (crashk_low_res.end) {
  493. ei.addr = crashk_low_res.start;
  494. ei.size = crashk_low_res.end - crashk_low_res.start + 1;
  495. ei.type = E820_RAM;
  496. add_e820_entry(params, &ei);
  497. }
  498. /* Exclude some ranges from crashk_res and add rest to memmap */
  499. ret = memmap_exclude_ranges(image, cmem, crashk_res.start,
  500. crashk_res.end);
  501. if (ret)
  502. goto out;
  503. for (i = 0; i < cmem->nr_ranges; i++) {
  504. ei.size = cmem->ranges[i].end - cmem->ranges[i].start + 1;
  505. /* If entry is less than a page, skip it */
  506. if (ei.size < PAGE_SIZE)
  507. continue;
  508. ei.addr = cmem->ranges[i].start;
  509. ei.type = E820_RAM;
  510. add_e820_entry(params, &ei);
  511. }
  512. out:
  513. vfree(cmem);
  514. return ret;
  515. }
  516. static int determine_backup_region(u64 start, u64 end, void *arg)
  517. {
  518. struct kimage *image = arg;
  519. image->arch.backup_src_start = start;
  520. image->arch.backup_src_sz = end - start + 1;
  521. /* Expecting only one range for backup region */
  522. return 1;
  523. }
  524. int crash_load_segments(struct kimage *image)
  525. {
  526. unsigned long src_start, src_sz, elf_sz;
  527. void *elf_addr;
  528. int ret;
  529. /*
  530. * Determine and load a segment for backup area. First 640K RAM
  531. * region is backup source
  532. */
  533. ret = walk_system_ram_res(KEXEC_BACKUP_SRC_START, KEXEC_BACKUP_SRC_END,
  534. image, determine_backup_region);
  535. /* Zero or postive return values are ok */
  536. if (ret < 0)
  537. return ret;
  538. src_start = image->arch.backup_src_start;
  539. src_sz = image->arch.backup_src_sz;
  540. /* Add backup segment. */
  541. if (src_sz) {
  542. /*
  543. * Ideally there is no source for backup segment. This is
  544. * copied in purgatory after crash. Just add a zero filled
  545. * segment for now to make sure checksum logic works fine.
  546. */
  547. ret = kexec_add_buffer(image, (char *)&crash_zero_bytes,
  548. sizeof(crash_zero_bytes), src_sz,
  549. PAGE_SIZE, 0, -1, 0,
  550. &image->arch.backup_load_addr);
  551. if (ret)
  552. return ret;
  553. pr_debug("Loaded backup region at 0x%lx backup_start=0x%lx memsz=0x%lx\n",
  554. image->arch.backup_load_addr, src_start, src_sz);
  555. }
  556. /* Prepare elf headers and add a segment */
  557. ret = prepare_elf_headers(image, &elf_addr, &elf_sz);
  558. if (ret)
  559. return ret;
  560. image->arch.elf_headers = elf_addr;
  561. image->arch.elf_headers_sz = elf_sz;
  562. ret = kexec_add_buffer(image, (char *)elf_addr, elf_sz, elf_sz,
  563. ELF_CORE_HEADER_ALIGN, 0, -1, 0,
  564. &image->arch.elf_load_addr);
  565. if (ret) {
  566. vfree((void *)image->arch.elf_headers);
  567. return ret;
  568. }
  569. pr_debug("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
  570. image->arch.elf_load_addr, elf_sz, elf_sz);
  571. return ret;
  572. }
  573. #endif /* CONFIG_KEXEC_FILE */