1 /*
2 * include/asm-x86/monitor.h
3 *
4 * Arch-specific monitor_op domctl handler.
5 *
6 * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com)
7 * Copyright (c) 2016, Bitdefender S.R.L.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License v2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef __ASM_X86_MONITOR_H__
23 #define __ASM_X86_MONITOR_H__
24
25 #include <xen/sched.h>
26
27 #define monitor_ctrlreg_bitmask(ctrlreg_index) (1U << (ctrlreg_index))
28
29 struct monitor_msr_bitmap {
30 DECLARE_BITMAP(low, 8192);
31 DECLARE_BITMAP(hypervisor, 8192);
32 DECLARE_BITMAP(high, 8192);
33 };
34
35 static inline
arch_monitor_allow_userspace(struct domain * d,bool allow_userspace)36 void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
37 {
38 d->arch.monitor.guest_request_userspace_enabled = allow_userspace;
39 }
40
41 static inline
arch_monitor_domctl_op(struct domain * d,struct xen_domctl_monitor_op * mop)42 int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
43 {
44 int rc = 0;
45
46 switch ( mop->op )
47 {
48 case XEN_DOMCTL_MONITOR_OP_EMULATE_EACH_REP:
49 domain_pause(d);
50 /*
51 * Enabling mem_access_emulate_each_rep without a vm_event subscriber
52 * is meaningless.
53 */
54 if ( d->max_vcpus && d->vcpu[0] && d->vcpu[0]->arch.vm_event )
55 d->arch.mem_access_emulate_each_rep = !!mop->event;
56 else
57 rc = -EINVAL;
58
59 domain_unpause(d);
60 break;
61
62 case XEN_DOMCTL_MONITOR_OP_CONTROL_REGISTERS:
63 d->arch.monitor.control_register_values = true;
64 break;
65
66 default:
67 rc = -EOPNOTSUPP;
68 }
69
70 return rc;
71 }
72
arch_monitor_get_capabilities(struct domain * d)73 static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
74 {
75 uint32_t capabilities = 0;
76
77 /*
78 * At the moment only Intel and AMD HVM domains are supported. However,
79 * event delivery could be extended to PV domains.
80 */
81 if ( !is_hvm_domain(d) )
82 return capabilities;
83
84 capabilities = ((1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) |
85 (1U << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) |
86 (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) |
87 (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
88 (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
89 (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
90 (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
91 (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED) |
92 (1U << XEN_DOMCTL_MONITOR_EVENT_INGUEST_PAGEFAULT));
93
94 if ( hvm_is_singlestep_supported() )
95 capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
96
97 if ( hvm_has_set_descriptor_access_exiting() )
98 capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS);
99
100 return capabilities;
101 }
102
103 int arch_monitor_domctl_event(struct domain *d,
104 struct xen_domctl_monitor_op *mop);
105
106 #ifdef CONFIG_HVM
107
108 int arch_monitor_init_domain(struct domain *d);
109
110 void arch_monitor_cleanup_domain(struct domain *d);
111
112 #else
113
arch_monitor_init_domain(struct domain * d)114 static inline int arch_monitor_init_domain(struct domain *d)
115 {
116 return -EOPNOTSUPP;
117 }
118
arch_monitor_cleanup_domain(struct domain * d)119 static inline void arch_monitor_cleanup_domain(struct domain *d) {}
120
121 #endif
122
123 bool monitored_msr(const struct domain *d, u32 msr);
124 bool monitored_msr_onchangeonly(const struct domain *d, u32 msr);
125
126 #endif /* __ASM_X86_MONITOR_H__ */
127