On Fri, 13 Nov 2026, Peter Maydell wrote:
We give QOM objects a reference count. This means that if you are
going to try to use one, you can take a ref to it, and then you're
guaranteed that it won't disappear while you're working with it.
For QDEV devices, we add the "realize" and "unrealize" steps to
the lifecycle. There is no "reference count for having a realized
device". So what do we intend here?
(1) We could say that if you have a reference to the device then you
can assume it's not going to be unrealized under your feet, and have
very careful rules about who can unrealize a device and when.
(2) We could say that if you have a reference to the device then it
might be unrealized, but it won't be deinitialized, and you can assume
that all the API calls you might make on it will in some sense still
work, and at any rate at least won't try to access memory that's been
freed or crash.
I have no idea but (2) seems to be impossible to achieve without likely
also patching all devices one by one that don't expect this now. So I
think requiring that a device should only be unrealized if the caller of
unrealize has the only reference to it would make sense. This is at least
easy to check but may not be easy to ensure in every case but, failing
that may only leave a leaked device at worst but not break things. So I'd
vote (1).
Regards,
BALATON Zoltan