> On Apr 25, 2022, at 1:34 PM, Jag Raman <[email protected]> wrote:
>
>
>
>> On Apr 25, 2022, at 5:56 AM, Stefan Hajnoczi <[email protected]> wrote:
>>
>> On Tue, Apr 19, 2022 at 04:44:18PM -0400, Jagannathan Raman wrote:
>>> +static void dma_unregister(vfu_ctx_t *vfu_ctx, vfu_dma_info_t *info)
>>> +{
>>> + VfuObject *o = vfu_get_private(vfu_ctx);
>>> + AddressSpace *dma_as = NULL;
>>> + MemoryRegion *mr = NULL;
>>> + ram_addr_t offset;
>>> +
>>> + mr = memory_region_from_host(info->vaddr, &offset);
>>> + if (!mr) {
>>> + return;
>>> + }
>>> +
>>> + dma_as = pci_device_iommu_address_space(o->pci_dev);
>>> +
>>> + memory_region_del_subregion(dma_as->root, mr);
>>> +
>>> + object_unparent((OBJECT(mr)));
>>
>> Where is obj->parent set?
>
> Yeah, it should be object_unref().
I think object_unparent() is the appropriate way to finalize the
MemoryRegion in this case.
‘mr’ is an owner-less MemoryRegion created by dma_register(). owner-less
MemoryRegions initialized using memory_region_init* functions are children
of the “/unattached” object.
The parent is set by dma_register() -> memory_region_init_ram_ptr() ->
memory_region_init() -> memory_region_do_init() ->
object_property_add_child() -> object_property_try_add_child().
Thank you!
--
Jag
>
> Thank you!
> --
> Jag
>
>>
>> If it is not set then this call is a nop and mr is not freed:
>>
>> void object_unparent(Object *obj)
>> {
>> if (obj->parent) {
>> object_property_del_child(obj->parent, obj);
>> }
>> }