crash_dump.c 15 KB

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