qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpu: Free queued CPU work
@ 2024-07-14 10:46 Akihiko Odaki
  2024-07-16  8:46 ` Paolo Bonzini
  2024-07-16 15:58 ` Alex Bennée
  0 siblings, 2 replies; 3+ messages in thread
From: Akihiko Odaki @ 2024-07-14 10:46 UTC (permalink / raw)
  To: Richard Henderson, Paolo Bonzini, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang
  Cc: qemu-devel, Akihiko Odaki

Running qemu-system-aarch64 -M virt -nographic and terminating it will
result in a LeakSanitizer error due to remaining queued CPU work so
free it.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/hw/core/cpu.h |  6 ++++++
 cpu-common.c          | 11 +++++++++++
 hw/core/cpu-common.c  |  1 +
 3 files changed, 18 insertions(+)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index a2c8536943f7..8e6466c1ddab 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1000,6 +1000,12 @@ void cpu_resume(CPUState *cpu);
  */
 void cpu_remove_sync(CPUState *cpu);
 
+/**
+ * free_queued_cpu_work() - free all items on CPU work queue
+ * @cpu: The CPU which work queue to free.
+ */
+void free_queued_cpu_work(CPUState *cpu);
+
 /**
  * process_queued_cpu_work() - process all items on CPU work queue
  * @cpu: The CPU which work queue to process.
diff --git a/cpu-common.c b/cpu-common.c
index ce78273af597..7ae136f98ca7 100644
--- a/cpu-common.c
+++ b/cpu-common.c
@@ -331,6 +331,17 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
     queue_work_on_cpu(cpu, wi);
 }
 
+void free_queued_cpu_work(CPUState *cpu)
+{
+    while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
+        struct qemu_work_item *wi = QSIMPLEQ_FIRST(&cpu->work_list);
+        QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
+        if (wi->free) {
+            g_free(wi);
+        }
+    }
+}
+
 void process_queued_cpu_work(CPUState *cpu)
 {
     struct qemu_work_item *wi;
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index b19e1fdacf22..d2e3e4570ab7 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -281,6 +281,7 @@ static void cpu_common_finalize(Object *obj)
         g_free(cpu->plugin_state);
     }
 #endif
+    free_queued_cpu_work(cpu);
     g_array_free(cpu->gdb_regs, TRUE);
     qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
     qemu_mutex_destroy(&cpu->work_mutex);

---
base-commit: f2cb4026fccfe073f84a4b440e41d3ed0c3134f6
change-id: 20240714-cpu-c4d28823b4c2

Best regards,
-- 
Akihiko Odaki <akihiko.odaki@daynix.com>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpu: Free queued CPU work
  2024-07-14 10:46 [PATCH] cpu: Free queued CPU work Akihiko Odaki
@ 2024-07-16  8:46 ` Paolo Bonzini
  2024-07-16 15:58 ` Alex Bennée
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-07-16  8:46 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Richard Henderson, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, qemu-devel

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cpu: Free queued CPU work
  2024-07-14 10:46 [PATCH] cpu: Free queued CPU work Akihiko Odaki
  2024-07-16  8:46 ` Paolo Bonzini
@ 2024-07-16 15:58 ` Alex Bennée
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Bennée @ 2024-07-16 15:58 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Richard Henderson, Paolo Bonzini, Eduardo Habkost,
	Marcel Apfelbaum, Philippe Mathieu-Daudé, Yanan Wang,
	qemu-devel

Akihiko Odaki <akihiko.odaki@daynix.com> writes:

> Running qemu-system-aarch64 -M virt -nographic and terminating it will
> result in a LeakSanitizer error due to remaining queued CPU work so
> free it.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>

FWIW this is likely the queued async task that
qemu_plugin_vcpu_init_hook sets up on the fake CPU -M virt creates at:

        /*
         * Instantiate a temporary CPU object to find out about what
         * we are about to deal with. Once this is done, get rid of
         * the object.
         */
        cpuobj = object_new(possible_cpus->cpus[0].type);
        armcpu = ARM_CPU(cpuobj);

        pa_bits = arm_pamax(armcpu);

        object_unref(cpuobj);

Anyway:

Tested-by: Alex Bennée <alex.bennee@linaro.org>


> ---
>  include/hw/core/cpu.h |  6 ++++++
>  cpu-common.c          | 11 +++++++++++
>  hw/core/cpu-common.c  |  1 +
>  3 files changed, 18 insertions(+)
>
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index a2c8536943f7..8e6466c1ddab 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -1000,6 +1000,12 @@ void cpu_resume(CPUState *cpu);
>   */
>  void cpu_remove_sync(CPUState *cpu);
>  
> +/**
> + * free_queued_cpu_work() - free all items on CPU work queue
> + * @cpu: The CPU which work queue to free.
> + */
> +void free_queued_cpu_work(CPUState *cpu);
> +
>  /**
>   * process_queued_cpu_work() - process all items on CPU work queue
>   * @cpu: The CPU which work queue to process.
> diff --git a/cpu-common.c b/cpu-common.c
> index ce78273af597..7ae136f98ca7 100644
> --- a/cpu-common.c
> +++ b/cpu-common.c
> @@ -331,6 +331,17 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
>      queue_work_on_cpu(cpu, wi);
>  }
>  
> +void free_queued_cpu_work(CPUState *cpu)
> +{
> +    while (!QSIMPLEQ_EMPTY(&cpu->work_list)) {
> +        struct qemu_work_item *wi = QSIMPLEQ_FIRST(&cpu->work_list);
> +        QSIMPLEQ_REMOVE_HEAD(&cpu->work_list, node);
> +        if (wi->free) {
> +            g_free(wi);
> +        }
> +    }
> +}
> +
>  void process_queued_cpu_work(CPUState *cpu)
>  {
>      struct qemu_work_item *wi;
> diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
> index b19e1fdacf22..d2e3e4570ab7 100644
> --- a/hw/core/cpu-common.c
> +++ b/hw/core/cpu-common.c
> @@ -281,6 +281,7 @@ static void cpu_common_finalize(Object *obj)
>          g_free(cpu->plugin_state);
>      }
>  #endif
> +    free_queued_cpu_work(cpu);
>      g_array_free(cpu->gdb_regs, TRUE);
>      qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
>      qemu_mutex_destroy(&cpu->work_mutex);
>
> ---
> base-commit: f2cb4026fccfe073f84a4b440e41d3ed0c3134f6
> change-id: 20240714-cpu-c4d28823b4c2
>
> Best regards,

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-16 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-14 10:46 [PATCH] cpu: Free queued CPU work Akihiko Odaki
2024-07-16  8:46 ` Paolo Bonzini
2024-07-16 15:58 ` Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).