blob: 509bdee3ab9071c6fbdbbd5f86cf95890ea1a4a9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +01002#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/*
David Hildenbrand434b90f2021-11-08 18:31:33 -080012 * 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.
David Hildenbrandcc5f27042021-11-08 18:31:48 -080015 * Returns "false" if the pfn is not backed by a RAM page, the caller may
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010016 * handle the pfn special in this case.
17 */
David Hildenbrandcc5f27042021-11-08 18:31:48 -080018static bool xen_vmcore_pfn_is_ram(struct vmcore_cb *cb, unsigned long pfn)
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010019{
20 struct xen_hvm_get_mem_type a = {
21 .domid = DOMID_SELF,
22 .pfn = pfn,
23 };
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010024
David Hildenbrand934fadf2021-11-08 18:31:41 -080025 if (HYPERVISOR_hvm_op(HVMOP_get_mem_type, &a)) {
26 pr_warn_once("Unexpected HVMOP_get_mem_type failure\n");
David Hildenbrandcc5f27042021-11-08 18:31:48 -080027 return true;
David Hildenbrand934fadf2021-11-08 18:31:41 -080028 }
David Hildenbrandd452a482021-11-08 18:31:37 -080029 return a.mem_type != HVMMEM_mmio_dm;
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010030}
David Hildenbrandcc5f27042021-11-08 18:31:48 -080031static struct vmcore_cb xen_vmcore_cb = {
32 .pfn_is_ram = xen_vmcore_pfn_is_ram,
33};
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010034#endif
35
36static void xen_hvm_exit_mmap(struct mm_struct *mm)
37{
38 struct xen_hvm_pagetable_dying a;
39 int rc;
40
41 a.domid = DOMID_SELF;
42 a.gpa = __pa(mm->pgd);
43 rc = HYPERVISOR_hvm_op(HVMOP_pagetable_dying, &a);
44 WARN_ON_ONCE(rc < 0);
45}
46
47static int is_pagetable_dying_supported(void)
48{
49 struct xen_hvm_pagetable_dying a;
50 int rc = 0;
51
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
62void __init xen_hvm_init_mmu_ops(void)
63{
64 if (is_pagetable_dying_supported())
Juergen Gross5c835112018-08-28 09:40:19 +020065 pv_ops.mmu.exit_mmap = xen_hvm_exit_mmap;
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010066#ifdef CONFIG_PROC_VMCORE
David Hildenbrandcc5f27042021-11-08 18:31:48 -080067 register_vmcore_cb(&xen_vmcore_cb);
Vitaly Kuznetsovfeef87eb2017-03-14 18:35:47 +010068#endif
69}