crash_dump.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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/os_info.h>
  16. #include <asm/elf.h>
  17. #include <asm/ipl.h>
  18. #include <asm/sclp.h>
  19. #define PTR_ADD(x, y) (((char *) (x)) + ((unsigned long) (y)))
  20. #define PTR_SUB(x, y) (((char *) (x)) - ((unsigned long) (y)))
  21. #define PTR_DIFF(x, y) ((unsigned long)(((char *) (x)) - ((unsigned long) (y))))
  22. /*
  23. * Return physical address for virtual address
  24. */
  25. static inline void *load_real_addr(void *addr)
  26. {
  27. unsigned long real_addr;
  28. asm volatile(
  29. " lra %0,0(%1)\n"
  30. " jz 0f\n"
  31. " la %0,0\n"
  32. "0:"
  33. : "=a" (real_addr) : "a" (addr) : "cc");
  34. return (void *)real_addr;
  35. }
  36. /*
  37. * Copy up to one page to vmalloc or real memory
  38. */
  39. static ssize_t copy_page_real(void *buf, void *src, size_t csize)
  40. {
  41. size_t size;
  42. if (is_vmalloc_addr(buf)) {
  43. BUG_ON(csize >= PAGE_SIZE);
  44. /* If buf is not page aligned, copy first part */
  45. size = min(roundup(__pa(buf), PAGE_SIZE) - __pa(buf), csize);
  46. if (size) {
  47. if (memcpy_real(load_real_addr(buf), src, size))
  48. return -EFAULT;
  49. buf += size;
  50. src += size;
  51. }
  52. /* Copy second part */
  53. size = csize - size;
  54. return (size) ? memcpy_real(load_real_addr(buf), src, size) : 0;
  55. } else {
  56. return memcpy_real(buf, src, csize);
  57. }
  58. }
  59. /*
  60. * Pointer to ELF header in new kernel
  61. */
  62. static void *elfcorehdr_newmem;
  63. /*
  64. * Copy one page from zfcpdump "oldmem"
  65. *
  66. * For pages below ZFCPDUMP_HSA_SIZE memory from the HSA is copied. Otherwise
  67. * real memory copy is used.
  68. */
  69. static ssize_t copy_oldmem_page_zfcpdump(char *buf, size_t csize,
  70. unsigned long src, int userbuf)
  71. {
  72. int rc;
  73. if (src < ZFCPDUMP_HSA_SIZE) {
  74. rc = memcpy_hsa(buf, src, csize, userbuf);
  75. } else {
  76. if (userbuf)
  77. rc = copy_to_user_real((void __force __user *) buf,
  78. (void *) src, csize);
  79. else
  80. rc = memcpy_real(buf, (void *) src, csize);
  81. }
  82. return rc ? rc : csize;
  83. }
  84. /*
  85. * Copy one page from kdump "oldmem"
  86. *
  87. * For the kdump reserved memory this functions performs a swap operation:
  88. * - [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE] is mapped to [0 - OLDMEM_SIZE].
  89. * - [0 - OLDMEM_SIZE] is mapped to [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE]
  90. */
  91. static ssize_t copy_oldmem_page_kdump(char *buf, size_t csize,
  92. unsigned long src, int userbuf)
  93. {
  94. int rc;
  95. if (src < OLDMEM_SIZE)
  96. src += OLDMEM_BASE;
  97. else if (src > OLDMEM_BASE &&
  98. src < OLDMEM_BASE + OLDMEM_SIZE)
  99. src -= OLDMEM_BASE;
  100. if (userbuf)
  101. rc = copy_to_user_real((void __force __user *) buf,
  102. (void *) src, csize);
  103. else
  104. rc = copy_page_real(buf, (void *) src, csize);
  105. return (rc == 0) ? rc : csize;
  106. }
  107. /*
  108. * Copy one page from "oldmem"
  109. */
  110. ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize,
  111. unsigned long offset, int userbuf)
  112. {
  113. unsigned long src;
  114. if (!csize)
  115. return 0;
  116. src = (pfn << PAGE_SHIFT) + offset;
  117. if (OLDMEM_BASE)
  118. return copy_oldmem_page_kdump(buf, csize, src, userbuf);
  119. else
  120. return copy_oldmem_page_zfcpdump(buf, csize, src, userbuf);
  121. }
  122. /*
  123. * Remap "oldmem" for kdump
  124. *
  125. * For the kdump reserved memory this functions performs a swap operation:
  126. * [0 - OLDMEM_SIZE] is mapped to [OLDMEM_BASE - OLDMEM_BASE + OLDMEM_SIZE]
  127. */
  128. static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma,
  129. unsigned long from, unsigned long pfn,
  130. unsigned long size, pgprot_t prot)
  131. {
  132. unsigned long size_old;
  133. int rc;
  134. if (pfn < OLDMEM_SIZE >> PAGE_SHIFT) {
  135. size_old = min(size, OLDMEM_SIZE - (pfn << PAGE_SHIFT));
  136. rc = remap_pfn_range(vma, from,
  137. pfn + (OLDMEM_BASE >> PAGE_SHIFT),
  138. size_old, prot);
  139. if (rc || size == size_old)
  140. return rc;
  141. size -= size_old;
  142. from += size_old;
  143. pfn += size_old >> PAGE_SHIFT;
  144. }
  145. return remap_pfn_range(vma, from, pfn, size, prot);
  146. }
  147. /*
  148. * Remap "oldmem" for zfcpdump
  149. *
  150. * We only map available memory above ZFCPDUMP_HSA_SIZE. Memory below
  151. * ZFCPDUMP_HSA_SIZE is read on demand using the copy_oldmem_page() function.
  152. */
  153. static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma,
  154. unsigned long from,
  155. unsigned long pfn,
  156. unsigned long size, pgprot_t prot)
  157. {
  158. unsigned long size_hsa;
  159. if (pfn < ZFCPDUMP_HSA_SIZE >> PAGE_SHIFT) {
  160. size_hsa = min(size, ZFCPDUMP_HSA_SIZE - (pfn << PAGE_SHIFT));
  161. if (size == size_hsa)
  162. return 0;
  163. size -= size_hsa;
  164. from += size_hsa;
  165. pfn += size_hsa >> PAGE_SHIFT;
  166. }
  167. return remap_pfn_range(vma, from, pfn, size, prot);
  168. }
  169. /*
  170. * Remap "oldmem" for kdump or zfcpdump
  171. */
  172. int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from,
  173. unsigned long pfn, unsigned long size, pgprot_t prot)
  174. {
  175. if (OLDMEM_BASE)
  176. return remap_oldmem_pfn_range_kdump(vma, from, pfn, size, prot);
  177. else
  178. return remap_oldmem_pfn_range_zfcpdump(vma, from, pfn, size,
  179. prot);
  180. }
  181. /*
  182. * Copy memory from old kernel
  183. */
  184. int copy_from_oldmem(void *dest, void *src, size_t count)
  185. {
  186. unsigned long copied = 0;
  187. int rc;
  188. if (OLDMEM_BASE) {
  189. if ((unsigned long) src < OLDMEM_SIZE) {
  190. copied = min(count, OLDMEM_SIZE - (unsigned long) src);
  191. rc = memcpy_real(dest, src + OLDMEM_BASE, copied);
  192. if (rc)
  193. return rc;
  194. }
  195. } else {
  196. if ((unsigned long) src < ZFCPDUMP_HSA_SIZE) {
  197. copied = min(count,
  198. ZFCPDUMP_HSA_SIZE - (unsigned long) src);
  199. rc = memcpy_hsa(dest, (unsigned long) src, copied, 0);
  200. if (rc)
  201. return rc;
  202. }
  203. }
  204. return memcpy_real(dest + copied, src + copied, count - copied);
  205. }
  206. /*
  207. * Alloc memory and panic in case of ENOMEM
  208. */
  209. static void *kzalloc_panic(int len)
  210. {
  211. void *rc;
  212. rc = kzalloc(len, GFP_KERNEL);
  213. if (!rc)
  214. panic("s390 kdump kzalloc (%d) failed", len);
  215. return rc;
  216. }
  217. /*
  218. * Get memory layout and create hole for oldmem
  219. */
  220. static struct mem_chunk *get_memory_layout(void)
  221. {
  222. struct mem_chunk *chunk_array;
  223. chunk_array = kzalloc_panic(MEMORY_CHUNKS * sizeof(struct mem_chunk));
  224. detect_memory_layout(chunk_array, 0);
  225. create_mem_hole(chunk_array, OLDMEM_BASE, OLDMEM_SIZE);
  226. return chunk_array;
  227. }
  228. /*
  229. * Initialize ELF note
  230. */
  231. static void *nt_init(void *buf, Elf64_Word type, void *desc, int d_len,
  232. const char *name)
  233. {
  234. Elf64_Nhdr *note;
  235. u64 len;
  236. note = (Elf64_Nhdr *)buf;
  237. note->n_namesz = strlen(name) + 1;
  238. note->n_descsz = d_len;
  239. note->n_type = type;
  240. len = sizeof(Elf64_Nhdr);
  241. memcpy(buf + len, name, note->n_namesz);
  242. len = roundup(len + note->n_namesz, 4);
  243. memcpy(buf + len, desc, note->n_descsz);
  244. len = roundup(len + note->n_descsz, 4);
  245. return PTR_ADD(buf, len);
  246. }
  247. /*
  248. * Initialize prstatus note
  249. */
  250. static void *nt_prstatus(void *ptr, struct save_area *sa)
  251. {
  252. struct elf_prstatus nt_prstatus;
  253. static int cpu_nr = 1;
  254. memset(&nt_prstatus, 0, sizeof(nt_prstatus));
  255. memcpy(&nt_prstatus.pr_reg.gprs, sa->gp_regs, sizeof(sa->gp_regs));
  256. memcpy(&nt_prstatus.pr_reg.psw, sa->psw, sizeof(sa->psw));
  257. memcpy(&nt_prstatus.pr_reg.acrs, sa->acc_regs, sizeof(sa->acc_regs));
  258. nt_prstatus.pr_pid = cpu_nr;
  259. cpu_nr++;
  260. return nt_init(ptr, NT_PRSTATUS, &nt_prstatus, sizeof(nt_prstatus),
  261. "CORE");
  262. }
  263. /*
  264. * Initialize fpregset (floating point) note
  265. */
  266. static void *nt_fpregset(void *ptr, struct save_area *sa)
  267. {
  268. elf_fpregset_t nt_fpregset;
  269. memset(&nt_fpregset, 0, sizeof(nt_fpregset));
  270. memcpy(&nt_fpregset.fpc, &sa->fp_ctrl_reg, sizeof(sa->fp_ctrl_reg));
  271. memcpy(&nt_fpregset.fprs, &sa->fp_regs, sizeof(sa->fp_regs));
  272. return nt_init(ptr, NT_PRFPREG, &nt_fpregset, sizeof(nt_fpregset),
  273. "CORE");
  274. }
  275. /*
  276. * Initialize timer note
  277. */
  278. static void *nt_s390_timer(void *ptr, struct save_area *sa)
  279. {
  280. return nt_init(ptr, NT_S390_TIMER, &sa->timer, sizeof(sa->timer),
  281. KEXEC_CORE_NOTE_NAME);
  282. }
  283. /*
  284. * Initialize TOD clock comparator note
  285. */
  286. static void *nt_s390_tod_cmp(void *ptr, struct save_area *sa)
  287. {
  288. return nt_init(ptr, NT_S390_TODCMP, &sa->clk_cmp,
  289. sizeof(sa->clk_cmp), KEXEC_CORE_NOTE_NAME);
  290. }
  291. /*
  292. * Initialize TOD programmable register note
  293. */
  294. static void *nt_s390_tod_preg(void *ptr, struct save_area *sa)
  295. {
  296. return nt_init(ptr, NT_S390_TODPREG, &sa->tod_reg,
  297. sizeof(sa->tod_reg), KEXEC_CORE_NOTE_NAME);
  298. }
  299. /*
  300. * Initialize control register note
  301. */
  302. static void *nt_s390_ctrs(void *ptr, struct save_area *sa)
  303. {
  304. return nt_init(ptr, NT_S390_CTRS, &sa->ctrl_regs,
  305. sizeof(sa->ctrl_regs), KEXEC_CORE_NOTE_NAME);
  306. }
  307. /*
  308. * Initialize prefix register note
  309. */
  310. static void *nt_s390_prefix(void *ptr, struct save_area *sa)
  311. {
  312. return nt_init(ptr, NT_S390_PREFIX, &sa->pref_reg,
  313. sizeof(sa->pref_reg), KEXEC_CORE_NOTE_NAME);
  314. }
  315. /*
  316. * Fill ELF notes for one CPU with save area registers
  317. */
  318. void *fill_cpu_elf_notes(void *ptr, struct save_area *sa)
  319. {
  320. ptr = nt_prstatus(ptr, sa);
  321. ptr = nt_fpregset(ptr, sa);
  322. ptr = nt_s390_timer(ptr, sa);
  323. ptr = nt_s390_tod_cmp(ptr, sa);
  324. ptr = nt_s390_tod_preg(ptr, sa);
  325. ptr = nt_s390_ctrs(ptr, sa);
  326. ptr = nt_s390_prefix(ptr, sa);
  327. return ptr;
  328. }
  329. /*
  330. * Initialize prpsinfo note (new kernel)
  331. */
  332. static void *nt_prpsinfo(void *ptr)
  333. {
  334. struct elf_prpsinfo prpsinfo;
  335. memset(&prpsinfo, 0, sizeof(prpsinfo));
  336. prpsinfo.pr_sname = 'R';
  337. strcpy(prpsinfo.pr_fname, "vmlinux");
  338. return nt_init(ptr, NT_PRPSINFO, &prpsinfo, sizeof(prpsinfo),
  339. KEXEC_CORE_NOTE_NAME);
  340. }
  341. /*
  342. * Get vmcoreinfo using lowcore->vmcore_info (new kernel)
  343. */
  344. static void *get_vmcoreinfo_old(unsigned long *size)
  345. {
  346. char nt_name[11], *vmcoreinfo;
  347. Elf64_Nhdr note;
  348. void *addr;
  349. if (copy_from_oldmem(&addr, &S390_lowcore.vmcore_info, sizeof(addr)))
  350. return NULL;
  351. memset(nt_name, 0, sizeof(nt_name));
  352. if (copy_from_oldmem(&note, addr, sizeof(note)))
  353. return NULL;
  354. if (copy_from_oldmem(nt_name, addr + sizeof(note), sizeof(nt_name) - 1))
  355. return NULL;
  356. if (strcmp(nt_name, "VMCOREINFO") != 0)
  357. return NULL;
  358. vmcoreinfo = kzalloc_panic(note.n_descsz);
  359. if (copy_from_oldmem(vmcoreinfo, addr + 24, note.n_descsz))
  360. return NULL;
  361. *size = note.n_descsz;
  362. return vmcoreinfo;
  363. }
  364. /*
  365. * Initialize vmcoreinfo note (new kernel)
  366. */
  367. static void *nt_vmcoreinfo(void *ptr)
  368. {
  369. unsigned long size;
  370. void *vmcoreinfo;
  371. vmcoreinfo = os_info_old_entry(OS_INFO_VMCOREINFO, &size);
  372. if (!vmcoreinfo)
  373. vmcoreinfo = get_vmcoreinfo_old(&size);
  374. if (!vmcoreinfo)
  375. return ptr;
  376. return nt_init(ptr, 0, vmcoreinfo, size, "VMCOREINFO");
  377. }
  378. /*
  379. * Initialize ELF header (new kernel)
  380. */
  381. static void *ehdr_init(Elf64_Ehdr *ehdr, int mem_chunk_cnt)
  382. {
  383. memset(ehdr, 0, sizeof(*ehdr));
  384. memcpy(ehdr->e_ident, ELFMAG, SELFMAG);
  385. ehdr->e_ident[EI_CLASS] = ELFCLASS64;
  386. ehdr->e_ident[EI_DATA] = ELFDATA2MSB;
  387. ehdr->e_ident[EI_VERSION] = EV_CURRENT;
  388. memset(ehdr->e_ident + EI_PAD, 0, EI_NIDENT - EI_PAD);
  389. ehdr->e_type = ET_CORE;
  390. ehdr->e_machine = EM_S390;
  391. ehdr->e_version = EV_CURRENT;
  392. ehdr->e_phoff = sizeof(Elf64_Ehdr);
  393. ehdr->e_ehsize = sizeof(Elf64_Ehdr);
  394. ehdr->e_phentsize = sizeof(Elf64_Phdr);
  395. ehdr->e_phnum = mem_chunk_cnt + 1;
  396. return ehdr + 1;
  397. }
  398. /*
  399. * Return CPU count for ELF header (new kernel)
  400. */
  401. static int get_cpu_cnt(void)
  402. {
  403. int i, cpus = 0;
  404. for (i = 0; zfcpdump_save_areas[i]; i++) {
  405. if (zfcpdump_save_areas[i]->pref_reg == 0)
  406. continue;
  407. cpus++;
  408. }
  409. return cpus;
  410. }
  411. /*
  412. * Return memory chunk count for ELF header (new kernel)
  413. */
  414. static int get_mem_chunk_cnt(void)
  415. {
  416. struct mem_chunk *chunk_array, *mem_chunk;
  417. int i, cnt = 0;
  418. chunk_array = get_memory_layout();
  419. for (i = 0; i < MEMORY_CHUNKS; i++) {
  420. mem_chunk = &chunk_array[i];
  421. if (chunk_array[i].type != CHUNK_READ_WRITE &&
  422. chunk_array[i].type != CHUNK_READ_ONLY)
  423. continue;
  424. if (mem_chunk->size == 0)
  425. continue;
  426. cnt++;
  427. }
  428. kfree(chunk_array);
  429. return cnt;
  430. }
  431. /*
  432. * Initialize ELF loads (new kernel)
  433. */
  434. static int loads_init(Elf64_Phdr *phdr, u64 loads_offset)
  435. {
  436. struct mem_chunk *chunk_array, *mem_chunk;
  437. int i;
  438. chunk_array = get_memory_layout();
  439. for (i = 0; i < MEMORY_CHUNKS; i++) {
  440. mem_chunk = &chunk_array[i];
  441. if (mem_chunk->size == 0)
  442. continue;
  443. if (chunk_array[i].type != CHUNK_READ_WRITE &&
  444. chunk_array[i].type != CHUNK_READ_ONLY)
  445. continue;
  446. else
  447. phdr->p_filesz = mem_chunk->size;
  448. phdr->p_type = PT_LOAD;
  449. phdr->p_offset = mem_chunk->addr;
  450. phdr->p_vaddr = mem_chunk->addr;
  451. phdr->p_paddr = mem_chunk->addr;
  452. phdr->p_memsz = mem_chunk->size;
  453. phdr->p_flags = PF_R | PF_W | PF_X;
  454. phdr->p_align = PAGE_SIZE;
  455. phdr++;
  456. }
  457. kfree(chunk_array);
  458. return i;
  459. }
  460. /*
  461. * Initialize notes (new kernel)
  462. */
  463. static void *notes_init(Elf64_Phdr *phdr, void *ptr, u64 notes_offset)
  464. {
  465. struct save_area *sa;
  466. void *ptr_start = ptr;
  467. int i;
  468. ptr = nt_prpsinfo(ptr);
  469. for (i = 0; zfcpdump_save_areas[i]; i++) {
  470. sa = zfcpdump_save_areas[i];
  471. if (sa->pref_reg == 0)
  472. continue;
  473. ptr = fill_cpu_elf_notes(ptr, sa);
  474. }
  475. ptr = nt_vmcoreinfo(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 elfcorehdr= has been passed via cmdline, we use that one */
  497. if (elfcorehdr_addr != ELFCORE_ADDR_MAX)
  498. return 0;
  499. mem_chunk_cnt = get_mem_chunk_cnt();
  500. alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +
  501. mem_chunk_cnt * sizeof(Elf64_Phdr);
  502. hdr = kzalloc_panic(alloc_size);
  503. /* Init elf header */
  504. ptr = ehdr_init(hdr, mem_chunk_cnt);
  505. /* Init program headers */
  506. phdr_notes = ptr;
  507. ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
  508. phdr_loads = ptr;
  509. ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
  510. /* Init notes */
  511. hdr_off = PTR_DIFF(ptr, hdr);
  512. ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
  513. /* Init loads */
  514. hdr_off = PTR_DIFF(ptr, hdr);
  515. loads_init(phdr_loads, hdr_off);
  516. *addr = (unsigned long long) hdr;
  517. elfcorehdr_newmem = hdr;
  518. *size = (unsigned long long) hdr_off;
  519. BUG_ON(elfcorehdr_size > alloc_size);
  520. return 0;
  521. }
  522. /*
  523. * Free ELF core header (new kernel)
  524. */
  525. void elfcorehdr_free(unsigned long long addr)
  526. {
  527. if (!elfcorehdr_newmem)
  528. return;
  529. kfree((void *)(unsigned long)addr);
  530. }
  531. /*
  532. * Read from ELF header
  533. */
  534. ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
  535. {
  536. void *src = (void *)(unsigned long)*ppos;
  537. src = elfcorehdr_newmem ? src : src - OLDMEM_BASE;
  538. memcpy(buf, src, count);
  539. *ppos += count;
  540. return count;
  541. }
  542. /*
  543. * Read from ELF notes data
  544. */
  545. ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos)
  546. {
  547. void *src = (void *)(unsigned long)*ppos;
  548. int rc;
  549. if (elfcorehdr_newmem) {
  550. memcpy(buf, src, count);
  551. } else {
  552. rc = copy_from_oldmem(buf, src, count);
  553. if (rc)
  554. return rc;
  555. }
  556. *ppos += count;
  557. return count;
  558. }