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

[Xen-changelog] [xen-unstable] vmx realmode: Emulate MSR accesses.



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1201772006 0
# Node ID 0d70e01c0012a0830334e99ad6e5c4ddac36329a
# Parent  a6c037d8cba3b2d600f2105a70056081bb9b37c1
vmx realmode: Emulate MSR accesses.
Signed-off-by: Nitin A Kamble <nitin.a.kamble@xxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
 xen/arch/x86/hvm/vmx/realmode.c   |   48 ++++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/vmx/vmx.c        |    8 +++---
 xen/include/asm-x86/hvm/vmx/vmx.h |    2 +
 3 files changed, 54 insertions(+), 4 deletions(-)

diff -r a6c037d8cba3 -r 0d70e01c0012 xen/arch/x86/hvm/vmx/realmode.c
--- a/xen/arch/x86/hvm/vmx/realmode.c   Thu Jan 31 09:13:27 2008 +0000
+++ b/xen/arch/x86/hvm/vmx/realmode.c   Thu Jan 31 09:33:26 2008 +0000
@@ -410,6 +410,52 @@ realmode_write_cr(
     return X86EMUL_OKAY;
 }
 
+static int
+realmode_read_msr(
+    unsigned long reg,
+    uint64_t *val,
+    struct x86_emulate_ctxt *ctxt)
+{
+    struct cpu_user_regs _regs = { .ecx = (uint32_t)reg };
+
+    if ( !vmx_msr_read_intercept(&_regs) )
+    {
+        struct realmode_emulate_ctxt *rm_ctxt =
+            container_of(ctxt, struct realmode_emulate_ctxt, ctxt);
+        rm_ctxt->exn_vector = (uint8_t)__vmread(VM_ENTRY_INTR_INFO);
+        rm_ctxt->exn_insn_len = 0;
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        return X86EMUL_EXCEPTION;
+    }
+
+    *val = ((uint64_t)(uint32_t)_regs.edx << 32) || (uint32_t)_regs.eax;
+    return X86EMUL_OKAY;
+}
+
+static int
+realmode_write_msr(
+    unsigned long reg,
+    uint64_t val,
+    struct x86_emulate_ctxt *ctxt)
+{
+    struct cpu_user_regs _regs = {
+        .edx = (uint32_t)(val >> 32),
+        .eax = (uint32_t)val,
+        .ecx = (uint32_t)reg };
+
+    if ( !vmx_msr_write_intercept(&_regs) )
+    {
+        struct realmode_emulate_ctxt *rm_ctxt =
+            container_of(ctxt, struct realmode_emulate_ctxt, ctxt);
+        rm_ctxt->exn_vector = (uint8_t)__vmread(VM_ENTRY_INTR_INFO);
+        rm_ctxt->exn_insn_len = 0;
+        __vmwrite(VM_ENTRY_INTR_INFO, 0);
+        return X86EMUL_EXCEPTION;
+    }
+
+    return X86EMUL_OKAY;
+}
+
 static int realmode_write_rflags(
     unsigned long val,
     struct x86_emulate_ctxt *ctxt)
@@ -495,6 +541,8 @@ static struct x86_emulate_ops realmode_e
     .write_io      = realmode_write_io,
     .read_cr       = realmode_read_cr,
     .write_cr      = realmode_write_cr,
+    .read_msr      = realmode_read_msr,
+    .write_msr     = realmode_write_msr,
     .write_rflags  = realmode_write_rflags,
     .wbinvd        = realmode_wbinvd,
     .cpuid         = realmode_cpuid,
diff -r a6c037d8cba3 -r 0d70e01c0012 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c        Thu Jan 31 09:13:27 2008 +0000
+++ b/xen/arch/x86/hvm/vmx/vmx.c        Thu Jan 31 09:33:26 2008 +0000
@@ -2315,7 +2315,7 @@ static int is_last_branch_msr(u32 ecx)
     return 0;
 }
 
-static int vmx_do_msr_read(struct cpu_user_regs *regs)
+int vmx_msr_read_intercept(struct cpu_user_regs *regs)
 {
     u64 msr_content = 0;
     u32 ecx = regs->ecx, eax, edx;
@@ -2507,7 +2507,7 @@ extern bool_t mtrr_def_type_msr_set(stru
 extern bool_t mtrr_def_type_msr_set(struct mtrr_state *v, u64 msr_content);
 extern bool_t pat_msr_set(u64 *pat, u64 msr);
 
-static int vmx_do_msr_write(struct cpu_user_regs *regs)
+int vmx_msr_write_intercept(struct cpu_user_regs *regs)
 {
     u32 ecx = regs->ecx;
     u64 msr_content;
@@ -2949,12 +2949,12 @@ asmlinkage void vmx_vmexit_handler(struc
         break;
     case EXIT_REASON_MSR_READ:
         inst_len = __get_instruction_length(); /* Safe: RDMSR */
-        if ( vmx_do_msr_read(regs) )
+        if ( vmx_msr_read_intercept(regs) )
             __update_guest_eip(inst_len);
         break;
     case EXIT_REASON_MSR_WRITE:
         inst_len = __get_instruction_length(); /* Safe: WRMSR */
-        if ( vmx_do_msr_write(regs) )
+        if ( vmx_msr_write_intercept(regs) )
             __update_guest_eip(inst_len);
         break;
 
diff -r a6c037d8cba3 -r 0d70e01c0012 xen/include/asm-x86/hvm/vmx/vmx.h
--- a/xen/include/asm-x86/hvm/vmx/vmx.h Thu Jan 31 09:13:27 2008 +0000
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h Thu Jan 31 09:33:26 2008 +0000
@@ -37,6 +37,8 @@ void vmx_cpuid_intercept(
 void vmx_cpuid_intercept(
     unsigned int *eax, unsigned int *ebx,
     unsigned int *ecx, unsigned int *edx);
+int vmx_msr_read_intercept(struct cpu_user_regs *regs);
+int vmx_msr_write_intercept(struct cpu_user_regs *regs);
 void vmx_wbinvd_intercept(void);
 void vmx_realmode(struct cpu_user_regs *regs);
 int vmx_realmode_io_complete(void);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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