From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Subject: [PULL 16/18] target/arm: Access halt state atomically
Date: Thu, 24 Sep 2026 17:23:51 +0200 [thread overview]
Message-ID: <20260924152353.36209-17-philmd@oss.qualcomm.com> (raw)
In-Reply-To: <20260924152353.36209-1-philmd@oss.qualcomm.com>
arm_cpu_has_work() runs without the BQL held and can inspect
halt_reason and event_register while other CPU contexts update
them. The WFxT timer may also consume HALT_WFE asynchronously.
Use atomic accesses for the halt state, including the WFI/WFE
and halt-exit stores. This keeps the halt/wakeup protocol
race-free and matches the atomic state transitions used by the
asynchronous wake-up paths.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20260923171116.31276-10-philmd@oss.qualcomm.com>
---
target/arm/cpu.c | 7 ++++---
target/arm/tcg/op_helper.c | 8 ++++----
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 5cfd3bcfc8e..090470da40a 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -144,20 +144,21 @@ int arm_cpu_mmu_index(CPUState *cs, bool ifetch)
static bool arm_cpu_has_work(CPUState *cs)
{
ARMCPU *cpu = ARM_CPU(cs);
+ ARMHaltReason halt_reason = qatomic_read(&cpu->env.halt_reason);
/*
* 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 (qatomic_read(&cpu->power_state) == PSCI_OFF) {
- g_assert(cpu->env.halt_reason == HALT_PSCI);
+ g_assert(halt_reason == HALT_PSCI);
return false;
}
/*
* A wake-up event should only wake us if we are halted on a WFE
*/
- if (cpu->env.halt_reason == HALT_WFE && cpu->env.event_register) {
+ if (halt_reason == HALT_WFE && qatomic_read(&cpu->env.event_register)) {
return true;
}
@@ -882,7 +883,7 @@ bool arm_cpu_exec_halt(CPUState *cs)
timer_del(cpu->wfxt_timer);
}
/* clear the halt reason */
- cpu->env.halt_reason = NOT_HALTED;
+ qatomic_set(&cpu->env.halt_reason, NOT_HALTED);
}
return leave_halt;
}
diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c
index c2b09176cb1..643b1482523 100644
--- a/target/arm/tcg/op_helper.c
+++ b/target/arm/tcg/op_helper.c
@@ -398,7 +398,7 @@ void HELPER(wfi)(CPUARMState *env, uint32_t insn_len)
target_el);
}
- env->halt_reason = HALT_WFI;
+ qatomic_set(&env->halt_reason, HALT_WFI);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
@@ -460,7 +460,7 @@ void HELPER(wfit)(CPUARMState *env, uint32_t rd)
} else {
timer_mod(cpu->wfxt_timer, nexttick);
}
- env->halt_reason = HALT_WFI;
+ qatomic_set(&env->halt_reason, HALT_WFI);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
@@ -629,7 +629,7 @@ void HELPER(wfe)(CPUARMState *env, uint32_t insn_len)
}
}
- env->halt_reason = HALT_WFE;
+ qatomic_set(&env->halt_reason, HALT_WFE);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
@@ -723,7 +723,7 @@ void HELPER(wfet)(CPUARMState *env, uint32_t rd)
}
}
- env->halt_reason = HALT_WFE;
+ qatomic_set(&env->halt_reason, HALT_WFE);
cs->exception_index = EXCP_HLT;
cs->halted = 1;
cpu_loop_exit(cs);
--
2.53.0
next prev parent reply other threads:[~2026-09-24 15:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 15:23 [PULL 00/18] Misc target/ patches for 2026-09-24 Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 01/18] target/mips: Fix zero in gen_mxu_d8sum Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 02/18] target/mips: Drop zero optimization in gen_mxu_s32mul Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 03/18] target/mips: Split out gen_mxu_logic Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 04/18] target/mips: Use gen_mxu_logic for gen_mxu_S32MAX_S32MIN Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 05/18] target/mips: Use gen_mxu_logic for gen_mxu_S32SLT Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 06/18] target/mips: Use gen_mxu_logic for gen_mxu_S32CPS Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 07/18] target/riscv: Stub out kvm functions Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 08/18] system: Document has_work() synchronization requirements Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 09/18] target/s390x: Use s390_cpu_get_state() consistently Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 10/18] target/s390x: Extend comment about PV cpu load state Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 11/18] target/s390x: Make s390_cpu_set_state() return void Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 12/18] target/s390x: Use S390CpuState for CPU state APIs Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 13/18] target/s390x: Access S390CpuState atomically Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 14/18] target/arm: Un-inline arm_set_cpu_power_state() Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 15/18] target/arm: Access PSCI state atomically Philippe Mathieu-Daudé
2026-09-24 15:23 ` Philippe Mathieu-Daudé [this message]
2026-09-24 15:23 ` [PULL 17/18] target/i386: Use an acquire load for interrupt_request() Philippe Mathieu-Daudé
2026-09-24 15:23 ` [PULL 18/18] target/ppc: Stop vCPU thread before calling parent_unrealize Philippe Mathieu-Daudé
2026-09-25 2:35 ` [PULL 00/18] Misc target/ patches for 2026-09-24 Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924152353.36209-17-philmd@oss.qualcomm.com \
--to=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.