Skip to content

Commit a6e0107

Browse files
govindraj-armTrustedFirmware Code Review
authored andcommitted
Merge changes from topic "ar/cve_wa_refactor" into integration
* changes: refactor(cpus): optimize CVE checking refactor(cpus): move errata check to common code refactor(cpus): drop unused argument forward_flag
2 parents 5776045 + fd04156 commit a6e0107

File tree

23 files changed

+139
-355
lines changed

23 files changed

+139
-355
lines changed

include/lib/cpus/aarch64/cpu_macros.S

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@
5050
* Numeric value expected to read from CPU's MIDR
5151
* _resetfunc:
5252
* Reset function for the CPU.
53-
* _extra1:
54-
* This is a placeholder for future per CPU operations. Currently,
55-
* some CPUs use this entry to set a test function to determine if
56-
* the workaround for CVE-2017-5715 needs to be applied or not.
57-
* _extra2:
58-
* This is a placeholder for future per CPU operations. Currently
59-
* some CPUs use this entry to set a function to disable the
60-
* workaround for CVE-2018-3639.
61-
* _extra3:
62-
* This is a placeholder for future per CPU operations. Currently,
63-
* some CPUs use this entry to set a test function to determine if
64-
* the workaround for CVE-2022-23960 needs to be applied or not.
65-
* _extra4:
66-
* This is a placeholder for future per CPU operations. Currently,
67-
* some CPUs use this entry to set a test function to determine if
68-
* the workaround for CVE-2024-7881 needs to be applied or not.
6953
* _e_handler:
7054
* This is a placeholder for future per CPU exception handlers.
7155
* _power_down_ops:
@@ -78,7 +62,6 @@
7862
* used to handle power down at subsequent levels
7963
*/
8064
.macro declare_cpu_ops_base _name:req, _midr:req, _resetfunc:req, \
81-
_extra1:req, _extra2:req, _extra3:req, _extra4:req, \
8265
_e_handler:req, _power_down_ops:vararg
8366
.section .cpu_ops, "a"
8467
.align 3
@@ -87,10 +70,6 @@
8770
#if defined(IMAGE_AT_EL3)
8871
.quad \_resetfunc
8972
#endif
90-
.quad \_extra1
91-
.quad \_extra2
92-
.quad \_extra3
93-
.quad \_extra4
9473
.quad \_e_handler
9574
#ifdef IMAGE_BL31
9675
/* Insert list of functions */
@@ -153,28 +132,13 @@
153132

154133
.macro declare_cpu_ops _name:req, _midr:req, _resetfunc:req, \
155134
_power_down_ops:vararg
156-
declare_cpu_ops_base \_name, \_midr, \_resetfunc, 0, 0, 0, 0, 0, \
157-
\_power_down_ops
135+
declare_cpu_ops_base \_name, \_midr, \_resetfunc, 0, \_power_down_ops
158136
.endm
159137

160138
.macro declare_cpu_ops_eh _name:req, _midr:req, _resetfunc:req, \
161139
_e_handler:req, _power_down_ops:vararg
162140
declare_cpu_ops_base \_name, \_midr, \_resetfunc, \
163-
0, 0, 0, 0, \_e_handler, \_power_down_ops
164-
.endm
165-
166-
.macro declare_cpu_ops_wa _name:req, _midr:req, \
167-
_resetfunc:req, _extra1:req, _extra2:req, \
168-
_extra3:req, _power_down_ops:vararg
169-
declare_cpu_ops_base \_name, \_midr, \_resetfunc, \
170-
\_extra1, \_extra2, \_extra3, 0, 0, \_power_down_ops
171-
.endm
172-
173-
.macro declare_cpu_ops_wa_4 _name:req, _midr:req, \
174-
_resetfunc:req, _extra1:req, _extra2:req, \
175-
_extra3:req, _extra4:req, _power_down_ops:vararg
176-
declare_cpu_ops_base \_name, \_midr, \_resetfunc, \
177-
\_extra1, \_extra2, \_extra3, \_extra4, 0, \_power_down_ops
141+
\_e_handler, \_power_down_ops
178142
.endm
179143

180144
/*
@@ -240,7 +204,7 @@
240204
* Default value is 0.
241205
*/
242206
.macro add_erratum_entry _cpu:req, _cve:req, _id:req, _chosen:req, _split_wa=0
243-
#if REPORT_ERRATA || ERRATA_ABI_SUPPORT
207+
#if INCLUDE_ERRATA_LIST
244208
.pushsection .rodata.errata_entries
245209
.align 3
246210
.ifndef \_cpu\()_errata_list_start

include/lib/cpus/cpu_ops.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
/* The number of CPU operations allowed */
2323
#define CPU_MAX_PWR_DWN_OPS 2
2424

25-
#if __aarch64__
26-
#define CPU_NO_EXTRA1_FUNC 0
27-
#define CPU_NO_EXTRA2_FUNC 0
28-
#define CPU_NO_EXTRA3_FUNC 0
29-
#define CPU_NO_EXTRA4_FUNC 0
30-
#endif /* __aarch64__ */
31-
32-
3325
/*
3426
* Define the sizes of the fields in the cpu_ops structure. Word size is set per
3527
* Aarch so keep these definitions the same and each can include whatever it
@@ -41,10 +33,6 @@
4133
#else
4234
#define CPU_RESET_FUNC_SIZE 0
4335
#endif /* IMAGE_AT_EL3 */
44-
#define CPU_EXTRA1_FUNC_SIZE CPU_WORD_SIZE
45-
#define CPU_EXTRA2_FUNC_SIZE CPU_WORD_SIZE
46-
#define CPU_EXTRA3_FUNC_SIZE CPU_WORD_SIZE
47-
#define CPU_EXTRA4_FUNC_SIZE CPU_WORD_SIZE
4836
#define CPU_E_HANDLER_FUNC_SIZE CPU_WORD_SIZE
4937
/* The power down core and cluster is needed only in BL31 and BL32 */
5038
#if defined(IMAGE_BL31) || defined(IMAGE_BL32)
@@ -86,11 +74,7 @@
8674
#define CPU_MIDR 0
8775
#define CPU_RESET_FUNC CPU_MIDR + CPU_MIDR_SIZE
8876
#if __aarch64__
89-
#define CPU_EXTRA1_FUNC CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
90-
#define CPU_EXTRA2_FUNC CPU_EXTRA1_FUNC + CPU_EXTRA1_FUNC_SIZE
91-
#define CPU_EXTRA3_FUNC CPU_EXTRA2_FUNC + CPU_EXTRA2_FUNC_SIZE
92-
#define CPU_EXTRA4_FUNC CPU_EXTRA3_FUNC + CPU_EXTRA3_FUNC_SIZE
93-
#define CPU_E_HANDLER_FUNC CPU_EXTRA4_FUNC + CPU_EXTRA4_FUNC_SIZE
77+
#define CPU_E_HANDLER_FUNC CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
9478
#define CPU_PWR_DWN_OPS CPU_E_HANDLER_FUNC + CPU_E_HANDLER_FUNC_SIZE
9579
#else
9680
#define CPU_PWR_DWN_OPS CPU_RESET_FUNC + CPU_RESET_FUNC_SIZE
@@ -117,10 +101,6 @@ struct cpu_ops {
117101
void (*reset_func)(void);
118102
#endif /* IMAGE_AT_EL3 */
119103
#if __aarch64__
120-
void (*extra1_func)(void);
121-
void (*extra2_func)(void);
122-
void (*extra3_func)(void);
123-
void (*extra4_func)(void);
124104
void (*e_handler_func)(long es);
125105
#endif /* __aarch64__ */
126106
#if (defined(IMAGE_BL31) || defined(IMAGE_BL32)) && CPU_MAX_PWR_DWN_OPS

include/lib/cpus/errata.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
#define ERRATA_APPLIES 1
2828
#define ERRATA_MISSING 2
2929

30+
/* Errata ID for smc workarounds */
31+
#define ARCH_WORKAROUND_2 2
32+
#define ARCH_WORKAROUND_3 3
33+
34+
#define INCLUDE_ERRATA_LIST ( \
35+
REPORT_ERRATA | \
36+
ERRATA_ABI_SUPPORT | \
37+
WORKAROUND_CVE_2017_5715 | \
38+
WORKAROUND_CVE_2018_3639 | \
39+
WORKAROUND_CVE_2022_23960 | \
40+
WORKAROUND_CVE_2024_7881)
41+
3042
#ifndef __ASSEMBLER__
3143
#include <lib/cassert.h>
3244

@@ -70,6 +82,8 @@ static inline bool errata_a75_764081_applies(void)
7082
bool check_if_trbe_disable_affected_core(void);
7183
int check_wa_cve_2024_7881(void);
7284
bool errata_ich_vmcr_el2_applies(void);
85+
struct erratum_entry *find_erratum_entry(uint32_t errata_id);
86+
int check_erratum_applies(uint32_t cve, int errata_id);
7387

7488
#else
7589

@@ -82,8 +96,6 @@ bool errata_ich_vmcr_el2_applies(void);
8296
* unlikely event that this does happen, prepending the CVE id with a 0 should
8397
* resolve the conflict
8498
*/
85-
#define ERRATUM(id) 0, id
86-
#define CVE(year, id) year, id
8799
#define NO_ISB 1
88100
#define NO_ASSERT 0
89101
#define NO_APPLY_AT_RESET 0
@@ -96,6 +108,9 @@ bool errata_ich_vmcr_el2_applies(void);
96108

97109
#endif /* __ASSEMBLER__ */
98110

111+
#define ERRATUM(id) 0, id
112+
#define CVE(year, id) year, id
113+
99114
/* Macro to get CPU revision code for checking errata version compatibility. */
100115
#define CPU_REV(r, p) ((r << 4) | p)
101116

include/lib/cpus/wa_cve_2017_5715.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

include/lib/cpus/wa_cve_2018_3639.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

include/lib/cpus/wa_cve_2022_23960.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/cpus/aarch64/cortex_a57.S

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,20 @@ func cortex_a57_disable_ext_debug
6565
ret
6666
endfunc cortex_a57_disable_ext_debug
6767

68+
/* Erratum entry and check function for SMCCC_ARCH_WORKAROUND_3 */
69+
add_erratum_entry cortex_a57, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
70+
71+
check_erratum_chosen cortex_a57, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
72+
6873
/*
6974
* Disable the over-read from the LDNP/STNP instruction. The SDEN doesn't
70-
* provide and erratum number, so assign it an obvious 1
75+
* provide and erratum number, so assign it an obvious 99999
7176
*/
72-
workaround_reset_start cortex_a57, ERRATUM(1), A57_DISABLE_NON_TEMPORAL_HINT
77+
workaround_reset_start cortex_a57, ERRATUM(99999), A57_DISABLE_NON_TEMPORAL_HINT
7378
sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_OVERREAD
74-
workaround_reset_end cortex_a57, ERRATUM(1)
79+
workaround_reset_end cortex_a57, ERRATUM(99999)
7580

76-
check_erratum_ls cortex_a57, ERRATUM(1), CPU_REV(1, 2)
81+
check_erratum_ls cortex_a57, ERRATUM(99999), CPU_REV(1, 2)
7782

7883
workaround_reset_start cortex_a57, ERRATUM(806969), ERRATA_A57_806969
7984
sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
@@ -187,11 +192,6 @@ cpu_reset_func_start cortex_a57
187192
sysreg_bit_set CORTEX_A57_ECTLR_EL1, CORTEX_A57_ECTLR_SMP_BIT
188193
cpu_reset_func_end cortex_a57
189194

190-
func check_smccc_arch_workaround_3
191-
mov x0, #ERRATA_APPLIES
192-
ret
193-
endfunc check_smccc_arch_workaround_3
194-
195195
/* ----------------------------------------------------
196196
* The CPU Ops core power down function for Cortex-A57.
197197
* ----------------------------------------------------
@@ -307,10 +307,7 @@ func cortex_a57_cpu_reg_dump
307307
ret
308308
endfunc cortex_a57_cpu_reg_dump
309309

310-
declare_cpu_ops_wa cortex_a57, CORTEX_A57_MIDR, \
310+
declare_cpu_ops cortex_a57, CORTEX_A57_MIDR, \
311311
cortex_a57_reset_func, \
312-
check_erratum_cortex_a57_5715, \
313-
CPU_NO_EXTRA2_FUNC, \
314-
check_smccc_arch_workaround_3, \
315312
cortex_a57_core_pwr_dwn, \
316313
cortex_a57_cluster_pwr_dwn

lib/cpus/aarch64/cortex_a72.S

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ func cortex_a72_disable_ext_debug
7676
ret
7777
endfunc cortex_a72_disable_ext_debug
7878

79-
func check_smccc_arch_workaround_3
79+
check_erratum_custom_start cortex_a72, ERRATUM(ARCH_WORKAROUND_3)
8080
cpu_check_csv2 x0, 1f
8181
mov x0, #ERRATA_APPLIES
8282
ret
8383
1:
8484
mov x0, #ERRATA_NOT_APPLIES
8585
ret
86-
endfunc check_smccc_arch_workaround_3
86+
check_erratum_custom_end cortex_a72, ERRATUM(ARCH_WORKAROUND_3)
87+
88+
/* Erratum entry and check function for SMCCC_ARCH_WORKAROUND_3 */
89+
add_erratum_entry cortex_a72, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
8790

8891
workaround_reset_start cortex_a72, ERRATUM(859971), ERRATA_A72_859971
8992
sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH
@@ -294,10 +297,7 @@ func cortex_a72_cpu_reg_dump
294297
ret
295298
endfunc cortex_a72_cpu_reg_dump
296299

297-
declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \
300+
declare_cpu_ops cortex_a72, CORTEX_A72_MIDR, \
298301
cortex_a72_reset_func, \
299-
check_erratum_cortex_a72_5715, \
300-
CPU_NO_EXTRA2_FUNC, \
301-
check_smccc_arch_workaround_3, \
302302
cortex_a72_core_pwr_dwn, \
303303
cortex_a72_cluster_pwr_dwn

lib/cpus/aarch64/cortex_a73.S

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func cortex_a73_disable_smp
3333
ret
3434
endfunc cortex_a73_disable_smp
3535

36-
func check_smccc_arch_workaround_3
37-
mov x0, #ERRATA_APPLIES
38-
ret
39-
endfunc check_smccc_arch_workaround_3
36+
/* Erratum entry and check function for SMCCC_ARCH_WORKAROUND_3 */
37+
add_erratum_entry cortex_a73, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
38+
39+
check_erratum_chosen cortex_a73, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
4040

4141
workaround_reset_start cortex_a73, ERRATUM(852427), ERRATA_A73_852427
4242
sysreg_bit_set CORTEX_A73_DIAGNOSTIC_REGISTER, BIT(12)
@@ -200,10 +200,7 @@ func cortex_a73_cpu_reg_dump
200200
ret
201201
endfunc cortex_a73_cpu_reg_dump
202202

203-
declare_cpu_ops_wa cortex_a73, CORTEX_A73_MIDR, \
203+
declare_cpu_ops cortex_a73, CORTEX_A73_MIDR, \
204204
cortex_a73_reset_func, \
205-
check_erratum_cortex_a73_5715, \
206-
CPU_NO_EXTRA2_FUNC, \
207-
check_smccc_arch_workaround_3, \
208205
cortex_a73_core_pwr_dwn, \
209206
cortex_a73_cluster_pwr_dwn

lib/cpus/aarch64/cortex_a75.S

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
cpu_reset_prologue cortex_a75
2222

23+
/* Erratum entry and check function for SMCCC_ARCH_WORKAROUND_3 */
24+
add_erratum_entry cortex_a75, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
25+
26+
check_erratum_chosen cortex_a75, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
27+
2328
workaround_reset_start cortex_a75, ERRATUM(764081), ERRATA_A75_764081
2429
sysreg_bit_set sctlr_el3, SCTLR_IESB_BIT
2530
workaround_reset_end cortex_a75, ERRATUM(764081)
@@ -131,11 +136,6 @@ cpu_reset_func_start cortex_a75
131136
#endif
132137
cpu_reset_func_end cortex_a75
133138

134-
func check_smccc_arch_workaround_3
135-
mov x0, #ERRATA_APPLIES
136-
ret
137-
endfunc check_smccc_arch_workaround_3
138-
139139
/* ---------------------------------------------
140140
* HW will do the cache maintenance while powering down
141141
* ---------------------------------------------
@@ -170,9 +170,6 @@ func cortex_a75_cpu_reg_dump
170170
ret
171171
endfunc cortex_a75_cpu_reg_dump
172172

173-
declare_cpu_ops_wa cortex_a75, CORTEX_A75_MIDR, \
173+
declare_cpu_ops cortex_a75, CORTEX_A75_MIDR, \
174174
cortex_a75_reset_func, \
175-
check_erratum_cortex_a75_5715, \
176-
CPU_NO_EXTRA2_FUNC, \
177-
check_smccc_arch_workaround_3, \
178175
cortex_a75_core_pwr_dwn

0 commit comments

Comments
 (0)