]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blob - arch/x86/xen/mmu_hvm.c
x86/xen: print a warning when HVMOP_get_mem_type fails
[mirror_ubuntu-kernels.git] / arch / x86 / xen / mmu_hvm.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
3 #include <linux/crash_dump.h>
4
5 #include <xen/interface/xen.h>
6 #include <xen/hvm.h>
7
8 #include "mmu.h"
9
10 #ifdef CONFIG_PROC_VMCORE
11 /*
12 * The kdump kernel has to check whether a pfn of the crashed kernel
13 * was a ballooned page. vmcore is using this function to decide
14 * whether to access a pfn of the crashed kernel.
15 * Returns 0 if the pfn is not backed by a RAM page, the caller may
16 * handle the pfn special in this case.
17 */
18 static int xen_oldmem_pfn_is_ram(unsigned long pfn)
19 {
20 struct xen_hvm_get_mem_type a = {
21 .domid = DOMID_SELF,
22 .pfn = pfn,
23 };
24
25 if (HYPERVISOR_hvm_op(HVMOP_get_mem_type, &a)) {
26 pr_warn_once("Unexpected HVMOP_get_mem_type failure\n");
27 return -ENXIO;
28 }
29 return a.mem_type != HVMMEM_mmio_dm;
30 }
31 #endif
32
33 static void xen_hvm_exit_mmap(struct mm_struct *mm)
34 {
35 struct xen_hvm_pagetable_dying a;
36 int rc;
37
38 a.domid = DOMID_SELF;
39 a.gpa = __pa(mm->pgd);
40 rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
41 WARN_ON_ONCE(rc < 0);
42 }
43
44 static int is_pagetable_dying_supported(void)
45 {
46 struct xen_hvm_pagetable_dying a;
47 int rc = 0;
48
49 a.domid = DOMID_SELF;
50 a.gpa = 0x00;
51 rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
52 if (rc < 0) {
53 printk(KERN_DEBUG "HVMOP_pagetable_dying not supported\n");
54 return 0;
55 }
56 return 1;
57 }
58
59 void __init xen_hvm_init_mmu_ops(void)
60 {
61 if (is_pagetable_dying_supported())
62 pv_ops.mmu.exit_mmap = xen_hvm_exit_mmap;
63 #ifdef CONFIG_PROC_VMCORE
64 WARN_ON(register_oldmem_pfn_is_ram(&xen_oldmem_pfn_is_ram));
65 #endif
66 }