From patchwork Wed May 4 06:52:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 9010941 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 48C319F1C1 for ; Wed, 4 May 2016 06:59:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B7B0202E9 for ; Wed, 4 May 2016 06:59:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9665520382 for ; Wed, 4 May 2016 06:59:29 +0000 (UTC) Received: from localhost ([::1]:45997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axqmL-0000em-Rp for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 May 2016 02:59:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axqjw-0004cc-C5 for qemu-devel@nongnu.org; Wed, 04 May 2016 02:57:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axqje-0006dw-Uk for qemu-devel@nongnu.org; Wed, 04 May 2016 02:56:50 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:46549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axqje-0006Zu-6V for qemu-devel@nongnu.org; Wed, 04 May 2016 02:56:38 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 May 2016 16:56:19 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 4 May 2016 16:56:16 +1000 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: aik@ozlabs.ru X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 0106D2BB0071; Wed, 4 May 2016 16:56:03 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u446tdGR8585688; Wed, 4 May 2016 16:55:47 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u446tFFa027959; Wed, 4 May 2016 16:55:15 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u446tE4o027314; Wed, 4 May 2016 16:55:15 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 4CFB5A03C5; Wed, 4 May 2016 16:52:41 +1000 (AEST) Received: from vpl2.ozlabs.ibm.com (vpl2.ozlabs.ibm.com [10.61.141.27]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id F1372E3A3C; Wed, 4 May 2016 16:52:35 +1000 (AEST) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Wed, 4 May 2016 16:52:14 +1000 Message-Id: <1462344751-28281-3-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 In-Reply-To: <1462344751-28281-1-git-send-email-aik@ozlabs.ru> References: <1462344751-28281-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16050406-1618-0000-0000-0000459E4369 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.143 Subject: [Qemu-devel] [PATCH qemu v16 02/19] memory: Call region_del() callbacks on memory listener unregistering X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Alexander Graf , Alex Williamson , qemu-ppc@nongnu.org, Paolo Bonzini , David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a new memory listener is registered, listener_add_address_space() is called and which in turn calls region_add() callbacks of memory regions. However when unregistering the memory listener, it is just removed from the listening chain and no region_del() is called. This adds listener_del_address_space() and uses it in memory_listener_unregister(). listener_add_address_space() was used as a template with the following changes: s/log_global_start/log_global_stop/ s/log_start/log_stop/ s/region_add/region_del/ This will allow the following patches to add/remove DMA windows dynamically from VFIO's PCI address space's region_add()/region_del(). Signed-off-by: Alexey Kardashevskiy --- memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/memory.c b/memory.c index f76f85d..f762a34 100644 --- a/memory.c +++ b/memory.c @@ -2185,6 +2185,49 @@ static void listener_add_address_space(MemoryListener *listener, flatview_unref(view); } +static void listener_del_address_space(MemoryListener *listener, + AddressSpace *as) +{ + FlatView *view; + FlatRange *fr; + + if (listener->address_space_filter + && listener->address_space_filter != as) { + return; + } + + if (listener->begin) { + listener->begin(listener); + } + if (global_dirty_log) { + if (listener->log_global_stop) { + listener->log_global_stop(listener); + } + } + + view = address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + MemoryRegionSection section = { + .mr = fr->mr, + .address_space = as, + .offset_within_region = fr->offset_in_region, + .size = fr->addr.size, + .offset_within_address_space = int128_get64(fr->addr.start), + .readonly = fr->readonly, + }; + if (fr->dirty_log_mask && listener->log_stop) { + listener->log_stop(listener, §ion, 0, fr->dirty_log_mask); + } + if (listener->region_del) { + listener->region_del(listener, §ion); + } + } + if (listener->commit) { + listener->commit(listener); + } + flatview_unref(view); +} + void memory_listener_register(MemoryListener *listener, AddressSpace *filter) { MemoryListener *other = NULL; @@ -2211,6 +2254,11 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *filter) void memory_listener_unregister(MemoryListener *listener) { + AddressSpace *as; + + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + listener_del_address_space(listener, as); + } QTAILQ_REMOVE(&memory_listeners, listener, link); }