Skip to content

Commit 21bd346

Browse files
Sean Christophersonsuryasaimadhu
authored andcommitted
KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR
Remove KVM's code to initialize IA32_FEAT_CTL MSR when KVM is loaded now that the MSR is initialized during boot on all CPUs that support VMX, i.e. on all CPUs that can possibly load kvm_intel. Note, don't WARN if IA32_FEAT_CTL is unlocked, even though the MSR is unconditionally locked by init_ia32_feat_ctl(). KVM isn't tied directly to a CPU vendor detection, whereas init_ia32_feat_ctl() is invoked if and only if the CPU vendor is recognized and known to support VMX. As a result, vmx_disabled_by_bios() may be reached without going through init_ia32_feat_ctl() and thus without locking IA32_FEAT_CTL. This quirk will be eliminated in a future patch. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 85c1729 commit 21bd346

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,24 +2207,26 @@ static __init int vmx_disabled_by_bios(void)
22072207
u64 msr;
22082208

22092209
rdmsrl(MSR_IA32_FEAT_CTL, msr);
2210-
if (msr & FEAT_CTL_LOCKED) {
2211-
/* launched w/ TXT and VMX disabled */
2212-
if (!(msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX)
2213-
&& tboot_enabled())
2214-
return 1;
2215-
/* launched w/o TXT and VMX only enabled w/ TXT */
2216-
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX)
2217-
&& (msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX)
2218-
&& !tboot_enabled()) {
2219-
printk(KERN_WARNING "kvm: disable TXT in the BIOS or "
2220-
"activate TXT before enabling KVM\n");
2221-
return 1;
2222-
}
2223-
/* launched w/o TXT and VMX disabled */
2224-
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX)
2225-
&& !tboot_enabled())
2226-
return 1;
2210+
2211+
if (unlikely(!(msr & FEAT_CTL_LOCKED)))
2212+
return 1;
2213+
2214+
/* launched w/ TXT and VMX disabled */
2215+
if (!(msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX) &&
2216+
tboot_enabled())
2217+
return 1;
2218+
/* launched w/o TXT and VMX only enabled w/ TXT */
2219+
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX) &&
2220+
(msr & FEAT_CTL_VMX_ENABLED_INSIDE_SMX) &&
2221+
!tboot_enabled()) {
2222+
pr_warn("kvm: disable TXT in the BIOS or "
2223+
"activate TXT before enabling KVM\n");
2224+
return 1;
22272225
}
2226+
/* launched w/o TXT and VMX disabled */
2227+
if (!(msr & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX) &&
2228+
!tboot_enabled())
2229+
return 1;
22282230

22292231
return 0;
22302232
}
@@ -2241,7 +2243,6 @@ static int hardware_enable(void)
22412243
{
22422244
int cpu = raw_smp_processor_id();
22432245
u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
2244-
u64 old, test_bits;
22452246

22462247
if (cr4_read_shadow() & X86_CR4_VMXE)
22472248
return -EBUSY;
@@ -2269,17 +2270,6 @@ static int hardware_enable(void)
22692270
*/
22702271
crash_enable_local_vmclear(cpu);
22712272

2272-
rdmsrl(MSR_IA32_FEAT_CTL, old);
2273-
2274-
test_bits = FEAT_CTL_LOCKED;
2275-
test_bits |= FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX;
2276-
if (tboot_enabled())
2277-
test_bits |= FEAT_CTL_VMX_ENABLED_INSIDE_SMX;
2278-
2279-
if ((old & test_bits) != test_bits) {
2280-
/* enable and lock */
2281-
wrmsrl(MSR_IA32_FEAT_CTL, old | test_bits);
2282-
}
22832273
kvm_cpu_vmxon(phys_addr);
22842274
if (enable_ept)
22852275
ept_sync_global();

0 commit comments

Comments
 (0)