xref: /rk3399_ARM-atf/lib/cpus/aarch64/wa_cve_2022_23960_bhb.S (revision ab471aebf2424d3b503edefef2b45f3fbb1b8d56)
1/*
2 * Copyright (c) 2025, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <context.h>
8
9#if WORKAROUND_CVE_2022_23960
10	/*
11	 * This macro applies the mitigation for CVE-2022-23960.
12         * The macro saves x2 to the CPU context.
13         * SP should point to the CPU context.
14	 */
15	.macro	apply_cve_2022_23960_bhb_wa _bhb_loop_count
16
17#if ENABLE_FEAT_CLRBHB
18	/*
19	 * Platforms with FEAT_CLRBHB can omit the loop.
20	 */
21	clrbhb
22	isb
23#endif /* ENABLE_FEAT_CLRBHB */
24
25#if ENABLE_FEAT_CLRBHB != 1
26	str	x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
27
28	/* CVE-BHB-NUM loop count */
29	mov	x2, \_bhb_loop_count
30
311:
32	/* b pc+4 part of the workaround */
33	b	2f
342:
35	subs	x2, x2, #1
36	bne	1b
37	speculation_barrier
38	ldr	x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2]
393:
40#endif	/* ENABLE_FEAT_CLRBHB != 1 */
41	.endm
42#endif /* WORKAROUND_CVE_2022_23960 */
43