From be8f96d2b5e5341f40cf0c5daad5d0152185c043 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 1 Apr 2019 13:13:17 +0200 Subject: [PATCH] 4.19-stable patches added patches: kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch --- ..._ia32_arch_capabilities-on-amd-hosts.patch | 122 ++++++++++++++++++ queue-4.19/series | 1 + 2 files changed, 123 insertions(+) create mode 100644 queue-4.19/kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch diff --git a/queue-4.19/kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch b/queue-4.19/kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch new file mode 100644 index 00000000000..2bc622380b9 --- /dev/null +++ b/queue-4.19/kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch @@ -0,0 +1,122 @@ +From 0cf9135b773bf32fba9dd8e6699c1b331ee4b749 Mon Sep 17 00:00:00 2001 +From: Sean Christopherson +Date: Thu, 7 Mar 2019 15:43:02 -0800 +Subject: KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts + +From: Sean Christopherson + +commit 0cf9135b773bf32fba9dd8e6699c1b331ee4b749 upstream. + +The CPUID flag ARCH_CAPABILITIES is unconditioinally exposed to host +userspace for all x86 hosts, i.e. KVM advertises ARCH_CAPABILITIES +regardless of hardware support under the pretense that KVM fully +emulates MSR_IA32_ARCH_CAPABILITIES. Unfortunately, only VMX hosts +handle accesses to MSR_IA32_ARCH_CAPABILITIES (despite KVM_GET_MSRS +also reporting MSR_IA32_ARCH_CAPABILITIES for all hosts). + +Move the MSR_IA32_ARCH_CAPABILITIES handling to common x86 code so +that it's emulated on AMD hosts. + +Fixes: 1eaafe91a0df4 ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported") +Cc: stable@vger.kernel.org +Reported-by: Xiaoyao Li +Cc: Jim Mattson +Signed-off-by: Sean Christopherson +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman + +--- + arch/x86/include/asm/kvm_host.h | 1 + + arch/x86/kvm/vmx.c | 14 -------------- + arch/x86/kvm/x86.c | 12 ++++++++++++ + 3 files changed, 13 insertions(+), 14 deletions(-) + +--- a/arch/x86/include/asm/kvm_host.h ++++ b/arch/x86/include/asm/kvm_host.h +@@ -528,6 +528,7 @@ struct kvm_vcpu_arch { + bool tpr_access_reporting; + u64 ia32_xss; + u64 microcode_version; ++ u64 arch_capabilities; + + /* + * Paging state of the vcpu +--- a/arch/x86/kvm/vmx.c ++++ b/arch/x86/kvm/vmx.c +@@ -970,7 +970,6 @@ struct vcpu_vmx { + u64 msr_guest_kernel_gs_base; + #endif + +- u64 arch_capabilities; + u64 spec_ctrl; + + u32 vm_entry_controls_shadow; +@@ -4104,12 +4103,6 @@ static int vmx_get_msr(struct kvm_vcpu * + + msr_info->data = to_vmx(vcpu)->spec_ctrl; + break; +- case MSR_IA32_ARCH_CAPABILITIES: +- if (!msr_info->host_initiated && +- !guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES)) +- return 1; +- msr_info->data = to_vmx(vcpu)->arch_capabilities; +- break; + case MSR_IA32_SYSENTER_CS: + msr_info->data = vmcs_read32(GUEST_SYSENTER_CS); + break; +@@ -4271,11 +4264,6 @@ static int vmx_set_msr(struct kvm_vcpu * + vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD, + MSR_TYPE_W); + break; +- case MSR_IA32_ARCH_CAPABILITIES: +- if (!msr_info->host_initiated) +- return 1; +- vmx->arch_capabilities = data; +- break; + case MSR_IA32_CR_PAT: + if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) { + if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data)) +@@ -6666,8 +6654,6 @@ static void vmx_vcpu_setup(struct vcpu_v + ++vmx->nmsrs; + } + +- vmx->arch_capabilities = kvm_get_arch_capabilities(); +- + vm_exit_controls_init(vmx, vmcs_config.vmexit_ctrl); + + /* 22.2.1, 20.8.1 */ +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -2350,6 +2350,11 @@ int kvm_set_msr_common(struct kvm_vcpu * + if (msr_info->host_initiated) + vcpu->arch.microcode_version = data; + break; ++ case MSR_IA32_ARCH_CAPABILITIES: ++ if (!msr_info->host_initiated) ++ return 1; ++ vcpu->arch.arch_capabilities = data; ++ break; + case MSR_EFER: + return set_efer(vcpu, data); + case MSR_K7_HWCR: +@@ -2654,6 +2659,12 @@ int kvm_get_msr_common(struct kvm_vcpu * + case MSR_IA32_UCODE_REV: + msr_info->data = vcpu->arch.microcode_version; + break; ++ case MSR_IA32_ARCH_CAPABILITIES: ++ if (!msr_info->host_initiated && ++ !guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES)) ++ return 1; ++ msr_info->data = vcpu->arch.arch_capabilities; ++ break; + case MSR_IA32_TSC: + msr_info->data = kvm_scale_tsc(vcpu, rdtsc()) + vcpu->arch.tsc_offset; + break; +@@ -8501,6 +8512,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(st + + int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) + { ++ vcpu->arch.arch_capabilities = kvm_get_arch_capabilities(); + kvm_vcpu_mtrr_init(vcpu); + vcpu_load(vcpu); + kvm_vcpu_reset(vcpu, false); diff --git a/queue-4.19/series b/queue-4.19/series index f22854241a1..692bfaa5095 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -122,3 +122,4 @@ cpu-hotplug-prevent-crash-when-cpu-bringup-fails-on-config_hotplug_cpu-n.patch x86-smp-enforce-config_hotplug_cpu-when-smp-y.patch kvm-reject-device-ioctls-from-processes-other-than-the-vm-s-creator.patch kvm-x86-update-rip-after-emulating-io.patch +kvm-x86-emulate-msr_ia32_arch_capabilities-on-amd-hosts.patch -- 2.47.2