mmu_hvm.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <linux/types.h>
  2. #include <linux/crash_dump.h>
  3. #include <xen/interface/xen.h>
  4. #include <xen/hvm.h>
  5. #include "mmu.h"
  6. #ifdef CONFIG_PROC_VMCORE
  7. /*
  8. * This function is used in two contexts:
  9. * - the kdump kernel has to check whether a pfn of the crashed kernel
  10. * was a ballooned page. vmcore is using this function to decide
  11. * whether to access a pfn of the crashed kernel.
  12. * - the kexec kernel has to check whether a pfn was ballooned by the
  13. * previous kernel. If the pfn is ballooned, handle it properly.
  14. * Returns 0 if the pfn is not backed by a RAM page, the caller may
  15. * handle the pfn special in this case.
  16. */
  17. static int xen_oldmem_pfn_is_ram(unsigned long pfn)
  18. {
  19. struct xen_hvm_get_mem_type a = {
  20. .domid = DOMID_SELF,
  21. .pfn = pfn,
  22. };
  23. int ram;
  24. if (HYPERVISOR_hvm_op(HVMOP_get_mem_type, &a))
  25. return -ENXIO;
  26. switch (a.mem_type) {
  27. case HVMMEM_mmio_dm:
  28. ram = 0;
  29. break;
  30. case HVMMEM_ram_rw:
  31. case HVMMEM_ram_ro:
  32. default:
  33. ram = 1;
  34. break;
  35. }
  36. return ram;
  37. }
  38. #endif
  39. static void xen_hvm_exit_mmap(struct mm_struct *mm)
  40. {
  41. struct xen_hvm_pagetable_dying a;
  42. int rc;
  43. a.domid = DOMID_SELF;
  44. a.gpa = __pa(mm->pgd);
  45. rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
  46. WARN_ON_ONCE(rc < 0);
  47. }
  48. static int is_pagetable_dying_supported(void)
  49. {
  50. struct xen_hvm_pagetable_dying a;
  51. int rc = 0;
  52. a.domid = DOMID_SELF;
  53. a.gpa = 0x00;
  54. rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
  55. if (rc < 0) {
  56. printk(KERN_DEBUG "HVMOP_pagetable_dying not supported\n");
  57. return 0;
  58. }
  59. return 1;
  60. }
  61. void __init xen_hvm_init_mmu_ops(void)
  62. {
  63. if (is_pagetable_dying_supported())
  64. pv_mmu_ops.exit_mmap = xen_hvm_exit_mmap;
  65. #ifdef CONFIG_PROC_VMCORE
  66. register_oldmem_pfn_is_ram(&xen_oldmem_pfn_is_ram);
  67. #endif
  68. }