From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIgI9-00022D-MY for qemu-devel@nongnu.org; Tue, 03 Feb 2015 11:25:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIgI6-0000CU-Fy for qemu-devel@nongnu.org; Tue, 03 Feb 2015 11:25:33 -0500 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:52250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIgI6-0000CO-7s for qemu-devel@nongnu.org; Tue, 03 Feb 2015 11:25:30 -0500 Received: by mail-we0-f181.google.com with SMTP id k48so46001429wev.12 for ; Tue, 03 Feb 2015 08:25:29 -0800 (PST) Sender: Paolo Bonzini Message-ID: <54D0F675.8070000@redhat.com> Date: Tue, 03 Feb 2015 17:25:25 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1422967705-1374-1-git-send-email-pbonzini@redhat.com> <1422976808.22865.452.camel@redhat.com> In-Reply-To: <1422976808.22865.452.camel@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] vfio: free dynamically-allocated data in instance_finalize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Williamson Cc: qemu-devel@nongnu.org On 03/02/2015 16:20, Alex Williamson wrote: > On Tue, 2015-02-03 at 13:48 +0100, Paolo Bonzini wrote: >> In order to enable out-of-BQL address space lookup, destruction of >> devices needs to be split in two phases. >> >> Unrealize is the first phase; once it complete no new accesses will >> be started, but there may still be pending memory accesses can still >> be completed. >> >> The second part is freeing the device, which only happens once all memory >> accesses are complete. At this point the reference count has dropped to >> zero, an RCU grace period must have completed (because the RCU-protected >> FlatViews hold a reference to the device via memory_region_ref). This is >> when instance_finalize is called. >> >> Freeing data belongs in an instance_finalize callback, because the >> dynamically allocated memory can still be used after unrealize by the >> pending memory accesses. >> >> In the case of VFIO, the unrealize callback is too early to munmap the >> BARs. The munmap must be delayed until memory accesses are complete. >> To do this, split vfio_unmap_bars in two. The removal step, now called >> vfio_unregister_bars, remains in vfio_exitfn. The reclamation step >> is vfio_unmap_bars and is moved to the instance_finalize callback. >> >> Similarly, quirk MemoryRegions have to be removed during >> vfio_unregister_bars, but freeing the data structure must be delayed >> to vfio_unmap_bars. >> >> Cc: Alex Williamson >> Signed-off-by: Paolo Bonzini >> --- >> This patch is part of the third installment 3 of the RCU work. >> Sending it out separately for Alex to review it. >> >> hw/vfio/pci.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- >> 1 file changed, 68 insertions(+), 10 deletions(-) > > Looks good to me. I don't see any external dependencies, so do you want > me to pull this in through my branch? Thanks, Yes, please. Paolo