Skip to content

Commit 0cf9135

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts
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: 1eaafe9 ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported") Cc: stable@vger.kernel.org Reported-by: Xiaoyao Li <xiaoyao.li@linux.intel.com> Cc: Jim Mattson <jmattson@google.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent ca0488a commit 0cf9135

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ struct kvm_vcpu_arch {
568568
bool tpr_access_reporting;
569569
u64 ia32_xss;
570570
u64 microcode_version;
571+
u64 arch_capabilities;
571572

572573
/*
573574
* Paging state of the vcpu

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,12 +1683,6 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
16831683

16841684
msr_info->data = to_vmx(vcpu)->spec_ctrl;
16851685
break;
1686-
case MSR_IA32_ARCH_CAPABILITIES:
1687-
if (!msr_info->host_initiated &&
1688-
!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
1689-
return 1;
1690-
msr_info->data = to_vmx(vcpu)->arch_capabilities;
1691-
break;
16921686
case MSR_IA32_SYSENTER_CS:
16931687
msr_info->data = vmcs_read32(GUEST_SYSENTER_CS);
16941688
break;
@@ -1895,11 +1889,6 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
18951889
vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD,
18961890
MSR_TYPE_W);
18971891
break;
1898-
case MSR_IA32_ARCH_CAPABILITIES:
1899-
if (!msr_info->host_initiated)
1900-
return 1;
1901-
vmx->arch_capabilities = data;
1902-
break;
19031892
case MSR_IA32_CR_PAT:
19041893
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
19051894
if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
@@ -4088,8 +4077,6 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
40884077
++vmx->nmsrs;
40894078
}
40904079

4091-
vmx->arch_capabilities = kvm_get_arch_capabilities();
4092-
40934080
vm_exit_controls_init(vmx, vmx_vmexit_ctrl());
40944081

40954082
/* 22.2.1, 20.8.1 */

arch/x86/kvm/vmx/vmx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ struct vcpu_vmx {
190190
u64 msr_guest_kernel_gs_base;
191191
#endif
192192

193-
u64 arch_capabilities;
194193
u64 spec_ctrl;
195194

196195
u32 vm_entry_controls_shadow;

arch/x86/kvm/x86.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,11 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
24432443
if (msr_info->host_initiated)
24442444
vcpu->arch.microcode_version = data;
24452445
break;
2446+
case MSR_IA32_ARCH_CAPABILITIES:
2447+
if (!msr_info->host_initiated)
2448+
return 1;
2449+
vcpu->arch.arch_capabilities = data;
2450+
break;
24462451
case MSR_EFER:
24472452
return set_efer(vcpu, data);
24482453
case MSR_K7_HWCR:
@@ -2747,6 +2752,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
27472752
case MSR_IA32_UCODE_REV:
27482753
msr_info->data = vcpu->arch.microcode_version;
27492754
break;
2755+
case MSR_IA32_ARCH_CAPABILITIES:
2756+
if (!msr_info->host_initiated &&
2757+
!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
2758+
return 1;
2759+
msr_info->data = vcpu->arch.arch_capabilities;
2760+
break;
27502761
case MSR_IA32_TSC:
27512762
msr_info->data = kvm_scale_tsc(vcpu, rdtsc()) + vcpu->arch.tsc_offset;
27522763
break;
@@ -8733,6 +8744,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
87338744

87348745
int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
87358746
{
8747+
vcpu->arch.arch_capabilities = kvm_get_arch_capabilities();
87368748
vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT;
87378749
kvm_vcpu_mtrr_init(vcpu);
87388750
vcpu_load(vcpu);

0 commit comments

Comments
 (0)