]> Git Repo - J-linux.git/commitdiff
Merge tag 'for-linus-bhb' of git://git.armlinux.org.uk/~rmk/linux-arm
authorLinus Torvalds <[email protected]>
Tue, 8 Mar 2022 17:08:06 +0000 (09:08 -0800)
committerLinus Torvalds <[email protected]>
Tue, 8 Mar 2022 17:08:06 +0000 (09:08 -0800)
Pull ARM spectre fixes from Russell King:
 "ARM Spectre BHB mitigations.

  These patches add Spectre BHB migitations for the following Arm CPUs
  to the 32-bit ARM kernels:
   - Cortex A15
   - Cortex A57
   - Cortex A72
   - Cortex A73
   - Cortex A75
   - Brahma B15
  for CVE-2022-23960"

* tag 'for-linus-bhb' of git://git.armlinux.org.uk/~rmk/linux-arm:
  ARM: include unprivileged BPF status in Spectre V2 reporting
  ARM: Spectre-BHB workaround
  ARM: use LOADADDR() to get load address of sections
  ARM: early traps initialisation
  ARM: report Spectre v2 status through sysfs

1  2 
arch/arm/include/asm/assembler.h
arch/arm/kernel/traps.c

index 6fe67963ba5a0885e68165e5ec591fed039dbcb9,49ea603fc8e3819f60fa2cc4df61a6371343225d..b50cc0169d5c4c071c2e069ffe82d100efa859b0
        .endm
  #endif
  
+ #if __LINUX_ARM_ARCH__ < 7
+       .macro  dsb, args
+       mcr     p15, 0, r0, c7, c10, 4
+       .endm
+       .macro  isb, args
+       mcr     p15, 0, r0, c7, r5, 4
+       .endm
+ #endif
        .macro asm_trace_hardirqs_off, save=1
  #if defined(CONFIG_TRACE_IRQFLAGS)
        .if \save
   */
  #define ALT_UP(instr...)                                      \
        .pushsection ".alt.smp.init", "a"                       ;\
 +      .align  2                                               ;\
        .long   9998b - .                                       ;\
  9997: instr                                                   ;\
        .if . - 9997b == 2                                      ;\
        .popsection
  #define ALT_UP_B(label)                                       \
        .pushsection ".alt.smp.init", "a"                       ;\
 +      .align  2                                               ;\
        .long   9998b - .                                       ;\
        W(b)    . + (label - 9998b)                                     ;\
        .popsection
diff --combined arch/arm/kernel/traps.c
index da04ed85855ae44b25670e8e94f9c256c18ece4f,90c887aa67a4458703907764cd309cfa9b54a93b..cae4a748811f8312f2f8c40424842932a92d7b08
@@@ -30,6 -30,7 +30,7 @@@
  #include <linux/atomic.h>
  #include <asm/cacheflush.h>
  #include <asm/exception.h>
+ #include <asm/spectre.h>
  #include <asm/unistd.h>
  #include <asm/traps.h>
  #include <asm/ptrace.h>
@@@ -67,14 -68,12 +68,14 @@@ void dump_backtrace_entry(unsigned lon
  {
        unsigned long end = frame + 4 + sizeof(struct pt_regs);
  
 -#ifdef CONFIG_KALLSYMS
 +#ifndef CONFIG_KALLSYMS
 +      printk("%sFunction entered at [<%08lx>] from [<%08lx>]\n",
 +              loglvl, where, from);
 +#elif defined CONFIG_BACKTRACE_VERBOSE
        printk("%s[<%08lx>] (%ps) from [<%08lx>] (%pS)\n",
                loglvl, where, (void *)where, from, (void *)from);
  #else
 -      printk("%sFunction entered at [<%08lx>] from [<%08lx>]\n",
 -              loglvl, where, from);
 +      printk("%s %ps from %pS\n", loglvl, (void *)where, (void *)from);
  #endif
  
        if (in_entry_text(from) && end <= ALIGN(frame, THREAD_SIZE))
@@@ -335,7 -334,7 +336,7 @@@ static void oops_end(unsigned long flag
        if (panic_on_oops)
                panic("Fatal exception");
        if (signr)
 -              do_exit(signr);
 +              make_task_dead(signr);
  }
  
  /*
@@@ -789,10 -788,59 +790,59 @@@ static inline void __init kuser_init(vo
  }
  #endif
  
+ #ifndef CONFIG_CPU_V7M
+ static void copy_from_lma(void *vma, void *lma_start, void *lma_end)
+ {
+       memcpy(vma, lma_start, lma_end - lma_start);
+ }
+ static void flush_vectors(void *vma, size_t offset, size_t size)
+ {
+       unsigned long start = (unsigned long)vma + offset;
+       unsigned long end = start + size;
+       flush_icache_range(start, end);
+ }
+ #ifdef CONFIG_HARDEN_BRANCH_HISTORY
+ int spectre_bhb_update_vectors(unsigned int method)
+ {
+       extern char __vectors_bhb_bpiall_start[], __vectors_bhb_bpiall_end[];
+       extern char __vectors_bhb_loop8_start[], __vectors_bhb_loop8_end[];
+       void *vec_start, *vec_end;
+       if (system_state >= SYSTEM_FREEING_INITMEM) {
+               pr_err("CPU%u: Spectre BHB workaround too late - system vulnerable\n",
+                      smp_processor_id());
+               return SPECTRE_VULNERABLE;
+       }
+       switch (method) {
+       case SPECTRE_V2_METHOD_LOOP8:
+               vec_start = __vectors_bhb_loop8_start;
+               vec_end = __vectors_bhb_loop8_end;
+               break;
+       case SPECTRE_V2_METHOD_BPIALL:
+               vec_start = __vectors_bhb_bpiall_start;
+               vec_end = __vectors_bhb_bpiall_end;
+               break;
+       default:
+               pr_err("CPU%u: unknown Spectre BHB state %d\n",
+                      smp_processor_id(), method);
+               return SPECTRE_VULNERABLE;
+       }
+       copy_from_lma(vectors_page, vec_start, vec_end);
+       flush_vectors(vectors_page, 0, vec_end - vec_start);
+       return SPECTRE_MITIGATED;
+ }
+ #endif
  void __init early_trap_init(void *vectors_base)
  {
- #ifndef CONFIG_CPU_V7M
-       unsigned long vectors = (unsigned long)vectors_base;
        extern char __stubs_start[], __stubs_end[];
        extern char __vectors_start[], __vectors_end[];
        unsigned i;
         * into the vector page, mapped at 0xffff0000, and ensure these
         * are visible to the instruction stream.
         */
-       memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
-       memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);
+       copy_from_lma(vectors_base, __vectors_start, __vectors_end);
+       copy_from_lma(vectors_base + 0x1000, __stubs_start, __stubs_end);
  
        kuser_init(vectors_base);
  
-       flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
+       flush_vectors(vectors_base, 0, PAGE_SIZE * 2);
+ }
  #else /* ifndef CONFIG_CPU_V7M */
+ void __init early_trap_init(void *vectors_base)
+ {
        /*
         * on V7-M there is no need to copy the vector table to a dedicated
         * memory area. The address is configurable and so a table in the kernel
         * image can be used.
         */
- #endif
  }
+ #endif
This page took 0.06316 seconds and 4 git commands to generate.