cpu: Free queued CPU work
PATCH 1/1 cpu: Free queued CPU work
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 <[email protected]>
--- include/hw/core/cpu.h | 6 ++++++ cpu-common.c | 11 +++++++++++ hw/core/cpu-common.c | 1 + 3 files changed, 18 insertions(+)
include/hw/core/cpu.h +6 -0
@@ -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.
cpu-common.c +11 -0
@@ -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;
hw/core/cpu-common.c +1 -0
@@ -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,
Signature · 1 line
Akihiko Odaki <[email protected]>
Paolo Bonzini
AppliedQueued, thanks.
Paolo
Quoted 5 lines · 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 <[email protected]>
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 <[email protected]>
Quoted 63 lines
--- include/hw/core/cpu.h | 6 ++++++ cpu-common.c | 11 +++++++++++ hw/core/cpu-common.c | 1 + 3 files changed, 18 insertions(+)include/hw/core/cpu.h +6
-0@@ -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. cpu-common.c +11
-0@@ -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;hw/core/cpu-common.c +1
-1@@ -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-c4d28823b4c2Best regards,
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro