From patchwork Tue Feb 10 18:37:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 438506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0FC53140145 for ; Wed, 11 Feb 2015 05:37:54 +1100 (AEDT) Received: from localhost ([::1]:41301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLFh1-0001K7-Hr for incoming@patchwork.ozlabs.org; Tue, 10 Feb 2015 13:37:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLFgZ-0000h4-6x for qemu-devel@nongnu.org; Tue, 10 Feb 2015 13:37:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLFgV-0006b5-6N for qemu-devel@nongnu.org; Tue, 10 Feb 2015 13:37:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLFgU-0006av-Ug for qemu-devel@nongnu.org; Tue, 10 Feb 2015 13:37:19 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1AIbHQm019884 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 10 Feb 2015 13:37:18 -0500 Received: from gimli.home (ovpn-113-68.phx2.redhat.com [10.3.113.68]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1AIbGLB024749; Tue, 10 Feb 2015 13:37:16 -0500 From: Alex Williamson To: qemu-devel@nongnu.org Date: Tue, 10 Feb 2015 11:37:16 -0700 Message-ID: <20150210183716.26101.26293.stgit@gimli.home> In-Reply-To: <20150210183106.26101.78658.stgit@gimli.home> References: <20150210183106.26101.78658.stgit@gimli.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [PULL 1/6] memory: unregister AddressSpace MemoryListener within BQL X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini address_space_destroy_dispatch is called from an RCU callback and hence outside the iothread mutex (BQL). However, after address_space_destroy no new accesses can hit the destroyed AddressSpace so it is not necessary to observe changes to the memory map. Move the memory_listener_unregister call earlier, to make it thread-safe again. Reported-by: Alex Williamson Fixes: 374f2981d1f10bc4307f250f24b2a7ddb9b14be0 Signed-off-by: Paolo Bonzini Signed-off-by: Alex Williamson --- exec.c | 6 +++++- include/exec/memory-internal.h | 1 + memory.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 6b79ad1..6dff7bc 100644 --- a/exec.c +++ b/exec.c @@ -2059,11 +2059,15 @@ void address_space_init_dispatch(AddressSpace *as) memory_listener_register(&as->dispatch_listener, as); } +void address_space_unregister(AddressSpace *as) +{ + memory_listener_unregister(&as->dispatch_listener); +} + void address_space_destroy_dispatch(AddressSpace *as) { AddressSpaceDispatch *d = as->dispatch; - memory_listener_unregister(&as->dispatch_listener); g_free(d); as->dispatch = NULL; } diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h index 25c43c0..fb467ac 100644 --- a/include/exec/memory-internal.h +++ b/include/exec/memory-internal.h @@ -23,6 +23,7 @@ typedef struct AddressSpaceDispatch AddressSpaceDispatch; void address_space_init_dispatch(AddressSpace *as); +void address_space_unregister(AddressSpace *as); void address_space_destroy_dispatch(AddressSpace *as); extern const MemoryRegionOps unassigned_mem_ops; diff --git a/memory.c b/memory.c index 9b91243..130152c 100644 --- a/memory.c +++ b/memory.c @@ -1978,6 +1978,7 @@ void address_space_destroy(AddressSpace *as) as->root = NULL; memory_region_transaction_commit(); QTAILQ_REMOVE(&address_spaces, as, address_spaces_link); + address_space_unregister(as); /* At this point, as->dispatch and as->current_map are dummy * entries that the guest should never use. Wait for the old