qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/16] memory: Stop piggybacking on memory region owners
@ 2025-09-01  6:09 Akihiko Odaki
  2025-09-01  6:09 ` [PATCH 01/16] docs/devel: Do not unparent in instance_finalize Akihiko Odaki
                   ` (16 more replies)
  0 siblings, 17 replies; 22+ messages in thread
From: Akihiko Odaki @ 2025-09-01  6:09 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,
	Harsh Prateek Bora, 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, Akihiko Odaki

Supersedes: https://lore.kernel.org/qemu-devel/20250828-san-v9-0-c0dff4b8a487@rsg.ci.i.u-tokyo.ac.jp/
("[PATCH v9 0/2] Fix check-qtest-ppc64 sanitizer errors")

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

With this series, I remove the "piggyback" hack altogather.
The key insight here is that the owners explicitly call
memory_region_del_subregion() to stop accepting new accesses to
its MemoryRegions when they are no longer needed. I code the fact by 
calling object_unparent() along with it.

While I could write a function like memory_region_unparent() and replace
such memory_region_del_subregion() calls, I used a few other insights to
simplify the code:
- Deletable MemoryRegions are of hotpluggable devices.
- Devices do no longer accept new accesses after unrealization.

So I made the common qdev code call memory_region_del_subregion() and
object_unparent(). In the end, this series makes the code simpler and
semantically robust, and kills the entire class of memory leak.

Patch [1, 2] removes object_unparent() calls in instance_finalize(),
which are incorrect.

Patch 3 makes the qdev code automatically call
memory_region_del_subregion().

Patch [4, 15] removes memory_region_del_subregion() calls that are
obviously no longer needed, demonstrating the benefit of automatic
automatic subregion deletion.

Patch 16 adds the object_unparent() call and stop piggybacking.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Akihiko Odaki (16):
      docs/devel: Do not unparent in instance_finalize
      vfio/pci: Do not unparent in instance_finalize
      qdev: Automatically delete memory subregions
      hw/char/diva-gsp: Do not delete the subregion
      hw/char/serial-pci-multi: Do not delete the subregion
      secondary-vga: Do not delete the subregions
      cmd646: Do not delete the subregions
      hw/ide/piix: Do not delete the subregions
      hw/ide/via: Do not delete the subregions
      hw/nvme: Do not delete the subregion
      pci: Do not delete the subregions
      hw/ppc/spapr_pci: Do not delete the subregions
      hw/usb/hcd-ehci: Do not delete the subregions
      hw/usb/hcd-xhci: Do not delete the subregions
      vfio-user: Do not delete the subregion
      memory: Stop piggybacking on memory region owners

 MAINTAINERS                |  1 +
 docs/devel/memory.rst      | 45 +++++++++++++++++-----------------------
 include/hw/qdev-core.h     |  2 ++
 include/system/memory.h    | 51 +++++++++++++++++++++++-----------------------
 hw/char/diva-gsp.c         |  1 -
 hw/char/serial-pci-multi.c |  1 -
 hw/core/qdev.c             | 29 ++++++++++++++++++++++++++
 hw/display/vga-pci.c       |  8 --------
 hw/ide/cmd646.c            | 12 -----------
 hw/ide/piix.c              | 13 ------------
 hw/ide/via.c               | 12 -----------
 hw/nvme/ctrl.c             |  2 --
 hw/pci/pci.c               | 20 ------------------
 hw/ppc/spapr_pci.c         | 22 --------------------
 hw/usb/hcd-ehci.c          |  4 ----
 hw/usb/hcd-xhci.c          | 10 ---------
 hw/vfio-user/pci.c         |  6 ------
 hw/vfio/pci.c              |  4 ----
 stubs/memory.c             |  9 ++++++++
 system/memory.c            | 11 +++-------
 stubs/meson.build          |  1 +
 21 files changed, 89 insertions(+), 175 deletions(-)
---
base-commit: e101d33792530093fa0b0a6e5f43e4d8cfe4581e
change-id: 20250831-mr-d0dc495bad11

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



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

end of thread, other threads:[~2025-09-01 13:43 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-01  6:09 [PATCH 00/16] memory: Stop piggybacking on memory region owners Akihiko Odaki
2025-09-01  6:09 ` [PATCH 01/16] docs/devel: Do not unparent in instance_finalize Akihiko Odaki
2025-09-01  6:10 ` [PATCH 02/16] vfio/pci: " Akihiko Odaki
2025-09-01 11:51   ` Cédric Le Goater
2025-09-01  6:10 ` [PATCH 03/16] qdev: Automatically delete memory subregions Akihiko Odaki
2025-09-01  6:10 ` [PATCH 04/16] hw/char/diva-gsp: Do not delete the subregion Akihiko Odaki
2025-09-01  6:10 ` [PATCH 05/16] hw/char/serial-pci-multi: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 06/16] secondary-vga: Do not delete the subregions Akihiko Odaki
2025-09-01  6:10 ` [PATCH 07/16] cmd646: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 08/16] hw/ide/piix: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 09/16] hw/ide/via: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 10/16] hw/nvme: Do not delete the subregion Akihiko Odaki
2025-09-01  6:10 ` [PATCH 11/16] pci: Do not delete the subregions Akihiko Odaki
2025-09-01  6:10 ` [PATCH 12/16] hw/ppc/spapr_pci: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 13/16] hw/usb/hcd-ehci: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 14/16] hw/usb/hcd-xhci: " Akihiko Odaki
2025-09-01  6:10 ` [PATCH 15/16] vfio-user: Do not delete the subregion Akihiko Odaki
2025-09-01  6:10 ` [PATCH 16/16] memory: Stop piggybacking on memory region owners Akihiko Odaki
2025-09-01 12:35 ` [PATCH 00/16] " Peter Maydell
2025-09-01 12:47   ` Peter Maydell
2025-09-01 13:27   ` Akihiko Odaki
2025-09-01 13:42     ` Peter Maydell

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