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

[Xen-devel] [PATCH 3/4] x86/vmx: Remove vmx_save_host_msrs() and host_msr_state



A pcpu's LSTAR, STAR and SYSCALL_MASK MSRs are unconditionally switched when
moving in and out of HVM vcpu context.  Two of these values are compile time
constants, and the third is directly available in an existing per-cpu
variable.

There is no need to save host state in vmx_cpu_up() into a different per-cpu
structure, so drop all the infrastructure.  vmx_restore_host_msrs() is
simplified to 3 plain WRMSR instructions.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Jun Nakajima <jun.nakajima@xxxxxxxxx>
CC: Kevin Tian <kevin.tian@xxxxxxxxx>
---
 xen/arch/x86/hvm/vmx/vmcs.c        |  2 --
 xen/arch/x86/hvm/vmx/vmx.c         | 33 +++++----------------------------
 xen/arch/x86/x86_64/traps.c        |  6 +++++-
 xen/include/asm-x86/hvm/vmx/vmcs.h |  1 -
 4 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index 62340bb..a6e1294 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -588,8 +588,6 @@ int vmx_cpu_up(void)
 
     BUG_ON(!(read_cr4() & X86_CR4_VMXE));
 
-    vmx_save_host_msrs();
-
     /* 
      * Ensure the current processor operating mode meets 
      * the requred CRO fixed bits in VMX operation. 
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index e3694b3..33e18af 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -358,8 +358,6 @@ static void vmx_vcpu_destroy(struct vcpu *v)
     passive_domain_destroy(v);
 }
 
-static DEFINE_PER_CPU(struct vmx_msr_state, host_msr_state);
-
 static const u32 msr_index[VMX_MSR_COUNT] =
 {
     [VMX_INDEX_MSR_LSTAR]        = MSR_LSTAR,
@@ -367,23 +365,10 @@ static const u32 msr_index[VMX_MSR_COUNT] =
     [VMX_INDEX_MSR_SYSCALL_MASK] = MSR_SYSCALL_MASK
 };
 
-void vmx_save_host_msrs(void)
-{
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    unsigned int i;
-
-    for ( i = 0; i < ARRAY_SIZE(msr_index); i++ )
-    {
-        ASSERT(msr_index[i]);
-        rdmsrl(msr_index[i], host_msr_state->msrs[i]);
-    }
-}
-
 #define WRITE_MSR(address) do {                                         \
         guest_msr_state->msrs[VMX_INDEX_MSR_ ## address] = msr_content; \
         __set_bit(VMX_INDEX_MSR_ ## address, &guest_msr_state->flags);  \
         wrmsrl(MSR_ ## address, msr_content);                           \
-        __set_bit(VMX_INDEX_MSR_ ## address, &host_msr_state->flags);   \
     } while ( 0 )
 
 static enum handler_return
@@ -436,7 +421,6 @@ long_mode_do_msr_write(unsigned int msr, uint64_t 
msr_content)
 {
     struct vcpu *v = current;
     struct vmx_msr_state *guest_msr_state = &v->arch.hvm_vmx.msr_state;
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
 
     HVM_DBG_LOG(DBG_LEVEL_MSR, "msr %#x content %#"PRIx64, msr, msr_content);
 
@@ -497,15 +481,10 @@ long_mode_do_msr_write(unsigned int msr, uint64_t 
msr_content)
  */
 static void vmx_restore_host_msrs(void)
 {
-    struct vmx_msr_state *host_msr_state = &this_cpu(host_msr_state);
-    int i;
-
-    while ( host_msr_state->flags )
-    {
-        i = find_first_set_bit(host_msr_state->flags);
-        wrmsrl(msr_index[i], host_msr_state->msrs[i]);
-        __clear_bit(i, &host_msr_state->flags);
-    }
+    /* Relies on the SYSCALL trampoline being at the start of the stubs. */
+    wrmsrl(MSR_STAR,         XEN_MSR_STAR);
+    wrmsrl(MSR_LSTAR,        this_cpu(stubs.addr));
+    wrmsrl(MSR_SYSCALL_MASK, XEN_SYSCALL_MASK);
 }
 
 static void vmx_save_guest_msrs(struct vcpu *v)
@@ -519,12 +498,11 @@ static void vmx_save_guest_msrs(struct vcpu *v)
 
 static void vmx_restore_guest_msrs(struct vcpu *v)
 {
-    struct vmx_msr_state *guest_msr_state, *host_msr_state;
+    struct vmx_msr_state *guest_msr_state;
     unsigned long guest_flags;
     int i;
 
     guest_msr_state = &v->arch.hvm_vmx.msr_state;
-    host_msr_state = &this_cpu(host_msr_state);
 
     wrmsrl(MSR_SHADOW_GS_BASE, v->arch.hvm_vmx.shadow_gs);
 
@@ -537,7 +515,6 @@ static void vmx_restore_guest_msrs(struct vcpu *v)
         HVM_DBG_LOG(DBG_LEVEL_2,
                     "restore guest's index %d msr %x with value %lx",
                     i, msr_index[i], guest_msr_state->msrs[i]);
-        __set_bit(i, &host_msr_state->flags);
         wrmsrl(msr_index[i], guest_msr_state->msrs[i]);
         __clear_bit(i, &guest_flags);
     }
diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c
index 5afe286..8697f1d 100644
--- a/xen/arch/x86/x86_64/traps.c
+++ b/xen/arch/x86/x86_64/traps.c
@@ -387,7 +387,11 @@ void subarch_percpu_traps_init(void)
 
     stub_page = map_domain_page(_mfn(this_cpu(stubs.mfn)));
 
-    /* Trampoline for SYSCALL entry from 64-bit mode. */
+    /*
+     * Trampoline for SYSCALL entry from 64-bit mode.  The VT-x HVM vcpu
+     * context switch logic relies on the SYSCALL trampoline being at the
+     * start of the stubs.
+     */
     wrmsrl(MSR_LSTAR, stub_va);
     offset = write_stub_trampoline(stub_page + (stub_va & ~PAGE_MASK),
                                    stub_va, stack_bottom,
diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h 
b/xen/include/asm-x86/hvm/vmx/vmcs.h
index 3eb11e7..99dde44 100644
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -28,7 +28,6 @@ extern int  vmx_cpu_up_prepare(unsigned int cpu);
 extern void vmx_cpu_dead(unsigned int cpu);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
-extern void vmx_save_host_msrs(void);
 
 struct vmcs_struct {
     u32 vmcs_revision_id;
-- 
2.1.4


_______________________________________________
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®.