crash_dump_32.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Memory preserving reboot related code.
  3. *
  4. * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
  5. * Copyright (C) IBM Corporation, 2004. All rights reserved
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/highmem.h>
  9. #include <linux/crash_dump.h>
  10. #include <asm/uaccess.h>
  11. static void *kdump_buf_page;
  12. /* Stores the physical address of elf header of crash image. */
  13. unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
  14. /**
  15. * copy_oldmem_page - copy one page from "oldmem"
  16. * @pfn: page frame number to be copied
  17. * @buf: target memory address for the copy; this can be in kernel address
  18. * space or user address space (see @userbuf)
  19. * @csize: number of bytes to copy
  20. * @offset: offset in bytes into the page (based on pfn) to begin the copy
  21. * @userbuf: if set, @buf is in user address space, use copy_to_user(),
  22. * otherwise @buf is in kernel address space, use memcpy().
  23. *
  24. * Copy a page from "oldmem". For this page, there is no pte mapped
  25. * in the current kernel. We stitch up a pte, similar to kmap_atomic.
  26. *
  27. * Calling copy_to_user() in atomic context is not desirable. Hence first
  28. * copying the data to a pre-allocated kernel page and then copying to user
  29. * space in non-atomic context.
  30. */
  31. ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
  32. size_t csize, unsigned long offset, int userbuf)
  33. {
  34. void *vaddr;
  35. if (!csize)
  36. return 0;
  37. vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
  38. if (!userbuf) {
  39. memcpy(buf, (vaddr + offset), csize);
  40. kunmap_atomic(vaddr, KM_PTE0);
  41. } else {
  42. if (!kdump_buf_page) {
  43. printk(KERN_WARNING "Kdump: Kdump buffer page not"
  44. " allocated\n");
  45. kunmap_atomic(vaddr, KM_PTE0);
  46. return -EFAULT;
  47. }
  48. copy_page(kdump_buf_page, vaddr);
  49. kunmap_atomic(vaddr, KM_PTE0);
  50. if (copy_to_user(buf, (kdump_buf_page + offset), csize))
  51. return -EFAULT;
  52. }
  53. return csize;
  54. }
  55. static int __init kdump_buf_page_init(void)
  56. {
  57. int ret = 0;
  58. kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
  59. if (!kdump_buf_page) {
  60. printk(KERN_WARNING "Kdump: Failed to allocate kdump buffer"
  61. " page\n");
  62. ret = -ENOMEM;
  63. }
  64. return ret;
  65. }
  66. arch_initcall(kdump_buf_page_init);