crash_dump.c 15 KB

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