Skip to content

Commit b7e02fc

Browse files
Marc Zyngieralex3788
authored andcommitted
FROMLIST: arm: Add BTB invalidation on switch_mm for Cortex-A9, A12 and A17
In order to avoid aliasing attacks against the branch predictor, some implementations require to invalidate the BTB when switching from one user context to another. For this, we reuse the existing implementation for Cortex-A8, and apply it to A9, A12 and A17. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> (cherry picked from git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git kpti commit efcd0e857a656bbd1c1da15ff984ad6402332c61) CVE-2017-5715 Change-Id: Ica839802de678a5456abadf09bb6434efd43da2c Signed-off-by: Tao Huang <huangtao@rock-chips.com> Reviewed-on: https://tp-biosrd-v02/gerrit/82396 Reviewed-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com> Tested-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com>
1 parent d2d6672 commit b7e02fc

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

arch/arm/mm/proc-v7-2level.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* even on Cortex-A8 revisions not affected by 430973.
4242
* If IBE is not set, the flush BTAC/BTB won't do anything.
4343
*/
44-
ENTRY(cpu_ca8_switch_mm)
44+
ENTRY(cpu_v7_btbinv_switch_mm)
4545
#ifdef CONFIG_MMU
4646
mov r2, #0
4747
mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB
@@ -66,7 +66,7 @@ ENTRY(cpu_v7_switch_mm)
6666
#endif
6767
bx lr
6868
ENDPROC(cpu_v7_switch_mm)
69-
ENDPROC(cpu_ca8_switch_mm)
69+
ENDPROC(cpu_v7_btbinv_switch_mm)
7070

7171
/*
7272
* cpu_v7_set_pte_ext(ptep, pte)

arch/arm/mm/proc-v7-3level.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
* Set the translation table base pointer to be pgd_phys (physical address of
5555
* the new TTB).
5656
*/
57+
ENTRY(cpu_v7_btbinv_switch_mm)
58+
#ifdef CONFIG_MMU
59+
mov r2, #0
60+
mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB
61+
#endif
5762
ENTRY(cpu_v7_switch_mm)
5863
#ifdef CONFIG_MMU
5964
mmid r2, r2
@@ -64,6 +69,7 @@ ENTRY(cpu_v7_switch_mm)
6469
#endif
6570
ret lr
6671
ENDPROC(cpu_v7_switch_mm)
72+
ENDPROC(cpu_v7_btbinv_switch_mm)
6773

6874
#ifdef __ARMEB__
6975
#define rl r3

arch/arm/mm/proc-v7.S

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ ENDPROC(cpu_v7_do_resume)
153153
#endif
154154

155155
/*
156-
* Cortex-A8
156+
* Cortex-A8/A12/A17 that require a BTB invalidation on switch_mm
157157
*/
158-
globl_equ cpu_ca8_proc_init, cpu_v7_proc_init
159-
globl_equ cpu_ca8_proc_fin, cpu_v7_proc_fin
160-
globl_equ cpu_ca8_reset, cpu_v7_reset
161-
globl_equ cpu_ca8_do_idle, cpu_v7_do_idle
162-
globl_equ cpu_ca8_dcache_clean_area, cpu_v7_dcache_clean_area
163-
globl_equ cpu_ca8_set_pte_ext, cpu_v7_set_pte_ext
164-
globl_equ cpu_ca8_suspend_size, cpu_v7_suspend_size
158+
globl_equ cpu_v7_btbinv_proc_init, cpu_v7_proc_init
159+
globl_equ cpu_v7_btbinv_proc_fin, cpu_v7_proc_fin
160+
globl_equ cpu_v7_btbinv_reset, cpu_v7_reset
161+
globl_equ cpu_v7_btbinv_do_idle, cpu_v7_do_idle
162+
globl_equ cpu_v7_btbinv_dcache_clean_area, cpu_v7_dcache_clean_area
163+
globl_equ cpu_v7_btbinv_set_pte_ext, cpu_v7_set_pte_ext
164+
globl_equ cpu_v7_btbinv_suspend_size, cpu_v7_suspend_size
165165
#ifdef CONFIG_ARM_CPU_SUSPEND
166-
globl_equ cpu_ca8_do_suspend, cpu_v7_do_suspend
167-
globl_equ cpu_ca8_do_resume, cpu_v7_do_resume
166+
globl_equ cpu_v7_btbinv_do_suspend, cpu_v7_do_suspend
167+
globl_equ cpu_v7_btbinv_do_resume, cpu_v7_do_resume
168168
#endif
169169

170170
/*
@@ -175,7 +175,7 @@ ENDPROC(cpu_v7_do_resume)
175175
globl_equ cpu_ca9mp_reset, cpu_v7_reset
176176
globl_equ cpu_ca9mp_do_idle, cpu_v7_do_idle
177177
globl_equ cpu_ca9mp_dcache_clean_area, cpu_v7_dcache_clean_area
178-
globl_equ cpu_ca9mp_switch_mm, cpu_v7_switch_mm
178+
globl_equ cpu_ca9mp_switch_mm, cpu_v7_btbinv_switch_mm
179179
globl_equ cpu_ca9mp_set_pte_ext, cpu_v7_set_pte_ext
180180
.globl cpu_ca9mp_suspend_size
181181
.equ cpu_ca9mp_suspend_size, cpu_v7_suspend_size + 4 * 2
@@ -490,8 +490,8 @@ __v7_setup_stack:
490490

491491
@ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
492492
define_processor_functions v7, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
493+
define_processor_functions v7_btbinv, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
493494
#ifndef CONFIG_ARM_LPAE
494-
define_processor_functions ca8, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
495495
define_processor_functions ca9mp, dabort=v7_early_abort, pabort=v7_pabort, suspend=1
496496
#endif
497497
#ifdef CONFIG_CPU_PJ4B
@@ -556,7 +556,7 @@ __v7_ca9mp_proc_info:
556556
__v7_ca8_proc_info:
557557
.long 0x410fc080
558558
.long 0xff0ffff0
559-
__v7_proc __v7_ca8_proc_info, __v7_setup, proc_fns = ca8_processor_functions
559+
__v7_proc __v7_ca8_proc_info, __v7_setup, proc_fns = v7_btbinv_processor_functions
560560
.size __v7_ca8_proc_info, . - __v7_ca8_proc_info
561561

562562
#endif /* CONFIG_ARM_LPAE */
@@ -600,7 +600,7 @@ __v7_ca7mp_proc_info:
600600
__v7_ca12mp_proc_info:
601601
.long 0x410fc0d0
602602
.long 0xff0ffff0
603-
__v7_proc __v7_ca12mp_proc_info, __v7_ca12mp_setup
603+
__v7_proc __v7_ca12mp_proc_info, __v7_ca12mp_setup, proc_fns = v7_btbinv_processor_functions
604604
.size __v7_ca12mp_proc_info, . - __v7_ca12mp_proc_info
605605

606606
/*
@@ -630,7 +630,7 @@ __v7_b15mp_proc_info:
630630
__v7_ca17mp_proc_info:
631631
.long 0x410fc0e0
632632
.long 0xff0ffff0
633-
__v7_proc __v7_ca17mp_proc_info, __v7_ca17mp_setup
633+
__v7_proc __v7_ca17mp_proc_info, __v7_ca17mp_setup, proc_fns = v7_btbinv_processor_functions
634634
.size __v7_ca17mp_proc_info, . - __v7_ca17mp_proc_info
635635

636636
/*

0 commit comments

Comments
 (0)