xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] mem_event: Allow emulating an instruction that caused a page fault
@ 2013-01-17 14:02 Razvan Cojocaru
  0 siblings, 0 replies; 14+ messages in thread
From: Razvan Cojocaru @ 2013-01-17 14:02 UTC (permalink / raw)
  To: xen-devel; +Cc: tim

This patch makes it possible to emulate an instruction that triggered
a page fault (received via the mem_event API). This is done by setting
the MEM_EVENT_FLAG_EMULATE in mem_event_response_t.flags. The purpose
of this is to be able to receive several distinct page fault mem_events
for the same address, and choose which ones are allowed to go through
from dom0 userspace.

Signed-off-by: Razvan Cojocaru <rzvncj@gmail.com>

diff -r b6195e277da5 -r c5db0882bfcf xen/arch/x86/mm/p2m.c
--- a/xen/arch/x86/mm/p2m.c	Wed Jan 16 14:15:44 2013 +0000
+++ b/xen/arch/x86/mm/p2m.c	Thu Jan 17 16:01:11 2013 +0200
@@ -1309,6 +1309,17 @@ bool_t p2m_mem_access_check(paddr_t gpa,
         }
     }
 
+    if ( v->arch.hvm_vmx.mem_event_emulate )
+    {
+        struct hvm_emulate_ctxt ctx[1] = {};
+
+        v->arch.hvm_vmx.mem_event_emulate = 0;
+        hvm_emulate_prepare(ctx, guest_cpu_user_regs());
+        hvm_emulate_one(ctx);
+
+        return 1;
+    }
+
     *req_ptr = NULL;
     req = xzalloc(mem_event_request_t);
     if ( req )
@@ -1347,8 +1358,15 @@ void p2m_mem_access_resume(struct domain
     /* Pull all responses off the ring */
     while( mem_event_get_response(d, &d->mem_event->access, &rsp) )
     {
+        d->vcpu[rsp.vcpu_id]->arch.hvm_vmx.mem_event_emulate = 0;
+
         if ( rsp.flags & MEM_EVENT_FLAG_DUMMY )
             continue;
+
+        /* Mark vcpu for skipping one instruction upon rescheduling */
+        if ( rsp.flags & MEM_EVENT_FLAG_EMULATE )
+            d->vcpu[rsp.vcpu_id]->arch.hvm_vmx.mem_event_emulate = 1;
+
         /* Unpause domain */
         if ( rsp.flags & MEM_EVENT_FLAG_VCPU_PAUSED )
             vcpu_unpause(d->vcpu[rsp.vcpu_id]);
diff -r b6195e277da5 -r c5db0882bfcf xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Wed Jan 16 14:15:44 2013 +0000
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Jan 17 16:01:11 2013 +0200
@@ -125,6 +125,8 @@ struct arch_vmx_struct {
     /* Remember EFLAGS while in virtual 8086 mode */
     uint32_t             vm86_saved_eflags;
     int                  hostenv_migrated;
+    /* Should we emulate the first instruction on VCPU resume after a mem_event? */
+    uint8_t              mem_event_emulate;
 };
 
 int vmx_create_vmcs(struct vcpu *v);
diff -r b6195e277da5 -r c5db0882bfcf xen/include/public/mem_event.h
--- a/xen/include/public/mem_event.h	Wed Jan 16 14:15:44 2013 +0000
+++ b/xen/include/public/mem_event.h	Thu Jan 17 16:01:11 2013 +0200
@@ -36,6 +36,7 @@
 #define MEM_EVENT_FLAG_EVICT_FAIL   (1 << 2)
 #define MEM_EVENT_FLAG_FOREIGN      (1 << 3)
 #define MEM_EVENT_FLAG_DUMMY        (1 << 4)
+#define MEM_EVENT_FLAG_EMULATE      (1 << 5) /* Emulate the instruction that caused the current mem_event */
 
 /* Reasons for the memory event request */
 #define MEM_EVENT_REASON_UNKNOWN     0    /* typical reason */

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-01-24 11:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.21624.1358431706.1399.xen-devel@lists.xen.org>
2013-01-17 15:38 ` [PATCH V2] mem_event: Allow emulating an instruction that caused a page fault Andres Lagar-Cavilla
2013-01-17 15:50   ` Razvan Cojocaru
2013-01-21 23:13   ` Razvan Cojocaru
2013-01-22 12:31     ` Tim Deegan
2013-01-22 12:53       ` Razvan Cojocaru
2013-01-22 13:20         ` Tim Deegan
2013-01-22 13:47           ` Razvan Cojocaru
2013-01-22 14:02             ` Andres Lagar-Cavilla
2013-01-22 14:22               ` Razvan Cojocaru
2013-01-22 14:26             ` Tim Deegan
2013-01-22 14:45               ` Razvan Cojocaru
2013-01-24 11:05                 ` Tim Deegan
2013-01-24 11:34                   ` Razvan Cojocaru
2013-01-17 14:02 Razvan Cojocaru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).