[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 3/6] x86/xsaves: enable xsaves/xrstors for hvm guest
This patch enables xsaves for hvm guest, includes: 1.handle xsaves vmcs init and vmexit. 2.add logic to write/read the XSS msr. Signed-off-by: Shuai Ruan <shuai.ruan@xxxxxxxxx> --- xen/arch/x86/hvm/hvm.c | 39 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/vmx/vmcs.c | 7 ++++++- xen/arch/x86/hvm/vmx/vmx.c | 18 ++++++++++++++++++ xen/arch/x86/xstate.c | 4 ++-- xen/include/asm-x86/hvm/vmx/vmcs.h | 5 +++++ xen/include/asm-x86/hvm/vmx/vmx.h | 2 ++ xen/include/asm-x86/xstate.h | 2 +- 7 files changed, 73 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 535d622..c548679 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4269,6 +4269,10 @@ void hvm_hypervisor_cpuid_leaf(uint32_t sub_idx, } } +#define XSAVEOPT (1 << 0) +#define XSAVEC (1 << 1) +#define XGETBV1 (1 << 2) +#define XSAVES (1 << 3) void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { @@ -4355,6 +4359,34 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, *ebx = _eax + _ebx; } } + if ( count == 1 ) + { + if ( cpu_has_xsaves ) + { + *ebx = XSTATE_AREA_MIN_SIZE; + if ( v->arch.xcr0 | v->arch.msr_ia32_xss ) + for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ ) + { + if ( !((v->arch.xcr0 | v->arch.msr_ia32_xss) + & (1ULL << sub_leaf)) ) + continue; + domain_cpuid(d, input, sub_leaf, &_eax, &_ebx, &_ecx, + &_edx); + *ebx = *ebx + _eax; + } + } + else + { + *eax &= ~XSAVES; + *ebx = *ecx = *edx = 0; + } + if ( !cpu_has_xgetbv1 ) + *eax &= ~XGETBV1; + if ( !cpu_has_xsavec ) + *eax &= ~XSAVEC; + if ( !cpu_has_xsaveopt ) + *eax &= ~XSAVEOPT; + } break; case 0x80000001: @@ -4454,6 +4486,9 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content) *msr_content = v->arch.hvm_vcpu.guest_efer; break; + case MSR_IA32_XSS: + *msr_content = v->arch.msr_ia32_xss; + case MSR_IA32_TSC: *msr_content = _hvm_rdtsc_intercept(); break; @@ -4573,6 +4608,10 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content) return X86EMUL_EXCEPTION; break; + case MSR_IA32_XSS: + v->arch.msr_ia32_xss = msr_content; + break; + case MSR_IA32_TSC: hvm_set_guest_tsc(v, msr_content); break; diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 4c5ceb5..8e61e3f 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -230,7 +230,8 @@ static int vmx_init_vmcs_config(void) SECONDARY_EXEC_ENABLE_EPT | SECONDARY_EXEC_ENABLE_RDTSCP | SECONDARY_EXEC_PAUSE_LOOP_EXITING | - SECONDARY_EXEC_ENABLE_INVPCID); + SECONDARY_EXEC_ENABLE_INVPCID | + SECONDARY_EXEC_XSAVES); rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL ) opt |= SECONDARY_EXEC_ENABLE_VMCS_SHADOWING; @@ -921,6 +922,7 @@ void virtual_vmcs_vmwrite(void *vvmcs, u32 vmcs_encoding, u64 val) virtual_vmcs_exit(vvmcs); } +#define VMX_XSS_EXIT_BITMAP 0 static int construct_vmcs(struct vcpu *v) { struct domain *d = v->domain; @@ -1204,6 +1206,9 @@ static int construct_vmcs(struct vcpu *v) __vmwrite(GUEST_PAT, guest_pat); } + if ( cpu_has_vmx_xsaves ) + __vmwrite(XSS_EXIT_BITMAP, VMX_XSS_EXIT_BITMAP); + vmx_vmcs_exit(v); /* PVH: paging mode is updated by arch_set_info_guest(). */ diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index fc29b89..7c950b3 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2683,6 +2683,16 @@ static int vmx_handle_apic_write(void) return vlapic_apicv_write(current, exit_qualification & 0xfff); } +static void vmx_handle_xsaves(void) +{ + WARN(); +} + +static void vmx_handle_xrstors(void) +{ + WARN(); +} + void vmx_vmexit_handler(struct cpu_user_regs *regs) { unsigned long exit_qualification, exit_reason, idtv_info, intr_info = 0; @@ -3201,6 +3211,14 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) vmx_vcpu_flush_pml_buffer(v); break; + case EXIT_REASON_XSAVES: + vmx_handle_xsaves(); + break; + + case EXIT_REASON_XRSTORS: + vmx_handle_xrstors(); + break; + case EXIT_REASON_ACCESS_GDTR_OR_IDTR: case EXIT_REASON_ACCESS_LDTR_OR_TR: case EXIT_REASON_VMX_PREEMPTION_TIMER_EXPIRED: diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 571ce13..699058d 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -14,8 +14,8 @@ #include <asm/xstate.h> #include <asm/asm_defns.h> -static bool_t __read_mostly cpu_has_xsaveopt; -static bool_t __read_mostly cpu_has_xsavec; +bool_t __read_mostly cpu_has_xsaveopt; +bool_t __read_mostly cpu_has_xsavec; bool_t __read_mostly cpu_has_xgetbv1; bool_t __read_mostly cpu_has_xsaves; diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index 1104bda..2687634 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -225,6 +225,7 @@ extern u32 vmx_vmentry_control; #define SECONDARY_EXEC_ENABLE_VMFUNC 0x00002000 #define SECONDARY_EXEC_ENABLE_VMCS_SHADOWING 0x00004000 #define SECONDARY_EXEC_ENABLE_PML 0x00020000 +#define SECONDARY_EXEC_XSAVES 0x00100000 extern u32 vmx_secondary_exec_control; #define VMX_EPT_EXEC_ONLY_SUPPORTED 0x00000001 @@ -287,6 +288,8 @@ extern u32 vmx_secondary_exec_control; (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_VMCS_SHADOWING) #define cpu_has_vmx_pml \ (vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_PML) +#define cpu_has_vmx_xsaves \ + (vmx_secondary_exec_control & SECONDARY_EXEC_XSAVES) #define VMCS_RID_TYPE_MASK 0x80000000 @@ -356,6 +359,8 @@ enum vmcs_field { #define EOI_EXIT_BITMAP(n) (EOI_EXIT_BITMAP0 + (n) * 2) /* n = 0...3 */ VMREAD_BITMAP = 0x00002026, VMWRITE_BITMAP = 0x00002028, + XSS_EXIT_BITMAP = 0x0000202c, + XSS_EXIT_BITMAP_HIGH = 0x0000202d, GUEST_PHYSICAL_ADDRESS = 0x00002400, VMCS_LINK_POINTER = 0x00002800, GUEST_IA32_DEBUGCTL = 0x00002802, diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 35f804a..b4c5e73 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -187,6 +187,8 @@ static inline unsigned long pi_get_pir(struct pi_desc *pi_desc, int group) #define EXIT_REASON_APIC_WRITE 56 #define EXIT_REASON_INVPCID 58 #define EXIT_REASON_PML_FULL 62 +#define EXIT_REASON_XSAVES 63 +#define EXIT_REASON_XRSTORS 64 /* * Interruption-information format diff --git a/xen/include/asm-x86/xstate.h b/xen/include/asm-x86/xstate.h index 47c2f59..75fa6eb 100644 --- a/xen/include/asm-x86/xstate.h +++ b/xen/include/asm-x86/xstate.h @@ -44,7 +44,7 @@ #define XSTATE_COMPACTION_ENABLED (1ULL << 63) extern u64 xfeature_mask; -extern bool_t cpu_has_xsaves, cpu_has_xgetbv1; +extern bool_t cpu_has_xsaves, cpu_has_xgetbv1 ,cpu_has_xsavec, cpu_has_xsaveopt; /* extended state save area */ struct __packed __attribute__((aligned (64))) xsave_struct -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |