Bipin Ravi | 8649974 | 2022-01-18 01:59:06 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022, 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. |
Bipin Ravi | 9ee6dd4 | 2022-10-13 17:25:51 -0500 | [diff] [blame] | 12 | * The macro saves x2 to the CPU context. |
Bipin Ravi | 8649974 | 2022-01-18 01:59:06 -0600 | [diff] [blame] | 13 | * SP should point to the CPU context. |
| 14 | */ |
| 15 | .macro apply_cve_2022_23960_bhb_wa _bhb_loop_count |
Bipin Ravi | 9ee6dd4 | 2022-10-13 17:25:51 -0500 | [diff] [blame] | 16 | str x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
Bipin Ravi | 8649974 | 2022-01-18 01:59:06 -0600 | [diff] [blame] | 17 | |
| 18 | /* CVE-BHB-NUM loop count */ |
| 19 | mov x2, \_bhb_loop_count |
| 20 | |
| 21 | 1: |
| 22 | /* b pc+4 part of the workaround */ |
| 23 | b 2f |
| 24 | 2: |
| 25 | subs x2, x2, #1 |
| 26 | bne 1b |
Bipin Ravi | 9ee6dd4 | 2022-10-13 17:25:51 -0500 | [diff] [blame] | 27 | speculation_barrier |
| 28 | ldr x2, [sp, #CTX_GPREGS_OFFSET + CTX_GPREG_X2] |
Bipin Ravi | 8649974 | 2022-01-18 01:59:06 -0600 | [diff] [blame] | 29 | .endm |
| 30 | #endif /* WORKAROUND_CVE_2022_23960 */ |