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

[Xen-devel] [PATCH 3/9] x86/vvmx: Extract operand reading logic into operand_read()



Extract the logic for reading operands from decode_vmx_inst() into
operand_read().   Future patches will replace operand reading logic
in elsewhere with calls to operand_read().

operand_read() must explicitly handle different operand sizes to avoid
corrupting the caller's stack.   This patch should not change the overall
behaviour of the code.

Signed-off-by: Euan Harris <euan.harris@xxxxxxxxxx>
---
 xen/arch/x86/hvm/vmx/vvmx.c | 59 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index 20e5e29031..df84592490 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -361,6 +361,40 @@ static void reg_write(struct cpu_user_regs *regs,
     *pval = value;
 }
 
+static int operand_read(void *buf, struct vmx_inst_op *op,
+                        struct cpu_user_regs *regs, unsigned int bytes)
+{
+    if ( op->type == VMX_INST_MEMREG_TYPE_REG )
+    {
+        switch ( bytes )
+        {
+        case 4:
+            *(uint32_t *)buf = reg_read(regs, op->reg_idx);
+
+        case 8:
+            *(uint64_t *)buf = reg_read(regs, op->reg_idx);
+
+        default:
+            ASSERT_UNREACHABLE();
+            return X86EMUL_UNHANDLEABLE;
+        }
+
+        return X86EMUL_OKAY;
+    }
+    else
+    {
+        pagefault_info_t pfinfo;
+        int rc = hvm_copy_from_guest_linear(buf, op->mem, bytes, 0, &pfinfo);
+
+        if ( rc == HVMTRANS_bad_linear_to_gfn )
+            hvm_inject_page_fault(pfinfo.ec, pfinfo.linear);
+        if ( rc != HVMTRANS_okay )
+            return X86EMUL_EXCEPTION;
+
+        return X86EMUL_OKAY;
+    }
+}
+
 static inline u32 __n2_pin_exec_control(struct vcpu *v)
 {
     return get_vvmcs(v, PIN_BASED_VM_EXEC_CONTROL);
@@ -440,7 +474,12 @@ static int decode_vmx_inst(struct cpu_user_regs *regs,
         decode->op[0].type = VMX_INST_MEMREG_TYPE_REG;
         decode->op[0].reg_idx = info.fields.reg1;
         if ( poperandS != NULL )
-            *poperandS = reg_read(regs, decode->op[0].reg_idx);
+        {
+            int rc = operand_read(poperandS, &decode->op[0], regs,
+                                  decode->op[0].len);
+            if ( rc != X86EMUL_OKAY )
+                return rc;
+        }
     }
     else
     {
@@ -475,20 +514,16 @@ static int decode_vmx_inst(struct cpu_user_regs *regs,
               offset + size - 1 > seg.limit) )
             goto gp_fault;
 
+        decode->op[0].mem = base;
+        decode->op[0].len = size;
+
         if ( poperandS != NULL )
         {
-            pagefault_info_t pfinfo;
-            int rc = hvm_copy_from_guest_linear(poperandS, base, size,
-                                                0, &pfinfo);
-
-            if ( rc == HVMTRANS_bad_linear_to_gfn )
-                hvm_inject_page_fault(pfinfo.ec, pfinfo.linear);
-            if ( rc != HVMTRANS_okay )
-                return X86EMUL_EXCEPTION;
+            int rc = operand_read(poperandS, &decode->op[0], regs,
+                                  decode->op[0].len);
+            if ( rc != X86EMUL_OKAY )
+                return rc;
         }
-
-        decode->op[0].mem = base;
-        decode->op[0].len = size;
     }
 
     decode->op[1].type = VMX_INST_MEMREG_TYPE_REG;
-- 
2.13.6


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

 


Rackspace

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