From: Andrew Cooper Date: Sun, 18 Dec 2016 14:56:28 +0000 (+0000) Subject: x86/vmx: Remove vmx_save_host_msrs() and host_msr_state X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~2730 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=394e66b0d04f0281b9c6231dad1377c4b9fea7d0;p=xen.git 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 Reviewed-by: Jan Beulich Acked-by: Kevin Tian --- diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 4499030d5e..e56456a069 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -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. diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index af20ff18d3..468bb789c8 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -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); } diff --git a/xen/arch/x86/x86_64/traps.c b/xen/arch/x86/x86_64/traps.c index 9f0ee0968c..d2b76d2616 100644 --- a/xen/arch/x86/x86_64/traps.c +++ b/xen/arch/x86/x86_64/traps.c @@ -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, diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index 4ee01dab9b..2b58d5e845 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -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;