From cc94e71b3ac5233d5ff6bc0156ded8ff03408c24 Mon Sep 17 00:00:00 2001 From: Boyan Karatotev Date: Thu, 26 Sep 2024 17:00:09 +0100 Subject: [PATCH] refactor(cpus): undo errata mitigations The workarounds introduced in the three patches starting at 888eafa00b99aa06b4ff688407336811a7ff439a assumed that any powerdown request will be (forced to be) terminal. This assumption can no longer be the case for new CPUs so there is a need to revisit these older cores. Since we may wake up, we now need to respect the workaround's recommendation that the workaround needs to be reverted on wakeup. So do exactly that. Introduce a new helper to toggle bits in assembly. This allows us to call the workaround twice, with the first call setting the workaround and second undoing it. This is also used for gelas' an travis' powerdown routines. This is so the same function can be called again Also fix the condition in the cpu helper macro as it was subtly wrong Change-Id: Iff9e5251dc9d8670d085d88c070f78991955e7c3 Signed-off-by: Boyan Karatotev --- include/lib/cpus/aarch64/cpu_macros.S | 2 +- lib/cpus/aarch64/cortex_a710.S | 1 + lib/cpus/aarch64/cortex_x3.S | 1 + lib/cpus/aarch64/neoverse_n2.S | 1 + lib/psci/aarch64/psci_helpers.S | 10 +++++++++- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/lib/cpus/aarch64/cpu_macros.S b/include/lib/cpus/aarch64/cpu_macros.S index ab6041289..ac26fd74b 100644 --- a/include/lib/cpus/aarch64/cpu_macros.S +++ b/include/lib/cpus/aarch64/cpu_macros.S @@ -463,7 +463,7 @@ * clobbers: x0-x10 (PCS compliant) */ .macro apply_erratum _cpu:req, _cve:req, _id:req, _chosen:req, _get_rev=GET_CPU_REV - .if (\_chosen & \_get_rev) + .if (\_chosen && \_get_rev) mov x9, x30 bl cpu_get_rev_var mov x10, x0 diff --git a/lib/cpus/aarch64/cortex_a710.S b/lib/cpus/aarch64/cortex_a710.S index 830771aa7..fef240c1c 100644 --- a/lib/cpus/aarch64/cortex_a710.S +++ b/lib/cpus/aarch64/cortex_a710.S @@ -162,6 +162,7 @@ workaround_reset_end cortex_a710, ERRATUM(2282622) check_erratum_ls cortex_a710, ERRATUM(2282622), CPU_REV(2, 1) +.global erratum_cortex_a710_2291219_wa workaround_runtime_start cortex_a710, ERRATUM(2291219), ERRATA_A710_2291219 /* Set/unset bit 36 in ACTLR2_EL1. The first call will set it, applying * the workaround. Second call clears it to undo it. */ diff --git a/lib/cpus/aarch64/cortex_x3.S b/lib/cpus/aarch64/cortex_x3.S index 7a339b489..7c6af8cb4 100644 --- a/lib/cpus/aarch64/cortex_x3.S +++ b/lib/cpus/aarch64/cortex_x3.S @@ -52,6 +52,7 @@ workaround_runtime_end cortex_x3, ERRATUM(2302506), NO_ISB check_erratum_ls cortex_x3, ERRATUM(2302506), CPU_REV(1, 1) +.global erratum_cortex_x3_2313909_wa workaround_runtime_start cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909 /* Set/unset bit 36 in ACTLR2_EL1. The first call will set it, applying * the workaround. Second call clears it to undo it. */ diff --git a/lib/cpus/aarch64/neoverse_n2.S b/lib/cpus/aarch64/neoverse_n2.S index 5cccff311..b9818cd64 100644 --- a/lib/cpus/aarch64/neoverse_n2.S +++ b/lib/cpus/aarch64/neoverse_n2.S @@ -165,6 +165,7 @@ workaround_reset_end neoverse_n2, ERRATUM(2280757) check_erratum_ls neoverse_n2, ERRATUM(2280757), CPU_REV(0, 0) +.global erratum_neoverse_n2_2326639_wa workaround_runtime_start neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639 /* Set/unset bit 36 in ACTLR2_EL1. The first call will set it, applying * the workaround. Second call clears it to undo it. */ diff --git a/lib/psci/aarch64/psci_helpers.S b/lib/psci/aarch64/psci_helpers.S index cca08c132..088ab43f4 100644 --- a/lib/psci/aarch64/psci_helpers.S +++ b/lib/psci/aarch64/psci_helpers.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -131,4 +131,12 @@ func psci_power_down_wfi 1: wfi b 1b + + /* + * in case the WFI wasn't terminal, we have to undo errata mitigations. + * These will be smart enough to handle being called the same way + */ + apply_erratum cortex_a710, ERRATUM(2291219), ERRATA_A710_2291219 + apply_erratum cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909, NO_GET_CPU_REV + apply_erratum neoverse_n2, ERRATUM(2326639), ERRATA_N2_2326639, NO_GET_CPU_REV endfunc psci_power_down_wfi