mmu_hvm.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/types.h>
  3. #include <linux/crash_dump.h>
  4. #include <xen/interface/xen.h>
  5. #include <xen/hvm.h>
  6. #include "mmu.h"
  7. #ifdef CONFIG_PROC_VMCORE
  8. /*
  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. * Returns "false" if the pfn is not backed by a RAM page, the caller may
  13. * handle the pfn special in this case.
  14. */
  15. static bool xen_vmcore_pfn_is_ram(struct vmcore_cb *cb, unsigned long pfn)
  16. {
  17. struct xen_hvm_get_mem_type a = {
  18. .domid = DOMID_SELF,
  19. .pfn = pfn,
  20. };
  21. if (HYPERVISOR_hvm_op(HVMOP_get_mem_type, &a)) {
  22. pr_warn_once("Unexpected HVMOP_get_mem_type failure\n");
  23. return true;
  24. }
  25. return a.mem_type != HVMMEM_mmio_dm;
  26. }
  27. static struct vmcore_cb xen_vmcore_cb = {
  28. .pfn_is_ram = xen_vmcore_pfn_is_ram,
  29. };
  30. #endif
  31. static void xen_hvm_exit_mmap(struct mm_struct *mm)
  32. {
  33. struct xen_hvm_pagetable_dying a;
  34. int rc;
  35. a.domid = DOMID_SELF;
  36. a.gpa = __pa(mm->pgd);
  37. rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
  38. WARN_ON_ONCE(rc < 0);
  39. }
  40. static int is_pagetable_dying_supported(void)
  41. {
  42. struct xen_hvm_pagetable_dying a;
  43. int rc = 0;
  44. a.domid = DOMID_SELF;
  45. a.gpa = 0x00;
  46. rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
  47. if (rc < 0) {
  48. printk(KERN_DEBUG "HVMOP_pagetable_dying not supported\n");
  49. return 0;
  50. }
  51. return 1;
  52. }
  53. void __init xen_hvm_init_mmu_ops(void)
  54. {
  55. if (is_pagetable_dying_supported())
  56. pv_ops.mmu.exit_mmap = xen_hvm_exit_mmap;
  57. #ifdef CONFIG_PROC_VMCORE
  58. register_vmcore_cb(&xen_vmcore_cb);
  59. #endif
  60. }