crash_dump.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * S390 kdump implementation
  3. *
  4. * Copyright IBM Corp. 2011
  5. * Author(s): Michael Holzheu <holzheu@linux.vnet.ibm.com>
  6. */
  7. #include <linux/crash_dump.h>
  8. #include <asm/lowcore.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/gfp.h>
  12. #include <linux/slab.h>
  13. #include <linux/bootmem.h>
  14. #include <linux/elf.h>
  15. #include <asm/asm-offsets.h>
  16. #include <linux/memblock.h>
  17. #include <asm/os_info.h>
  18. #include <asm/elf.h>
  19. #include <asm/ipl.h>
  20. #include <asm/sclp.h>
  21. #define PTR_ADD(x, y) (((char *) (x)) + ((unsigned long) (y)))
  22. #define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
  23. #define PTR_DIFF(x, y) ((unsigned long)(((char *) (x)) - ((unsigned long) (y))))
  24. static struct memblock_region oldmem_region;
  25. static struct memblock_type oldmem_type = {
  26. .cnt = 1,
  27. .max = 1,
  28. .total_size = 0,
  29. .regions = &oldmem_region,
  30. };
  31. struct save_area {
  32. struct list_head list;
  33. u64 psw[2];
  34. u64 ctrs[16];
  35. u64 gprs[16];
  36. u32 acrs[16];
  37. u64 fprs[16];
  38. u32 fpc;
  39. u32 prefix;
  40. u64 todpreg;
  41. u64 timer;
  42. u64 todcmp;
  43. u64 vxrs_low[16];
  44. __vector128 vxrs_high[16];
  45. };
  46. static LIST_HEAD(dump_save_areas);
  47. /*
  48. * Allocate a save area
  49. */
  50. struct save_area * __init save_area_alloc(bool is_boot_cpu)
  51. {
  52. struct save_area *sa;
  53. sa = (void *) memblock_alloc(sizeof(*sa), 8);
  54. if (is_boot_cpu)
  55. list_add(&sa->list, &dump_save_areas);
  56. else
  57. list_add_tail(&sa->list, &dump_save_areas);
  58. return sa;
  59. }
  60. /*
  61. * Return the address of the save area for the boot CPU
  62. */
  63. struct save_area * __init save_area_boot_cpu(void)
  64. {
  65. return list_first_entry_or_null(&dump_save_areas, struct save_area, list);
  66. }
  67. /*
  68. * Copy CPU registers into the save area
  69. */
  70. void __init save_area_add_regs(struct save_area *sa, void *regs)
  71. {
  72. struct lowcore *lc;
  73. lc = (struct lowcore *)(regs - __LC_FPREGS_SAVE_AREA);
  74. memcpy(&sa->psw, &lc->psw_save_area, sizeof(sa->psw));
  75. memcpy(&sa->ctrs, &lc->cregs_save_area, sizeof(sa->ctrs));
  76. memcpy(&sa->gprs, &lc->gpregs_save_area, sizeof(sa->gprs));
  77. memcpy(&sa->acrs, &lc->access_regs_save_area, sizeof(sa->acrs));
  78. memcpy(&sa->fprs, &lc->floating_pt_save_area, sizeof(sa->fprs));
  79. memcpy(&sa->fpc, &lc->fpt_creg_save_area, sizeof(sa->fpc));
  80. memcpy(&sa->prefix, &lc->prefixreg_save_area, sizeof(sa->prefix));
  81. memcpy(&sa->todpreg, &lc->tod_progreg_save_area, sizeof(sa->todpreg));
  82. memcpy(&sa->timer, &lc->cpu_timer_save_area, sizeof(sa->timer));
  83. memcpy(&sa->todcmp, &lc->clock_comp_save_area, sizeof(sa->todcmp));
  84. }
  85. /*
  86. * Copy vector registers into the save area
  87. */
  88. void __init save_area_add_vxrs(struct save_area *sa, __vector128 *vxrs)
  89. {
  90. int i;
  91. /* Copy lower halves of vector registers 0-15 */
  92. for (i = 0; i < 16; i++)
  93. memcpy(&sa->vxrs_low[i], &vxrs[i].u[2], 8);
  94. /* Copy vector registers 16-31 */
  95. memcpy(sa->vxrs_high, vxrs + 16, 16 * sizeof(__vector128));
  96. }
  97. /*
  98. * Return physical address for virtual address
  99. */
  100. static inline void *load_real_addr(void *addr)
  101. {
  102. unsigned long real_addr;
  103. asm volatile(
  104. " lra %0,0(%1)\n"
  105. " jz 0f\n"
  106. " la %0,0\n"
  107. "0:"
  108. : "=a" (real_addr) : "a" (addr) : "cc");
  109. return (void *)real_addr;
  110. }
  111. /*
  112. * Copy memory of the old, dumped system to a kernel space virtual address
  113. */
  114. int copy_oldmem_kernel(void *dst, void *src, size_t count)
  115. {
  116. unsigned long from, len;
  117. void *ra;
  118. int rc;
  119. while (count) {
  120. from = __pa(src);
  121. if (!OLDMEM_BASE && from < sclp.hsa_size) {
  122. /* Copy from zfcpdump HSA area */
  123. len = min(count, sclp.hsa_size - from);
  124. rc = memcpy_hsa_kernel(dst, from, len);
  125. if (rc)
  126. return rc;
  127. } else {
  128. /* Check for swapped kdump oldmem areas */
  129. if (OLDMEM_BASE && from - OLDMEM_BASE < OLDMEM_SIZE) {
  130. from -= OLDMEM_BASE;
  131. len = min(count, OLDMEM_SIZE - from);
  132. } else if (OLDMEM_BASE && from < OLDMEM_SIZE) {
  133. len = min(count, OLDMEM_SIZE - from);
  134. from += OLDMEM_BASE;
  135. } else {
  136. len = count;
  137. }
  138. if (is_vmalloc_or_module_addr(dst)) {
  139. ra = load_real_addr(dst);
  140. len = min(PAGE_SIZE - offset_in_page(ra), len);
  141. } else {
  142. ra = dst;
  143. }
  144. if (memcpy_real(ra, (void *) from, len))
  145. return -EFAULT;
  146. }
  147. dst += len;
  148. src += len;
  149. count -= len;
  150. }
  151. return 0;
  152. }
  153. /*
  154. * Copy memory of the old, dumped system to a user space virtual address
  155. */
  156. static int copy_oldmem_user(void __user *dst, void *src, size_t count)
  157. {
  158. unsigned long from, len;
  159. int rc;
  160. while (count) {
  161. from = __pa(src);
  162. if (!OLDMEM_BASE && from < sclp.hsa_size) {
  163. /* Copy from zfcpdump HSA area */
  164. len = min(count, sclp.hsa_size - from);
  165. rc = memcpy_hsa_user(dst, from, len);
  166. if (rc)
  167. return rc;
  168. } else {
  169. /* Check for swapped kdump oldmem areas */
  170. if (OLDMEM_BASE && from - OLDMEM_BASE < OLDMEM_SIZE) {
  171. from -= OLDMEM_BASE;
  172. len = min(count, OLDMEM_SIZE - from);
  173. } else if (OLDMEM_BASE && from < OLDMEM_SIZE) {
  174. len = min(count, OLDMEM_SIZE - from);
  175. from += OLDMEM_BASE;
  176. } else {
  177. len = count;
  178. }
  179. rc = copy_to_user_real(dst, (void *) from, count);
  180. if (rc)
  181. return rc;
  182. }
  183. dst += len;
  184. src += len;
  185. count -= len;
  186. }
  187. return 0;
  188. }
  189. /*
  190. * Copy one page from "oldmem"
  191. */
  192. ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
  193. unsigned long offset, int userbuf)
  194. {
  195. void *src;
  196. int rc;
  197. if (!csize)
  198. return 0;
  199. src = (void *) (pfn << PAGE_SHIFT) + offset;
  200. if (userbuf)
  201. rc = copy_oldmem_user((void __force __user *) buf, src, csize);
  202. else
  203. rc = copy_oldmem_kernel((void *) buf, src, csize);
  204. return rc;
  205. }
  206. /*
  207. * Remap "oldmem" for kdump
  208. *
  209. * For the kdump reserved memory this functions performs a swap operation:
  210. * [0 - OLDMEM_SIZE] is mapped to [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE]
  211. */
  212. static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
  213. unsigned long from, unsigned long pfn,
  214. unsigned long size, pgprot_t prot)
  215. {
  216. unsigned long size_old;
  217. int rc;
  218. if (pfn < OLDMEM_SIZE >> PAGE_SHIFT) {
  219. size_old = min(size, OLDMEM_SIZE - (pfn << PAGE_SHIFT));
  220. rc = remap_pfn_range(vma, from,
  221. pfn + (OLDMEM_BASE >> PAGE_SHIFT),
  222. size_old, prot);
  223. if (rc || size == size_old)
  224. return rc;
  225. size -= size_old;
  226. from += size_old;
  227. pfn += size_old >> PAGE_SHIFT;
  228. }
  229. return remap_pfn_range(vma, from, pfn, size, prot);
  230. }
  231. /*
  232. * Remap "oldmem" for zfcpdump
  233. *
  234. * We only map available memory above HSA size. Memory below HSA size
  235. * is read on demand using the copy_oldmem_page() function.
  236. */
  237. static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
  238. unsigned long from,
  239. unsigned long pfn,
  240. unsigned long size, pgprot_t prot)
  241. {
  242. unsigned long hsa_end = sclp.hsa_size;
  243. unsigned long size_hsa;
  244. if (pfn < hsa_end >> PAGE_SHIFT) {
  245. size_hsa = min(size, hsa_end - (pfn << PAGE_SHIFT));
  246. if (size == size_hsa)
  247. return 0;
  248. size -= size_hsa;
  249. from += size_hsa;
  250. pfn += size_hsa >> PAGE_SHIFT;
  251. }
  252. return remap_pfn_range(vma, from, pfn, size, prot);
  253. }
  254. /*
  255. * Remap "oldmem" for kdump or zfcpdump
  256. */
  257. int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from,
  258. unsigned long pfn, unsigned long size, pgprot_t prot)
  259. {
  260. if (OLDMEM_BASE)
  261. return remap_oldmem_pfn_range_kdump(vma, from, pfn, size, prot);
  262. else
  263. return remap_oldmem_pfn_range_zfcpdump(vma, from, pfn, size,
  264. prot);
  265. }
  266. /*
  267. * Alloc memory and panic in case of ENOMEM
  268. */
  269. static void *kzalloc_panic(int len)
  270. {
  271. void *rc;
  272. rc = kzalloc(len, GFP_KERNEL);
  273. if (!rc)
  274. panic("s390 kdump kzalloc (%d) failed", len);
  275. return rc;
  276. }
  277. /*
  278. * Initialize ELF note
  279. */
  280. static void *nt_init_name(void *buf, Elf64_Word type, void *desc, int d_len,
  281. const char *name)
  282. {
  283. Elf64_Nhdr *note;
  284. u64 len;
  285. note = (Elf64_Nhdr *)buf;
  286. note->n_namesz = strlen(name) + 1;
  287. note->n_descsz = d_len;
  288. note->n_type = type;
  289. len = sizeof(Elf64_Nhdr);
  290. memcpy(buf + len, name, note->n_namesz);
  291. len = roundup(len + note->n_namesz, 4);
  292. memcpy(buf + len, desc, note->n_descsz);
  293. len = roundup(len + note->n_descsz, 4);
  294. return PTR_ADD(buf, len);
  295. }
  296. static inline void *nt_init(void *buf, Elf64_Word type, void *desc, int d_len)
  297. {
  298. const char *note_name = "LINUX";
  299. if (type == NT_PRPSINFO || type == NT_PRSTATUS || type == NT_PRFPREG)
  300. note_name = KEXEC_CORE_NOTE_NAME;
  301. return nt_init_name(buf, type, desc, d_len, note_name);
  302. }
  303. /*
  304. * Fill ELF notes for one CPU with save area registers
  305. */
  306. static void *fill_cpu_elf_notes(void *ptr, int cpu, struct save_area *sa)
  307. {
  308. struct elf_prstatus nt_prstatus;
  309. elf_fpregset_t nt_fpregset;
  310. /* Prepare prstatus note */
  311. memset(&nt_prstatus, 0, sizeof(nt_prstatus));
  312. memcpy(&nt_prstatus.pr_reg.gprs, sa->gprs, sizeof(sa->gprs));
  313. memcpy(&nt_prstatus.pr_reg.psw, sa->psw, sizeof(sa->psw));
  314. memcpy(&nt_prstatus.pr_reg.acrs, sa->acrs, sizeof(sa->acrs));
  315. nt_prstatus.pr_pid = cpu;
  316. /* Prepare fpregset (floating point) note */
  317. memset(&nt_fpregset, 0, sizeof(nt_fpregset));
  318. memcpy(&nt_fpregset.fpc, &sa->fpc, sizeof(sa->fpc));
  319. memcpy(&nt_fpregset.fprs, &sa->fprs, sizeof(sa->fprs));
  320. /* Create ELF notes for the CPU */
  321. ptr = nt_init(ptr, NT_PRSTATUS, &nt_prstatus, sizeof(nt_prstatus));
  322. ptr = nt_init(ptr, NT_PRFPREG, &nt_fpregset, sizeof(nt_fpregset));
  323. ptr = nt_init(ptr, NT_S390_TIMER, &sa->timer, sizeof(sa->timer));
  324. ptr = nt_init(ptr, NT_S390_TODCMP, &sa->todcmp, sizeof(sa->todcmp));
  325. ptr = nt_init(ptr, NT_S390_TODPREG, &sa->todpreg, sizeof(sa->todpreg));
  326. ptr = nt_init(ptr, NT_S390_CTRS, &sa->ctrs, sizeof(sa->ctrs));
  327. ptr = nt_init(ptr, NT_S390_PREFIX, &sa->prefix, sizeof(sa->prefix));
  328. if (MACHINE_HAS_VX) {
  329. ptr = nt_init(ptr, NT_S390_VXRS_HIGH,
  330. &sa->vxrs_high, sizeof(sa->vxrs_high));
  331. ptr = nt_init(ptr, NT_S390_VXRS_LOW,
  332. &sa->vxrs_low, sizeof(sa->vxrs_low));
  333. }
  334. return ptr;
  335. }
  336. /*
  337. * Initialize prpsinfo note (new kernel)
  338. */
  339. static void *nt_prpsinfo(void *ptr)
  340. {
  341. struct elf_prpsinfo prpsinfo;
  342. memset(&prpsinfo, 0, sizeof(prpsinfo));
  343. prpsinfo.pr_sname = 'R';
  344. strcpy(prpsinfo.pr_fname, "vmlinux");
  345. return nt_init(ptr, NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo));
  346. }
  347. /*
  348. * Get vmcoreinfo using lowcore->vmcore_info (new kernel)
  349. */
  350. static void *get_vmcoreinfo_old(unsigned long *size)
  351. {
  352. char nt_name[11], *vmcoreinfo;
  353. Elf64_Nhdr note;
  354. void *addr;
  355. if (copy_oldmem_kernel(&addr, &S390_lowcore.vmcore_info, sizeof(addr)))
  356. return NULL;
  357. memset(nt_name, 0, sizeof(nt_name));
  358. if (copy_oldmem_kernel(&note, addr, sizeof(note)))
  359. return NULL;
  360. if (copy_oldmem_kernel(nt_name, addr + sizeof(note),
  361. sizeof(nt_name) - 1))
  362. return NULL;
  363. if (strcmp(nt_name, "VMCOREINFO") != 0)
  364. return NULL;
  365. vmcoreinfo = kzalloc_panic(note.n_descsz);
  366. if (copy_oldmem_kernel(vmcoreinfo, addr + 24, note.n_descsz))
  367. return NULL;
  368. *size = note.n_descsz;
  369. return vmcoreinfo;
  370. }
  371. /*
  372. * Initialize vmcoreinfo note (new kernel)
  373. */
  374. static void *nt_vmcoreinfo(void *ptr)
  375. {
  376. unsigned long size;
  377. void *vmcoreinfo;
  378. vmcoreinfo = os_info_old_entry(OS_INFO_VMCOREINFO, &size);
  379. if (!vmcoreinfo)
  380. vmcoreinfo = get_vmcoreinfo_old(&size);
  381. if (!vmcoreinfo)
  382. return ptr;
  383. return nt_init_name(ptr, 0, vmcoreinfo, size, "VMCOREINFO");
  384. }
  385. /*
  386. * Initialize final note (needed for /proc/vmcore code)
  387. */
  388. static void *nt_final(void *ptr)
  389. {
  390. Elf64_Nhdr *note;
  391. note = (Elf64_Nhdr *) ptr;
  392. note->n_namesz = 0;
  393. note->n_descsz = 0;
  394. note->n_type = 0;
  395. return PTR_ADD(ptr, sizeof(Elf64_Nhdr));
  396. }
  397. /*
  398. * Initialize ELF header (new kernel)
  399. */
  400. static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt)
  401. {
  402. memset(ehdr, 0, sizeof(*ehdr));
  403. memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
  404. ehdr->e_ident[EI_CLASS] = ELFCLASS64;
  405. ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
  406. ehdr->e_ident[EI_VERSION] = EV_CURRENT;
  407. memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
  408. ehdr->e_type = ET_CORE;
  409. ehdr->e_machine = EM_S390;
  410. ehdr->e_version = EV_CURRENT;
  411. ehdr->e_phoff = sizeof(Elf64_Ehdr);
  412. ehdr->e_ehsize = sizeof(Elf64_Ehdr);
  413. ehdr->e_phentsize = sizeof(Elf64_Phdr);
  414. ehdr->e_phnum = mem_chunk_cnt + 1;
  415. return ehdr + 1;
  416. }
  417. /*
  418. * Return CPU count for ELF header (new kernel)
  419. */
  420. static int get_cpu_cnt(void)
  421. {
  422. struct save_area *sa;
  423. int cpus = 0;
  424. list_for_each_entry(sa, &dump_save_areas, list)
  425. if (sa->prefix != 0)
  426. cpus++;
  427. return cpus;
  428. }
  429. /*
  430. * Return memory chunk count for ELF header (new kernel)
  431. */
  432. static int get_mem_chunk_cnt(void)
  433. {
  434. int cnt = 0;
  435. u64 idx;
  436. for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
  437. MEMBLOCK_NONE, NULL, NULL, NULL)
  438. cnt++;
  439. return cnt;
  440. }
  441. /*
  442. * Initialize ELF loads (new kernel)
  443. */
  444. static void loads_init(Elf64_Phdr *phdr, u64 loads_offset)
  445. {
  446. phys_addr_t start, end;
  447. u64 idx;
  448. for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
  449. MEMBLOCK_NONE, &start, &end, NULL) {
  450. phdr->p_filesz = end - start;
  451. phdr->p_type = PT_LOAD;
  452. phdr->p_offset = start;
  453. phdr->p_vaddr = start;
  454. phdr->p_paddr = start;
  455. phdr->p_memsz = end - start;
  456. phdr->p_flags = PF_R | PF_W | PF_X;
  457. phdr->p_align = PAGE_SIZE;
  458. phdr++;
  459. }
  460. }
  461. /*
  462. * Initialize notes (new kernel)
  463. */
  464. static void *notes_init(Elf64_Phdr *phdr, void *ptr, u64 notes_offset)
  465. {
  466. struct save_area *sa;
  467. void *ptr_start = ptr;
  468. int cpu;
  469. ptr = nt_prpsinfo(ptr);
  470. cpu = 1;
  471. list_for_each_entry(sa, &dump_save_areas, list)
  472. if (sa->prefix != 0)
  473. ptr = fill_cpu_elf_notes(ptr, cpu++, sa);
  474. ptr = nt_vmcoreinfo(ptr);
  475. ptr = nt_final(ptr);
  476. memset(phdr, 0, sizeof(*phdr));
  477. phdr->p_type = PT_NOTE;
  478. phdr->p_offset = notes_offset;
  479. phdr->p_filesz = (unsigned long) PTR_SUB(ptr, ptr_start);
  480. phdr->p_memsz = phdr->p_filesz;
  481. return ptr;
  482. }
  483. /*
  484. * Create ELF core header (new kernel)
  485. */
  486. int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size)
  487. {
  488. Elf64_Phdr *phdr_notes, *phdr_loads;
  489. int mem_chunk_cnt;
  490. void *ptr, *hdr;
  491. u32 alloc_size;
  492. u64 hdr_off;
  493. /* If we are not in kdump or zfcpdump mode return */
  494. if (!OLDMEM_BASE && ipl_info.type != IPL_TYPE_FCP_DUMP)
  495. return 0;
  496. /* If we cannot get HSA size for zfcpdump return error */
  497. if (ipl_info.type == IPL_TYPE_FCP_DUMP && !sclp.hsa_size)
  498. return -ENODEV;
  499. /* For kdump, exclude previous crashkernel memory */
  500. if (OLDMEM_BASE) {
  501. oldmem_region.base = OLDMEM_BASE;
  502. oldmem_region.size = OLDMEM_SIZE;
  503. oldmem_type.total_size = OLDMEM_SIZE;
  504. }
  505. mem_chunk_cnt = get_mem_chunk_cnt();
  506. alloc_size = 0x1000 + get_cpu_cnt() * 0x4a0 +
  507. mem_chunk_cnt * sizeof(Elf64_Phdr);
  508. hdr = kzalloc_panic(alloc_size);
  509. /* Init elf header */
  510. ptr = ehdr_init(hdr, mem_chunk_cnt);
  511. /* Init program headers */
  512. phdr_notes = ptr;
  513. ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
  514. phdr_loads = ptr;
  515. ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
  516. /* Init notes */
  517. hdr_off = PTR_DIFF(ptr, hdr);
  518. ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
  519. /* Init loads */
  520. hdr_off = PTR_DIFF(ptr, hdr);
  521. loads_init(phdr_loads, hdr_off);
  522. *addr = (unsigned long long) hdr;
  523. *size = (unsigned long long) hdr_off;
  524. BUG_ON(elfcorehdr_size > alloc_size);
  525. return 0;
  526. }
  527. /*
  528. * Free ELF core header (new kernel)
  529. */
  530. void elfcorehdr_free(unsigned long long addr)
  531. {
  532. kfree((void *)(unsigned long)addr);
  533. }
  534. /*
  535. * Read from ELF header
  536. */
  537. ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
  538. {
  539. void *src = (void *)(unsigned long)*ppos;
  540. memcpy(buf, src, count);
  541. *ppos += count;
  542. return count;
  543. }
  544. /*
  545. * Read from ELF notes data
  546. */
  547. ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos)
  548. {
  549. void *src = (void *)(unsigned long)*ppos;
  550. memcpy(buf, src, count);
  551. *ppos += count;
  552. return count;
  553. }