linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/speculation/mds: Avoid clearing CPU buffers in native machine with old microcode
@ 2019-06-23  3:35 Zhenzhong Duan
  2019-06-23  3:35 ` [PATCH v2] x86/speculation/mds: Eliminate leaks by trace_hardirqs_on() Zhenzhong Duan
  0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2019-06-23  3:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, x86, hpa, jgross, ndesaulniers, gregkh, Zhenzhong Duan

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@oracle.com>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] x86/speculation/mds: Eliminate leaks by trace_hardirqs_on()
  2019-06-23  3:35 [PATCH] x86/speculation/mds: Avoid clearing CPU buffers in native machine with old microcode Zhenzhong Duan
@ 2019-06-23  3:35 ` Zhenzhong Duan
  2019-06-26 13:07   ` [tip:x86/pti] " tip-bot for Zhenzhong Duan
  0 siblings, 1 reply; 3+ messages in thread
From: Zhenzhong Duan @ 2019-06-23  3:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, x86, hpa, jgross, ndesaulniers, gregkh, Zhenzhong Duan

Move mds_idle_clear_cpu_buffers() after trace_hardirqs_on() to ensure
all store buffer entries are flushed.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
---
-v2: remove pointless changes which made a double flush

 arch/x86/include/asm/mwait.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index eb0f80c..e28f8b7 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -86,9 +86,9 @@ static inline void __mwaitx(unsigned long eax, unsigned long ebx,
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
-	mds_idle_clear_cpu_buffers();
-
 	trace_hardirqs_on();
+
+	mds_idle_clear_cpu_buffers();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [tip:x86/pti] x86/speculation/mds: Eliminate leaks by trace_hardirqs_on()
  2019-06-23  3:35 ` [PATCH v2] x86/speculation/mds: Eliminate leaks by trace_hardirqs_on() Zhenzhong Duan
@ 2019-06-26 13:07   ` tip-bot for Zhenzhong Duan
  0 siblings, 0 replies; 3+ messages in thread
From: tip-bot for Zhenzhong Duan @ 2019-06-26 13:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, mingo, tglx, linux-kernel, zhenzhong.duan

Commit-ID:  ab3765a050f7bea942f114d07278e1775e38199b
Gitweb:     https://git.kernel.org/tip/ab3765a050f7bea942f114d07278e1775e38199b
Author:     Zhenzhong Duan <zhenzhong.duan@oracle.com>
AuthorDate: Sun, 23 Jun 2019 11:35:04 +0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 26 Jun 2019 15:01:50 +0200

x86/speculation/mds: Eliminate leaks by trace_hardirqs_on()

Move mds_idle_clear_cpu_buffers() after trace_hardirqs_on() to ensure
all store buffer entries are flushed.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: bp@alien8.de
Cc: hpa@zytor.com
Cc: jgross@suse.com
Cc: ndesaulniers@google.com
Cc: gregkh@linuxfoundation.org
Link: https://lkml.kernel.org/r/1561260904-29669-2-git-send-email-zhenzhong.duan@oracle.com

---
 arch/x86/include/asm/mwait.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index eb0f80ce8524..e28f8b723b5c 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -86,9 +86,9 @@ static inline void __mwaitx(unsigned long eax, unsigned long ebx,
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
-	mds_idle_clear_cpu_buffers();
-
 	trace_hardirqs_on();
+
+	mds_idle_clear_cpu_buffers();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-26 13:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-23  3:35 [PATCH] x86/speculation/mds: Avoid clearing CPU buffers in native machine with old microcode Zhenzhong Duan
2019-06-23  3:35 ` [PATCH v2] x86/speculation/mds: Eliminate leaks by trace_hardirqs_on() Zhenzhong Duan
2019-06-26 13:07   ` [tip:x86/pti] " tip-bot for Zhenzhong Duan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).