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

[Xen-changelog] [xen master] x86emul: support RDPID



commit 58f1bba440335870b41738b669c0680dafba7b49
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Thu Jan 19 10:33:29 2017 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Jan 19 10:33:29 2017 +0100

    x86emul: support RDPID
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 tools/tests/x86_emulator/test_x86_emulator.c | 15 +++++++++++++++
 tools/tests/x86_emulator/x86_emulate.c       |  8 +++++++-
 xen/arch/x86/x86_emulate/x86_emulate.c       | 18 +++++++++++++++++-
 xen/include/public/arch-x86/cpufeatureset.h  |  1 +
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/tools/tests/x86_emulator/test_x86_emulator.c 
b/tools/tests/x86_emulator/test_x86_emulator.c
index 5abecf4..245d1c6 100644
--- a/tools/tests/x86_emulator/test_x86_emulator.c
+++ b/tools/tests/x86_emulator/test_x86_emulator.c
@@ -158,6 +158,11 @@ static int read_msr(
     case 0xc0000080: /* EFER */
         *val = ctxt->addr_size > 32 ? 0x500 /* LME|LMA */ : 0;
         return X86EMUL_OKAY;
+
+    case 0xc0000103: /* TSC_AUX */
+#define TSC_AUX_VALUE 0xCACACACA
+        *val = TSC_AUX_VALUE;
+        return X86EMUL_OKAY;
     }
 
     return X86EMUL_UNHANDLEABLE;
@@ -1472,6 +1477,16 @@ int main(int argc, char **argv)
     else
         printf("skipped\n");
 
+    printf("%-40s", "Testing rdpid %ecx...");
+    instr[0] = 0xF3; instr[1] = 0x0f; instr[2] = 0xC7; instr[3] = 0xf9;
+    regs.eip = (unsigned long)&instr[0];
+    rc = x86_emulate(&ctxt, &emulops);
+    if ( (rc != X86EMUL_OKAY) ||
+         (regs.ecx != TSC_AUX_VALUE) ||
+         (regs.eip != (unsigned long)&instr[4]) )
+        goto fail;
+    printf("okay\n");
+
     printf("%-40s", "Testing movq %mm3,(%ecx)...");
     if ( stack_exec && cpu_has_mmx )
     {
diff --git a/tools/tests/x86_emulator/x86_emulate.c 
b/tools/tests/x86_emulator/x86_emulate.c
index 73411f8..6153262 100644
--- a/tools/tests/x86_emulator/x86_emulate.c
+++ b/tools/tests/x86_emulator/x86_emulate.c
@@ -60,9 +60,15 @@ int emul_test_cpuid(
     if ( leaf == 1 )
         res->c |= 1U << 22;
 
-    /* The emulator doesn't itself use ADCX/ADOX, so we can always run the 
test. */
+    /*
+     * The emulator doesn't itself use ADCX/ADOX/RDPID, so we can always run
+     * the respective tests.
+     */
     if ( leaf == 7 && subleaf == 0 )
+    {
         res->b |= 1U << 19;
+        res->c |= 1U << 22;
+    }
 
     return X86EMUL_OKAY;
 }
diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c 
b/xen/arch/x86/x86_emulate/x86_emulate.c
index 4f53837..6533d06 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -1367,6 +1367,7 @@ static bool vcpu_has(
 #define vcpu_has_smap()        vcpu_has(         7, EBX, 20, ctxt, ops)
 #define vcpu_has_clflushopt()  vcpu_has(         7, EBX, 23, ctxt, ops)
 #define vcpu_has_clwb()        vcpu_has(         7, EBX, 24, ctxt, ops)
+#define vcpu_has_rdpid()       vcpu_has(         7, ECX, 22, ctxt, ops)
 
 #define vcpu_must_have(feat) \
     generate_exception_if(!vcpu_has_##feat(), EXC_UD)
@@ -5800,8 +5801,23 @@ x86_emulate(
                 break;
 #endif
 
+            case 7: /* rdseed / rdpid */
+                if ( repe_prefix() ) /* rdpid */
+                {
+                    uint64_t tsc_aux;
+
+                    generate_exception_if(ea.type != OP_REG, EXC_UD);
+                    vcpu_must_have(rdpid);
+                    fail_if(!ops->read_msr);
+                    if ( (rc = ops->read_msr(MSR_TSC_AUX, &tsc_aux,
+                                             ctxt)) != X86EMUL_OKAY )
+                        goto done;
+                    dst = ea;
+                    dst.val = tsc_aux;
+                    dst.bytes = 4;
+                    break;
+                }
 #ifdef HAVE_GAS_RDSEED
-            case 7: /* rdseed */
                 generate_exception_if(rep_prefix(), EXC_UD);
                 host_and_vcpu_must_have(rdseed);
                 dst = ea;
diff --git a/xen/include/public/arch-x86/cpufeatureset.h 
b/xen/include/public/arch-x86/cpufeatureset.h
index c9b38e5..306200b 100644
--- a/xen/include/public/arch-x86/cpufeatureset.h
+++ b/xen/include/public/arch-x86/cpufeatureset.h
@@ -227,6 +227,7 @@ XEN_CPUFEATURE(AVX512VBMI,    6*32+ 1) /*A  AVX-512 Vector 
Byte Manipulation Ins
 XEN_CPUFEATURE(PKU,           6*32+ 3) /*H  Protection Keys for Userspace */
 XEN_CPUFEATURE(OSPKE,         6*32+ 4) /*!  OS Protection Keys Enable */
 XEN_CPUFEATURE(AVX512_VPOPCNTDQ, 6*32+14) /*A  POPCNT for vectors of DW/QW */
+XEN_CPUFEATURE(RDPID,         6*32+22) /*A  RDPID instruction */
 
 /* AMD-defined CPU features, CPUID level 0x80000007.edx, word 7 */
 XEN_CPUFEATURE(ITSC,          7*32+ 8) /*   Invariant TSC */
--
generated by git-patchbot for /home/xen/git/xen.git#master

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

 


Rackspace

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