]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.9/powerpc-64s-add-barrier_nospec.patch
5891d94763f892faee9cf9ad91dadfe035d4a98f
[thirdparty/kernel/stable-queue.git] / queue-4.9 / powerpc-64s-add-barrier_nospec.patch
1 From ae3def2b67ef8b1755e9f1249b95e4561191007d Mon Sep 17 00:00:00 2001
2 From: Michal Suchanek <msuchanek@suse.de>
3 Date: Thu, 11 Apr 2019 21:45:57 +1000
4 Subject: powerpc/64s: Add barrier_nospec
5
6 commit a6b3964ad71a61bb7c61d80a60bea7d42187b2eb upstream.
7
8 A no-op form of ori (or immediate of 0 into r31 and the result stored
9 in r31) has been re-tasked as a speculation barrier. The instruction
10 only acts as a barrier on newer machines with appropriate firmware
11 support. On older CPUs it remains a harmless no-op.
12
13 Implement barrier_nospec using this instruction.
14
15 mpe: The semantics of the instruction are believed to be that it
16 prevents execution of subsequent instructions until preceding branches
17 have been fully resolved and are no longer executing speculatively.
18 There is no further documentation available at this time.
19
20 Signed-off-by: Michal Suchanek <msuchanek@suse.de>
21 Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
22 Signed-off-by: Sasha Levin <sashal@kernel.org>
23 ---
24 arch/powerpc/include/asm/barrier.h | 15 +++++++++++++++
25 1 file changed, 15 insertions(+)
26
27 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
28 index 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 --
54 2.19.1
55