[PATCH 2/4] cpus: Access CPUState::thread_kicked atomically

Philippe Mathieu-Daudé posted 4 patches 4 months, 2 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Alexander Graf <agraf@csgraf.de>, Mads Ynddal <mads@ynddal.dk>, Peter Maydell <peter.maydell@linaro.org>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>
[PATCH 2/4] cpus: Access CPUState::thread_kicked atomically
Posted by Philippe Mathieu-Daudé 4 months, 2 weeks ago
cpus_kick_thread() is called via cpu_exit() -> qemu_cpu_kick(),
and also via gdb_syscall_handling(). Access the CPUState field
using atomic accesses. See commit 8ac2ca02744 ("accel: use atomic
accesses for exit_request") for rationale.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/cpus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/system/cpus.c b/system/cpus.c
index 6062226d4ac..818a8047198 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -480,10 +480,10 @@ void qemu_process_cpu_events(CPUState *cpu)
 
 void cpus_kick_thread(CPUState *cpu)
 {
-    if (cpu->thread_kicked) {
+    if (qatomic_read(&cpu->thread_kicked)) {
         return;
     }
-    cpu->thread_kicked = true;
+    qatomic_set(&cpu->thread_kicked, true);
 
 #ifndef _WIN32
     int err = pthread_kill(cpu->thread->thread, SIG_IPI);
-- 
2.51.0


Re: [PATCH 2/4] cpus: Access CPUState::thread_kicked atomically
Posted by Manos Pitsidianakis 4 months, 1 week ago
On Thu, Sep 25, 2025 at 5:55 AM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> cpus_kick_thread() is called via cpu_exit() -> qemu_cpu_kick(),
> and also via gdb_syscall_handling(). Access the CPUState field
> using atomic accesses. See commit 8ac2ca02744 ("accel: use atomic
> accesses for exit_request") for rationale.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  system/cpus.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/system/cpus.c b/system/cpus.c
> index 6062226d4ac..818a8047198 100644
> --- a/system/cpus.c
> +++ b/system/cpus.c
> @@ -480,10 +480,10 @@ void qemu_process_cpu_events(CPUState *cpu)
>
>  void cpus_kick_thread(CPUState *cpu)
>  {
> -    if (cpu->thread_kicked) {
> +    if (qatomic_read(&cpu->thread_kicked)) {
>          return;
>      }
> -    cpu->thread_kicked = true;
> +    qatomic_set(&cpu->thread_kicked, true);
>
>  #ifndef _WIN32
>      int err = pthread_kill(cpu->thread->thread, SIG_IPI);
> --
> 2.51.0
>

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>