KVM: VMX: Set VMENTER_L1D_FLUSH_NOT_REQUIRED if !X86_BUG_L1TF
PATCH 1/1 KVM: VMX: Set VMENTER_L1D_FLUSH_NOT_REQUIRED if !X86_BUG_L1TF
The l1tf_vmx_mitigation is only set to VMENTER_L1D_FLUSH_NOT_REQUIRED when the ARCH_CAPABILITIES MSR indicates that L1D flush is not required. However, if the CPU is not affected by L1TF, l1tf_vmx_mitigation will still be set to VMENTER_L1D_FLUSH_AUTO. This is certainly not the best option for a !X86_BUG_L1TF CPU.
So force l1tf_vmx_mitigation to VMENTER_L1D_FLUSH_NOT_REQUIRED to make it more explicit in case users are checking the vmentry_l1d_flush parameter.
--- arch/x86/kvm/vmx/vmx.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kvm/vmx/vmx.c +2 -0
@@ -7896,6 +7896,8 @@ static int __init vmx_init(void)vmx_exit ();return r; } + }else { + l1tf_vmx_mitigation =VMENTER_L1D_FLUSH_NOT_REQUIRED ; }#ifdef CONFIG_KEXEC_CORE
Signature · 1 line
2.18.1
Quoted 19 lines · Waiman Long
The
l1tf_vmx_mitigationis only set toVMENTER_L1D_FLUSH_NOT_REQUIREDwhen theARCH_CAPABILITIESMSR indicates that L1D flush is not required. However, if the CPU is not affected by L1TF,l1tf_vmx_mitigationwill still be set toVMENTER_L1D_FLUSH_AUTO. This is certainly not the best option for a !X86_BUG_L1TF CPU.So force
l1tf_vmx_mitigationtoVMENTER_L1D_FLUSH_NOT_REQUIREDto make it more explicit in case users are checking thevmentry_l1d_flushparameter.Signed-off-by Waiman Long <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static int __init vmx_init(void) · line 7903
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +2
-0@@ -7896,6 +7896,8 @@ static int __init vmx_init(void)vmx_exit ();return r; } + }else { + l1tf_vmx_mitigation =VMENTER_L1D_FLUSH_NOT_REQUIRED ; }#ifdef CONFIG_KEXEC_CORE
Ping. Any comment on that one?
Cheers,
Longman
Borislav Petkov
maintainerQuoted 27 lines · Waiman Long
Quoted 26 lines · Waiman Long
The
l1tf_vmx_mitigationis only set toVMENTER_L1D_FLUSH_NOT_REQUIREDwhen theARCH_CAPABILITIESMSR indicates that L1D flush is not required. However, if the CPU is not affected by L1TF,l1tf_vmx_mitigationwill still be set toVMENTER_L1D_FLUSH_AUTO. This is certainly not the best option for a !X86_BUG_L1TF CPU.So force
l1tf_vmx_mitigationtoVMENTER_L1D_FLUSH_NOT_REQUIREDto make it more explicit in case users are checking thevmentry_l1d_flushparameter.Signed-off-by Waiman Long <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/kvm/vmx/vmx.c +2
-0@@ -7896,6 +7896,8 @@ static int __init vmx_init(void)vmx_exit ();return r; } + }else { + l1tf_vmx_mitigation =VMENTER_L1D_FLUSH_NOT_REQUIRED ; }
Quoted 3 lines
arch/x86/kvm/vmx/vmx.c static int __init vmx_init(void) · line 7903
Quoted 1 line
arch/x86/kvm/vmx/vmx.c +0
-0#ifdef CONFIG_KEXEC_CORE Ping. Any comment on that one?
I'd move that logic with the if (boot_cpu_has(X86_BUG_L1TF)) check inside vmx_setup_l1d_flush() so that I have this:
if (!boot_cpu_has_bug(X86_BUG_L1TF)) {
l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NOT_REQUIRED;
return 0;
}
if (!enable_ept) {
...
}inside the function and outside am left with:
r = vmx_setup_l1d_flush(vmentry_l1d_flush_param);
if (r) {
vmx_exit();
return r;
}only. This way I'm concentrating the whole l1tf_vmx_mitigation picking apart in one place.
Also, note that X86_BUG flags are checked with boot_cpu_has_bug() even if it boils down to the same thing now.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePaolo Bonzini
maintainerQuoted 15 lines · Borislav Petkov
I'd move that logic with the if (
boot_cpu_has(X86_BUG_L1TF)) check insidevmx_setup_l1d_flush()so that I have this:if (!boot_cpu_has_bug(X86_BUG_L1TF)) { l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NOT_REQUIRED; return 0; } if (!enable_ept) { ... }inside the function and outside am left with:
Quoted 8 lines
r = vmx_setup_l1d_flush(vmentry_l1d_flush_param); if (r) { vmx_exit(); return r; }only. This way I'm concentrating the whole
l1tf_vmx_mitigationpicking apart in one place.
Right you are, I'm sending v2.
Paolo
Quoted 20 lines · Waiman Long
The
l1tf_vmx_mitigationis only set toVMENTER_L1D_FLUSH_NOT_REQUIREDwhen theARCH_CAPABILITIESMSR indicates that L1D flush is not required. However, if the CPU is not affected by L1TF,l1tf_vmx_mitigationwill still be set toVMENTER_L1D_FLUSH_AUTO. This is certainly not the best option for a !X86_BUG_L1TF CPU.So force
l1tf_vmx_mitigationtoVMENTER_L1D_FLUSH_NOT_REQUIREDto make it more explicit in case users are checking thevmentry_l1d_flushparameter.Signed-off-by Waiman Long <[email protected]>--- arch/x86/kvm/vmx/vmx.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/kvm/vmx/vmx.c +0
-0
arch/x86/kvm/vmx/vmx.c static int __init vmx_init(void) · line 7903
Quoted 8 lines
arch/x86/kvm/vmx/vmx.c +2
-0@@ -7896,6 +7896,8 @@ static int __init vmx_init(void)vmx_exit ();return r; } + }else { + l1tf_vmx_mitigation =VMENTER_L1D_FLUSH_NOT_REQUIRED ; }#ifdef CONFIG_KEXEC_CORE
Queued (for -rc2), thanks.
Paolo