[PATCH v2 00/12] qdev: Automatically delete memory subregions

Akihiko Odaki posted 12 patches 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251010-subregion-v2-0-435a472bc9cd@rsg.ci.i.u-tokyo.ac.jp
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Gerd Hoffmann <kraxel@redhat.com>, John Snow <jsnow@redhat.com>, Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>, Jesper Devantier <foss@defmacro.it>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
MAINTAINERS                |  1 +
include/hw/qdev-core.h     |  1 +
hw/char/diva-gsp.c         |  1 -
hw/char/serial-pci-multi.c |  1 -
hw/core/qdev.c             | 14 ++++++++++++++
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 ----------
stubs/memory.c             |  9 +++++++++
stubs/meson.build          |  1 +
16 files changed, 26 insertions(+), 105 deletions(-)
[PATCH v2 00/12] qdev: Automatically delete memory subregions
Posted by Akihiko Odaki 1 month ago
This patch series was spun off from "[PATCH v2 00/15] Fix memory region
leaks and use-after-finalization":
https://lore.kernel.org/qemu-devel/20250915-use-v2-0-f4c7ff13bfe9@rsg.ci.i.u-tokyo.ac.jp/

It is a common requirement of qdev to delete memory subregions to hide
them from address spaces during unrealization. pci automatically
deletes the IO subregions, but this process is manually implemented
in other places, which is tedious and error-prone.

Implement the logic to delete subregions in qdev to cover all devices.

Note that some code removed in this series to delete subregions are
apparently just unnecessary and can be removed without a change of qdev.
They are still included in this series and follows the qdev change since
removing them without the qdev change will cause regression if I fail to
distinguish necessary and unnecessary code.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
Changes in v2:
- Dropped patch "hw/pci-bridge: Do not assume immediate MemoryRegion
  finalization" as it was unnecessary as pointed out by Peter Xu.
- Dropped patch "[PATCH] vfio-user: Do not delete the subregion". It is
  a fix unlike the other patches so I submitted it separately.
- Expanded the patch message of "qdev: Automatically delete memory
  subregions" to explain that existing memory_region_del_subregion()
  calls in the device-specific code will be no-op.
- Link to v1: https://lore.kernel.org/qemu-devel/20250917-subregion-v1-0-bef37d9b4f73@rsg.ci.i.u-tokyo.ac.jp

---
Akihiko Odaki (12):
      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

 MAINTAINERS                |  1 +
 include/hw/qdev-core.h     |  1 +
 hw/char/diva-gsp.c         |  1 -
 hw/char/serial-pci-multi.c |  1 -
 hw/core/qdev.c             | 14 ++++++++++++++
 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 ----------
 stubs/memory.c             |  9 +++++++++
 stubs/meson.build          |  1 +
 16 files changed, 26 insertions(+), 105 deletions(-)
---
base-commit: 94474a7733a57365d5a27efc28c05462e90e8944
change-id: 20250917-subregion-907ced7da1ed

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