Commit 49965e0ffb for qemu.org
commit 49965e0ffbe396984a28ac35a640de9f7c120773
Author: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Date: Tue Sep 22 08:54:39 2026 +0200
target/arm: Access PSCI state atomically
Use qatomic_set() when updating ARMCPU::power_state and
CPUARMState::halt_reason. Read ARMCPU::power_state atomically in
arm_cpu_has_work(), which can run without the BQL held.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20260923171116.31276-9-philmd@oss.qualcomm.com>
diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
index 213e7ae056..ef14a1f8a9 100644
--- a/target/arm/arm-powerctl.c
+++ b/target/arm/arm-powerctl.c
@@ -49,8 +49,8 @@ void arm_set_cpu_power_state(ARMCPU *cpu, ARMPSCIState state)
{
CPUARMState *env = &cpu->env;
- cpu->power_state = state;
- env->halt_reason = state == PSCI_OFF ? HALT_PSCI : NOT_HALTED;
+ qatomic_set(&cpu->power_state, state);
+ qatomic_set(&env->halt_reason, state == PSCI_OFF ? HALT_PSCI : NOT_HALTED);
}
static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 76aa47ac50..5cfd3bcfc8 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -149,7 +149,7 @@ static bool arm_cpu_has_work(CPUState *cs)
* Only another PSCI call can wake the CPU up in which case the
* power_state would be set by arm_set_cpu_on_and_reset_async_work()
*/
- if (cpu->power_state == PSCI_OFF) {
+ if (qatomic_read(&cpu->power_state) == PSCI_OFF) {
g_assert(cpu->env.halt_reason == HALT_PSCI);
return false;
}