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 default:
63 rc = -EOPNOTSUPP;
64 }
65
66 return rc;
67 }
68
arch_monitor_get_capabilities(struct domain * d)69 static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
70 {
71 uint32_t capabilities = 0;
72
73 /*
74 * At the moment only Intel HVM domains are supported. However, event
75 * delivery could be extended to AMD and PV domains.
76 */
77 if ( !is_hvm_domain(d) || !cpu_has_vmx )
78 return capabilities;
79
80 capabilities = (1U << XEN_DOMCTL_MONITOR_EVENT_WRITE_CTRLREG) |
81 (1U << XEN_DOMCTL_MONITOR_EVENT_MOV_TO_MSR) |
82 (1U << XEN_DOMCTL_MONITOR_EVENT_SOFTWARE_BREAKPOINT) |
83 (1U << XEN_DOMCTL_MONITOR_EVENT_GUEST_REQUEST) |
84 (1U << XEN_DOMCTL_MONITOR_EVENT_DEBUG_EXCEPTION) |
85 (1U << XEN_DOMCTL_MONITOR_EVENT_CPUID) |
86 (1U << XEN_DOMCTL_MONITOR_EVENT_INTERRUPT) |
87 (1U << XEN_DOMCTL_MONITOR_EVENT_EMUL_UNIMPLEMENTED);
88
89 /* Since we know this is on VMX, we can just call the hvm func */
90 if ( hvm_is_singlestep_supported() )
91 capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_SINGLESTEP);
92
93 if ( hvm_funcs.set_descriptor_access_exiting )
94 capabilities |= (1U << XEN_DOMCTL_MONITOR_EVENT_DESC_ACCESS);
95
96 return capabilities;
97 }
98
99 int arch_monitor_domctl_event(struct domain *d,
100 struct xen_domctl_monitor_op *mop);
101
102 int arch_monitor_init_domain(struct domain *d);
103
104 void arch_monitor_cleanup_domain(struct domain *d);
105
106 bool monitored_msr(const struct domain *d, u32 msr);
107
108 #endif /* __ASM_X86_MONITOR_H__ */
109