[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 5/7] x86: replace monitor_write_data.do_write with enum



After trapping a control-register write vm-event and -until- deciding if that
write is to be permitted or not (VM_EVENT_FLAG_DENY) and doing the actual write,
there cannot and should not be another trapped control-register write event.
That is: currently -only one- of the fields of monitor_write_data.do_write can
be true at any given moment and therefore it would be more appropriate to
replace those fields with an enum value.

Signed-off-by: Corneliu ZUZU <czuzu@xxxxxxxxxxxxxxx>
---
 xen/arch/x86/hvm/hvm.c       | 18 ++++++++-----
 xen/arch/x86/vm_event.c      | 63 ++++++++++++++------------------------------
 xen/include/asm-x86/domain.h | 20 +++++++-------
 3 files changed, 41 insertions(+), 60 deletions(-)

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 2f48846..4596662 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2156,8 +2156,9 @@ int hvm_set_cr0(unsigned long value, bool_t may_defer)
             /* The actual write will occur in vcpu_enter_write_data(), if
              * permitted.
              */
-            v->arch.vm_event->write_data.do_write.cr0 = 1;
-            v->arch.vm_event->write_data.cr0 = value;
+            ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+            v->arch.vm_event->write_data.status = MWS_CR0;
+            v->arch.vm_event->write_data.value = value;
 
             return X86EMUL_OKAY;
         }
@@ -2260,8 +2261,9 @@ int hvm_set_cr3(unsigned long value, bool_t may_defer)
             /* The actual write will occur in vcpu_enter_write_data(), if
              * permitted.
              */
-            v->arch.vm_event->write_data.do_write.cr3 = 1;
-            v->arch.vm_event->write_data.cr3 = value;
+            ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+            v->arch.vm_event->write_data.status = MWS_CR3;
+            v->arch.vm_event->write_data.value = value;
 
             return X86EMUL_OKAY;
         }
@@ -2342,8 +2344,9 @@ int hvm_set_cr4(unsigned long value, bool_t may_defer)
             /* The actual write will occur in vcpu_enter_write_data(), if
              * permitted.
              */
-            v->arch.vm_event->write_data.do_write.cr4 = 1;
-            v->arch.vm_event->write_data.cr4 = value;
+            ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+            v->arch.vm_event->write_data.status = MWS_CR4;
+            v->arch.vm_event->write_data.value = value;
 
             return X86EMUL_OKAY;
         }
@@ -3724,7 +3727,8 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t 
msr_content,
         /* The actual write will occur in vcpu_enter_write_data(), if
          * permitted.
          */
-        v->arch.vm_event->write_data.do_write.msr = 1;
+        ASSERT(MWS_NOWRITE == v->arch.vm_event->write_data.status);
+        v->arch.vm_event->write_data.status = MWS_MSR;
         v->arch.vm_event->write_data.msr = msr;
         v->arch.vm_event->write_data.value = msr_content;
 
diff --git a/xen/arch/x86/vm_event.c b/xen/arch/x86/vm_event.c
index 94b50fc..94342d5 100644
--- a/xen/arch/x86/vm_event.c
+++ b/xen/arch/x86/vm_event.c
@@ -74,30 +74,8 @@ void vm_event_register_write_resume(struct vcpu *v, 
vm_event_response_t *rsp)
     if ( (rsp->flags & VM_EVENT_FLAG_DENY) &&
          (rsp->flags & VM_EVENT_FLAG_VCPU_PAUSED) )
     {
-        struct monitor_write_data *w = &v->arch.vm_event->write_data;
-
-        ASSERT(w);
-
-        switch ( rsp->reason )
-        {
-        case VM_EVENT_REASON_MOV_TO_MSR:
-            w->do_write.msr = 0;
-            break;
-        case VM_EVENT_REASON_WRITE_CTRLREG:
-            switch ( rsp->u.write_ctrlreg.index )
-            {
-            case VM_EVENT_X86_CR0:
-                w->do_write.cr0 = 0;
-                break;
-            case VM_EVENT_X86_CR3:
-                w->do_write.cr3 = 0;
-                break;
-            case VM_EVENT_X86_CR4:
-                w->do_write.cr4 = 0;
-                break;
-            }
-            break;
-        }
+        ASSERT(v->arch.vm_event);
+        v->arch.vm_event->write_data.status = MWS_NOWRITE;
     }
 }
 
@@ -208,29 +186,28 @@ static inline void vcpu_enter_write_data(struct vcpu *v)
         v->arch.vm_event->emulate_flags = 0;
     }
 
-    if ( w->do_write.msr )
-    {
-        hvm_msr_write_intercept(w->msr, w->value, 0);
-        w->do_write.msr = 0;
-    }
-
-    if ( w->do_write.cr0 )
-    {
-        hvm_set_cr0(w->cr0, 0);
-        w->do_write.cr0 = 0;
-    }
+    if ( likely(MWS_NOWRITE == w->status) )
+        return;
 
-    if ( w->do_write.cr4 )
+    switch ( w->status )
     {
-        hvm_set_cr4(w->cr4, 0);
-        w->do_write.cr4 = 0;
+    case MWS_MSR:
+        hvm_msr_write_intercept(w->msr, w->value, 0);
+        break;
+    case MWS_CR0:
+        hvm_set_cr0(w->value, 0);
+        break;
+    case MWS_CR3:
+        hvm_set_cr3(w->value, 0);
+        break;
+    case MWS_CR4:
+        hvm_set_cr4(w->value, 0);
+        break;
+    default:
+        break;
     }
 
-    if ( w->do_write.cr3 )
-    {
-        hvm_set_cr3(w->cr3, 0);
-        w->do_write.cr3 = 0;
-    }
+    w->status = MWS_NOWRITE;
 }
 
 static inline void vcpu_enter_adjust_traps(struct vcpu *v)
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 783fa4f..0ed2761 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -259,19 +259,19 @@ struct pv_domain
     struct cpuidmasks *cpuidmasks;
 };
 
-struct monitor_write_data {
-    struct {
-        unsigned int msr : 1;
-        unsigned int cr0 : 1;
-        unsigned int cr3 : 1;
-        unsigned int cr4 : 1;
-    } do_write;
+enum monitor_write_status
+{
+    MWS_NOWRITE = 0,
+    MWS_MSR,
+    MWS_CR0,
+    MWS_CR3,
+    MWS_CR4,
+};
 
+struct monitor_write_data {
+    enum monitor_write_status status;
     uint32_t msr;
     uint64_t value;
-    uint64_t cr0;
-    uint64_t cr3;
-    uint64_t cr4;
 };
 
 struct arch_domain
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.