]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/emul: Pass a full cpuid_policy into x86_emulate()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 19 Jul 2018 15:52:06 +0000 (15:52 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 17 May 2019 15:37:46 +0000 (16:37 +0100)
This will be used to simplify feature checking.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/fuzz/x86_instruction_emulator/fuzz-emul.c
tools/tests/x86_emulator/test_x86_emulator.c
xen/arch/x86/hvm/emulate.c
xen/arch/x86/mm/shadow/common.c
xen/arch/x86/pv/emul-priv-op.c
xen/arch/x86/pv/ro-page-fault.c
xen/arch/x86/x86_emulate/x86_emulate.c
xen/arch/x86/x86_emulate/x86_emulate.h

index 8ab3626f5eb140cd6f10cf79075bca81ce61e99c..1457cd2cc56e2a5b9516a2bcdbc14681c2a01bf0 100644 (file)
@@ -830,6 +830,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
     struct x86_emulate_ctxt ctxt = {
         .data = &state,
         .regs = &input.regs,
+        .cpuid = &cp,
         .addr_size = 8 * sizeof(void *),
         .sp_size = 8 * sizeof(void *),
     };
index e9cf5f7b6ae6ffe138b0617823c3b7a0b9236619..5a59242270ac3f8fc604006bd0d4fde3aa293598 100644 (file)
@@ -472,7 +472,7 @@ int main(int argc, char **argv)
 
     ctxt.regs = &regs;
     ctxt.force_writeback = 0;
-    ctxt.vendor    = X86_VENDOR_UNKNOWN;
+    ctxt.cpuid     = &cp;
     ctxt.lma       = sizeof(void *) == 8;
     ctxt.addr_size = 8 * sizeof(void *);
     ctxt.sp_size   = 8 * sizeof(void *);
index 78cef4735963e6358c4aeccbaec7199e77446496..0c63a517e899768c00f5a507cc6450ab988fccde 100644 (file)
@@ -2594,7 +2594,7 @@ void hvm_emulate_init_once(
 
     hvmemul_ctxt->validate = validate;
     hvmemul_ctxt->ctxt.regs = regs;
-    hvmemul_ctxt->ctxt.vendor = curr->domain->arch.cpuid->x86_vendor;
+    hvmemul_ctxt->ctxt.cpuid = curr->domain->arch.cpuid;
     hvmemul_ctxt->ctxt.force_writeback = true;
 }
 
index 2d448553886d1c8a4b05e68d534d098809d7e45f..795201dc8227f5b8d0c2c18757b0fa55bdcb3277 100644 (file)
@@ -140,7 +140,7 @@ const struct x86_emulate_ops *shadow_init_emulation(
     memset(sh_ctxt, 0, sizeof(*sh_ctxt));
 
     sh_ctxt->ctxt.regs = regs;
-    sh_ctxt->ctxt.vendor = v->domain->arch.cpuid->x86_vendor;
+    sh_ctxt->ctxt.cpuid = v->domain->arch.cpuid;
     sh_ctxt->ctxt.lma = hvm_long_mode_active(v);
 
     /* Segment cache initialisation. Primed with CS. */
index af74f50dc8eec65f18b838552c6a055f773d288e..aedec5f795e00b63bf72f8f99e4e87c0bbdbfe2a 100644 (file)
@@ -1243,7 +1243,7 @@ int pv_emulate_privileged_op(struct cpu_user_regs *regs)
     struct domain *currd = curr->domain;
     struct priv_op_ctxt ctxt = {
         .ctxt.regs = regs,
-        .ctxt.vendor = currd->arch.cpuid->x86_vendor,
+        .ctxt.cpuid = currd->arch.cpuid,
         .ctxt.lma = !is_pv_32bit_domain(currd),
     };
     int rc;
index e7a7179dda2ab15fde2dbab6a60aa8b64763e54a..9d4913d9327baca564ed62bada75c06ecdbaa10a 100644 (file)
@@ -351,7 +351,7 @@ int pv_ro_page_fault(unsigned long addr, struct cpu_user_regs *regs)
     unsigned int addr_size = is_pv_32bit_domain(currd) ? 32 : BITS_PER_LONG;
     struct x86_emulate_ctxt ctxt = {
         .regs      = regs,
-        .vendor    = currd->arch.cpuid->x86_vendor,
+        .cpuid     = currd->arch.cpuid,
         .addr_size = addr_size,
         .sp_size   = addr_size,
         .lma       = addr_size > 32,
index 75ce0172dc40f44ec288f1204d3d485c97fe7121..23765e602b11d9ff069e400b9c155e645d8a88a0 100644 (file)
@@ -1930,6 +1930,7 @@ protmode_load_seg(
     struct x86_emulate_ctxt *ctxt,
     const struct x86_emulate_ops *ops)
 {
+    const struct cpuid_policy *cp = ctxt->cpuid;
     enum x86_segment sel_seg = (sel & 4) ? x86_seg_ldtr : x86_seg_gdtr;
     struct { uint32_t a, b; } desc, desc_hi = {};
     uint8_t dpl, rpl;
@@ -1954,7 +1955,7 @@ protmode_load_seg(
         case x86_seg_tr:
             goto raise_exn;
         }
-        if ( ctxt->vendor != X86_VENDOR_AMD || !ops->read_segment ||
+        if ( cp->x86_vendor != X86_VENDOR_AMD || !ops->read_segment ||
              ops->read_segment(seg, sreg, ctxt) != X86EMUL_OKAY )
             memset(sreg, 0, sizeof(*sreg));
         else
@@ -2081,7 +2082,7 @@ protmode_load_seg(
          */
         bool wide = desc.b & 0x1000
                     ? false : (desc.b & 0xf00) != 0xc00 &&
-                               ctxt->vendor != X86_VENDOR_AMD
+                               cp->x86_vendor != X86_VENDOR_AMD
                                ? mode_64bit() : ctxt->lma;
 
         if ( wide )
@@ -2099,7 +2100,7 @@ protmode_load_seg(
             default:
                 return rc;
             }
-            if ( !mode_64bit() && ctxt->vendor == X86_VENDOR_AMD &&
+            if ( !mode_64bit() && cp->x86_vendor == X86_VENDOR_AMD &&
                  (desc.b & 0xf00) != 0xc00 )
                 desc_hi.b = desc_hi.a = 0;
             if ( (desc_hi.b & 0x00001f00) ||
index 55a9e0ed5168f1d790a84e7f778daee25968d805..398df5ff09931f64a27ee3b7a1032b64c8ee67c5 100644 (file)
@@ -502,8 +502,8 @@ struct x86_emulate_ctxt
      * Input-only state:
      */
 
-    /* CPU vendor (X86_VENDOR_UNKNOWN for "don't care") */
-    unsigned char vendor;
+    /* CPUID Policy for the domain. */
+    const struct cpuid_policy *cpuid;
 
     /* Set this if writes may have side effects. */
     bool force_writeback;