All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: [patch 4/8] MDS basics 4
Date: Tue, 19 Feb 2019 13:44:10 +0100	[thread overview]
Message-ID: <20190219125346.141295571@linutronix.de> (raw)
In-Reply-To: 20190219124406.449727187@linutronix.de

Subject: [patch 4/8] x86/speculation/mds: Conditionaly clear CPU buffers on idle entry
From: Thomas Gleixner <tglx@linutronix.de>

Add a static key which controls the invocation of the CPU buffer clear
mechanism on idle entry. This is independent of other MDS mitigations
because the idle entry invocation to mitigate the potential leakage due to
store buffer repartitioning is only necessary on SMT systems.

Add the actual invocations to the different halt/mwait variants which
covers all usage sites. mwaitx is not patched as it's not available on
Intel CPUs.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/include/asm/irqflags.h      |    4 ++++
 arch/x86/include/asm/mwait.h         |    7 +++++++
 arch/x86/include/asm/nospec-branch.h |    1 +
 arch/x86/kernel/cpu/bugs.c           |    2 ++
 4 files changed, 14 insertions(+)

--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -6,6 +6,8 @@
 
 #ifndef __ASSEMBLY__
 
+#include <asm/nospec-branch.h>
+
 /* Provide __cpuidle; we can't safely include <linux/cpu.h> */
 #define __cpuidle __attribute__((__section__(".cpuidle.text")))
 
@@ -54,11 +56,13 @@ static inline void native_irq_enable(voi
 
 static inline __cpuidle void native_safe_halt(void)
 {
+	mds_clear_cpu_buffers(&idle_mds_clear_cpu_buffers);
 	asm volatile("sti; hlt": : :"memory");
 }
 
 static inline __cpuidle void native_halt(void)
 {
+	mds_clear_cpu_buffers(&idle_mds_clear_cpu_buffers);
 	asm volatile("hlt": : :"memory");
 }
 
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -6,6 +6,7 @@
 #include <linux/sched/idle.h>
 
 #include <asm/cpufeature.h>
+#include <asm/nospec-branch.h>
 
 #define MWAIT_SUBSTATE_MASK		0xf
 #define MWAIT_CSTATE_MASK		0xf
@@ -40,6 +41,8 @@ static inline void __monitorx(const void
 
 static inline void __mwait(unsigned long eax, unsigned long ecx)
 {
+	mds_clear_cpu_buffers(&idle_mds_clear_cpu_buffers);
+
 	/* "mwait %eax, %ecx;" */
 	asm volatile(".byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));
@@ -74,6 +77,8 @@ static inline void __mwait(unsigned long
 static inline void __mwaitx(unsigned long eax, unsigned long ebx,
 			    unsigned long ecx)
 {
+	/* No MDS buffer clear as this is AMD/HYGON only */
+
 	/* "mwaitx %eax, %ebx, %ecx;" */
 	asm volatile(".byte 0x0f, 0x01, 0xfb;"
 		     :: "a" (eax), "b" (ebx), "c" (ecx));
@@ -81,6 +86,8 @@ static inline void __mwaitx(unsigned lon
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
+	mds_clear_cpu_buffers(&idle_mds_clear_cpu_buffers);
+
 	trace_hardirqs_on();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -338,6 +338,7 @@ DECLARE_STATIC_KEY_FALSE(switch_mm_cond_
 DECLARE_STATIC_KEY_FALSE(switch_mm_always_ibpb);
 
 DECLARE_STATIC_KEY_FALSE(user_mds_clear_cpu_buffers);
+DECLARE_STATIC_KEY_FALSE(idle_mds_clear_cpu_buffers);
 
 #endif /* __ASSEMBLY__ */
 
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -65,6 +65,8 @@ DEFINE_STATIC_KEY_FALSE(switch_mm_always
 
 /* Control MDS CPU buffer clear before returning to user space */
 DEFINE_STATIC_KEY_FALSE(user_mds_clear_cpu_buffers);
+/* Control MDS CPU buffer clear before idling (halt, mwait) */
+DEFINE_STATIC_KEY_FALSE(idle_mds_clear_cpu_buffers);
 
 void __init check_bugs(void)
 {

  parent reply	other threads:[~2019-02-19 13:38 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19 12:44 [patch 0/8] MDS basics 0 Thomas Gleixner
2019-02-19 12:44 ` [patch 1/8] MDS basics 1 Thomas Gleixner
2019-02-19 14:00   ` [MODERATED] " Borislav Petkov
2019-02-19 12:44 ` [patch 2/8] MDS basics 2 Thomas Gleixner
2019-02-19 12:44 ` [patch 3/8] MDS basics 3 Thomas Gleixner
2019-02-19 16:04   ` [MODERATED] " Andi Kleen
2019-02-19 21:44     ` Thomas Gleixner
2019-02-19 22:13       ` Thomas Gleixner
2019-02-20 16:59       ` [MODERATED] " Andi Kleen
2019-02-20 21:28         ` Thomas Gleixner
2019-02-19 12:44 ` Thomas Gleixner [this message]
2019-02-19 13:54   ` [MODERATED] Re: [patch 4/8] MDS basics 4 Andrew Cooper
2019-02-19 14:02     ` Thomas Gleixner
2019-02-19 14:07       ` Thomas Gleixner
2019-02-19 16:09         ` [MODERATED] " Andi Kleen
2019-02-19 16:17           ` Peter Zijlstra
2019-02-19 17:16       ` Thomas Gleixner
2019-02-19 16:08     ` [MODERATED] " Andi Kleen
2019-02-19 16:23       ` Andrew Cooper
2019-02-19 16:07   ` Andi Kleen
2019-02-19 18:29     ` Thomas Gleixner
2019-02-19 12:44 ` [patch 5/8] MDS basics 5 Thomas Gleixner
2019-02-19 15:07   ` Thomas Gleixner
2019-02-19 16:13     ` [MODERATED] " Andi Kleen
2019-02-19 17:37       ` Thomas Gleixner
2019-02-20  0:05         ` Thomas Gleixner
2019-02-19 16:03   ` [MODERATED] " Andi Kleen
2019-02-19 17:40     ` Thomas Gleixner
2019-02-19 17:44       ` [MODERATED] " Andrew Cooper
2019-02-19 17:52         ` Thomas Gleixner
2019-02-19 12:44 ` [patch 6/8] MDS basics 6 Thomas Gleixner
2019-02-19 12:44 ` [patch 7/8] MDS basics 7 Thomas Gleixner
2019-02-19 12:44 ` [patch 8/8] MDS basics 8 Thomas Gleixner
2019-02-19 14:17   ` [MODERATED] " Greg KH
2019-02-19 14:22     ` Thomas Gleixner
2019-02-19 17:27   ` [MODERATED] " Andrew Cooper
2019-02-19 14:03 ` [MODERATED] Re: [patch 0/8] MDS basics 0 Andrew Cooper
2019-02-19 14:09   ` Thomas Gleixner
2019-02-19 14:10   ` [MODERATED] " Tyler Hicks
2019-02-19 15:56 ` Andi Kleen
2019-02-19 17:42   ` Thomas Gleixner
2019-02-21 16:14 ` [MODERATED] Encrypted Message Jon Masters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190219125346.141295571@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=speck@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.