crash_dump.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Routines for doing kexec-based kdump
  4. *
  5. * Copyright (C) 2017 Linaro Limited
  6. * Author: AKASHI Takahiro <[email protected]>
  7. */
  8. #include <linux/crash_dump.h>
  9. #include <linux/errno.h>
  10. #include <linux/io.h>
  11. #include <linux/uio.h>
  12. #include <asm/memory.h>
  13. ssize_t copy_oldmem_page(struct iov_iter *iter, unsigned long pfn,
  14. size_t csize, unsigned long offset)
  15. {
  16. void *vaddr;
  17. if (!csize)
  18. return 0;
  19. vaddr = memremap(__pfn_to_phys(pfn), PAGE_SIZE, MEMREMAP_WB);
  20. if (!vaddr)
  21. return -ENOMEM;
  22. csize = copy_to_iter(vaddr + offset, csize, iter);
  23. memunmap(vaddr);
  24. return csize;
  25. }
  26. /**
  27. * elfcorehdr_read - read from ELF core header
  28. * @buf: buffer where the data is placed
  29. * @count: number of bytes to read
  30. * @ppos: address in the memory
  31. *
  32. * This function reads @count bytes from elf core header which exists
  33. * on crash dump kernel's memory.
  34. */
  35. ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
  36. {
  37. memcpy(buf, phys_to_virt((phys_addr_t)*ppos), count);
  38. *ppos += count;
  39. return count;
  40. }