]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
powerpc/fsl: Add barrier_nospec implementation for NXP PowerPC Book3E
authorDiana Craciun <diana.craciun@nxp.com>
Fri, 27 Jul 2018 23:06:37 +0000 (09:06 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 7 Aug 2018 14:32:24 +0000 (00:32 +1000)
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>
arch/powerpc/Kconfig
arch/powerpc/include/asm/barrier.h
arch/powerpc/lib/feature-fixups.c

index 846c89ed7fa3b9c2973edd3eca9d998c9485e5c1..8b6cd6780d8fd8844d8d2b304e19ee55a832383c 100644 (file)
@@ -245,7 +245,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 n
index cdc6960506e2b850c19c16a48f3ab9327fcb1cc3..fbe8df433019007e4122d241cdfccfdae270e291 100644 (file)
@@ -78,12 +78,18 @@ do {                                                                        \
        ___p1;                                                          \
 })
 
+#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 0e604b41b5d19549e14e4491e2fa79ddb38136c4..e613b02bb2f0c3817fef705602e0b95d4cdeba23 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;