On Thu, 19 Nov 2026, Peter Maydell wrote:
On Wed, 18 Nov 2026 at 18:58, Bernhard Beschow <[email protected]> wrote:
Am 14. November 2026 10:37:09 UTC schrieb Peter Maydell 
<[email protected]>:
One thing I'm not sure about is what unrealize is actually for.
Is there ever anything that a device needs to do in unrealize that
it could not postpone to deinit?

I think this question boils down to what the difference between init() and 
realize() is. deinit() and unrealize() should be their respective duals, i.e. 
undo what has been done there.

The main reason IMHO that we have split init and realize is:
(1) init can't fail, so operations that can fail go in realize
(2) operations that depend on properties set on the device
    need to go in realize, which runs after properties are set

But neither of those apply to unrealize:
* unrealize can't fail
* there's no equivalent of setting properties that happens
  during the unrealize-and-destroy sequence

"Undo in unrealize what you did in realize, and undo in
deinit what you did in init" sounds like a nice rule, except
for the fact that we have no reference counting for "keep
this device realized', so there's no way for users of the
device to make sure that things they're relying on don't
go away if you clean them up in unrealize.

I think the question is if an unrealized device is useful to keep for anything. I can't think of a reason but I don't know a lot of details of QEMU so there might be some cases when that happens. I think this was your question too. If there's no reason to keep unrealized devices I'd say unrealize should not be called by anybody except qdev itself and do that on destroying the object which should only happen if there are no references left so that would ensure we won't have unrealized devices and other parts don't have to deal with it (which I think is better than trying to handle it at some places that could miss others or introduce problems in future models that don't handle this).

Currently within qdev hw/code/bus.c seems to be unrealizing devices apart from qdev itself, and some other device models call qdev_unrealize. Probably those should be reviewed why those are needed and if they could be replaced with proper refcounting so devices would be freed and unrealized by that or if there's any reason to keep devices unrealized but not destroyed. I've found these with
git grep "object_property_set.*realized\|qdev_unrealize"

Regards,
BALATON Zoltan

Reply via email to