On Mon, 1 Sept 2025 at 14:28, Akihiko Odaki <od...@rsg.ci.i.u-tokyo.ac.jp> wrote: > This approach is clearly not working. The problem here is that there are > devices that never get realized (so never get unrealized either).
Yes, the "instance_init -> instance_finalize" lifecycle path is valid: it gets used when we want to introspect a device (e.g. find out what properties it has). device-introspect-test does this for every device compiled into QEMU. The instance_init -> realize -> unrealize -> instance_finalize path on the other hand only really needs to work for pluggable devices, because only those will get unrealized. So we have a lot of devices where if we ever exercised this path we'd find we had memory leaks or other bugs. (Many devices for SoC objects and devices only used in SoC objects don't implement unrealize at all.) > I'm thinking of a solution that fixes all possible circular references > originated from owners without breaking anything else, but I don't have > one for now. I think overall I like Peter Xu's patch, with the underlying model being "MemoryRegions are not reference counted objects that should be considered to have a separate existence from the device that backs them; unless they're the 'lives forever, no owner' kind then what you want is to hold a reference to the owning device". -- PMM