powerpc/64: Add CONFIG_PPC_BARRIER_NOSPEC
authorMichael Ellerman <mpe@ellerman.id.au>
Thu, 11 Apr 2019 11:46:08 +0000 (21:46 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Apr 2019 06:36:41 +0000 (08:36 +0200)
commit 179ab1cbf883575c3a585bcfc0f2160f1d22a149 upstream.

Add a config symbol to encode which platforms support the
barrier_nospec speculation barrier. Currently this is just Book3S 64
but we will add Book3E in a future patch.

Signed-off-by: Diana Craciun <diana.craciun@nxp.com>
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/include/asm/setup.h
arch/powerpc/kernel/Makefile
arch/powerpc/kernel/module.c
arch/powerpc/kernel/vmlinux.lds.S
arch/powerpc/lib/feature-fixups.c

index 0a6bb48854e3ead3060f4ba52087fe64a5487458..a238698178fca35d04c016e6d60223ba22125a57 100644 (file)
@@ -128,7 +128,7 @@ config PPC
        select ARCH_HAS_GCOV_PROFILE_ALL
        select GENERIC_SMP_IDLE_THREAD
        select GENERIC_CMOS_UPDATE
-       select GENERIC_CPU_VULNERABILITIES      if PPC_BOOK3S_64
+       select GENERIC_CPU_VULNERABILITIES      if PPC_BARRIER_NOSPEC
        select GENERIC_TIME_VSYSCALL_OLD
        select GENERIC_CLOCKEVENTS
        select GENERIC_CLOCKEVENTS_BROADCAST if SMP
@@ -164,6 +164,11 @@ config PPC
        select HAVE_ARCH_HARDENED_USERCOPY
        select HAVE_KERNEL_GZIP
 
+config PPC_BARRIER_NOSPEC
+    bool
+    default y
+    depends on PPC_BOOK3S_64
+
 config GENERIC_CSUM
        def_bool CPU_LITTLE_ENDIAN
 
index a8131162104f01ba706ca51d68f77ccbee18c0bf..465a643168977c463e58ee9619ab8722ef155be7 100644 (file)
@@ -77,7 +77,7 @@ do {                                                                  \
 
 #define smp_mb__before_spinlock()   smp_mb()
 
-#ifdef CONFIG_PPC_BOOK3S_64
+#ifdef CONFIG_PPC_BARRIER_NOSPEC
 /*
  * Prevent execution of subsequent instructions until preceding branches have
  * been fully resolved and are no longer executing speculatively.
@@ -87,10 +87,10 @@ do {                                                                        \
 // This also acts as a compiler barrier due to the memory clobber.
 #define barrier_nospec() asm (stringify_in_c(barrier_nospec_asm) ::: "memory")
 
-#else /* !CONFIG_PPC_BOOK3S_64 */
+#else /* !CONFIG_PPC_BARRIER_NOSPEC */
 #define barrier_nospec_asm
 #define barrier_nospec()
-#endif
+#endif /* CONFIG_PPC_BARRIER_NOSPEC */
 
 #include <asm-generic/barrier.h>
 
index 84ae150ce6a67e8e66d9508992b6ffcfc9799127..38525bd2ed6566505c5f8ad002ec248b6a8a8d4f 100644 (file)
@@ -55,7 +55,7 @@ void setup_barrier_nospec(void);
 void do_barrier_nospec_fixups(bool enable);
 extern bool barrier_nospec_enabled;
 
-#ifdef CONFIG_PPC_BOOK3S_64
+#ifdef CONFIG_PPC_BARRIER_NOSPEC
 void do_barrier_nospec_fixups_range(bool enable, void *start, void *end);
 #else
 static inline void do_barrier_nospec_fixups_range(bool enable, void *start, void *end) { };
index 13885786282b53a91dfaf83810ac1f0a48ba6990..d80fbf0884ffafe48b251c649c725608ff544342 100644 (file)
@@ -44,9 +44,10 @@ obj-$(CONFIG_PPC64)          += setup_64.o sys_ppc32.o \
 obj-$(CONFIG_VDSO32)           += vdso32/
 obj-$(CONFIG_HAVE_HW_BREAKPOINT)       += hw_breakpoint.o
 obj-$(CONFIG_PPC_BOOK3S_64)    += cpu_setup_ppc970.o cpu_setup_pa6t.o
-obj-$(CONFIG_PPC_BOOK3S_64)    += cpu_setup_power.o security.o
+obj-$(CONFIG_PPC_BOOK3S_64)    += cpu_setup_power.o
 obj-$(CONFIG_PPC_BOOK3S_64)    += mce.o mce_power.o
 obj-$(CONFIG_PPC_BOOK3E_64)    += exceptions-64e.o idle_book3e.o
+obj-$(CONFIG_PPC_BARRIER_NOSPEC) += security.o
 obj-$(CONFIG_PPC64)            += vdso64/
 obj-$(CONFIG_ALTIVEC)          += vecemu.o
 obj-$(CONFIG_PPC_970_NAP)      += idle_power4.o
index d30f0626dcd0327e47381c64e5b48b9b16570907..3b1c3bb9102526e699f4da71a05c74c7ce54eee1 100644 (file)
@@ -72,13 +72,15 @@ int module_finalize(const Elf_Ehdr *hdr,
                do_feature_fixups(powerpc_firmware_features,
                                  (void *)sect->sh_addr,
                                  (void *)sect->sh_addr + sect->sh_size);
+#endif /* CONFIG_PPC64 */
 
+#ifdef CONFIG_PPC_BARRIER_NOSPEC
        sect = find_section(hdr, sechdrs, "__spec_barrier_fixup");
        if (sect != NULL)
                do_barrier_nospec_fixups_range(barrier_nospec_enabled,
                                  (void *)sect->sh_addr,
                                  (void *)sect->sh_addr + sect->sh_size);
-#endif
+#endif /* CONFIG_PPC_BARRIER_NOSPEC */
 
        sect = find_section(hdr, sechdrs, "__lwsync_fixup");
        if (sect != NULL)
index 61def0be6914d58387f225ce43551024b0b05dce..5c6cf58943b96da278f3ea0d58a087701cdba0ac 100644 (file)
@@ -153,14 +153,16 @@ SECTIONS
                *(__rfi_flush_fixup)
                __stop___rfi_flush_fixup = .;
        }
+#endif /* CONFIG_PPC64 */
 
+#ifdef CONFIG_PPC_BARRIER_NOSPEC
        . = ALIGN(8);
        __spec_barrier_fixup : AT(ADDR(__spec_barrier_fixup) - LOAD_OFFSET) {
                __start___barrier_nospec_fixup = .;
                *(__barrier_nospec_fixup)
                __stop___barrier_nospec_fixup = .;
        }
-#endif
+#endif /* CONFIG_PPC_BARRIER_NOSPEC */
 
        EXCEPTION_TABLE(0)
 
index a1222c441df5fe67891cf321099806f2e2a9d632..5df57f7bae0aedb4f482c237ed7ca037ddf5531b 100644 (file)
@@ -304,6 +304,9 @@ void do_barrier_nospec_fixups_range(bool enable, void *fixup_start, void *fixup_
        printk(KERN_DEBUG "barrier-nospec: patched %d locations\n", i);
 }
 
+#endif /* CONFIG_PPC_BOOK3S_64 */
+
+#ifdef CONFIG_PPC_BARRIER_NOSPEC
 void do_barrier_nospec_fixups(bool enable)
 {
        void *start, *end;
@@ -313,8 +316,7 @@ void do_barrier_nospec_fixups(bool enable)
 
        do_barrier_nospec_fixups_range(enable, start, end);
 }
-
-#endif /* CONFIG_PPC_BOOK3S_64 */
+#endif /* CONFIG_PPC_BARRIER_NOSPEC */
 
 void do_lwsync_fixups(unsigned long value, void *fixup_start, void *fixup_end)
 {