Am 14. November 2026 10:37:09 UTC schrieb Peter Maydell 
<[email protected]>:
>On Fri, 13 Nov 2026 at 20:07, BALATON Zoltan <[email protected]> wrote:
>>
>> 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).
>
>The good news about (2) is that the only devices that can be
>unrealized is the ones that can be hot-unplugged, which is
>"PCI devices and a handful of others", so we wouldn't have to look
>at literally every device. But I agree that if we can figure out a
>viable rule for when you're allowed to unrealize then that would
>probably be less work to implement.
>
>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.

Best regards,
Bernhard

Reply via email to