From: Peter Xu <peterx@redhat.com>
To: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
qemu-devel@nongnu.org,
"Alex Williamson" <alex.williamson@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"David Hildenbrand" <david@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Helge Deller" <deller@gmx.de>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"John Snow" <jsnow@redhat.com>,
qemu-block@nongnu.org, "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>,
qemu-ppc@nongnu.org, "John Levon" <john.levon@nutanix.com>,
"Thanos Makatos" <thanos.makatos@nutanix.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"BALATON Zoltan" <balaton@eik.bme.hu>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Harsh Prateek Bora" <harshpb@linux.ibm.com>,
"Alexey Kardashevskiy" <aik@ozlabs.ru>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Fabiano Rosas" <farosas@suse.de>,
"Thomas Huth" <thuth@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"Hervé Poussineau" <hpoussin@reactos.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Artyom Tarasenko" <atar4qemu@gmail.com>
Subject: Re: [PATCH 00/14] Fix memory region use-after-finalization
Date: Fri, 10 Oct 2025 11:32:46 -0400 [thread overview]
Message-ID: <aOknHiJRVfe0s_hT@x1.local> (raw)
In-Reply-To: <036d19ce-490b-49d2-b114-0b5a91e5e66c@rsg.ci.i.u-tokyo.ac.jp>
On Fri, Oct 10, 2025 at 07:20:04PM +0900, Akihiko Odaki wrote:
> On 2025/10/03 0:03, Paolo Bonzini wrote:
> > On 9/17/25 12:32, Akihiko Odaki wrote:
> > > Based-on: <20250917-use-v3-0-72c2a6887c6c@rsg.ci.i.u-tokyo.ac.jp>
> > > ("[PATCH v3 0/7] Do not unparent in instance_finalize()")
> > >
> > > 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/
> > >
> > > When developing the next version of "[PATCH 00/16] memory: Stop
> > > piggybacking on memory region owners*", I faced multiple memory region
> > > leaks and use-after-finalization. This series extracts their fixes so
> > > that the number of Cc: won't explode.
> > >
> > > Patch "qdev: Automatically delete memory subregions" and the succeeding
> > > patches are for refactoring, but patch "vfio-user: Do not delete the
> > > subregion" does fix use-after-finalization.
> > >
> > > * https://lore.kernel.org/qemu-devel/20250901-mr-v1-0-
> > > dd7cb6b1480b@rsg.ci.i.u-tokyo.ac.jp/
> > >
> > > Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> >
> > This makes sense, but I think it is not bisectable, because of this in
> > memory_region_del_subregion():
> >
> > assert(subregion->container == mr);
> > subregion->container = NULL;
> >
> > You would need to add a temporary
> >
> > if (subregion->container == NULL) {
> > return;
> > }
> >
> > and undo it at the end of the series. Do you agree? With this change I
> > can apply it.
>
> It is unnecessary because patch "qdev: Automatically delete memory
> subregions" satisfies the following:
>
> 1. the device-specific code can assume that subregions they added are
> present until it finishes unrealization. The unrealize() callback can also
> assume the subregions are present and delete them. qdev satisfies this by
> deleting subregions only after calling the unrealize().
>
> 2. qdev should delete the remaining subregions before it finishes
> unrealization to ensure that the devices are hidden from the guest. qdev
> satisfies this by checking if memory regions have containers before
> deleting.
There's another option, which is to have the auto-detach patch for qdev
merged, meanwhile we can still keep the "good citizens" who do explicit
detachments in unrealize(), so that it won't confuse the reader on a
specific device about when did the MR went away. I believe there will be
developers get confused by them otherwise.
The auto detach will only be a final safety belt to make sure MRs won't get
leaked.
If that is an option, it may also explain my original question on what
problem we're fixing... the extreme case is what this series removed
afterwards are exactly all such uses that may need an explicit detachment
of MRs (ignoring there can be owner-shared MR links, which is even out of
the picture). Then the auto-detach feature may fix nothing, so we merge a
patch, looks good, logically sensible, but not functioning.
The reality might be, we may still have some qdev that should unlink the
MRs in unrealize(), but they didn't. However again I suspect it's rare,
especially considering the recently merged auto-detach in finalize(). I'd
just go and fix them, but only if they're a real problem (aka,
unpluggable). Then, we know why we introduce a change, and especially, when
the change can go away.
OTOH, if we merge auto-detach of qdev MRs, we likely need to stick it
forever because justifying it not needed will be extremely hard if not
impossible.. after all we do not know what it fixes. So if we can at least
list the devices that may be fixed with it in the commit message, it would
be a benefit.
Once again, feel free to treat my comment as a pure question.
Thanks,
--
Peter Xu
prev parent reply other threads:[~2025-10-10 15:35 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 10:32 [PATCH 00/14] Fix memory region use-after-finalization Akihiko Odaki
2025-09-17 10:32 ` [PATCH 01/14] hw/pci-bridge: Do not assume immediate MemoryRegion finalization Akihiko Odaki
2025-10-02 18:47 ` Peter Xu
2025-10-03 13:38 ` Akihiko Odaki
2025-09-17 10:32 ` [PATCH 02/14] qdev: Automatically delete memory subregions Akihiko Odaki
2025-10-02 19:23 ` Peter Xu
2025-10-02 19:40 ` Peter Xu
2025-10-03 14:01 ` Akihiko Odaki
2025-10-03 15:26 ` Peter Xu
2025-10-10 5:55 ` Akihiko Odaki
2025-09-17 10:32 ` [PATCH 03/14] vfio-user: Do not delete the subregion Akihiko Odaki
2025-09-17 10:32 ` [PATCH 04/14] hw/char/diva-gsp: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 05/14] hw/char/serial-pci-multi: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 06/14] secondary-vga: Do not delete the subregions Akihiko Odaki
2025-09-17 10:32 ` [PATCH 07/14] cmd646: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 08/14] hw/ide/piix: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 09/14] hw/ide/via: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 10/14] hw/nvme: Do not delete the subregion Akihiko Odaki
2025-09-17 10:32 ` [PATCH 11/14] pci: Do not delete the subregions Akihiko Odaki
2025-09-17 10:32 ` [PATCH 12/14] hw/ppc/spapr_pci: " Akihiko Odaki
2025-09-17 10:32 ` [PATCH 13/14] hw/usb/hcd-ehci: " Akihiko Odaki
2025-09-17 10:33 ` [PATCH 14/14] hw/usb/hcd-xhci: " Akihiko Odaki
2025-10-02 15:03 ` [PATCH 00/14] Fix memory region use-after-finalization Paolo Bonzini
2025-10-10 10:20 ` Akihiko Odaki
2025-10-10 15:32 ` Peter Xu [this message]
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=aOknHiJRVfe0s_hT@x1.local \
--to=peterx@redhat.com \
--cc=aik@ozlabs.ru \
--cc=alex.bennee@linaro.org \
--cc=alex.williamson@redhat.com \
--cc=arikalo@gmail.com \
--cc=atar4qemu@gmail.com \
--cc=aurelien@aurel32.net \
--cc=balaton@eik.bme.hu \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=david@redhat.com \
--cc=deller@gmx.de \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=foss@defmacro.it \
--cc=harshpb@linux.ibm.com \
--cc=hpoussin@reactos.org \
--cc=its@irrelevant.dk \
--cc=jcmvbkbc@gmail.com \
--cc=jiaxun.yang@flygoat.com \
--cc=john.levon@nutanix.com \
--cc=jsnow@redhat.com \
--cc=kbusch@kernel.org \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=npiggin@gmail.com \
--cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thanos.makatos@nutanix.com \
--cc=thuth@redhat.com \
--cc=wangyanan55@huawei.com \
/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 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).