All of lore.kernel.org
 help / color / mirror / Atom feed
From: Corneliu ZUZU <czuzu@bitdefender.com>
To: xen-devel@lists.xen.org
Cc: Kevin Tian <kevin.tian@intel.com>,
	Tamas K Lengyel <tamas@tklengyel.com>, Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Razvan Cojocaru <rcojocaru@bitdefender.com>,
	Jun Nakajima <jun.nakajima@intel.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Stefano Stabellini <stefano.stabellini@citrix.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH 5/7] xen/vm-events: Move hvm_event_* functions to common-side.
Date: Mon,  8 Feb 2016 18:58:00 +0200	[thread overview]
Message-ID: <1454950682-9459-6-git-send-email-czuzu@bitdefender.com> (raw)
In-Reply-To: <1454950682-9459-1-git-send-email-czuzu@bitdefender.com>

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 <czuzu@bitdefender.com>
---
 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 <http://www.gnu.org/licenses/>.
-*/
-
-#include <xen/vm_event.h>
-#include <xen/paging.h>
-#include <xen/monitor.h>
-#include <asm/hvm/event.h>
-#include <asm/altp2m.h>
-#include <public/vm_event.h>
-
-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 = &current->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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <xen/hvm/event.h>
+
+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 <xen/event.h>
 #include <xen/paging.h>
 #include <xen/monitor.h>
+#include <xen/hvm/event.h>
 #include <xen/cpu.h>
 #include <xen/wait.h>
 #include <xen/mem_access.h>
@@ -58,7 +59,7 @@
 #include <asm/hvm/cacheattr.h>
 #include <asm/hvm/trace.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/event.h>
+#include <asm/hvm/event_arch.h>
 #include <asm/hvm/vmx/vmx.h>
 #include <asm/hvm/svm/svm.h> /* for cpu_has_tsc_ratio */
 #include <asm/altp2m.h>
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 <xen/hypercall.h>
 #include <xen/perfc.h>
 #include <xen/monitor.h>
+#include <xen/hvm/event.h>
 #include <asm/current.h>
 #include <asm/io.h>
 #include <asm/iocap.h>
@@ -51,7 +52,6 @@
 #include <asm/hvm/vpt.h>
 #include <public/hvm/save.h>
 #include <asm/hvm/trace.h>
-#include <asm/hvm/event.h>
 #include <asm/xenoprof.h>
 #include <asm/debugger.h>
 #include <asm/apic.h>
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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <xen/hvm/event.h>
+#include <xen/vm_event.h>           /* for vm_event_# calls */
+#include <xen/monitor.h>
+#include <asm/hvm/event_arch.h>     /* for hvm_event_arch_# calls */
+#if CONFIG_X86
+#include <asm/altp2m.h>
+#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 <http://www.gnu.org/licenses/>.
+ */
+
+#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 <http://www.gnu.org/licenses/>.
- */
-
-#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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_X86_HVM_EVENT_ARCH_H__
+#define __ASM_X86_HVM_EVENT_ARCH_H__
+
+#include <xen/sched.h>
+#include <xen/paging.h>
+#include <public/vm_event.h>
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __HVM_EVENT_H__
+#define __HVM_EVENT_H__
+
+#include <xen/sched.h>              /* for struct vcpu */
+#include <public/vm_event.h>        /* 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

  parent reply	other threads:[~2016-02-08 16:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-08 16:57 [PATCH 0/7] Vm-events: move monitor vm-events code to common code Corneliu ZUZU
2016-02-08 16:57 ` [PATCH 1/7] arm: move arch/arm/hvm.c to arch/arm/hvm/hvm.c Corneliu ZUZU
2016-02-08 17:04   ` Andrew Cooper
2016-02-08 17:12     ` Corneliu ZUZU
2016-02-08 17:14       ` Andrew Cooper
2016-02-09 11:03   ` Stefano Stabellini
2016-02-09 11:28     ` Corneliu ZUZU
2016-02-09 11:55       ` Jan Beulich
2016-02-09 12:22         ` Stefano Stabellini
2016-02-09 12:32         ` Corneliu ZUZU
2016-02-09 17:40           ` Tamas K Lengyel
2016-02-09 19:19             ` Corneliu ZUZU
2016-02-08 16:57 ` [PATCH 2/7] x86: hvm events: merge 2 functions into 1 Corneliu ZUZU
2016-02-08 17:15   ` Andrew Cooper
2016-02-08 17:30     ` Tamas K Lengyel
2016-02-08 17:49     ` Corneliu ZUZU
2016-02-08 18:17       ` Tamas K Lengyel
2016-02-08 18:45         ` Corneliu ZUZU
2016-02-09 11:19   ` Jan Beulich
2016-02-09 11:52     ` Corneliu ZUZU
2016-02-09 12:12       ` Jan Beulich
2016-02-09 12:24         ` Corneliu ZUZU
2016-02-08 16:57 ` [PATCH 3/7] xen/vm-events: Move monitor_domctl to common-side Corneliu ZUZU
2016-02-08 18:15   ` Tamas K Lengyel
2016-02-08 18:43     ` Corneliu ZUZU
2016-02-08 18:50       ` Tamas K Lengyel
2016-02-08 16:57 ` [PATCH 4/7] Rename monitor_x86.c to monitor.c and monitor_arch.h to monitor.h Corneliu ZUZU
2016-02-08 18:18   ` Tamas K Lengyel
2016-02-08 18:55     ` Corneliu ZUZU
2016-02-08 16:58 ` Corneliu ZUZU [this message]
2016-02-08 16:58 ` [PATCH 6/7] Rename event_x86.c to event.c and event_arch.h to event.h + minor fixes Corneliu ZUZU
2016-02-08 16:58 ` [PATCH 7/7] arch.monitor: move bits to common (arch_domain to domain) Corneliu ZUZU
2016-02-08 18:29   ` Tamas K Lengyel
2016-02-09  7:14     ` Corneliu ZUZU
2016-02-08 17:06 ` [PATCH 0/7] Vm-events: move monitor vm-events code to common code Corneliu ZUZU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454950682-9459-6-git-send-email-czuzu@bitdefender.com \
    --to=czuzu@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jun.nakajima@intel.com \
    --cc=keir@xen.org \
    --cc=kevin.tian@intel.com \
    --cc=rcojocaru@bitdefender.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=tamas@tklengyel.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.