]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc/fsl: Add barrier_nospec implementation for NXP PowerPC Book3E
authorDiana Craciun <diana.craciun@nxp.com>
Thu, 11 Apr 2019 11:46:11 +0000 (21:46 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Apr 2019 06:36:41 +0000 (08:36 +0200)
commit ebcd1bfc33c7a90df941df68a6e5d4018c022fba upstream.

Implement the barrier_nospec as a isync;sync instruction sequence.
The implementation uses the infrastructure built for BOOK3S 64.

Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
[mpe: Split out of larger patch]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/Kconfig
arch/powerpc/include/asm/barrier.h
arch/powerpc/lib/feature-fixups.c

index a238698178fca35d04c016e6d60223ba22125a57..fa8f2aa8818928ce10d6e7c36c297d679d7bb4f9 100644 (file)
@@ -167,7 +167,7 @@ config PPC
 config PPC_BARRIER_NOSPEC
     bool
     default y
-    depends on PPC_BOOK3S_64
+    depends on PPC_BOOK3S_64 || PPC_FSL_BOOK3E
 
 config GENERIC_CSUM
        def_bool CPU_LITTLE_ENDIAN
index 465a643168977c463e58ee9619ab8722ef155be7..80024c4f2093cbcbf5b4e953b54f16bb5a52d963 100644 (file)
@@ -77,12 +77,18 @@ do {                                                                        \
 
 #define smp_mb__before_spinlock()   smp_mb()
 
+#ifdef CONFIG_PPC_BOOK3S_64
+#define NOSPEC_BARRIER_SLOT   nop
+#elif defined(CONFIG_PPC_FSL_BOOK3E)
+#define NOSPEC_BARRIER_SLOT   nop; nop
+#endif
+
 #ifdef CONFIG_PPC_BARRIER_NOSPEC
 /*
  * Prevent execution of subsequent instructions until preceding branches have
  * been fully resolved and are no longer executing speculatively.
  */
-#define barrier_nospec_asm NOSPEC_BARRIER_FIXUP_SECTION; nop
+#define barrier_nospec_asm NOSPEC_BARRIER_FIXUP_SECTION; NOSPEC_BARRIER_SLOT
 
 // This also acts as a compiler barrier due to the memory clobber.
 #define barrier_nospec() asm (stringify_in_c(barrier_nospec_asm) ::: "memory")
index 5df57f7bae0aedb4f482c237ed7ca037ddf5531b..b3e362437ec40110bb2fa15190806c5fdeda01fa 100644 (file)
@@ -318,6 +318,37 @@ void do_barrier_nospec_fixups(bool enable)
 }
 #endif /* CONFIG_PPC_BARRIER_NOSPEC */
 
+#ifdef CONFIG_PPC_FSL_BOOK3E
+void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_end)
+{
+       unsigned int instr[2], *dest;
+       long *start, *end;
+       int i;
+
+       start = fixup_start;
+       end = fixup_end;
+
+       instr[0] = PPC_INST_NOP;
+       instr[1] = PPC_INST_NOP;
+
+       if (enable) {
+               pr_info("barrier-nospec: using isync; sync as speculation barrier\n");
+               instr[0] = PPC_INST_ISYNC;
+               instr[1] = PPC_INST_SYNC;
+       }
+
+       for (i = 0; start < end; start++, i++) {
+               dest = (void *)start + *start;
+
+               pr_devel("patching dest %lx\n", (unsigned long)dest);
+               patch_instruction(dest, instr[0]);
+               patch_instruction(dest + 1, instr[1]);
+       }
+
+       printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i);
+}
+#endif /* CONFIG_PPC_FSL_BOOK3E */
+
 void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end)
 {
        long *start, *end;