1 /******************************************************************************
4 * Memory event common structures.
6 * Copyright (c) 2009 by Citrix Systems, Inc. (Patrick Colp)
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #ifndef _XEN_PUBLIC_VM_EVENT_H
28 #define _XEN_PUBLIC_VM_EVENT_H
32 #define VM_EVENT_INTERFACE_VERSION 0x00000006
34 #if defined(__XEN__) || defined(__XEN_TOOLS__)
43 * VCPU_PAUSED in a request signals that the vCPU triggering the event has been
45 * VCPU_PAUSED in a response signals to unpause the vCPU
47 #define VM_EVENT_FLAG_VCPU_PAUSED (1 << 0)
48 /* Flags to aid debugging vm_event */
49 #define VM_EVENT_FLAG_FOREIGN (1 << 1)
51 * The following flags can be set in response to a mem_access event.
53 * Emulate the fault-causing instruction (if set in the event response flags).
54 * This will allow the guest to continue execution without lifting the page
55 * access restrictions.
57 #define VM_EVENT_FLAG_EMULATE (1 << 2)
59 * Same as VM_EVENT_FLAG_EMULATE, but with write operations or operations
60 * potentially having side effects (like memory mapped or port I/O) disabled.
62 #define VM_EVENT_FLAG_EMULATE_NOWRITE (1 << 3)
64 * Toggle singlestepping on vm_event response.
65 * Requires the vCPU to be paused already (synchronous events only).
67 #define VM_EVENT_FLAG_TOGGLE_SINGLESTEP (1 << 4)
69 * Data is being sent back to the hypervisor in the event response, to be
70 * returned by the read function when emulating an instruction.
71 * This flag is only useful when combined with VM_EVENT_FLAG_EMULATE
72 * and takes precedence if combined with VM_EVENT_FLAG_EMULATE_NOWRITE
73 * (i.e. if both VM_EVENT_FLAG_EMULATE_NOWRITE and
74 * VM_EVENT_FLAG_SET_EMUL_READ_DATA are set, only the latter will be honored).
76 #define VM_EVENT_FLAG_SET_EMUL_READ_DATA (1 << 5)
78 * Deny completion of the operation that triggered the event.
79 * Currently only useful for MSR and control-register write events.
80 * Requires the vCPU to be paused already (synchronous events only).
82 #define VM_EVENT_FLAG_DENY (1 << 6)
84 * This flag can be set in a request or a response
86 * On a request, indicates that the event occurred in the alternate p2m
87 * specified by the altp2m_idx request field.
89 * On a response, indicates that the VCPU should resume in the alternate p2m
90 * specified by the altp2m_idx response field if possible.
92 #define VM_EVENT_FLAG_ALTERNATE_P2M (1 << 7)
94 * Set the vCPU registers to the values in the vm_event response.
95 * At the moment x86-only, applies to EAX-EDX, ESP, EBP, ESI, EDI, R8-R15,
97 * Requires the vCPU to be paused already (synchronous events only).
99 #define VM_EVENT_FLAG_SET_REGISTERS (1 << 8)
101 * Instruction cache is being sent back to the hypervisor in the event response
102 * to be used by the emulator. This flag is only useful when combined with
103 * VM_EVENT_FLAG_EMULATE and does not take presedence if combined with
104 * VM_EVENT_FLAG_EMULATE_NOWRITE or VM_EVENT_FLAG_SET_EMUL_READ_DATA, (i.e.
105 * if any of those flags are set, only those will be honored).
107 #define VM_EVENT_FLAG_SET_EMUL_INSN_DATA (1 << 9)
109 * Have a one-shot VM_EVENT_REASON_INTERRUPT event sent for the first
110 * interrupt pending after resuming the VCPU.
112 #define VM_EVENT_FLAG_GET_NEXT_INTERRUPT (1 << 10)
114 * Execute fast singlestepping on vm_event response.
115 * Requires the vCPU to be paused already (synchronous events only).
117 * On a response requires setting the p2midx field of fast_singlestep to which
118 * Xen will switch the vCPU to on the occurance of the first singlestep, after
119 * which singlestep gets automatically disabled.
121 #define VM_EVENT_FLAG_FAST_SINGLESTEP (1 << 11)
124 * Reasons for the vm event request
128 #define VM_EVENT_REASON_UNKNOWN 0
129 /* Memory access violation */
130 #define VM_EVENT_REASON_MEM_ACCESS 1
131 /* Memory sharing event */
132 #define VM_EVENT_REASON_MEM_SHARING 2
133 /* Memory paging event */
134 #define VM_EVENT_REASON_MEM_PAGING 3
135 /* A control register was updated */
136 #define VM_EVENT_REASON_WRITE_CTRLREG 4
137 /* An MSR was updated. */
138 #define VM_EVENT_REASON_MOV_TO_MSR 5
139 /* Debug operation executed (e.g. int3) */
140 #define VM_EVENT_REASON_SOFTWARE_BREAKPOINT 6
141 /* Single-step (e.g. MTF) */
142 #define VM_EVENT_REASON_SINGLESTEP 7
143 /* An event has been requested via HVMOP_guest_request_vm_event. */
144 #define VM_EVENT_REASON_GUEST_REQUEST 8
145 /* A debug exception was caught */
146 #define VM_EVENT_REASON_DEBUG_EXCEPTION 9
148 #define VM_EVENT_REASON_CPUID 10
150 * Privileged call executed (e.g. SMC).
151 * Note: event may be generated even if SMC condition check fails on some CPUs.
152 * As this behavior is CPU-specific, users are advised to not rely on it.
153 * These kinds of events will be filtered out in future versions.
155 #define VM_EVENT_REASON_PRIVILEGED_CALL 11
156 /* An interrupt has been delivered. */
157 #define VM_EVENT_REASON_INTERRUPT 12
158 /* A descriptor table register was accessed. */
159 #define VM_EVENT_REASON_DESCRIPTOR_ACCESS 13
160 /* Current instruction is not implemented by the emulator */
161 #define VM_EVENT_REASON_EMUL_UNIMPLEMENTED 14
163 /* Supported values for the vm_event_write_ctrlreg index. */
164 #define VM_EVENT_X86_CR0 0
165 #define VM_EVENT_X86_CR3 1
166 #define VM_EVENT_X86_CR4 2
167 #define VM_EVENT_X86_XCR0 3
169 /* The limit field is right-shifted by 12 bits if .ar.g is set. */
170 struct vm_event_x86_selector_reg {
176 * Using custom vCPU structs (i.e. not hvm_hw_cpu) for both x86 and ARM
177 * so as to not fill the vm_event ring buffer too quickly.
179 struct vm_event_regs_x86 {
204 uint64_t sysenter_cs;
205 uint64_t sysenter_esp;
206 uint64_t sysenter_eip;
217 struct vm_event_x86_selector_reg cs;
218 struct vm_event_x86_selector_reg ss;
219 struct vm_event_x86_selector_reg ds;
220 struct vm_event_x86_selector_reg es;
221 struct vm_event_x86_selector_reg fs;
222 struct vm_event_x86_selector_reg gs;
235 * Only the register 'pc' can be set on a vm_event response using the
236 * VM_EVENT_FLAG_SET_REGISTERS flag.
238 struct vm_event_regs_arm {
248 * mem_access flag definitions
250 * These flags are set only as part of a mem_event request.
252 * R/W/X: Defines the type of violation that has triggered the event
253 * Multiple types can be set in a single violation!
254 * GLA_VALID: If the gla field holds a guest VA associated with the event
255 * FAULT_WITH_GLA: If the violation was triggered by accessing gla
256 * FAULT_IN_GPT: If the violation was triggered during translating gla
258 #define MEM_ACCESS_R (1 << 0)
259 #define MEM_ACCESS_W (1 << 1)
260 #define MEM_ACCESS_X (1 << 2)
261 #define MEM_ACCESS_RWX (MEM_ACCESS_R | MEM_ACCESS_W | MEM_ACCESS_X)
262 #define MEM_ACCESS_RW (MEM_ACCESS_R | MEM_ACCESS_W)
263 #define MEM_ACCESS_RX (MEM_ACCESS_R | MEM_ACCESS_X)
264 #define MEM_ACCESS_WX (MEM_ACCESS_W | MEM_ACCESS_X)
265 #define MEM_ACCESS_GLA_VALID (1 << 3)
266 #define MEM_ACCESS_FAULT_WITH_GLA (1 << 4)
267 #define MEM_ACCESS_FAULT_IN_GPT (1 << 5)
269 struct vm_event_mem_access {
272 uint64_t gla; /* if flags has MEM_ACCESS_GLA_VALID set */
273 uint32_t flags; /* MEM_ACCESS_* */
277 struct vm_event_write_ctrlreg {
284 struct vm_event_singlestep {
288 struct vm_event_fast_singlestep {
292 struct vm_event_debug {
294 uint64_t pending_dbg; /* Behaves like the VT-x PENDING_DBG field. */
295 uint32_t insn_length;
296 uint8_t type; /* HVMOP_TRAP_* */
300 struct vm_event_mov_to_msr {
306 #define VM_EVENT_DESC_IDTR 1
307 #define VM_EVENT_DESC_GDTR 2
308 #define VM_EVENT_DESC_LDTR 3
309 #define VM_EVENT_DESC_TR 4
311 struct vm_event_desc_access {
314 uint32_t instr_info; /* VMX: VMCS Instruction-Information */
316 uint64_t exit_qualification; /* VMX: VMCS Exit Qualification */
319 uint8_t descriptor; /* VM_EVENT_DESC_* */
324 struct vm_event_cpuid {
325 uint32_t insn_length;
331 struct vm_event_interrupt_x86 {
339 #define MEM_PAGING_DROP_PAGE (1 << 0)
340 #define MEM_PAGING_EVICT_FAIL (1 << 1)
342 struct vm_event_paging {
348 struct vm_event_sharing {
354 struct vm_event_emul_read_data {
356 /* The struct is used in a union with vm_event_regs_x86. */
357 uint8_t data[sizeof(struct vm_event_regs_x86) - sizeof(uint32_t)];
360 struct vm_event_emul_insn_data {
361 uint8_t data[16]; /* Has to be completely filled */
364 typedef struct vm_event_st {
365 uint32_t version; /* VM_EVENT_INTERFACE_VERSION */
366 uint32_t flags; /* VM_EVENT_FLAG_* */
367 uint32_t reason; /* VM_EVENT_REASON_* */
369 uint16_t altp2m_idx; /* may be used during request and response */
373 struct vm_event_paging mem_paging;
374 struct vm_event_sharing mem_sharing;
375 struct vm_event_mem_access mem_access;
376 struct vm_event_write_ctrlreg write_ctrlreg;
377 struct vm_event_mov_to_msr mov_to_msr;
378 struct vm_event_desc_access desc_access;
379 struct vm_event_singlestep singlestep;
380 struct vm_event_fast_singlestep fast_singlestep;
381 struct vm_event_debug software_breakpoint;
382 struct vm_event_debug debug_exception;
383 struct vm_event_cpuid cpuid;
385 struct vm_event_interrupt_x86 x86;
391 struct vm_event_regs_x86 x86;
392 struct vm_event_regs_arm arm;
396 struct vm_event_emul_read_data read;
397 struct vm_event_emul_insn_data insn;
400 } vm_event_request_t, vm_event_response_t;
402 DEFINE_RING_TYPES(vm_event, vm_event_request_t, vm_event_response_t);
404 #endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
405 #endif /* _XEN_PUBLIC_VM_EVENT_H */
410 * c-file-style: "BSD"
413 * indent-tabs-mode: nil