[PATCH] x86/speculation/mds: Avoid clearing CPU buffers in native machine with old microcode

From: Zhenzhong Duan
Date: Sun Jun 23 2019 - 23:32:33 EST


Commit 22dd8365088b ("x86/speculation/mds: Add mitigation mode VMWERV") add
an internal mitigation mode VWWERV which enables the invocation of the CPU
buffer clearing even if X86_FEATURE_MD_CLEAR is not set.

This wastes a few CPU cycles for native machine with an old microcode
unnecessorily. Avoid it by checking if it's running in native machine.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@xxxxxxxxxx>
---
arch/x86/kernel/cpu/bugs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 03b4cc0..03f5a77 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -233,7 +233,9 @@ static void x86_amd_ssb_disable(void)

static void __init mds_select_mitigation(void)
{
- if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off()) {
+ if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off() ||
+ (hypervisor_is_type(X86_HYPER_NATIVE) &&
+ !boot_cpu_has(X86_FEATURE_MD_CLEAR))) {
mds_mitigation = MDS_MITIGATION_OFF;
return;
}
--
1.8.3.1