qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] memory: Stop piggybacking on memory region owners
@ 2025-09-06  2:39 Akihiko Odaki
  2025-09-06  2:39 ` [PATCH v2 1/3] qom: Do not finalize twice Akihiko Odaki
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Akihiko Odaki @ 2025-09-06  2:39 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alex Williamson, Cédric Le Goater, Paolo Bonzini,
	Daniel P. Berrangé, Eduardo Habkost, Peter Xu,
	David Hildenbrand, Philippe Mathieu-Daudé, Richard Henderson,
	Helge Deller, Marc-André Lureau, Michael S. Tsirkin,
	Gerd Hoffmann, John Snow, qemu-block, Keith Busch, Klaus Jensen,
	Jesper Devantier, Marcel Apfelbaum, Nicholas Piggin, qemu-ppc,
	John Levon, Thanos Makatos, Yanan Wang, BALATON Zoltan,
	Jiaxun Yang, Daniel Henrique Barboza, David Gibson,
	Harsh Prateek Bora, Alexey Kardashevskiy, Alex Bennée,
	Fabiano Rosas, Thomas Huth, Laurent Vivier, Peter Maydell,
	Dmitry Osipenko, Akihiko Odaki

Supersedes: <20250828-san-v9-0-c0dff4b8a487@rsg.ci.i.u-tokyo.ac.jp>
("[PATCH v9 0/2] Fix check-qtest-ppc64 sanitizer errors")

Based-on: <20250906-use-v1-0-c51caafd1eb7@rsg.ci.i.u-tokyo.ac.jp>
("[PATCH 00/22] Fix memory region leaks and use-after-finalization")

MemoryRegions used to "piggyback" on their owners instead of using their
reference counters due to the circular dependencies between them, which
caused memory leak.

I tried to fix it with "[PATCH v9 0/2] Fix check-qtest-ppc64 sanitizer
errors" but it resulted in a lengthy discussion; ultimately it is
attributed to the fact that "piggybacking" is hard to understand and
forces us design trade-offs. It was also insufficient because it only
deals with the container/subregion pattern and did not deal with
AddressSpace and DMA. Fixing all possible memory leaks require checking
the referrer at many places where memory_region_ref() is called.

With this series, I remove the "piggyback" hack altogather.
The key insight here is that the unparented devices have the finalizable
MemoryRegions and they do not need them. I code the fact by calling
object_unparent() in device_unparent(). This eliminates the entire class
of memory leaks caused by references from owners to their MemoryRegions.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Changes in v2:
- Expanded the message of patch
  "vfio/pci: Do not unparent in instance_finalize()".
- Changed to exploit the unparenting timing instead of the unrealization
  timing.
- Link to v1: https://lore.kernel.org/qemu-devel/20250901-mr-v1-0-dd7cb6b1480b@rsg.ci.i.u-tokyo.ac.jp

---
Akihiko Odaki (3):
      qom: Do not finalize twice
      virtio-gpu-virgl: Add virtio-gpu-virgl-hostmem-region type
      memory: Stop piggybacking on memory region owners

 docs/devel/memory.rst         | 41 +++++++++++++++++-----------------
 include/qom/object.h          |  1 +
 include/system/memory.h       | 51 +++++++++++++++++++++----------------------
 hw/core/qdev.c                | 16 ++++++++++++++
 hw/display/virtio-gpu-virgl.c | 50 ++++++++++++++++++++++++++++++------------
 qom/object.c                  |  5 +++++
 system/memory.c               | 33 ++++++++++++++++++++--------
 7 files changed, 127 insertions(+), 70 deletions(-)
---
base-commit: e101d33792530093fa0b0a6e5f43e4d8cfe4581e
change-id: 20250831-mr-d0dc495bad11
prerequisite-message-id: <20250906-use-v1-0-c51caafd1eb7@rsg.ci.i.u-tokyo.ac.jp>
prerequisite-patch-id: d464fda86a3c79ff8e6d7a2e623d979b2a47019b
prerequisite-patch-id: 17b153237f69c898b9c5b93aad0d5116d0bfe49f
prerequisite-patch-id: a323f67e01c672ab2958a237ea54b77f1443e2d1
prerequisite-patch-id: 019969fe248bd57ddcda1ff5fc960b214ccffefe
prerequisite-patch-id: 74ded25b212b75b2f7d1859fedc601cf33d59107
prerequisite-patch-id: 43f841a1924749e2a5a3b74b35e54f89afb7e3c5
prerequisite-patch-id: 44300da5065efee0390be5d450225868e01cecfc
prerequisite-patch-id: 4af306d6f3d0a4585015c5907ca1e1dcfced77d3
prerequisite-patch-id: fff78c7af9b0a56190a1b4afbb122c460a6b0e7d
prerequisite-patch-id: 3d38803ce09ba9c93f2a876f54309e673b396ab1
prerequisite-patch-id: 822094864ad7a6a702fee098e4835621bd8092fe
prerequisite-patch-id: 5757efd81557b060257b5db6dec6fd189076ee77
prerequisite-patch-id: bd912830a326f13186bf38e916655ec980e11af8
prerequisite-patch-id: fe6b92112288829e60f10c305742a544f45e8984
prerequisite-patch-id: ac4ff0c11dcc1fc5d08b4fc480c14721fde574ad
prerequisite-patch-id: ff398fa97b5f2feee85372fdf108d82d8d5526b0
prerequisite-patch-id: 7ac446ae76e05dd267a63889ff775ac609712c31
prerequisite-patch-id: b49a74cd5f31348c3dc13dcfd1dad629e6b30387
prerequisite-patch-id: 8f61fe1b81cf3ec906ebbf61776573edd96c1e8c
prerequisite-patch-id: 01fb8ccbe7326021a94a8d7531189568d2e311a7
prerequisite-patch-id: 974b0fc6d7c8d6d56b8f44597260647e1a53cf38
prerequisite-patch-id: 55c4711a2a4e6b02b8b512e0283f8feaf7d3bfa3

Best regards,
--  
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>



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

end of thread, other threads:[~2025-09-29 14:46 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-06  2:39 [PATCH v2 0/3] memory: Stop piggybacking on memory region owners Akihiko Odaki
2025-09-06  2:39 ` [PATCH v2 1/3] qom: Do not finalize twice Akihiko Odaki
2025-09-23  9:27   ` Paolo Bonzini
2025-09-06  2:39 ` [PATCH v2 2/3] virtio-gpu-virgl: Add virtio-gpu-virgl-hostmem-region type Akihiko Odaki
2025-09-06  2:39 ` [PATCH v2 3/3] memory: Stop piggybacking on memory region owners Akihiko Odaki
2025-09-10 21:45   ` Peter Xu
2025-09-11  3:40     ` Akihiko Odaki
2025-09-11 22:26       ` Peter Xu
2025-09-18 12:04         ` Akihiko Odaki
2025-09-24 21:14           ` Peter Xu
2025-09-25  9:03             ` Peter Maydell
2025-09-25 20:05               ` Peter Xu
2025-09-26  9:09                 ` Peter Maydell
2025-09-26 15:16                   ` Peter Xu
2025-09-26 15:59                     ` Peter Maydell
2025-09-26 16:56                       ` Peter Maydell
2025-09-26 17:10                         ` Peter Xu
2025-09-29 12:45                     ` Peter Maydell
2025-09-29 14:37                       ` Peter Xu
2025-09-29 14:43                         ` Peter Maydell
2025-09-23  8:41   ` Paolo Bonzini

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