diff options
author | Wanpeng Li <wanpeng.li@linux.intel.com> | 2014-12-02 06:14:59 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-12-05 07:57:39 -0500 |
commit | 203000993de5098c9b7da3b131cffa7978029994 (patch) | |
tree | 6ef02e8e4e5bbd6c953c56ac86f52831da0d7577 | |
parent | f53cd63c2dfcf8f306f4ed31e78840bf9a04bc0b (diff) |
kvm: vmx: add MSR logic for XSAVES
Add logic to get/set the XSS model-specific register.
Signed-off-by: Wanpeng Li <wanpeng.li@linux.intel.com>
Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | arch/x86/include/asm/kvm_host.h | 1 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 29 |
2 files changed, 29 insertions, 1 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 0271f6bcf123..0c4c88c008ce 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h | |||
@@ -362,6 +362,7 @@ struct kvm_vcpu_arch { | |||
362 | int mp_state; | 362 | int mp_state; |
363 | u64 ia32_misc_enable_msr; | 363 | u64 ia32_misc_enable_msr; |
364 | bool tpr_access_reporting; | 364 | bool tpr_access_reporting; |
365 | u64 ia32_xss; | ||
365 | 366 | ||
366 | /* | 367 | /* |
367 | * Paging state of the vcpu | 368 | * Paging state of the vcpu |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 88048c72b6b1..ad1153a725a2 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -99,6 +99,8 @@ module_param_named(enable_shadow_vmcs, enable_shadow_vmcs, bool, S_IRUGO); | |||
99 | static bool __read_mostly nested = 0; | 99 | static bool __read_mostly nested = 0; |
100 | module_param(nested, bool, S_IRUGO); | 100 | module_param(nested, bool, S_IRUGO); |
101 | 101 | ||
102 | static u64 __read_mostly host_xss; | ||
103 | |||
102 | #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD) | 104 | #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD) |
103 | #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE) | 105 | #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE) |
104 | #define KVM_VM_CR0_ALWAYS_ON \ | 106 | #define KVM_VM_CR0_ALWAYS_ON \ |
@@ -2570,6 +2572,11 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) | |||
2570 | if (!nested_vmx_allowed(vcpu)) | 2572 | if (!nested_vmx_allowed(vcpu)) |
2571 | return 1; | 2573 | return 1; |
2572 | return vmx_get_vmx_msr(vcpu, msr_index, pdata); | 2574 | return vmx_get_vmx_msr(vcpu, msr_index, pdata); |
2575 | case MSR_IA32_XSS: | ||
2576 | if (!vmx_xsaves_supported()) | ||
2577 | return 1; | ||
2578 | data = vcpu->arch.ia32_xss; | ||
2579 | break; | ||
2573 | case MSR_TSC_AUX: | 2580 | case MSR_TSC_AUX: |
2574 | if (!to_vmx(vcpu)->rdtscp_enabled) | 2581 | if (!to_vmx(vcpu)->rdtscp_enabled) |
2575 | return 1; | 2582 | return 1; |
@@ -2661,6 +2668,22 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) | |||
2661 | break; | 2668 | break; |
2662 | case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: | 2669 | case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC: |
2663 | return 1; /* they are read-only */ | 2670 | return 1; /* they are read-only */ |
2671 | case MSR_IA32_XSS: | ||
2672 | if (!vmx_xsaves_supported()) | ||
2673 | return 1; | ||
2674 | /* | ||
2675 | * The only supported bit as of Skylake is bit 8, but | ||
2676 | * it is not supported on KVM. | ||
2677 | */ | ||
2678 | if (data != 0) | ||
2679 | return 1; | ||
2680 | vcpu->arch.ia32_xss = data; | ||
2681 | if (vcpu->arch.ia32_xss != host_xss) | ||
2682 | add_atomic_switch_msr(vmx, MSR_IA32_XSS, | ||
2683 | vcpu->arch.ia32_xss, host_xss); | ||
2684 | else | ||
2685 | clear_atomic_switch_msr(vmx, MSR_IA32_XSS); | ||
2686 | break; | ||
2664 | case MSR_TSC_AUX: | 2687 | case MSR_TSC_AUX: |
2665 | if (!vmx->rdtscp_enabled) | 2688 | if (!vmx->rdtscp_enabled) |
2666 | return 1; | 2689 | return 1; |
@@ -2896,7 +2919,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) | |||
2896 | SECONDARY_EXEC_ENABLE_INVPCID | | 2919 | SECONDARY_EXEC_ENABLE_INVPCID | |
2897 | SECONDARY_EXEC_APIC_REGISTER_VIRT | | 2920 | SECONDARY_EXEC_APIC_REGISTER_VIRT | |
2898 | SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | | 2921 | SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY | |
2899 | SECONDARY_EXEC_SHADOW_VMCS; | 2922 | SECONDARY_EXEC_SHADOW_VMCS | |
2923 | SECONDARY_EXEC_XSAVES; | ||
2900 | if (adjust_vmx_controls(min2, opt2, | 2924 | if (adjust_vmx_controls(min2, opt2, |
2901 | MSR_IA32_VMX_PROCBASED_CTLS2, | 2925 | MSR_IA32_VMX_PROCBASED_CTLS2, |
2902 | &_cpu_based_2nd_exec_control) < 0) | 2926 | &_cpu_based_2nd_exec_control) < 0) |
@@ -3019,6 +3043,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) | |||
3019 | } | 3043 | } |
3020 | } | 3044 | } |
3021 | 3045 | ||
3046 | if (cpu_has_xsaves) | ||
3047 | rdmsrl(MSR_IA32_XSS, host_xss); | ||
3048 | |||
3022 | return 0; | 3049 | return 0; |
3023 | } | 3050 | } |
3024 | 3051 | ||