crash_dump.c 15 KB

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