On 01/03/2016 15:06, Markus Armbruster wrote:
> Paolo Bonzini <[email protected]> writes:
> 
>> On 29/02/2016 19:40, Markus Armbruster wrote:
>>> -    memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s),
>>> +    s->ivshmem_bar2 = g_new(MemoryRegion, 1);
>>> +    memory_region_init_ram_ptr(s->ivshmem_bar2, OBJECT(s),
>>>                                 "ivshmem.bar2", s->ivshmem_size, ptr);
>>> -    qemu_set_ram_fd(s->ivshmem.ram_addr, fd);
>>> -    vmstate_register_ram(&s->ivshmem, DEVICE(s));
>>> -    memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>>> +    qemu_set_ram_fd(s->ivshmem_bar2->ram_addr, fd);
>>
>> This is missing an instance_finalize callback to do
>>
>>     if (s->ivshmem_bar2) {
>>         object_unparent(s->ivshmem_bar2);
>>         g_free(s->ivshmem_bar2);
>>     }
> 
> Since it's allocated within ivshmem_realize(), I guess I could free it
> in ivshmem_exit().

Unfortunately you can't, because the guest might be using it at the time
of hot-unplug (e.g. DMAing from disk to it).  Unrealize is the place
where you hide stuff, and in this case the PCI core does it for you;
finalize is the place where you free stuff.

This is mentioned (though not really in these terms) in docs/memory.txt.

Paolo

>> or, alternatively just use a flag (e.g. s->bar2_mapped) and allocate it
>> directly in the IVShmemState struct.
> 
> I'll see what comes out nicer.  Thanks!
> 

Reply via email to