Joe Epstein
2011-Jan-02 22:13 UTC
[Xen-devel] [PATCH 2 of 3] mem_access changes: interface changes
* Holds the corresponding function changes to produce memory events on CR0, CR3, and CR4 changes, as well as on non-debugger INT3s. * Modified mem_event to add a reason NOTE: the included patches are based on a previous patch series from me on Dec 28th, purely for readability. To apply the patches to the repository, see the attached patch on the PATCH 0 of 3 email. Signed-off-by: Joe Epstein <jepstein98@gmail.com> diff -r 1535fee95f47 xen/include/asm-x86/hvm/hvm.h --- a/xen/include/asm-x86/hvm/hvm.h Sun Jan 02 13:19:51 2011 -0800 +++ b/xen/include/asm-x86/hvm/hvm.h Sun Jan 02 13:20:06 2011 -0800 @@ -370,4 +370,12 @@ int hvm_x2apic_msr_read(struct vcpu *v, unsigned int msr, uint64_t *msr_content); int hvm_x2apic_msr_write(struct vcpu *v, unsigned int msr, uint64_t msr_content); +/* Called for current VCPU on crX changes by guest */ +int hvm_memory_event_cr0(unsigned long value, unsigned long old); +int hvm_memory_event_cr3(unsigned long value, unsigned long old); +int hvm_memory_event_cr4(unsigned long value, unsigned long old); + +/* Called for current VCPU on int3 */ +int hvm_memory_event_int3(unsigned long gla); + #endif /* __ASM_X86_HVM_HVM_H__ */ diff -r 1535fee95f47 xen/include/asm-x86/hvm/vcpu.h --- a/xen/include/asm-x86/hvm/vcpu.h Sun Jan 02 13:19:51 2011 -0800 +++ b/xen/include/asm-x86/hvm/vcpu.h Sun Jan 02 13:20:06 2011 -0800 @@ -114,6 +114,11 @@ /* We may write up to m128 as a number of device-model transactions. */ paddr_t mmio_large_write_pa; unsigned int mmio_large_write_bytes; + + /* Pending hw/sw interrupt */ + int inject_trap; /* -1 for nothing to inject */ + int inject_error_code; + unsigned long inject_cr2; }; #endif /* __ASM_X86_HVM_VCPU_H__ */ diff -r 1535fee95f47 xen/include/public/hvm/hvm_op.h --- a/xen/include/public/hvm/hvm_op.h Sun Jan 02 13:19:51 2011 -0800 +++ b/xen/include/public/hvm/hvm_op.h Sun Jan 02 13:20:06 2011 -0800 @@ -187,7 +187,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_mem_access_t); #define HVMOP_get_mem_access 13 -/* Notify that a region of memory is to have specific access types */ +/* Get the specific access type for that region of memory */ struct xen_hvm_get_mem_access { /* Domain to be queried. */ domid_t domid; @@ -199,4 +199,22 @@ typedef struct xen_hvm_get_mem_access xen_hvm_get_mem_access_t; DEFINE_XEN_GUEST_HANDLE(xen_hvm_get_mem_access_t); +#define HVMOP_inject_trap 14 +/* Inject a trap into a VCPU, which will get taken up on the next + * scheduling of it */ +struct xen_hvm_inject_trap { + /* Domain to be queried. */ + domid_t domid; + /* VCPU */ + uint32_t vcpuid; + /* Trap number */ + uint32_t trap; + /* Error code, or -1 to skip */ + uint32_t error_code; + /* CR2 for page faults */ + uint64_t cr2; +}; +typedef struct xen_hvm_inject_trap xen_hvm_inject_trap_t; +DEFINE_XEN_GUEST_HANDLE(xen_hvm_inject_trap_t); + #endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ diff -r 1535fee95f47 xen/include/public/hvm/params.h --- a/xen/include/public/hvm/params.h Sun Jan 02 13:19:51 2011 -0800 +++ b/xen/include/public/hvm/params.h Sun Jan 02 13:20:06 2011 -0800 @@ -124,6 +124,19 @@ */ #define HVM_PARAM_ACPI_IOPORTS_LOCATION 19 -#define HVM_NR_PARAMS 20 +/* Enable blocking memory events, async or sync (pause vcpu until response) + * onchangeonly indicates messages only on a change of value */ +#define HVM_PARAM_MEMORY_EVENT_CR0 20 +#define HVM_PARAM_MEMORY_EVENT_CR3 21 +#define HVM_PARAM_MEMORY_EVENT_CR4 22 +#define HVM_PARAM_MEMORY_EVENT_INT3 23 + +#define HVMPME_MODE_MASK (3 << 0) +#define HVMPME_mode_disabled 0 +#define HVMPME_mode_async 1 +#define HVMPME_mode_sync 2 +#define HVMPME_onchangeonly (1 << 2) + +#define HVM_NR_PARAMS 24 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */ diff -r 1535fee95f47 xen/include/public/mem_event.h --- a/xen/include/public/mem_event.h Sun Jan 02 13:19:51 2011 -0800 +++ b/xen/include/public/mem_event.h Sun Jan 02 13:20:06 2011 -0800 @@ -34,6 +34,14 @@ /* Memory event flags */ #define MEM_EVENT_FLAG_VCPU_PAUSED (1 << 0) +/* Reasons for the memory event request */ +#define MEM_EVENT_REASON_UNKNOWN 0 /* typical reason */ +#define MEM_EVENT_REASON_VIOLATION 1 /* access violation, GFN is address */ +#define MEM_EVENT_REASON_CR0 2 /* CR0 was hit: gfn is CR0 value */ +#define MEM_EVENT_REASON_CR3 3 /* CR3 was hit: gfn is CR3 value */ +#define MEM_EVENT_REASON_CR4 4 /* CR4 was hit: gfn is CR4 value */ +#define MEM_EVENT_REASON_INT3 5 /* int3 was hit: gla/gfn are RIP */ + typedef struct mem_event_shared_page { uint32_t port; } mem_event_shared_page_t; @@ -49,11 +57,13 @@ uint32_t p2mt; - uint32_t access_r:1; - uint32_t access_w:1; - uint32_t access_x:1; - uint32_t gla_valid:1; - uint32_t available:28; + uint16_t access_r:1; + uint16_t access_w:1; + uint16_t access_x:1; + uint16_t gla_valid:1; + uint16_t available:12; + + uint16_t reason; } mem_event_request_t, mem_event_response_t; DEFINE_RING_TYPES(mem_event, mem_event_request_t, mem_event_response_t); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel