Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 09 Jan 2019 11:00:58 -0000 Received: from mga17.intel.com ([192.55.52.151]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1ga8fW-0005lh-BK for speck@linutronix.de; Fri, 21 Dec 2018 01:27:58 +0100 From: Andi Kleen Subject: [MODERATED] [PATCH v3 07/32] MDSv3 21 Date: Thu, 20 Dec 2018 16:27:17 -0800 Message-Id: <9c8a184d16e326ed0af123d112bedb89ecc34e6b.1545351936.git.ak@linux.intel.com> In-Reply-To: References: In-Reply-To: References: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 To: speck@linutronix.de Cc: Andi Kleen List-ID: NMIs don't go through C code when exiting to user space, so we need to add an assembler clear cpu for this case. Only used with mds=full, because otherwise we assume NMIs don't touch other users or kernel sensitive data. Signed-off-by: Andi Kleen --- arch/x86/entry/entry_64.S | 12 ++++++++++++ arch/x86/include/asm/clearcpu.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index ce25d84023c0..19b235ca2878 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -39,6 +39,7 @@ #include #include #include +#include #include "calling.h" @@ -1403,6 +1404,17 @@ ENTRY(nmi) movq $-1, %rsi call do_nmi + /* + * Clear only when force clearing was enabled. Otherwise + * we assume NMI code is not sensitive. + * If you don't have jump labels we always clear too. + */ +#ifdef HAVE_JUMP_LABEL + STATIC_BRANCH_JMP l_yes=.Lno_clear_cpu key=force_cpu_clear, branch=1 +#endif + CLEAR_CPU +.Lno_clear_cpu: + /* * Return back to user mode. We must *not* do the normal exit * work, because we don't want to enable interrupts. diff --git a/arch/x86/include/asm/clearcpu.h b/arch/x86/include/asm/clearcpu.h index 4a570b3b0f5e..cc03ca14140b 100644 --- a/arch/x86/include/asm/clearcpu.h +++ b/arch/x86/include/asm/clearcpu.h @@ -2,6 +2,8 @@ #ifndef _ASM_CLEARCPU_H #define _ASM_CLEARCPU_H 1 +#ifndef __ASSEMBLY__ + #include #include #include @@ -46,4 +48,16 @@ static inline void clear_cpu_idle(void) DECLARE_STATIC_KEY_FALSE(force_cpu_clear); +#else + +.macro CLEAR_CPU + /* Clear CPU buffers that could leak. Instruction must be in memory form. */ + ALTERNATIVE_2 "", __stringify(push $__USER_DS ; verw (% _ASM_SP ) ; add $8, % _ASM_SP ),\ + X86_FEATURE_MB_CLEAR, \ + "call do_clear_cpu", \ + X86_BUG_MDS_CLEAR_CPU +.endm + +#endif + #endif -- 2.17.2