فهرست منبع

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 <akihiko.odaki@daynix.com>
Link: https://lore.kernel.org/r/20240714-cpu-v1-1-19c2f8de2055@daynix.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Akihiko Odaki 1 سال پیش
والد
کامیت
f8b64d35a6
3فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  1. 11 0
      cpu-common.c
  2. 1 0
      hw/core/cpu-common.c
  3. 6 0
      include/hw/core/cpu.h

+ 11 - 0
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);
     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)
 void process_queued_cpu_work(CPUState *cpu)
 {
 {
     struct qemu_work_item *wi;
     struct qemu_work_item *wi;

+ 1 - 0
hw/core/cpu-common.c

@@ -281,6 +281,7 @@ static void cpu_common_finalize(Object *obj)
         g_free(cpu->plugin_state);
         g_free(cpu->plugin_state);
     }
     }
 #endif
 #endif
+    free_queued_cpu_work(cpu);
     g_array_free(cpu->gdb_regs, TRUE);
     g_array_free(cpu->gdb_regs, TRUE);
     qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
     qemu_lockcnt_destroy(&cpu->in_ioctl_lock);
     qemu_mutex_destroy(&cpu->work_mutex);
     qemu_mutex_destroy(&cpu->work_mutex);

+ 6 - 0
include/hw/core/cpu.h

@@ -1000,6 +1000,12 @@ void cpu_resume(CPUState *cpu);
  */
  */
 void cpu_remove_sync(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
  * process_queued_cpu_work() - process all items on CPU work queue
  * @cpu: The CPU which work queue to process.
  * @cpu: The CPU which work queue to process.