x86/vm_event: toggle singlestep from vm_event response
authorTamas K Lengyel <tlengyel@novetta.com>
Fri, 10 Jul 2015 12:04:21 +0000 (14:04 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 10 Jul 2015 12:04:21 +0000 (14:04 +0200)
Add an option to the vm_event response to toggle singlestepping on the vCPU.
This is only supported on Intel CPUs which have Monitor Trap Flag capability.

Signed-off-by: Tamas K Lengyel <tlengyel@novetta.com>
Acked-by: Razvan Cojocaru <rcojocaru@bitdefender.com>
Acked-by: Ian Campbell <Ian.campbell@citrix.com>
MAINTAINERS
xen/arch/x86/Makefile
xen/arch/x86/hvm/hvm.c
xen/arch/x86/vm_event.c [new file with mode: 0644]
xen/common/vm_event.c
xen/include/asm-arm/vm_event.h [new file with mode: 0644]
xen/include/asm-x86/hvm/hvm.h
xen/include/asm-x86/vm_event.h [new file with mode: 0644]
xen/include/public/vm_event.h

index e6616d2e2b55269a388f2c3e918a5b5b52ac35ac..1e746880179c318d18bb8d6352ab002cffc3f426 100644 (file)
@@ -388,6 +388,7 @@ F:  xen/common/vm_event.c
 F:     xen/common/mem_access.c
 F:     xen/arch/x86/hvm/event.c
 F:     xen/arch/x86/monitor.c
+F:     xen/arch/x86/vm_event.c
 
 XENTRACE
 M:     George Dunlap <george.dunlap@eu.citrix.com>
index 37e547cfeecf09fa3edff9c08e6fcc5c7b39782c..5f2495121f4fe452fd09fdc4045d398c2ed834f0 100644 (file)
@@ -60,6 +60,7 @@ obj-y += machine_kexec.o
 obj-y += crash.o
 obj-y += tboot.o
 obj-y += hpet.o
+obj-y += vm_event.o
 obj-y += xstate.o
 
 obj-$(crash_debug) += gdbstub.o
index 31ae4d477ff858b0c9516357e3ea9da3e695074a..ebcf7a9af637984588bf1546d006500ad88d4101 100644 (file)
@@ -6453,6 +6453,16 @@ int hvm_debug_op(struct vcpu *v, int32_t op)
     return rc;
 }
 
+void hvm_toggle_singlestep(struct vcpu *v)
+{
+    ASSERT(atomic_read(&v->pause_count));
+
+    if ( !hvm_is_singlestep_supported() )
+        return;
+
+    v->arch.hvm_vcpu.single_step = !v->arch.hvm_vcpu.single_step;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
new file mode 100644 (file)
index 0000000..c390225
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * arch/x86/vm_event.c
+ *
+ * Architecture-specific vm_event handling routines
+ *
+ * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#include <xen/sched.h>
+#include <asm/hvm/hvm.h>
+
+void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v)
+{
+    if ( !is_hvm_domain(d) || !atomic_read(&v->vm_event_pause_count) )
+        return;
+
+    hvm_toggle_singlestep(v);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 120a78a59f355adb8ee399683c14c995c0524542..a4b9c36cd66012594f65744150e57ffa108acd8a 100644 (file)
@@ -27,6 +27,7 @@
 #include <xen/vm_event.h>
 #include <xen/mem_access.h>
 #include <asm/p2m.h>
+#include <asm/vm_event.h>
 #include <xsm/xsm.h>
 
 /* for public/io/ring.h macros */
@@ -399,9 +400,13 @@ void vm_event_resume(struct domain *d, struct vm_event_domain *ved)
 
         };
 
-        /* Unpause domain. */
         if ( rsp.flags & VM_EVENT_FLAG_VCPU_PAUSED )
+        {
+            if ( rsp.flags & VM_EVENT_FLAG_TOGGLE_SINGLESTEP )
+                vm_event_toggle_singlestep(d, v);
+
             vm_event_vcpu_unpause(v);
+        }
     }
 }
 
diff --git a/xen/include/asm-arm/vm_event.h b/xen/include/asm-arm/vm_event.h
new file mode 100644 (file)
index 0000000..a517495
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * vm_event.h: architecture specific vm_event handling routines
+ *
+ * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com)
+ *
+ * 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef __ASM_ARM_VM_EVENT_H__
+#define __ASM_ARM_VM_EVENT_H__
+
+#include <xen/sched.h>
+
+static inline
+void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v)
+{
+    /* Not supported on ARM. */
+}
+
+#endif /* __ASM_ARM_VM_EVENT_H__ */
index bff47b40bba68e11525e6f1fa796c7505ec6e346..35f1300855099f2a3a8aaf8804d5904e2a0bffbc 100644 (file)
@@ -443,6 +443,9 @@ static inline void hvm_set_info_guest(struct vcpu *v)
 
 int hvm_debug_op(struct vcpu *v, int32_t op);
 
+/* Caller should pause vcpu before calling this function */
+void hvm_toggle_singlestep(struct vcpu *v);
+
 static inline void hvm_invalidate_regs_fields(struct cpu_user_regs *regs)
 {
 #ifndef NDEBUG
diff --git a/xen/include/asm-x86/vm_event.h b/xen/include/asm-x86/vm_event.h
new file mode 100644 (file)
index 0000000..7cc3a3d
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * vm_event.h: architecture specific vm_event handling routines
+ *
+ * Copyright (c) 2015 Tamas K Lengyel (tamas@tklengyel.com)
+ *
+ * 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, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef __ASM_X86_VM_EVENT_H__
+#define __ASM_X86_VM_EVENT_H__
+
+#include <xen/sched.h>
+
+void vm_event_toggle_singlestep(struct domain *d, struct vcpu *v);
+
+#endif /* __ASM_X86_VM_EVENT_H__ */
index aa22052115be346a740f8d029af393f33b01c570..c756c7cca7b69e6ab8e07353b66649564b0440f7 100644 (file)
@@ -44,9 +44,9 @@
  *  paused
  * VCPU_PAUSED in a response signals to unpause the vCPU
  */
-#define VM_EVENT_FLAG_VCPU_PAUSED     (1 << 0)
-/* Flags to aid debugging mem_event */
-#define VM_EVENT_FLAG_FOREIGN         (1 << 1)
+#define VM_EVENT_FLAG_VCPU_PAUSED       (1 << 0)
+/* Flags to aid debugging vm_event */
+#define VM_EVENT_FLAG_FOREIGN           (1 << 1)
 /*
  * The following flags can be set in response to a mem_access event.
  *
  * This will allow the guest to continue execution without lifting the page
  * access restrictions.
  */
-#define VM_EVENT_FLAG_EMULATE         (1 << 2)
+#define VM_EVENT_FLAG_EMULATE           (1 << 2)
 /*
  * Same as MEM_ACCESS_EMULATE, but with write operations or operations
  * potentially having side effects (like memory mapped or port I/O) disabled.
  */
-#define VM_EVENT_FLAG_EMULATE_NOWRITE (1 << 3)
+#define VM_EVENT_FLAG_EMULATE_NOWRITE   (1 << 3)
+/*
+ * Toggle singlestepping on vm_event response.
+ * Requires the vCPU to be paused already (synchronous events only).
+ */
+#define VM_EVENT_FLAG_TOGGLE_SINGLESTEP (1 << 4)
 
 /*
  * Reasons for the vm event request