From mboxrd@z Thu Jan 1 00:00:00 1970 From: Corneliu ZUZU Subject: [PATCH 5/7] xen/vm-events: Move hvm_event_* functions to common-side. Date: Mon, 8 Feb 2016 18:58:00 +0200 Message-ID: <1454950682-9459-6-git-send-email-czuzu@bitdefender.com> References: <1454950682-9459-1-git-send-email-czuzu@bitdefender.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1454950682-9459-1-git-send-email-czuzu@bitdefender.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Kevin Tian , Tamas K Lengyel , Keir Fraser , Ian Campbell , Razvan Cojocaru , Jun Nakajima , Andrew Cooper , Stefano Stabellini , Jan Beulich List-Id: xen-devel@lists.xenproject.org 1. Moved hvm_event_traps, hvm_event_cr, hvm_event_guest_request, hvm_event_software_breakpoint from arch-side to common-side 1.1. Moved arch/x86/hvm/event.c to common/hvm/event.c # see files: arch/x86/hvm/Makefile, xen/common/hvm/Makefile, xen/common/hvm/event.c # changes: - moved hvm_event_fill_regs to arch-side (arch_hvm_event_fill_regs) - added vcpu parameter to hvm_event_traps - surrounded common hvm_event_* implementations w/ CONFIG_HAS_VM_EVENT_* - moved hvm_event_msr to arch-side (see x86/hvm/event_x86.c) - moved rip->gfn code in hvm_event_software_breakpoint to arch-side (see arch_hvm_event_gfn_of_ip) and renamed rip param to ip - i.e. now the parameter is a 'generic' instruction pointer, rather than the Intel X86_64 RIP register) 1.2. Moved asm-x86/hvm/event.h to xen/hvm/event.h # see files: arch/x86/hvm/hvm.c, arch/x86/hvm/vmx/vmx.c 2. Added x86/hvm/event_x86.c => will rename in next commit to event.c (not done in this commit to avoid git seeing this as being the modified old event.c => keeping the same name would have rendered an unnecessarily bulky diff) # see files: arch/x86/hvm/Makefile # implements X86-specific hvm_event_msr 3. Added asm-x86/hvm/event_arch.h, asm-arm/hvm/event_arch.h (renamed to event.h in next commit, reason is the same as @ (2.). # define/implement: arch_hvm_event_fill_regs, arch_hvm_event_gfn_of_ip, hvm_event_msr (X86 side only) Signed-off-by: Corneliu ZUZU --- xen/arch/x86/hvm/Makefile | 2 +- xen/arch/x86/hvm/event.c | 203 ----------------------------------- xen/arch/x86/hvm/event_x86.c | 51 +++++++++ xen/arch/x86/hvm/hvm.c | 3 +- xen/arch/x86/hvm/vmx/vmx.c | 2 +- xen/common/hvm/Makefile | 1 + xen/common/hvm/event.c | 172 +++++++++++++++++++++++++++++ xen/include/asm-arm/hvm/event_arch.h | 40 +++++++ xen/include/asm-x86/hvm/event.h | 44 -------- xen/include/asm-x86/hvm/event_arch.h | 93 ++++++++++++++++ xen/include/xen/hvm/event.h | 71 ++++++++++++ 11 files changed, 432 insertions(+), 250 deletions(-) delete mode 100644 xen/arch/x86/hvm/event.c create mode 100644 xen/arch/x86/hvm/event_x86.c create mode 100644 xen/common/hvm/event.c create mode 100644 xen/include/asm-arm/hvm/event_arch.h delete mode 100644 xen/include/asm-x86/hvm/event.h create mode 100644 xen/include/asm-x86/hvm/event_arch.h create mode 100644 xen/include/xen/hvm/event.h diff --git a/xen/arch/x86/hvm/Makefile b/xen/arch/x86/hvm/Makefile index 794e793..15daa09 100644 --- a/xen/arch/x86/hvm/Makefile +++ b/xen/arch/x86/hvm/Makefile @@ -3,7 +3,7 @@ subdir-y += vmx obj-y += asid.o obj-y += emulate.o -obj-y += event.o +obj-y += event_x86.o obj-y += hpet.o obj-y += hvm.o obj-y += i8254.o diff --git a/xen/arch/x86/hvm/event.c b/xen/arch/x86/hvm/event.c deleted file mode 100644 index 5ffc485..0000000 --- a/xen/arch/x86/hvm/event.c +++ /dev/null @@ -1,203 +0,0 @@ -/* -* event.c: Common hardware virtual machine event abstractions. -* -* Copyright (c) 2004, Intel Corporation. -* Copyright (c) 2005, International Business Machines Corporation. -* Copyright (c) 2008, Citrix Systems, Inc. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* this program; If not, see . -*/ - -#include -#include -#include -#include -#include -#include - -static void hvm_event_fill_regs(vm_event_request_t *req) -{ - const struct cpu_user_regs *regs = guest_cpu_user_regs(); - const struct vcpu *curr = current; - - req->data.regs.x86.rax = regs->eax; - req->data.regs.x86.rcx = regs->ecx; - req->data.regs.x86.rdx = regs->edx; - req->data.regs.x86.rbx = regs->ebx; - req->data.regs.x86.rsp = regs->esp; - req->data.regs.x86.rbp = regs->ebp; - req->data.regs.x86.rsi = regs->esi; - req->data.regs.x86.rdi = regs->edi; - - req->data.regs.x86.r8 = regs->r8; - req->data.regs.x86.r9 = regs->r9; - req->data.regs.x86.r10 = regs->r10; - req->data.regs.x86.r11 = regs->r11; - req->data.regs.x86.r12 = regs->r12; - req->data.regs.x86.r13 = regs->r13; - req->data.regs.x86.r14 = regs->r14; - req->data.regs.x86.r15 = regs->r15; - - req->data.regs.x86.rflags = regs->eflags; - req->data.regs.x86.rip = regs->eip; - - req->data.regs.x86.msr_efer = curr->arch.hvm_vcpu.guest_efer; - req->data.regs.x86.cr0 = curr->arch.hvm_vcpu.guest_cr[0]; - req->data.regs.x86.cr3 = curr->arch.hvm_vcpu.guest_cr[3]; - req->data.regs.x86.cr4 = curr->arch.hvm_vcpu.guest_cr[4]; -} - -static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) -{ - int rc; - struct vcpu *curr = current; - struct domain *currd = curr->domain; - - rc = vm_event_claim_slot(currd, &currd->vm_event->monitor); - switch ( rc ) - { - case 0: - break; - case -ENOSYS: - /* - * If there was no ring to handle the event, then - * simply continue executing normally. - */ - return 1; - default: - return rc; - }; - - if ( sync ) - { - req->flags |= VM_EVENT_FLAG_VCPU_PAUSED; - vm_event_vcpu_pause(curr); - } - - if ( altp2m_active(currd) ) - { - req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M; - req->altp2m_idx = vcpu_altp2m(curr).p2midx; - } - - hvm_event_fill_regs(req); - vm_event_put_request(currd, &currd->vm_event->monitor, req); - - return 1; -} - -bool_t hvm_event_cr(unsigned int index, unsigned long value, unsigned long old) -{ - struct arch_domain *currad = ¤t->domain->arch; - unsigned int ctrlreg_bitmask = monitor_ctrlreg_bitmask(index); - - if ( (currad->monitor.write_ctrlreg_enabled & ctrlreg_bitmask) && - (!(currad->monitor.write_ctrlreg_onchangeonly & ctrlreg_bitmask) || - value != old) ) - { - vm_event_request_t req = { - .reason = VM_EVENT_REASON_WRITE_CTRLREG, - .vcpu_id = current->vcpu_id, - .u.write_ctrlreg.index = index, - .u.write_ctrlreg.new_value = value, - .u.write_ctrlreg.old_value = old - }; - - hvm_event_traps(currad->monitor.write_ctrlreg_sync & ctrlreg_bitmask, - &req); - return 1; - } - - return 0; -} - -void hvm_event_msr(unsigned int msr, uint64_t value) -{ - struct vcpu *curr = current; - vm_event_request_t req = { - .reason = VM_EVENT_REASON_MOV_TO_MSR, - .vcpu_id = curr->vcpu_id, - .u.mov_to_msr.msr = msr, - .u.mov_to_msr.value = value, - }; - - if ( curr->domain->arch.monitor.mov_to_msr_enabled ) - hvm_event_traps(1, &req); -} - -void hvm_event_guest_request(void) -{ - struct vcpu *curr = current; - struct arch_domain *currad = &curr->domain->arch; - - if ( currad->monitor.guest_request_enabled ) - { - vm_event_request_t req = { - .reason = VM_EVENT_REASON_GUEST_REQUEST, - .vcpu_id = curr->vcpu_id, - }; - - hvm_event_traps(currad->monitor.guest_request_sync, &req); - } -} - -int hvm_event_software_breakpoint(unsigned long rip, bool_t single_step) -{ - int rc = 0; - struct vcpu *curr = current; - struct arch_domain *ad = &curr->domain->arch; - bool_t enabled = ( single_step ? ad->monitor.singlestep_enabled - : ad->monitor.software_breakpoint_enabled ); - - if ( enabled ) - { - uint64_t gfn; - struct segment_register sreg; - uint32_t pfec = PFEC_page_present | PFEC_insn_fetch; - vm_event_request_t req = { - .vcpu_id = curr->vcpu_id, - }; - - hvm_get_segment_register(curr, x86_seg_ss, &sreg); - if ( sreg.attr.fields.dpl == 3 ) - pfec |= PFEC_user_mode; - - hvm_get_segment_register(curr, x86_seg_cs, &sreg); - gfn = paging_gva_to_gfn(curr, sreg.base + rip, &pfec); - - if ( single_step ) - { - req.reason = VM_EVENT_REASON_SINGLESTEP; - req.u.singlestep.gfn = gfn; - } - else - { - req.reason = VM_EVENT_REASON_SOFTWARE_BREAKPOINT; - req.u.software_breakpoint.gfn = gfn; - } - - rc = hvm_event_traps(1, &req); - } - - return rc; -} - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/arch/x86/hvm/event_x86.c b/xen/arch/x86/hvm/event_x86.c new file mode 100644 index 0000000..7b54f18 --- /dev/null +++ b/xen/arch/x86/hvm/event_x86.c @@ -0,0 +1,51 @@ +/* + * arch/x86/hvm/event_x86.c + * + * Arch-specific hardware virtual machine event abstractions. + * + * Copyright (c) 2004, Intel Corporation. + * Copyright (c) 2005, International Business Machines Corporation. + * Copyright (c) 2008, Citrix Systems, Inc. + * Copyright (c) 2016, Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#include + +void hvm_event_msr(unsigned int msr, uint64_t value) +{ + struct vcpu *curr = current; + + if ( curr->domain->arch.monitor.mov_to_msr_enabled ) + { + vm_event_request_t req = { + .reason = VM_EVENT_REASON_MOV_TO_MSR, + .vcpu_id = curr->vcpu_id, + .u.mov_to_msr.msr = msr, + .u.mov_to_msr.value = value, + }; + + hvm_event_traps(curr, 1, &req); + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 9063eb5..d90ca10 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,7 @@ #include #include #include -#include +#include #include #include /* for cpu_has_tsc_ratio */ #include diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index f7708fe..23e7bc5 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,6 @@ #include #include #include -#include #include #include #include diff --git a/xen/common/hvm/Makefile b/xen/common/hvm/Makefile index a464a57..66ae866 100644 --- a/xen/common/hvm/Makefile +++ b/xen/common/hvm/Makefile @@ -1 +1,2 @@ +obj-y += event.o obj-y += save.o diff --git a/xen/common/hvm/event.c b/xen/common/hvm/event.c new file mode 100644 index 0000000..149ea79 --- /dev/null +++ b/xen/common/hvm/event.c @@ -0,0 +1,172 @@ +/* +* xen/common/hvm/event.c +* +* Common hardware virtual machine event abstractions. +* +* Copyright (c) 2004, Intel Corporation. +* Copyright (c) 2005, International Business Machines Corporation. +* Copyright (c) 2008, Citrix Systems, Inc. +* Copyright (c) 2016, Bitdefender S.R.L. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; If not, see . +*/ + +#include +#include /* for vm_event_# calls */ +#include +#include /* for hvm_event_arch_# calls */ +#if CONFIG_X86 +#include +#endif + +int hvm_event_traps(struct vcpu *v, + uint8_t sync, + vm_event_request_t *req) +{ + int rc; + struct domain *d = v->domain; + + rc = vm_event_claim_slot(d, &d->vm_event->monitor); + switch ( rc ) + { + case 0: + break; + case -ENOSYS: + /* + * If there was no ring to handle the event, then + * simply continue executing normally. + */ + return 1; + default: + return rc; + }; + + if ( sync ) + { + req->flags |= VM_EVENT_FLAG_VCPU_PAUSED; + vm_event_vcpu_pause(v); + } + +#if CONFIG_X86 + if ( altp2m_active(d) ) + { + req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M; + req->altp2m_idx = vcpu_altp2m(v).p2midx; + } +#endif + + arch_hvm_event_fill_regs(req); + + vm_event_put_request(d, &d->vm_event->monitor, req); + + return 1; +} + +#if CONFIG_HAS_VM_EVENT_WRITE_CTRLREG + +bool_t hvm_event_cr(unsigned int index, + unsigned long value, + unsigned long old) +{ + struct vcpu *curr = current; + struct arch_domain *ad = &curr->domain->arch; + unsigned int ctrlreg_bitmask = monitor_ctrlreg_bitmask(index); + + if ( (ad->monitor.write_ctrlreg_enabled & ctrlreg_bitmask) && + (!(ad->monitor.write_ctrlreg_onchangeonly & ctrlreg_bitmask) || + value != old) ) + { + bool_t sync = !!(ad->monitor.write_ctrlreg_sync & ctrlreg_bitmask); + + vm_event_request_t req = { + .reason = VM_EVENT_REASON_WRITE_CTRLREG, + .vcpu_id = curr->vcpu_id, + .u.write_ctrlreg.index = index, + .u.write_ctrlreg.new_value = value, + .u.write_ctrlreg.old_value = old + }; + + hvm_event_traps(curr, sync, &req); + return 1; + } + + return 0; +} + +#endif // HAS_VM_EVENT_WRITE_CTRLREG + +#if CONFIG_HAS_VM_EVENT_GUEST_REQUEST + +void hvm_event_guest_request(void) +{ + struct vcpu *curr = current; + struct arch_domain *ad = &curr->domain->arch; + + if ( ad->monitor.guest_request_enabled ) + { + vm_event_request_t req = { + .reason = VM_EVENT_REASON_GUEST_REQUEST, + .vcpu_id = curr->vcpu_id, + }; + + hvm_event_traps(curr, ad->monitor.guest_request_sync, &req); + } +} + +#endif // HAS_VM_EVENT_GUEST_REQUEST + +#if CONFIG_HAS_VM_EVENT_SINGLESTEP || CONFIG_HAS_VM_EVENT_SOFTWARE_BREAKPOINT + +int hvm_event_software_breakpoint(unsigned long ip, bool_t single_step) +{ + int rc = 0; + struct vcpu *curr = current; + struct arch_domain *ad = &curr->domain->arch; + bool_t enabled = ( single_step ? ad->monitor.singlestep_enabled + : ad->monitor.software_breakpoint_enabled ); + + if ( enabled ) + { + uint64_t gfn = arch_hvm_event_gfn_of_ip(ip); + vm_event_request_t req = { + .vcpu_id = curr->vcpu_id, + }; + + if ( single_step ) + { + req.reason = VM_EVENT_REASON_SINGLESTEP; + req.u.singlestep.gfn = gfn; + } + else + { + req.reason = VM_EVENT_REASON_SOFTWARE_BREAKPOINT; + req.u.software_breakpoint.gfn = gfn; + } + + rc = hvm_event_traps(curr, 1, &req); + } + + return rc; +} + +#endif // HAS_VM_EVENT_SINGLESTEP || HAS_VM_EVENT_SOFTWARE_BREAKPOINT + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-arm/hvm/event_arch.h b/xen/include/asm-arm/hvm/event_arch.h new file mode 100644 index 0000000..beebca2 --- /dev/null +++ b/xen/include/asm-arm/hvm/event_arch.h @@ -0,0 +1,40 @@ +/* + * include/asm-arm/hvm/event_arch.h + * + * Arch-specific hardware virtual machine event abstractions. + * + * Copyright (c) 2016, Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#ifndef __ASM_ARM_HVM_EVENT_ARCH_H__ +#define __ASM_ARM_HVM_EVENT_ARCH_H__ + +static inline +void arch_hvm_event_fill_regs(vm_event_request_t *req) +{ + /* Not supported on ARM. */ +} + +#endif /* __ASM_ARM_HVM_EVENT_ARCH_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-x86/hvm/event.h b/xen/include/asm-x86/hvm/event.h deleted file mode 100644 index 7c2252b..0000000 --- a/xen/include/asm-x86/hvm/event.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * event.h: Hardware virtual machine assist events. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; If not, see . - */ - -#ifndef __ASM_X86_HVM_EVENT_H__ -#define __ASM_X86_HVM_EVENT_H__ - -/* - * Called for current VCPU on crX/MSR changes by guest. - * The event might not fire if the client has subscribed to it in onchangeonly - * mode, hence the bool_t return type for control register write events. - */ -bool_t hvm_event_cr(unsigned int index, unsigned long value, - unsigned long old); -#define hvm_event_crX(what, new, old) \ - hvm_event_cr(VM_EVENT_X86_##what, new, old) -void hvm_event_msr(unsigned int msr, uint64_t value); -int hvm_event_software_breakpoint(unsigned long rip, - bool_t single_step); -void hvm_event_guest_request(void); - -#endif /* __ASM_X86_HVM_EVENT_H__ */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/include/asm-x86/hvm/event_arch.h b/xen/include/asm-x86/hvm/event_arch.h new file mode 100644 index 0000000..b9fb559 --- /dev/null +++ b/xen/include/asm-x86/hvm/event_arch.h @@ -0,0 +1,93 @@ +/* + * include/asm-x86/hvm/event_arch.h + * + * Arch-specific hardware virtual machine event abstractions. + * + * Copyright (c) 2016, Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#ifndef __ASM_X86_HVM_EVENT_ARCH_H__ +#define __ASM_X86_HVM_EVENT_ARCH_H__ + +#include +#include +#include + +static inline +void arch_hvm_event_fill_regs(vm_event_request_t *req) +{ + const struct cpu_user_regs *regs = guest_cpu_user_regs(); + const struct vcpu *curr = current; + + req->data.regs.x86.rax = regs->eax; + req->data.regs.x86.rcx = regs->ecx; + req->data.regs.x86.rdx = regs->edx; + req->data.regs.x86.rbx = regs->ebx; + req->data.regs.x86.rsp = regs->esp; + req->data.regs.x86.rbp = regs->ebp; + req->data.regs.x86.rsi = regs->esi; + req->data.regs.x86.rdi = regs->edi; + + req->data.regs.x86.r8 = regs->r8; + req->data.regs.x86.r9 = regs->r9; + req->data.regs.x86.r10 = regs->r10; + req->data.regs.x86.r11 = regs->r11; + req->data.regs.x86.r12 = regs->r12; + req->data.regs.x86.r13 = regs->r13; + req->data.regs.x86.r14 = regs->r14; + req->data.regs.x86.r15 = regs->r15; + + req->data.regs.x86.rflags = regs->eflags; + req->data.regs.x86.rip = regs->eip; + + req->data.regs.x86.msr_efer = curr->arch.hvm_vcpu.guest_efer; + req->data.regs.x86.cr0 = curr->arch.hvm_vcpu.guest_cr[0]; + req->data.regs.x86.cr3 = curr->arch.hvm_vcpu.guest_cr[3]; + req->data.regs.x86.cr4 = curr->arch.hvm_vcpu.guest_cr[4]; +} + +/* + * Returns the GFN of the given instruction pointer. + * Needed by hvm_event_software_breakpoint. + */ +static inline +uint64_t arch_hvm_event_gfn_of_ip(unsigned long ip) +{ + struct vcpu *curr = current; + struct segment_register sreg; + uint32_t pfec = PFEC_page_present | PFEC_insn_fetch; + + hvm_get_segment_register(curr, x86_seg_ss, &sreg); + if ( 3 == sreg.attr.fields.dpl ) + pfec |= PFEC_user_mode; + + hvm_get_segment_register(curr, x86_seg_cs, &sreg); + + return (uint64_t) paging_gva_to_gfn(curr, sreg.base + ip, &pfec); +} + +void hvm_event_msr(unsigned int msr, uint64_t value); + +#endif /* __ASM_X86_HVM_EVENT_ARCH_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/xen/hvm/event.h b/xen/include/xen/hvm/event.h new file mode 100644 index 0000000..85e63d6 --- /dev/null +++ b/xen/include/xen/hvm/event.h @@ -0,0 +1,71 @@ +/* + * include/xen/hvm/event.h + * + * Common hardware virtual machine event abstractions. + * + * Copyright (c) 2016, Bitdefender S.R.L. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; If not, see . + */ + +#ifndef __HVM_EVENT_H__ +#define __HVM_EVENT_H__ + +#include /* for struct vcpu */ +#include /* for vm_event_request_t */ + +#if CONFIG_HAS_VM_EVENT_WRITE_CTRLREG + +/* + * Called for current VCPU on crX/MSR changes by guest. + * The event might not fire if the client has subscribed to it in onchangeonly + * mode, hence the bool_t return type for control register write events. + */ +bool_t hvm_event_cr(unsigned int index, + unsigned long value, + unsigned long old); + +#if CONFIG_X86 +#define hvm_event_crX(what, new, old) \ + hvm_event_cr(VM_EVENT_X86_##what, new, old) +#endif + +#endif // HAS_VM_EVENT_WRITE_CTRLREG + +#if CONFIG_HAS_VM_EVENT_SINGLESTEP || CONFIG_HAS_VM_EVENT_SOFTWARE_BREAKPOINT + +int hvm_event_software_breakpoint(unsigned long ip, + bool_t single_step); +#endif // HAS_VM_EVENT_SINGLESTEP || HAS_VM_EVENT_SOFTWARE_BREAKPOINT + +#if CONFIG_HAS_VM_EVENT_GUEST_REQUEST + +void hvm_event_guest_request(void); + +#endif // HAS_VM_EVENT_GUEST_REQUEST + +int hvm_event_traps(struct vcpu *v, + uint8_t sync, + vm_event_request_t *req); + +#endif /* __HVM_EVENT_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- 2.5.0