From patchwork Mon Feb 8 16:58:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 8252271 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5DD43BEEE5 for ; Mon, 8 Feb 2016 17:01:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4EAC7203B8 for ; Mon, 8 Feb 2016 17:01:24 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39B70203B7 for ; Mon, 8 Feb 2016 17:01:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aSp8u-0005S6-CC; Mon, 08 Feb 2016 16:58:28 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aSp8s-0005RP-FO for xen-devel@lists.xen.org; Mon, 08 Feb 2016 16:58:26 +0000 Received: from [193.109.254.147] by server-14.bemta-14.messagelabs.com id 3D/06-07165-139C8B65; Mon, 08 Feb 2016 16:58:25 +0000 X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1454950704!22014019!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59298 invoked from network); 8 Feb 2016 16:58:24 -0000 Received: from mx01.buh.bitdefender.com (HELO mx01.buh.bitdefender.com) (91.199.104.161) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Feb 2016 16:58:24 -0000 Comment: DomainKeys? See http://domainkeys.sourceforge.net/ DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=bitdefender.com; b=KRIO6I1HwFb589UvnH86uOnGvgi7kBhetuUOGOlNm8SGhAp8zlG2kG5v1JITHtlZvb7eolVDwgiyAMrqfvBI1dLV+uLY38GgBswUF7eQelVi0BC6qkGQfa9pIS/3zBn43ShU0jUjbuWmVuKAH7s4Lw9yuCcyKj/zsqZTcafWJQMqPX9OF8F0VB7MlUVlfyhOuch0YgpYy7a8Ug5fbjvyQrUTRJkSDhhnf4GRyswvsFreql0NPVpEhux8o8DI8JiUTTkBfDsURi/5ug5XoRwH2hW7R6eKTXlTDNwadFALYO02LwiUra/GHhgTK1S2OBiTfS3s58KYjkN6yDo43vOG8g==; h=Received:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:X-BitDefender-Scanner:X-BitDefender-Spam:X-BitDefender-SpamStamp:X-BitDefender-CF-Stamp; DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=bitdefender.com; h=from:to :cc:subject:date:message-id:in-reply-to:references; s=default; bh=dJtWJ5LlmuwZaGYJ9B298feKUxg=; b=rVU66QWhHe/C8fMqqF2B2jLpDN/a iEZ9qH7pkHznQpOhIIoWTGrspWEY9U3P5iWwaor7MH3eJMG1OCH+LNXZu2ThffzT 8ZqiUCRsZi+eC7SPA7h+zj7Ux3FKhNf9tXR8a72+HRbi87XVpp6kkwR5WW8QReOn KElKyW+JiexcUCDBnl2FCclnqq10KnewUMItM6sLF7DmDJ8Fg9Vw1yOVVModUydd vGPZLYwi+8Da9b5zyeOmVAuvWTWgM8JPAsp2ULAXjSvJtaLUsoiyp3tl+srOOuCg oZ5kwiADnqW1IauQXQ0xel3x/yp+N0drzqHurKwuKoZt2BR9NfPTJQPXcw== Received: (qmail 25692 invoked from network); 8 Feb 2016 18:58:21 +0200 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.buh.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 8 Feb 2016 18:58:21 +0200 Received: from smtp02.buh.bitdefender.net (unknown [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 8C4CB7FBD9 for ; Mon, 8 Feb 2016 18:58:21 +0200 (EET) Received: (qmail 31590 invoked from network); 8 Feb 2016 18:58:21 +0200 Received: from 82-137-8-119.rdsnet.ro (HELO localhost.localdomain) (czuzu@bitdefender.com@82.137.8.119) by smtp02.buh.bitdefender.net with AES128-SHA256 encrypted SMTP; 8 Feb 2016 18:58:20 +0200 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Mon, 8 Feb 2016 18:58:00 +0200 Message-Id: <1454950682-9459-6-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454950682-9459-1-git-send-email-czuzu@bitdefender.com> References: <1454950682-9459-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.4 on smtp02.buh.bitdefender.net, sigver: 7.64434 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.743, Dats: 413947, Stamp: 3], Multi: [Enabled, t: (0.000014, 0.015130)], BW: [Enabled, t: (0.000006,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.013347), Flags: 2A917CE3; NN_TP_TAG_HTTP; NN_NO_CONTENT_TYPE; NN_LEGIT_SUMM_400_WORDS; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.016293)], URL: [Enabled, t: (0.000030)], RTDA: [Enabled, t: (0.022332), Hit: No, Details: v2.3.3; Id: 2m1gha7.1aaoi8ji7.2bhj8], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Kevin Tian , Tamas K Lengyel , Keir Fraser , Ian Campbell , Razvan Cojocaru , Jun Nakajima , Andrew Cooper , Stefano Stabellini , Jan Beulich Subject: [Xen-devel] [PATCH 5/7] xen/vm-events: Move hvm_event_* functions to common-side. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: + */