1288917Sroyger/****************************************************************************** 2288917Sroyger * vm_event.h 3288917Sroyger * 4288917Sroyger * Memory event common structures. 5288917Sroyger * 6288917Sroyger * Copyright (c) 2009 by Citrix Systems, Inc. (Patrick Colp) 7288917Sroyger * 8288917Sroyger * Permission is hereby granted, free of charge, to any person obtaining a copy 9288917Sroyger * of this software and associated documentation files (the "Software"), to 10288917Sroyger * deal in the Software without restriction, including without limitation the 11288917Sroyger * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 12288917Sroyger * sell copies of the Software, and to permit persons to whom the Software is 13288917Sroyger * furnished to do so, subject to the following conditions: 14288917Sroyger * 15288917Sroyger * The above copyright notice and this permission notice shall be included in 16288917Sroyger * all copies or substantial portions of the Software. 17288917Sroyger * 18288917Sroyger * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19288917Sroyger * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20288917Sroyger * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21288917Sroyger * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22288917Sroyger * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23288917Sroyger * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24288917Sroyger * DEALINGS IN THE SOFTWARE. 25288917Sroyger */ 26288917Sroyger 27288917Sroyger#ifndef _XEN_PUBLIC_VM_EVENT_H 28288917Sroyger#define _XEN_PUBLIC_VM_EVENT_H 29288917Sroyger 30288917Sroyger#include "xen.h" 31288917Sroyger 32288917Sroyger#define VM_EVENT_INTERFACE_VERSION 0x00000001 33288917Sroyger 34288917Sroyger#if defined(__XEN__) || defined(__XEN_TOOLS__) 35288917Sroyger 36288917Sroyger#include "io/ring.h" 37288917Sroyger 38288917Sroyger/* 39288917Sroyger * Memory event flags 40288917Sroyger */ 41288917Sroyger 42288917Sroyger/* 43288917Sroyger * VCPU_PAUSED in a request signals that the vCPU triggering the event has been 44288917Sroyger * paused 45288917Sroyger * VCPU_PAUSED in a response signals to unpause the vCPU 46288917Sroyger */ 47288917Sroyger#define VM_EVENT_FLAG_VCPU_PAUSED (1 << 0) 48288917Sroyger/* Flags to aid debugging vm_event */ 49288917Sroyger#define VM_EVENT_FLAG_FOREIGN (1 << 1) 50288917Sroyger/* 51288917Sroyger * The following flags can be set in response to a mem_access event. 52288917Sroyger * 53288917Sroyger * Emulate the fault-causing instruction (if set in the event response flags). 54288917Sroyger * This will allow the guest to continue execution without lifting the page 55288917Sroyger * access restrictions. 56288917Sroyger */ 57288917Sroyger#define VM_EVENT_FLAG_EMULATE (1 << 2) 58288917Sroyger/* 59288917Sroyger * Same as VM_EVENT_FLAG_EMULATE, but with write operations or operations 60288917Sroyger * potentially having side effects (like memory mapped or port I/O) disabled. 61288917Sroyger */ 62288917Sroyger#define VM_EVENT_FLAG_EMULATE_NOWRITE (1 << 3) 63288917Sroyger/* 64288917Sroyger * Toggle singlestepping on vm_event response. 65288917Sroyger * Requires the vCPU to be paused already (synchronous events only). 66288917Sroyger */ 67288917Sroyger#define VM_EVENT_FLAG_TOGGLE_SINGLESTEP (1 << 4) 68288917Sroyger/* 69288917Sroyger * Data is being sent back to the hypervisor in the event response, to be 70288917Sroyger * returned by the read function when emulating an instruction. 71288917Sroyger * This flag is only useful when combined with VM_EVENT_FLAG_EMULATE 72288917Sroyger * and takes precedence if combined with VM_EVENT_FLAG_EMULATE_NOWRITE 73288917Sroyger * (i.e. if both VM_EVENT_FLAG_EMULATE_NOWRITE and 74288917Sroyger * VM_EVENT_FLAG_SET_EMUL_READ_DATA are set, only the latter will be honored). 75288917Sroyger */ 76288917Sroyger#define VM_EVENT_FLAG_SET_EMUL_READ_DATA (1 << 5) 77288917Sroyger /* 78288917Sroyger * Deny completion of the operation that triggered the event. 79288917Sroyger * Currently only useful for MSR, CR0, CR3 and CR4 write events. 80288917Sroyger */ 81288917Sroyger#define VM_EVENT_FLAG_DENY (1 << 6) 82288917Sroyger/* 83288917Sroyger * This flag can be set in a request or a response 84288917Sroyger * 85288917Sroyger * On a request, indicates that the event occurred in the alternate p2m specified by 86288917Sroyger * the altp2m_idx request field. 87288917Sroyger * 88288917Sroyger * On a response, indicates that the VCPU should resume in the alternate p2m specified 89288917Sroyger * by the altp2m_idx response field if possible. 90288917Sroyger */ 91288917Sroyger#define VM_EVENT_FLAG_ALTERNATE_P2M (1 << 7) 92288917Sroyger 93288917Sroyger/* 94288917Sroyger * Reasons for the vm event request 95288917Sroyger */ 96288917Sroyger 97288917Sroyger/* Default case */ 98288917Sroyger#define VM_EVENT_REASON_UNKNOWN 0 99288917Sroyger/* Memory access violation */ 100288917Sroyger#define VM_EVENT_REASON_MEM_ACCESS 1 101288917Sroyger/* Memory sharing event */ 102288917Sroyger#define VM_EVENT_REASON_MEM_SHARING 2 103288917Sroyger/* Memory paging event */ 104288917Sroyger#define VM_EVENT_REASON_MEM_PAGING 3 105288917Sroyger/* A control register was updated */ 106288917Sroyger#define VM_EVENT_REASON_WRITE_CTRLREG 4 107288917Sroyger/* An MSR was updated. */ 108288917Sroyger#define VM_EVENT_REASON_MOV_TO_MSR 5 109288917Sroyger/* Debug operation executed (e.g. int3) */ 110288917Sroyger#define VM_EVENT_REASON_SOFTWARE_BREAKPOINT 6 111288917Sroyger/* Single-step (e.g. MTF) */ 112288917Sroyger#define VM_EVENT_REASON_SINGLESTEP 7 113288917Sroyger/* An event has been requested via HVMOP_guest_request_vm_event. */ 114288917Sroyger#define VM_EVENT_REASON_GUEST_REQUEST 8 115288917Sroyger 116288917Sroyger/* Supported values for the vm_event_write_ctrlreg index. */ 117288917Sroyger#define VM_EVENT_X86_CR0 0 118288917Sroyger#define VM_EVENT_X86_CR3 1 119288917Sroyger#define VM_EVENT_X86_CR4 2 120288917Sroyger#define VM_EVENT_X86_XCR0 3 121288917Sroyger 122288917Sroyger/* 123288917Sroyger * Using a custom struct (not hvm_hw_cpu) so as to not fill 124288917Sroyger * the vm_event ring buffer too quickly. 125288917Sroyger */ 126288917Sroygerstruct vm_event_regs_x86 { 127288917Sroyger uint64_t rax; 128288917Sroyger uint64_t rcx; 129288917Sroyger uint64_t rdx; 130288917Sroyger uint64_t rbx; 131288917Sroyger uint64_t rsp; 132288917Sroyger uint64_t rbp; 133288917Sroyger uint64_t rsi; 134288917Sroyger uint64_t rdi; 135288917Sroyger uint64_t r8; 136288917Sroyger uint64_t r9; 137288917Sroyger uint64_t r10; 138288917Sroyger uint64_t r11; 139288917Sroyger uint64_t r12; 140288917Sroyger uint64_t r13; 141288917Sroyger uint64_t r14; 142288917Sroyger uint64_t r15; 143288917Sroyger uint64_t rflags; 144288917Sroyger uint64_t dr7; 145288917Sroyger uint64_t rip; 146288917Sroyger uint64_t cr0; 147288917Sroyger uint64_t cr2; 148288917Sroyger uint64_t cr3; 149288917Sroyger uint64_t cr4; 150288917Sroyger uint64_t sysenter_cs; 151288917Sroyger uint64_t sysenter_esp; 152288917Sroyger uint64_t sysenter_eip; 153288917Sroyger uint64_t msr_efer; 154288917Sroyger uint64_t msr_star; 155288917Sroyger uint64_t msr_lstar; 156288917Sroyger uint64_t fs_base; 157288917Sroyger uint64_t gs_base; 158288917Sroyger uint32_t cs_arbytes; 159288917Sroyger uint32_t _pad; 160288917Sroyger}; 161288917Sroyger 162288917Sroyger/* 163288917Sroyger * mem_access flag definitions 164288917Sroyger * 165288917Sroyger * These flags are set only as part of a mem_event request. 166288917Sroyger * 167288917Sroyger * R/W/X: Defines the type of violation that has triggered the event 168288917Sroyger * Multiple types can be set in a single violation! 169288917Sroyger * GLA_VALID: If the gla field holds a guest VA associated with the event 170288917Sroyger * FAULT_WITH_GLA: If the violation was triggered by accessing gla 171288917Sroyger * FAULT_IN_GPT: If the violation was triggered during translating gla 172288917Sroyger */ 173288917Sroyger#define MEM_ACCESS_R (1 << 0) 174288917Sroyger#define MEM_ACCESS_W (1 << 1) 175288917Sroyger#define MEM_ACCESS_X (1 << 2) 176288917Sroyger#define MEM_ACCESS_RWX (MEM_ACCESS_R | MEM_ACCESS_W | MEM_ACCESS_X) 177288917Sroyger#define MEM_ACCESS_RW (MEM_ACCESS_R | MEM_ACCESS_W) 178288917Sroyger#define MEM_ACCESS_RX (MEM_ACCESS_R | MEM_ACCESS_X) 179288917Sroyger#define MEM_ACCESS_WX (MEM_ACCESS_W | MEM_ACCESS_X) 180288917Sroyger#define MEM_ACCESS_GLA_VALID (1 << 3) 181288917Sroyger#define MEM_ACCESS_FAULT_WITH_GLA (1 << 4) 182288917Sroyger#define MEM_ACCESS_FAULT_IN_GPT (1 << 5) 183288917Sroyger 184288917Sroygerstruct vm_event_mem_access { 185288917Sroyger uint64_t gfn; 186288917Sroyger uint64_t offset; 187288917Sroyger uint64_t gla; /* if flags has MEM_ACCESS_GLA_VALID set */ 188288917Sroyger uint32_t flags; /* MEM_ACCESS_* */ 189288917Sroyger uint32_t _pad; 190288917Sroyger}; 191288917Sroyger 192288917Sroygerstruct vm_event_write_ctrlreg { 193288917Sroyger uint32_t index; 194288917Sroyger uint32_t _pad; 195288917Sroyger uint64_t new_value; 196288917Sroyger uint64_t old_value; 197288917Sroyger}; 198288917Sroyger 199288917Sroygerstruct vm_event_debug { 200288917Sroyger uint64_t gfn; 201288917Sroyger}; 202288917Sroyger 203288917Sroygerstruct vm_event_mov_to_msr { 204288917Sroyger uint64_t msr; 205288917Sroyger uint64_t value; 206288917Sroyger}; 207288917Sroyger 208288917Sroyger#define MEM_PAGING_DROP_PAGE (1 << 0) 209288917Sroyger#define MEM_PAGING_EVICT_FAIL (1 << 1) 210288917Sroyger 211288917Sroygerstruct vm_event_paging { 212288917Sroyger uint64_t gfn; 213288917Sroyger uint32_t p2mt; 214288917Sroyger uint32_t flags; 215288917Sroyger}; 216288917Sroyger 217288917Sroygerstruct vm_event_sharing { 218288917Sroyger uint64_t gfn; 219288917Sroyger uint32_t p2mt; 220288917Sroyger uint32_t _pad; 221288917Sroyger}; 222288917Sroyger 223288917Sroygerstruct vm_event_emul_read_data { 224288917Sroyger uint32_t size; 225288917Sroyger /* The struct is used in a union with vm_event_regs_x86. */ 226288917Sroyger uint8_t data[sizeof(struct vm_event_regs_x86) - sizeof(uint32_t)]; 227288917Sroyger}; 228288917Sroyger 229288917Sroygertypedef struct vm_event_st { 230288917Sroyger uint32_t version; /* VM_EVENT_INTERFACE_VERSION */ 231288917Sroyger uint32_t flags; /* VM_EVENT_FLAG_* */ 232288917Sroyger uint32_t reason; /* VM_EVENT_REASON_* */ 233288917Sroyger uint32_t vcpu_id; 234288917Sroyger uint16_t altp2m_idx; /* may be used during request and response */ 235288917Sroyger uint16_t _pad[3]; 236288917Sroyger 237288917Sroyger union { 238288917Sroyger struct vm_event_paging mem_paging; 239288917Sroyger struct vm_event_sharing mem_sharing; 240288917Sroyger struct vm_event_mem_access mem_access; 241288917Sroyger struct vm_event_write_ctrlreg write_ctrlreg; 242288917Sroyger struct vm_event_mov_to_msr mov_to_msr; 243288917Sroyger struct vm_event_debug software_breakpoint; 244288917Sroyger struct vm_event_debug singlestep; 245288917Sroyger } u; 246288917Sroyger 247288917Sroyger union { 248288917Sroyger union { 249288917Sroyger struct vm_event_regs_x86 x86; 250288917Sroyger } regs; 251288917Sroyger 252288917Sroyger struct vm_event_emul_read_data emul_read_data; 253288917Sroyger } data; 254288917Sroyger} vm_event_request_t, vm_event_response_t; 255288917Sroyger 256288917SroygerDEFINE_RING_TYPES(vm_event, vm_event_request_t, vm_event_response_t); 257288917Sroyger 258288917Sroyger#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ 259288917Sroyger#endif /* _XEN_PUBLIC_VM_EVENT_H */ 260288917Sroyger 261288917Sroyger/* 262288917Sroyger * Local variables: 263288917Sroyger * mode: C 264288917Sroyger * c-file-style: "BSD" 265288917Sroyger * c-basic-offset: 4 266288917Sroyger * tab-width: 4 267288917Sroyger * indent-tabs-mode: nil 268288917Sroyger * End: 269288917Sroyger */ 270