From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aam1C-0000Wx-TH for qemu-devel@nongnu.org; Tue, 01 Mar 2016 10:15:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aam17-0001Us-8h for qemu-devel@nongnu.org; Tue, 01 Mar 2016 10:15:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aam17-0001Un-2r for qemu-devel@nongnu.org; Tue, 01 Mar 2016 10:15:17 -0500 References: <1456771254-17511-1-git-send-email-armbru@redhat.com> <1456771254-17511-31-git-send-email-armbru@redhat.com> <56D5811C.7090108@redhat.com> <87y4a2gumw.fsf@blackfin.pond.sub.org> From: Paolo Bonzini Message-ID: <56D5B200.2020505@redhat.com> Date: Tue, 1 Mar 2016 16:15:12 +0100 MIME-Version: 1.0 In-Reply-To: <87y4a2gumw.fsf@blackfin.pond.sub.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 30/38] ivshmem: Simplify memory regions for BAR 2 (shared memory) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: claudio.fontana@huawei.com, cam@cs.ualberta.ca, mlureau@redhat.com, qemu-devel@nongnu.org, david.marchand@6wind.com On 01/03/2016 15:06, Markus Armbruster wrote: > Paolo Bonzini 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! >