qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors
@ 2024-07-08  6:55 Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 1/9] spapr: Free stdout path Akihiko Odaki
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki, Peter Maydell

Based-on: <3ad18bc590ef28e1526e8053568086b453e7ffde.1718211878.git.quic_mathbern@quicinc.com>
("[PATCH] cpu: fix memleak of 'halt_cond' and 'thread'")

I saw various sanitizer errors when running check-qtest-ppc64. While
I could just turn off sanitizers, I decided to tackle them this time.

Unfortunately, GLib does not free test data in some cases so some
sanitizer errors remain. All sanitizer errors will be gone with this
patch series combined with the following change for GLib:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4120

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
Changes in v3:
- Added patch "memory: Clarify that we use owner's reference count".
- Added patch "memory: Refer to docs/devel/memory.rst for 'owner'".
- Fixed the message of patch
  "memory: Do not create circular reference with subregion".
- Dropped patch "cpu: Free cpu_ases" in favor of:
  https://lore.kernel.org/r/20240607115649.214622-7-salil.mehta@huawei.com/
  ("[PATCH V13 6/8] physmem: Add helper function to destroy CPU
  AddressSpace")
- Dropped patches "hw/ide: Convert macio ide_irq into GPIO line" and
  "hw/ide: Remove internal DMA qemu_irq" in favor of commit efb359346c7a
  ("hw/ide/macio: switch from using qemu_allocate_irq() to qdev input
  GPIOs")
- Dropped patch "hw/isa/vt82c686: Define a GPIO line between vt82c686
  and i8259" in favor of:
  https://patchew.org/QEMU/20240704205854.18537-1-shentey@gmail.com/
  ("[PATCH 0/3] Resolve vt82c686 and piix4 qemu_irq memory leaks")
- Dropped pulled patches.
- Link to v2: https://lore.kernel.org/r/20240627-san-v2-0-750bb0946dbd@daynix.com

Changes in v2:
- Rebased to "[PATCH] cpu: fix memleak of 'halt_cond' and 'thread'".
  (Philippe Mathieu-Daudé)
- Converted IRQs into GPIO lines and removed one qemu_irq usage.
  (Peter Maydell)
- s/suppresses/fixes/ (Michael S. Tsirkin)
- Corrected title of patch "hw/virtio: Free vqs after vhost_dev_cleanup()"
  (was "hw/virtio: Free vqs before vhost_dev_cleanup()")
- Link to v1: https://lore.kernel.org/r/20240626-san-v1-0-f3cc42302189@daynix.com

---
Akihiko Odaki (9):
      spapr: Free stdout path
      ppc/vof: Fix unaligned FDT property access
      migration: Free removed SaveStateEntry
      memory: Do not refer to "memory region's reference count"
      memory: Refer to docs/devel/memory.rst for "owner"
      memory: Clarify that owner may be missing
      memory: Clarify owner must not call memory_region_ref()
      memory: Do not create circular reference with subregion
      tests/qtest: Delete previous boot file

 include/exec/memory.h        | 22 +++++++---------------
 hw/ppc/spapr_vof.c           |  2 +-
 hw/ppc/vof.c                 |  2 +-
 migration/savevm.c           |  2 ++
 system/memory.c              | 11 +++++++++--
 tests/qtest/migration-test.c | 18 +++++++++++-------
 6 files changed, 31 insertions(+), 26 deletions(-)
---
base-commit: f2cb4026fccfe073f84a4b440e41d3ed0c3134f6
change-id: 20240625-san-097afaf4f1c2

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



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

* [PATCH v3 1/9] spapr: Free stdout path
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 2/9] ppc/vof: Fix unaligned FDT property access Akihiko Odaki
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

This fixes LeakSanitizer warnings.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/ppc/spapr_vof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_vof.c b/hw/ppc/spapr_vof.c
index 09f29be0b9de..c02eaacfed0b 100644
--- a/hw/ppc/spapr_vof.c
+++ b/hw/ppc/spapr_vof.c
@@ -28,7 +28,7 @@ target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr,
 
 void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt)
 {
-    char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
+    g_autofree char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
 
     vof_build_dt(fdt, spapr->vof);
 

-- 
2.45.2



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

* [PATCH v3 2/9] ppc/vof: Fix unaligned FDT property access
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 1/9] spapr: Free stdout path Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 3/9] migration: Free removed SaveStateEntry Akihiko Odaki
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki, Peter Maydell

FDT properties are aligned by 4 bytes, not 8 bytes.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/ppc/vof.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c
index e3b430a81f4f..b5b6514d79fc 100644
--- a/hw/ppc/vof.c
+++ b/hw/ppc/vof.c
@@ -646,7 +646,7 @@ static void vof_dt_memory_available(void *fdt, GArray *claimed, uint64_t base)
     mem0_reg = fdt_getprop(fdt, offset, "reg", &proplen);
     g_assert(mem0_reg && proplen == sizeof(uint32_t) * (ac + sc));
     if (sc == 2) {
-        mem0_end = be64_to_cpu(*(uint64_t *)(mem0_reg + sizeof(uint32_t) * ac));
+        mem0_end = ldq_be_p(mem0_reg + sizeof(uint32_t) * ac);
     } else {
         mem0_end = be32_to_cpu(*(uint32_t *)(mem0_reg + sizeof(uint32_t) * ac));
     }

-- 
2.45.2



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

* [PATCH v3 3/9] migration: Free removed SaveStateEntry
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 1/9] spapr: Free stdout path Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 2/9] ppc/vof: Fix unaligned FDT property access Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 4/9] memory: Do not refer to "memory region's reference count" Akihiko Odaki
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

This fixes LeakSanitizer warnings.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 migration/savevm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/migration/savevm.c b/migration/savevm.c
index deb57833f8a8..85958d7b09cd 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -874,6 +874,8 @@ int vmstate_replace_hack_for_ppc(VMStateIf *obj, int instance_id,
 
     if (se) {
         savevm_state_handler_remove(se);
+        g_free(se->compat);
+        g_free(se);
     }
     return vmstate_register(obj, instance_id, vmsd, opaque);
 }

-- 
2.45.2



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

* [PATCH v3 4/9] memory: Do not refer to "memory region's reference count"
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (2 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 3/9] migration: Free removed SaveStateEntry Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 5/9] memory: Refer to docs/devel/memory.rst for "owner" Akihiko Odaki
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

Now MemoryRegions do have their own reference counts, but they will not
be used when their owners are not themselves. However, the documentation
of memory_region_ref() says it adds "1 to a memory region's reference
count", which is confusing. Avoid referring to "memory region's
reference count" and just say: "Add a reference to a memory region".
Make a similar change to memory_region_unref() too.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/exec/memory.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index c26ede33d21e..a5af05864274 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1243,7 +1243,7 @@ void memory_region_init(MemoryRegion *mr,
                         uint64_t size);
 
 /**
- * memory_region_ref: Add 1 to a memory region's reference count
+ * memory_region_ref: Add a reference to a memory region
  *
  * Whenever memory regions are accessed outside the BQL, they need to be
  * preserved against hot-unplug.  MemoryRegions actually do not have their
@@ -1260,7 +1260,7 @@ void memory_region_init(MemoryRegion *mr,
 void memory_region_ref(MemoryRegion *mr);
 
 /**
- * memory_region_unref: Remove 1 to a memory region's reference count
+ * memory_region_unref: Remove a reference to a memory region
  *
  * Whenever memory regions are accessed outside the BQL, they need to be
  * preserved against hot-unplug.  MemoryRegions actually do not have their

-- 
2.45.2



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

* [PATCH v3 5/9] memory: Refer to docs/devel/memory.rst for "owner"
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (3 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 4/9] memory: Do not refer to "memory region's reference count" Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 6/9] memory: Clarify that owner may be missing Akihiko Odaki
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

memory_region_ref() and memory_region_unref() used to have their own
descriptions of "owner", but they are somewhat out-of-date and
misleading.

In particular, they say "whenever memory regions are accessed outside
the BQL, they need to be preserved against hot-unplug", but protecting
against hot-unplug is not mandatory if it is known that they will never
be hot-unplugged. They also say "MemoryRegions actually do not have
their own reference count", but they actually do. They just will not be
used unless their owners are not themselves.

Refer to docs/devel/memory.rst as the single source of truth instead of
maintaining duplicate descriptions of "owner".

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/exec/memory.h | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index a5af05864274..e1bd29550c15 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1245,15 +1245,8 @@ void memory_region_init(MemoryRegion *mr,
 /**
  * memory_region_ref: Add a reference to a memory region
  *
- * Whenever memory regions are accessed outside the BQL, they need to be
- * preserved against hot-unplug.  MemoryRegions actually do not have their
- * own reference count; they piggyback on a QOM object, their "owner".
  * This function adds a reference to the owner.
- *
- * All MemoryRegions must have an owner if they can disappear, even if the
- * device they belong to operates exclusively under the BQL.  This is because
- * the region could be returned at any time by memory_region_find, and this
- * is usually under guest control.
+ * See docs/devel/memory.rst to know about owner.
  *
  * @mr: the #MemoryRegion
  */
@@ -1262,10 +1255,8 @@ void memory_region_ref(MemoryRegion *mr);
 /**
  * memory_region_unref: Remove a reference to a memory region
  *
- * Whenever memory regions are accessed outside the BQL, they need to be
- * preserved against hot-unplug.  MemoryRegions actually do not have their
- * own reference count; they piggyback on a QOM object, their "owner".
  * This function removes a reference to the owner and possibly destroys it.
+ * See docs/devel/memory.rst to know about owner.
  *
  * @mr: the #MemoryRegion
  */

-- 
2.45.2



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

* [PATCH v3 6/9] memory: Clarify that owner may be missing
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (4 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 5/9] memory: Refer to docs/devel/memory.rst for "owner" Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 7/9] memory: Clarify owner must not call memory_region_ref() Akihiko Odaki
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

A memory region may not have an owner, and memory_region_ref() and
memory_region_unref() do nothing for such.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/exec/memory.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index e1bd29550c15..847c84c86db0 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1245,7 +1245,7 @@ void memory_region_init(MemoryRegion *mr,
 /**
  * memory_region_ref: Add a reference to a memory region
  *
- * This function adds a reference to the owner.
+ * This function adds a reference to the owner if present.
  * See docs/devel/memory.rst to know about owner.
  *
  * @mr: the #MemoryRegion
@@ -1255,8 +1255,8 @@ void memory_region_ref(MemoryRegion *mr);
 /**
  * memory_region_unref: Remove a reference to a memory region
  *
- * This function removes a reference to the owner and possibly destroys it.
- * See docs/devel/memory.rst to know about owner.
+ * This function removes a reference to the owner and possibly destroys it if
+ * present. See docs/devel/memory.rst to know about owner.
  *
  * @mr: the #MemoryRegion
  */

-- 
2.45.2



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

* [PATCH v3 7/9] memory: Clarify owner must not call memory_region_ref()
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (5 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 6/9] memory: Clarify that owner may be missing Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 8/9] memory: Do not create circular reference with subregion Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 9/9] tests/qtest: Delete previous boot file Akihiko Odaki
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/exec/memory.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 847c84c86db0..32bb430acdc4 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -1246,6 +1246,7 @@ void memory_region_init(MemoryRegion *mr,
  * memory_region_ref: Add a reference to a memory region
  *
  * This function adds a reference to the owner if present.
+ * The owner must not call this function as it results in a circular reference.
  * See docs/devel/memory.rst to know about owner.
  *
  * @mr: the #MemoryRegion

-- 
2.45.2



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

* [PATCH v3 8/9] memory: Do not create circular reference with subregion
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (6 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 7/9] memory: Clarify owner must not call memory_region_ref() Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  6:55 ` [PATCH v3 9/9] tests/qtest: Delete previous boot file Akihiko Odaki
  8 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

memory_region_update_container_subregions() calls memory_region_ref()
on behalf of the owner of the container. memory_region_ref() must not
be called if the owner of the container also owns the subregion.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 system/memory.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/system/memory.c b/system/memory.c
index 2d6952136066..09c98042e443 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2625,7 +2625,10 @@ static void memory_region_update_container_subregions(MemoryRegion *subregion)
 
     memory_region_transaction_begin();
 
-    memory_region_ref(subregion);
+    if (mr->owner != subregion->owner) {
+        memory_region_ref(subregion);
+    }
+
     QTAILQ_FOREACH(other, &mr->subregions, subregions_link) {
         if (subregion->priority >= other->priority) {
             QTAILQ_INSERT_BEFORE(other, subregion, subregions_link);
@@ -2683,7 +2686,11 @@ void memory_region_del_subregion(MemoryRegion *mr,
         assert(alias->mapped_via_alias >= 0);
     }
     QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link);
-    memory_region_unref(subregion);
+
+    if (mr->owner != subregion->owner) {
+        memory_region_unref(subregion);
+    }
+
     memory_region_update_pending |= mr->enabled && subregion->enabled;
     memory_region_transaction_commit();
 }

-- 
2.45.2



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

* [PATCH v3 9/9] tests/qtest: Delete previous boot file
  2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
                   ` (7 preceding siblings ...)
  2024-07-08  6:55 ` [PATCH v3 8/9] memory: Do not create circular reference with subregion Akihiko Odaki
@ 2024-07-08  6:55 ` Akihiko Odaki
  2024-07-08  7:17   ` Thomas Huth
  8 siblings, 1 reply; 11+ messages in thread
From: Akihiko Odaki @ 2024-07-08  6:55 UTC (permalink / raw)
  To: Eduardo Habkost, Marcel Apfelbaum, Philippe Mathieu-Daudé,
	Yanan Wang, John Snow, BALATON Zoltan, Jiaxun Yang,
	Nicholas Piggin, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Michael S. Tsirkin,
	Alex Bennée, Peter Xu, Fabiano Rosas, Paolo Bonzini,
	David Hildenbrand, Thomas Huth, Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc, Akihiko Odaki

A test run may create boot files several times. Delete the previous boot
file before creating a new one.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/qtest/migration-test.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 70b606b88864..6c06100d91e2 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -144,12 +144,23 @@ static char *bootpath;
 #include "tests/migration/ppc64/a-b-kernel.h"
 #include "tests/migration/s390x/a-b-bios.h"
 
+static void bootfile_delete(void)
+{
+    unlink(bootpath);
+    g_free(bootpath);
+    bootpath = NULL;
+}
+
 static void bootfile_create(char *dir, bool suspend_me)
 {
     const char *arch = qtest_get_arch();
     unsigned char *content;
     size_t len;
 
+    if (bootpath) {
+        bootfile_delete();
+    }
+
     bootpath = g_strdup_printf("%s/bootsect", dir);
     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
         /* the assembled x86 boot sector should be exactly one sector large */
@@ -177,13 +188,6 @@ static void bootfile_create(char *dir, bool suspend_me)
     fclose(bootfile);
 }
 
-static void bootfile_delete(void)
-{
-    unlink(bootpath);
-    g_free(bootpath);
-    bootpath = NULL;
-}
-
 /*
  * Wait for some output in the serial output file,
  * we get an 'A' followed by an endless string of 'B's

-- 
2.45.2



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

* Re: [PATCH v3 9/9] tests/qtest: Delete previous boot file
  2024-07-08  6:55 ` [PATCH v3 9/9] tests/qtest: Delete previous boot file Akihiko Odaki
@ 2024-07-08  7:17   ` Thomas Huth
  0 siblings, 0 replies; 11+ messages in thread
From: Thomas Huth @ 2024-07-08  7:17 UTC (permalink / raw)
  To: Akihiko Odaki, Eduardo Habkost, Marcel Apfelbaum,
	Philippe Mathieu-Daudé, Yanan Wang, John Snow,
	BALATON Zoltan, Jiaxun Yang, Nicholas Piggin,
	Daniel Henrique Barboza, David Gibson, Harsh Prateek Bora,
	Alexey Kardashevskiy, Michael S. Tsirkin, Alex Bennée,
	Peter Xu, Fabiano Rosas, Paolo Bonzini, David Hildenbrand,
	Laurent Vivier
  Cc: qemu-devel, qemu-block, qemu-ppc

On 08/07/2024 08.55, Akihiko Odaki wrote:
> A test run may create boot files several times. Delete the previous boot
> file before creating a new one.
> 
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>   tests/qtest/migration-test.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)


Acked-by: Thomas Huth <thuth@redhat.com>



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

end of thread, other threads:[~2024-07-08  7:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-08  6:55 [PATCH v3 0/9] Fix check-qtest-ppc64 sanitizer errors Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 1/9] spapr: Free stdout path Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 2/9] ppc/vof: Fix unaligned FDT property access Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 3/9] migration: Free removed SaveStateEntry Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 4/9] memory: Do not refer to "memory region's reference count" Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 5/9] memory: Refer to docs/devel/memory.rst for "owner" Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 6/9] memory: Clarify that owner may be missing Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 7/9] memory: Clarify owner must not call memory_region_ref() Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 8/9] memory: Do not create circular reference with subregion Akihiko Odaki
2024-07-08  6:55 ` [PATCH v3 9/9] tests/qtest: Delete previous boot file Akihiko Odaki
2024-07-08  7:17   ` Thomas Huth

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).