]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - queue-4.9/powerpc-64s-add-barrier_nospec.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.9 / powerpc-64s-add-barrier_nospec.patch
CommitLineData
45d80ddf
SL
1From ae3def2b67ef8b1755e9f1249b95e4561191007d Mon Sep 17 00:00:00 2001
2From: Michal Suchanek <msuchanek@suse.de>
3Date: Thu, 11 Apr 2019 21:45:57 +1000
4Subject: powerpc/64s: Add barrier_nospec
5
6commit a6b3964ad71a61bb7c61d80a60bea7d42187b2eb upstream.
7
8A no-op form of ori (or immediate of 0 into r31 and the result stored
9in r31) has been re-tasked as a speculation barrier. The instruction
10only acts as a barrier on newer machines with appropriate firmware
11support. On older CPUs it remains a harmless no-op.
12
13Implement barrier_nospec using this instruction.
14
15mpe: The semantics of the instruction are believed to be that it
16prevents execution of subsequent instructions until preceding branches
17have been fully resolved and are no longer executing speculatively.
18There is no further documentation available at this time.
19
20Signed-off-by: Michal Suchanek <msuchanek@suse.de>
21Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
22Signed-off-by: Sasha Levin <sashal@kernel.org>
23---
24 arch/powerpc/include/asm/barrier.h | 15 +++++++++++++++
25 1 file changed, 15 insertions(+)
26
27diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
28index 798ab37c9930..352ea3e3cc05 100644
29--- a/arch/powerpc/include/asm/barrier.h
30+++ b/arch/powerpc/include/asm/barrier.h
31@@ -77,6 +77,21 @@ do { \
32
33 #define smp_mb__before_spinlock() smp_mb()
34
35+#ifdef CONFIG_PPC_BOOK3S_64
36+/*
37+ * Prevent execution of subsequent instructions until preceding branches have
38+ * been fully resolved and are no longer executing speculatively.
39+ */
40+#define barrier_nospec_asm ori 31,31,0
41+
42+// This also acts as a compiler barrier due to the memory clobber.
43+#define barrier_nospec() asm (stringify_in_c(barrier_nospec_asm) ::: "memory")
44+
45+#else /* !CONFIG_PPC_BOOK3S_64 */
46+#define barrier_nospec_asm
47+#define barrier_nospec()
48+#endif
49+
50 #include <asm-generic/barrier.h>
51
52 #endif /* _ASM_POWERPC_BARRIER_H */
53--
542.19.1
55