]> xenbits.xensource.com Git - xen.git/commitdiff
x86/vmx: Remove vmx_save_host_msrs() and host_msr_state
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sun, 18 Dec 2016 14:56:28 +0000 (14:56 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 21 Feb 2017 11:06:39 +0000 (11:06 +0000)
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@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/hvm/vmx/vmcs.c
xen/arch/x86/hvm/vmx/vmx.c
xen/arch/x86/x86_64/traps.c
xen/include/asm-x86/hvm/vmx/vmcs.h

index 4499030d5e373287ca0a2898d76cb41bbb0320ed..e56456a069a158586d7a3b69df8d556c2f4b050a 100644 (file)
@@ -601,8 +601,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. 
index af20ff18d33a81f0024b2aff44f61956e9ab3966..468bb789c89e846e481493ac2244649613781514 100644 (file)
@@ -360,8 +360,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,
@@ -369,23 +367,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
@@ -438,7 +423,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);
 
@@ -499,15 +483,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)
@@ -521,12 +500,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);
 
@@ -539,7 +517,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);
     }
index 9f0ee0968c87cad45a56d7ad25555868a6fb2d7d..d2b76d261618b75504d948758c7b9189a7d7074d 100644 (file)
@@ -386,7 +386,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,
index 4ee01dab9b354cbc71818a554ad15893a35df4a4..2b58d5e845a08e9ca661bc98acc5117beba57930 100644 (file)
@@ -27,7 +27,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;