From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 04/15] memory: MemoryRegion topology must be stable when updating Date: Thu, 09 Aug 2012 11:24:49 +0300 Message-ID: <502373D1.9050109@redhat.com> References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-5-git-send-email-qemulist@gmail.com> <50222DB6.8020505@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Anthony Liguori , Jan Kiszka , Marcelo Tosatti , Stefan Hajnoczi , Paolo Bonzini , Blue Swirl , =?ISO-8859-1?Q?Andreas_F=E4rber?= To: liu ping fan Return-path: Received: from mx1.redhat.com ([209.132.183.28]:63623 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752342Ab2HIIZA (ORCPT ); Thu, 9 Aug 2012 04:25:00 -0400 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On 08/09/2012 10:28 AM, liu ping fan wrote: >> >> Seems to me that nothing in memory.c can susceptible to races. It must >> already be called under the big qemu lock, and with the exception of >> mutators (memory_region_set_*), changes aren't directly visible. >> > Yes, what I want to do is "prepare unplug out of protection of global > lock". When io-dispatch and mmio-dispatch are all out of big lock, we > will run into the following scene: > In vcpu context A, qdev_unplug_complete()-> delete subregion; > In context B, write pci bar --> pci mapping update -> add subregion Why do you want unlocked unplug? Unplug is rare and complicated; there are no performance considerations on one hand, and difficulty of testing for lock correctness on the other. I think it is better if it remains protected by the global lock. > >> I think it's sufficient to take the mem_map_lock at the beginning of >> core_begin() and drop it at the end of core_commit(). That means all >> updates of volatile state, phys_map, are protected. >> > The mem_map_lock is to protect both address_space_io and > address_space_memory. When without the protection of big lock, > competing will raise among the updaters > (memory_region_{add,del}_subregion and the readers > generate_memory_topology()->render_memory_region(). These should all run under the big qemu lock, for the same reasons. They are rare and not performance sensitive. Only phys_map reads are performance sensitive. > > If just in core_begin/commit, we will duplicate it for > xx_begin/commit, right? No. Other listeners will be protected by the global lock. > And at the same time, mr->subregions is > exposed under SMP without big lock. > Who accesses it? IMO locking should look like: phys_map: mem_map_lock dispatch callbacks: device specific lock (or big qemu lock for unconverted devices) everything else: big qemu lock -- error compiling committee.c: too many arguments to function From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzO39-0002dz-9j for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:25:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzO37-0008Ge-08 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:24:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzO36-0008GT-O7 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 04:24:56 -0400 Message-ID: <502373D1.9050109@redhat.com> Date: Thu, 09 Aug 2012 11:24:49 +0300 From: Avi Kivity MIME-Version: 1.0 References: <1344407156-25562-1-git-send-email-qemulist@gmail.com> <1344407156-25562-5-git-send-email-qemulist@gmail.com> <50222DB6.8020505@redhat.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 04/15] memory: MemoryRegion topology must be stable when updating List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: kvm@vger.kernel.org, Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, Blue Swirl , Anthony Liguori , Stefan Hajnoczi , Paolo Bonzini , =?ISO-8859-1?Q?Andreas_F=E4rber?= On 08/09/2012 10:28 AM, liu ping fan wrote: >> >> Seems to me that nothing in memory.c can susceptible to races. It must >> already be called under the big qemu lock, and with the exception of >> mutators (memory_region_set_*), changes aren't directly visible. >> > Yes, what I want to do is "prepare unplug out of protection of global > lock". When io-dispatch and mmio-dispatch are all out of big lock, we > will run into the following scene: > In vcpu context A, qdev_unplug_complete()-> delete subregion; > In context B, write pci bar --> pci mapping update -> add subregion Why do you want unlocked unplug? Unplug is rare and complicated; there are no performance considerations on one hand, and difficulty of testing for lock correctness on the other. I think it is better if it remains protected by the global lock. > >> I think it's sufficient to take the mem_map_lock at the beginning of >> core_begin() and drop it at the end of core_commit(). That means all >> updates of volatile state, phys_map, are protected. >> > The mem_map_lock is to protect both address_space_io and > address_space_memory. When without the protection of big lock, > competing will raise among the updaters > (memory_region_{add,del}_subregion and the readers > generate_memory_topology()->render_memory_region(). These should all run under the big qemu lock, for the same reasons. They are rare and not performance sensitive. Only phys_map reads are performance sensitive. > > If just in core_begin/commit, we will duplicate it for > xx_begin/commit, right? No. Other listeners will be protected by the global lock. > And at the same time, mr->subregions is > exposed under SMP without big lock. > Who accesses it? IMO locking should look like: phys_map: mem_map_lock dispatch callbacks: device specific lock (or big qemu lock for unconverted devices) everything else: big qemu lock -- error compiling committee.c: too many arguments to function