All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Wenchao Wang" <wenchao.wang@intel.com>,
	"Laurent Vivier" <lvivier@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Cameron Esfahani" <dirty@apple.com>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	haxm-team@intel.com, "Paul Durrant" <paul@xen.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	xen-devel@lists.xenproject.org,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Reinoud Zandijk" <reinoud@netbsd.org>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Kamil Rytarowski" <kamil@netbsd.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Thomas Huth" <thuth@redhat.com>, "Colin Xu" <colin.xu@intel.com>,
	"Mark Kanda" <mark.kanda@oracle.com>
Subject: [PATCH v4 01/13] cpu: Free cpu->cpu_ases in cpu_address_space_destroy()
Date: Wed, 23 Mar 2022 18:17:39 +0100	[thread overview]
Message-ID: <20220323171751.78612-2-philippe.mathieu.daude@gmail.com> (raw)
In-Reply-To: <20220323171751.78612-1-philippe.mathieu.daude@gmail.com>

From: Mark Kanda <mark.kanda@oracle.com>

Create cpu_address_space_destroy() to free a CPU's cpu_ases list.

vCPU hotunplug related leak reported by Valgrind:

==132362== 216 bytes in 1 blocks are definitely lost in loss record 7,119 of 8,549
==132362==    at 0x4C3ADBB: calloc (vg_replace_malloc.c:1117)
==132362==    by 0x69EE4CD: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.5600.4)
==132362==    by 0x7E34AF: cpu_address_space_init (physmem.c:751)
==132362==    by 0x45053E: qemu_init_vcpu (cpus.c:635)
==132362==    by 0x76B4A7: x86_cpu_realizefn (cpu.c:6520)
==132362==    by 0x9343ED: device_set_realized (qdev.c:531)
==132362==    by 0x93E26F: property_set_bool (object.c:2273)
==132362==    by 0x93C23E: object_property_set (object.c:1408)
==132362==    by 0x9406DC: object_property_set_qobject (qom-qobject.c:28)
==132362==    by 0x93C5A9: object_property_set_bool (object.c:1477)
==132362==    by 0x933C81: qdev_realize (qdev.c:333)
==132362==    by 0x455E9A: qdev_device_add_from_qdict (qdev-monitor.c:713)

Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220321141409.3112932-5-mark.kanda@oracle.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 cpu.c                     | 1 +
 include/exec/cpu-common.h | 7 +++++++
 softmmu/physmem.c         | 5 +++++
 3 files changed, 13 insertions(+)

diff --git a/cpu.c b/cpu.c
index be1f8b074c..59352a1487 100644
--- a/cpu.c
+++ b/cpu.c
@@ -174,6 +174,7 @@ void cpu_exec_unrealizefn(CPUState *cpu)
         tcg_exec_unrealizefn(cpu);
     }
 
+    cpu_address_space_destroy(cpu);
     cpu_list_remove(cpu);
 }
 
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 50a7d2912e..b17ad61ae4 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -111,6 +111,13 @@ size_t qemu_ram_pagesize_largest(void);
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
+/**
+ * cpu_address_space_destroy:
+ * @cpu: CPU for this address space
+ *
+ * Cleanup CPU's cpu_ases list.
+ */
+void cpu_address_space_destroy(CPUState *cpu);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 43ae70fbe2..aec61ca07a 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -762,6 +762,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
+void cpu_address_space_destroy(CPUState *cpu)
+{
+    g_free(cpu->cpu_ases);
+}
+
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
-- 
2.35.1



WARNING: multiple messages have this Message-ID (diff)
From: "Philippe Mathieu-Daudé" <philippe.mathieu.daude@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Paul Durrant" <paul@xen.org>, "Peter Xu" <peterx@redhat.com>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	haxm-team@intel.com, "Colin Xu" <colin.xu@intel.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Kamil Rytarowski" <kamil@netbsd.org>,
	"Reinoud Zandijk" <reinoud@netbsd.org>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	xen-devel@lists.xenproject.org,
	"Laurent Vivier" <lvivier@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Cameron Esfahani" <dirty@apple.com>,
	"Roman Bolshakov" <r.bolshakov@yadro.com>,
	"Sunil Muthuswamy" <sunilmut@microsoft.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Wenchao Wang" <wenchao.wang@intel.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH v4 01/13] cpu: Free cpu->cpu_ases in cpu_address_space_destroy()
Date: Wed, 23 Mar 2022 18:17:39 +0100	[thread overview]
Message-ID: <20220323171751.78612-2-philippe.mathieu.daude@gmail.com> (raw)
In-Reply-To: <20220323171751.78612-1-philippe.mathieu.daude@gmail.com>

From: Mark Kanda <mark.kanda@oracle.com>

Create cpu_address_space_destroy() to free a CPU's cpu_ases list.

vCPU hotunplug related leak reported by Valgrind:

==132362== 216 bytes in 1 blocks are definitely lost in loss record 7,119 of 8,549
==132362==    at 0x4C3ADBB: calloc (vg_replace_malloc.c:1117)
==132362==    by 0x69EE4CD: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.5600.4)
==132362==    by 0x7E34AF: cpu_address_space_init (physmem.c:751)
==132362==    by 0x45053E: qemu_init_vcpu (cpus.c:635)
==132362==    by 0x76B4A7: x86_cpu_realizefn (cpu.c:6520)
==132362==    by 0x9343ED: device_set_realized (qdev.c:531)
==132362==    by 0x93E26F: property_set_bool (object.c:2273)
==132362==    by 0x93C23E: object_property_set (object.c:1408)
==132362==    by 0x9406DC: object_property_set_qobject (qom-qobject.c:28)
==132362==    by 0x93C5A9: object_property_set_bool (object.c:1477)
==132362==    by 0x933C81: qdev_realize (qdev.c:333)
==132362==    by 0x455E9A: qdev_device_add_from_qdict (qdev-monitor.c:713)

Signed-off-by: Mark Kanda <mark.kanda@oracle.com>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20220321141409.3112932-5-mark.kanda@oracle.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 cpu.c                     | 1 +
 include/exec/cpu-common.h | 7 +++++++
 softmmu/physmem.c         | 5 +++++
 3 files changed, 13 insertions(+)

diff --git a/cpu.c b/cpu.c
index be1f8b074c..59352a1487 100644
--- a/cpu.c
+++ b/cpu.c
@@ -174,6 +174,7 @@ void cpu_exec_unrealizefn(CPUState *cpu)
         tcg_exec_unrealizefn(cpu);
     }
 
+    cpu_address_space_destroy(cpu);
     cpu_list_remove(cpu);
 }
 
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 50a7d2912e..b17ad61ae4 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -111,6 +111,13 @@ size_t qemu_ram_pagesize_largest(void);
  */
 void cpu_address_space_init(CPUState *cpu, int asidx,
                             const char *prefix, MemoryRegion *mr);
+/**
+ * cpu_address_space_destroy:
+ * @cpu: CPU for this address space
+ *
+ * Cleanup CPU's cpu_ases list.
+ */
+void cpu_address_space_destroy(CPUState *cpu);
 
 void cpu_physical_memory_rw(hwaddr addr, void *buf,
                             hwaddr len, bool is_write);
diff --git a/softmmu/physmem.c b/softmmu/physmem.c
index 43ae70fbe2..aec61ca07a 100644
--- a/softmmu/physmem.c
+++ b/softmmu/physmem.c
@@ -762,6 +762,11 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
     }
 }
 
+void cpu_address_space_destroy(CPUState *cpu)
+{
+    g_free(cpu->cpu_ases);
+}
+
 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
 {
     /* Return the AddressSpace corresponding to the specified index */
-- 
2.35.1



  reply	other threads:[~2022-03-23 17:18 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 17:17 [PATCH v4 00/13] accel: Fix vCPU memory leaks Philippe Mathieu-Daudé
2022-03-23 17:17 ` Philippe Mathieu-Daudé
2022-03-23 17:17 ` Philippe Mathieu-Daudé [this message]
2022-03-23 17:17   ` [PATCH v4 01/13] cpu: Free cpu->cpu_ases in cpu_address_space_destroy() Philippe Mathieu-Daudé
2022-03-23 18:56   ` Philippe Mathieu-Daudé
2022-03-23 18:56     ` Philippe Mathieu-Daudé
2022-03-23 19:14     ` Mark Kanda
2022-03-23 19:14       ` Mark Kanda
2022-03-23 17:17 ` [PATCH v4 02/13] target/i386/kvm: Free xsave_buf when destroying vCPU Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 21:15   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 03/13] target/i386/hvf: Free resources when vCPU is destroyed Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 21:19   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 04/13] accel/hvf: Remove pointless assertion Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 17:17 ` [PATCH v4 05/13] accel/tcg: Init TCG cflags in vCPU thread handler Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 21:29   ` Richard Henderson
2022-06-20 20:04   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 06/13] accel/tcg: Reorganize tcg_accel_ops_init() Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 21:31   ` Richard Henderson
2022-06-20 20:09   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 07/13] accel-ops: Introduce create_vcpu_thread_precheck / postcheck handlers Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 22:26   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 08/13] accel/tcg: Extract rr_create_vcpu_thread_precheck() Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 17:17 ` [PATCH v4 09/13] accel/all: Extract common_vcpu_thread_create() Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 22:11   ` Richard Henderson
2022-03-23 22:15   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 10/13] accel-ops: Introduce common_vcpu_thread_destroy() and .precheck handler Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 22:31   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 11/13] accel/tcg: Add rr_destroy_vcpu_thread_precheck() Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 22:42   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 12/13] softmmu/cpus: Free cpu->thread in generic_destroy_vcpu_thread() Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 17:30   ` Mark Kanda
2022-03-23 17:30     ` Mark Kanda
2022-03-23 22:42   ` Richard Henderson
2022-03-23 17:17 ` [PATCH v4 13/13] softmmu/cpus: Free cpu->halt_cond " Philippe Mathieu-Daudé
2022-03-23 17:17   ` Philippe Mathieu-Daudé
2022-03-23 22:43   ` 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=20220323171751.78612-2-philippe.mathieu.daude@gmail.com \
    --to=philippe.mathieu.daude@gmail.com \
    --cc=anthony.perard@citrix.com \
    --cc=colin.xu@intel.com \
    --cc=david@redhat.com \
    --cc=dirty@apple.com \
    --cc=eduardo@habkost.net \
    --cc=f4bug@amsat.org \
    --cc=haxm-team@intel.com \
    --cc=kamil@netbsd.org \
    --cc=lvivier@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mark.kanda@oracle.com \
    --cc=mtosatti@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=r.bolshakov@yadro.com \
    --cc=reinoud@netbsd.org \
    --cc=richard.henderson@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sunilmut@microsoft.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    --cc=wenchao.wang@intel.com \
    --cc=xen-devel@lists.xenproject.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.