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

[Xen-devel] [PATCH 2/9] x86/vvmx: Unify operands in struct vmx_inst_decoded



This change prepares the way for abstracting the code which reads
memory and register operands into a generic operand_read() function in
a future patch.

Operand 1 may either be a memory location or a register, depending on
the instruction being handled.   Operand 2 may only be a register, but
it is now represented in the same way as operand 1 and so has a type
field.   This will always equal VMX_INST_MEMREG_TYPE_REG.

References to the old structure map to the new one as follows:

  mem  -> op[0].mem
  len  -> op[0].len
  reg1 -> op[0].reg
  reg2 -> op[1].reg

References to type always map to op[0].type in this patch because
previously operand 2 could only be a register and so type was never
checked when accessing it.

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

diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index 9d87786894..20e5e29031 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -195,16 +195,16 @@ bool_t nvmx_ept_enabled(struct vcpu *v)
 struct vmx_inst_decoded {
 #define VMX_INST_MEMREG_TYPE_MEMORY 0
 #define VMX_INST_MEMREG_TYPE_REG    1
-    int type;
-    union {
-        struct {
-            unsigned long mem;
-            unsigned int  len;
+    struct vmx_inst_op {
+        int type;
+        union {
+            struct {
+                unsigned long mem;
+                unsigned int  len;
+            };
+            unsigned int reg_idx;
         };
-        unsigned int reg1;
-    };
-
-    unsigned int reg2;
+    } op[2];
 };
 
 enum vmx_ops_result {
@@ -437,16 +437,16 @@ static int decode_vmx_inst(struct cpu_user_regs *regs,
     info.word = offset;
 
     if ( info.fields.memreg ) {
-        decode->type = VMX_INST_MEMREG_TYPE_REG;
-        decode->reg1 = info.fields.reg1;
+        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->reg1);
+            *poperandS = reg_read(regs, decode->op[0].reg_idx);
     }
     else
     {
         bool mode_64bit = (vmx_guest_x86_mode(v) == 8);
 
-        decode->type = VMX_INST_MEMREG_TYPE_MEMORY;
+        decode->op[0].type = VMX_INST_MEMREG_TYPE_MEMORY;
 
         if ( info.fields.segment > x86_seg_gs )
             goto gp_fault;
@@ -486,11 +486,13 @@ static int decode_vmx_inst(struct cpu_user_regs *regs,
             if ( rc != HVMTRANS_okay )
                 return X86EMUL_EXCEPTION;
         }
-        decode->mem = base;
-        decode->len = size;
+
+        decode->op[0].mem = base;
+        decode->op[0].len = size;
     }
 
-    decode->reg2 = info.fields.reg2;
+    decode->op[1].type = VMX_INST_MEMREG_TYPE_REG;
+    decode->op[1].reg_idx = info.fields.reg2;
 
     return X86EMUL_OKAY;
 
@@ -1770,7 +1772,8 @@ int nvmx_handle_vmptrst(struct cpu_user_regs *regs)
 
     gpa = nvcpu->nv_vvmcxaddr;
 
-    rc = hvm_copy_to_guest_linear(decode.mem, &gpa, decode.len, 0, &pfinfo);
+    rc = hvm_copy_to_guest_linear(decode.op[0].mem, &gpa,
+                                  decode.op[0].len, 0, &pfinfo);
     if ( rc == HVMTRANS_bad_linear_to_gfn )
         hvm_inject_page_fault(pfinfo.ec, pfinfo.linear);
     if ( rc != HVMTRANS_okay )
@@ -1850,23 +1853,24 @@ int nvmx_handle_vmread(struct cpu_user_regs *regs)
         return X86EMUL_OKAY;
     }
 
-    rc = get_vvmcs_safe(v, reg_read(regs, decode.reg2), &value);
+    rc = get_vvmcs_safe(v, reg_read(regs, decode.op[1].reg_idx), &value);
     if ( rc != VMX_INSN_SUCCEED )
     {
         vmfail(regs, rc);
         return X86EMUL_OKAY;
     }
 
-    switch ( decode.type ) {
+    switch ( decode.op[0].type ) {
     case VMX_INST_MEMREG_TYPE_MEMORY:
-        rc = hvm_copy_to_guest_linear(decode.mem, &value, decode.len, 0, 
&pfinfo);
+        rc = hvm_copy_to_guest_linear(decode.op[0].mem, &value,
+                                      decode.op[0].len, 0, &pfinfo);
         if ( rc == HVMTRANS_bad_linear_to_gfn )
             hvm_inject_page_fault(pfinfo.ec, pfinfo.linear);
         if ( rc != HVMTRANS_okay )
             return X86EMUL_EXCEPTION;
         break;
     case VMX_INST_MEMREG_TYPE_REG:
-        reg_write(regs, decode.reg1, value);
+        reg_write(regs, decode.op[0].reg_idx, value);
         break;
     }
 
@@ -1893,7 +1897,7 @@ int nvmx_handle_vmwrite(struct cpu_user_regs *regs)
         return X86EMUL_OKAY;
     }
 
-    vmcs_encoding = reg_read(regs, decode.reg2);
+    vmcs_encoding = reg_read(regs, decode.op[1].reg_idx);
     err = set_vvmcs_safe(v, vmcs_encoding, operand);
     if ( err != VMX_INSN_SUCCEED )
     {
@@ -1931,7 +1935,7 @@ int nvmx_handle_invept(struct cpu_user_regs *regs)
     if ( (ret = decode_vmx_inst(regs, &decode, &eptp, 0)) != X86EMUL_OKAY )
         return ret;
 
-    switch ( reg_read(regs, decode.reg2) )
+    switch ( reg_read(regs, decode.op[1].reg_idx) )
     {
     case INVEPT_SINGLE_CONTEXT:
     {
@@ -1959,7 +1963,7 @@ int nvmx_handle_invvpid(struct cpu_user_regs *regs)
     if ( (ret = decode_vmx_inst(regs, &decode, &vpid, 0)) != X86EMUL_OKAY )
         return ret;
 
-    switch ( reg_read(regs, decode.reg2) )
+    switch ( reg_read(regs, decode.op[1].reg_idx) )
     {
     /* Just invalidate all tlb entries for all types! */
     case INVVPID_INDIVIDUAL_ADDR:
-- 
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®.