diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2018-01-29 15:20:16 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-02-05 15:34:57 -0500 |
commit | ac1ab12a3e6e878274e7107c8c6f326694a1c1f3 (patch) | |
tree | b6feeba64225d0ca373c8c7eaa5489ec7a04e67a | |
parent | e61938a921a46347d7725badc40ec436ebfff977 (diff) |
lockin/x86: Implement sync_core_before_usermode()
Ensure that a core serializing instruction is issued before returning to
user-mode. x86 implements return to user-space through sysexit, sysrel,
and sysretq, which are not core serializing.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrea Parri <parri.andrea@gmail.com>
Cc: Andrew Hunter <ahh@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Avi Kivity <avi@scylladb.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Dave Watson <davejwatson@fb.com>
Cc: David Sehr <sehr@google.com>
Cc: Greg Hackmann <ghackmann@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maged Michael <maged.michael@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-api@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Link: http://lkml.kernel.org/r/20180129202020.8515-8-mathieu.desnoyers@efficios.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | arch/x86/Kconfig | 1 | ||||
-rw-r--r-- | arch/x86/include/asm/sync_core.h | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 423e4b64e683..31030ade4690 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
@@ -61,6 +61,7 @@ config X86 | |||
61 | select ARCH_HAS_SG_CHAIN | 61 | select ARCH_HAS_SG_CHAIN |
62 | select ARCH_HAS_STRICT_KERNEL_RWX | 62 | select ARCH_HAS_STRICT_KERNEL_RWX |
63 | select ARCH_HAS_STRICT_MODULE_RWX | 63 | select ARCH_HAS_STRICT_MODULE_RWX |
64 | select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE | ||
64 | select ARCH_HAS_UBSAN_SANITIZE_ALL | 65 | select ARCH_HAS_UBSAN_SANITIZE_ALL |
65 | select ARCH_HAS_ZONE_DEVICE if X86_64 | 66 | select ARCH_HAS_ZONE_DEVICE if X86_64 |
66 | select ARCH_HAVE_NMI_SAFE_CMPXCHG | 67 | select ARCH_HAVE_NMI_SAFE_CMPXCHG |
diff --git a/arch/x86/include/asm/sync_core.h b/arch/x86/include/asm/sync_core.h new file mode 100644 index 000000000000..c67caafd3381 --- /dev/null +++ b/arch/x86/include/asm/sync_core.h | |||
@@ -0,0 +1,28 @@ | |||
1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
2 | #ifndef _ASM_X86_SYNC_CORE_H | ||
3 | #define _ASM_X86_SYNC_CORE_H | ||
4 | |||
5 | #include <linux/preempt.h> | ||
6 | #include <asm/processor.h> | ||
7 | #include <asm/cpufeature.h> | ||
8 | |||
9 | /* | ||
10 | * Ensure that a core serializing instruction is issued before returning | ||
11 | * to user-mode. x86 implements return to user-space through sysexit, | ||
12 | * sysrel, and sysretq, which are not core serializing. | ||
13 | */ | ||
14 | static inline void sync_core_before_usermode(void) | ||
15 | { | ||
16 | /* With PTI, we unconditionally serialize before running user code. */ | ||
17 | if (static_cpu_has(X86_FEATURE_PTI)) | ||
18 | return; | ||
19 | /* | ||
20 | * Return from interrupt and NMI is done through iret, which is core | ||
21 | * serializing. | ||
22 | */ | ||
23 | if (in_irq() || in_nmi()) | ||
24 | return; | ||
25 | sync_core(); | ||
26 | } | ||
27 | |||
28 | #endif /* _ASM_X86_SYNC_CORE_H */ | ||