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

[Xen-devel] [PATCH v4 6/7] X86: MSR_IA32_BNDCFGS save/restore



From ca79f76865b7d93292dc8fea280b541b56bfd5a7 Mon Sep 17 00:00:00 2001
From: Liu Jinsong <jinsong.liu@xxxxxxxxx>
Date: Mon, 2 Dec 2013 04:18:52 +0800
Subject: [PATCH v4 6/7] X86: MSR_IA32_BNDCFGS save/restore

Signed-off-by: Liu Jinsong <jinsong.liu@xxxxxxxxx>
---
 xen/arch/x86/hvm/vmx/vmx.c         |   50 +++++++++++++++++++++++++++++++++++-
 xen/include/asm-x86/hvm/vmx/vmcs.h |    2 +
 2 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index e2d19df..d18b2be 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -580,13 +580,61 @@ static int vmx_load_vmcs_ctxt(struct vcpu *v, struct 
hvm_hw_cpu *ctxt)
     return 0;
 }
 
-/* Temporarily NULL, could be added in the future */
+static bool_t vmx_has_mpx(void)
+{
+    unsigned int eax, ebx, edx, ecx = 0;
+
+    hvm_cpuid(7, &eax, &ebx, &ecx, &edx);
+
+    return !!(ebx & cpufeat_mask(X86_FEATURE_MPX));
+}
+
+static void vmx_save_msr_bndcfgs(struct vcpu *v, struct hvm_msr *ctxt)
+{
+    if ( !vmx_has_mpx() )
+        return;
+
+    ctxt->msr[ctxt->count].index = MSR_IA32_BNDCFGS;
+    vmx_vmcs_enter(v);
+    __vmread(GUEST_BNDCFGS, &ctxt->msr[ctxt->count++].val);
+    vmx_vmcs_exit(v);
+}
+
+static int vmx_load_msr_bndcfgs(struct vcpu *v, uint64_t val)
+{
+    if ( !vmx_has_mpx() )
+        return -EINVAL;
+
+    vmx_vmcs_enter(v);
+    __vmwrite(GUEST_BNDCFGS, val);
+    vmx_vmcs_exit(v);
+
+    return 0;
+}
+
 static void vmx_save_msr(struct vcpu *v, struct hvm_msr *ctxt)
 {
+    /* save MSR_IA32_BNDCFGS */
+    vmx_save_msr_bndcfgs(v, ctxt);
 }
 
 static int vmx_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
 {
+    int i;
+
+    for ( i = 0; i < ctxt->count; i++ )
+    {
+        switch ( ctxt->msr[i].index )
+        {
+        case MSR_IA32_BNDCFGS:
+            if ( vmx_load_msr_bndcfgs(v, ctxt->msr[i].val) )
+                return -EINVAL;
+            break;
+        default:
+            break;
+        }
+    }
+
     return 0;
 }
 
diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h 
b/xen/include/asm-x86/hvm/vmx/vmcs.h
index 75cd653..45dcfa1 100644
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -367,6 +367,8 @@ enum vmcs_field {
     GUEST_PDPTR2_HIGH               = 0x0000280f,
     GUEST_PDPTR3                    = 0x00002810,
     GUEST_PDPTR3_HIGH               = 0x00002811,
+    GUEST_BNDCFGS                   = 0x00002812,
+    GUEST_BNDCFGS_HIGH              = 0x00002813,
     HOST_PAT                        = 0x00002c00,
     HOST_PAT_HIGH                   = 0x00002c01,
     HOST_EFER                       = 0x00002c02,
-- 
1.7.1

Attachment: 0006-X86-MSR_IA32_BNDCFGS-save-restore.patch
Description: 0006-X86-MSR_IA32_BNDCFGS-save-restore.patch

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

 


Rackspace

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