Skip to content

Commit 28c1c9f

Browse files
KarimAllah AhmedKAGA-KOKO
authored andcommitted
KVM/VMX: Emulate MSR_IA32_ARCH_CAPABILITIES
Intel processors use MSR_IA32_ARCH_CAPABILITIES MSR to indicate RDCL_NO (bit 0) and IBRS_ALL (bit 1). This is a read-only MSR. By default the contents will come directly from the hardware, but user-space can still override it. [dwmw2: The bit in kvm_cpuid_7_0_edx_x86_features can be unconditional] Signed-off-by: KarimAllah Ahmed <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Paolo Bonzini <[email protected]> Reviewed-by: Darren Kenny <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jun Nakajima <[email protected]> Cc: [email protected] Cc: Dave Hansen <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Asit Mallick <[email protected]> Cc: Arjan Van De Ven <[email protected]> Cc: Greg KH <[email protected]> Cc: Dan Williams <[email protected]> Cc: Tim Chen <[email protected]> Cc: Ashok Raj <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 15d4507 commit 28c1c9f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
394394

395395
/* cpuid 7.0.edx*/
396396
const u32 kvm_cpuid_7_0_edx_x86_features =
397-
F(AVX512_4VNNIW) | F(AVX512_4FMAPS);
397+
F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(ARCH_CAPABILITIES);
398398

399399
/* all calls to cpuid_count() should be made on the same cpu */
400400
get_cpu();

arch/x86/kvm/vmx.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ struct vcpu_vmx {
594594
u64 msr_guest_kernel_gs_base;
595595
#endif
596596

597+
u64 arch_capabilities;
598+
597599
u32 vm_entry_controls_shadow;
598600
u32 vm_exit_controls_shadow;
599601
u32 secondary_exec_control;
@@ -3260,6 +3262,12 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
32603262
case MSR_IA32_TSC:
32613263
msr_info->data = guest_read_tsc(vcpu);
32623264
break;
3265+
case MSR_IA32_ARCH_CAPABILITIES:
3266+
if (!msr_info->host_initiated &&
3267+
!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
3268+
return 1;
3269+
msr_info->data = to_vmx(vcpu)->arch_capabilities;
3270+
break;
32633271
case MSR_IA32_SYSENTER_CS:
32643272
msr_info->data = vmcs_read32(GUEST_SYSENTER_CS);
32653273
break;
@@ -3395,6 +3403,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
33953403
vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD,
33963404
MSR_TYPE_W);
33973405
break;
3406+
case MSR_IA32_ARCH_CAPABILITIES:
3407+
if (!msr_info->host_initiated)
3408+
return 1;
3409+
vmx->arch_capabilities = data;
3410+
break;
33983411
case MSR_IA32_CR_PAT:
33993412
if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) {
34003413
if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data))
@@ -5657,6 +5670,8 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx)
56575670
++vmx->nmsrs;
56585671
}
56595672

5673+
if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES))
5674+
rdmsrl(MSR_IA32_ARCH_CAPABILITIES, vmx->arch_capabilities);
56605675

56615676
vm_exit_controls_init(vmx, vmcs_config.vmexit_ctrl);
56625677

arch/x86/kvm/x86.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ static u32 msrs_to_save[] = {
10091009
#endif
10101010
MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA,
10111011
MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS, MSR_TSC_AUX,
1012+
MSR_IA32_ARCH_CAPABILITIES
10121013
};
10131014

10141015
static unsigned num_msrs_to_save;

0 commit comments

Comments
 (0)