From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQapk-0007aq-BD for qemu-devel@nongnu.org; Fri, 12 Apr 2013 06:03:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQapj-0001Lh-2x for qemu-devel@nongnu.org; Fri, 12 Apr 2013 06:03:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11686) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQapi-0001Lc-SL for qemu-devel@nongnu.org; Fri, 12 Apr 2013 06:03:51 -0400 Message-ID: <5167DBFC.2060405@redhat.com> Date: Fri, 12 Apr 2013 12:03:40 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1364804434-7980-1-git-send-email-qemulist@gmail.com> <1364804434-7980-3-git-send-email-qemulist@gmail.com> <20130411101118.GC9165@stefanha-thinkpad.redhat.com> <20130412083855.GC31055@stefanha-thinkpad.redhat.com> In-Reply-To: <20130412083855.GC31055@stefanha-thinkpad.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/5] hostmem: make hostmem global and RAM hotunplg safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Peter Maydell , Anthony Liguori , Jan Kiszka , Marcelo Tosatti , liu ping fan , qemu-devel@nongnu.org, Vasilis Liaskovitis Il 12/04/2013 10:38, Stefan Hajnoczi ha scritto: >> > Yes, protect. Supposed we have HostMem A, and it will become B. Then >> > hostmem_lookup will either see A or B. If it see A, it should use A >> > refcnt agaist hostmem_listener_commit to drop A. This refcnt has no >> > relation with mr's object's refcnt. > My question is why you are accessing cur_hostmem outside hostmem_lock > but then assigning it inside the lock on the next line... > >>>> > >> + cur_hostmem = next_hostmem; > ...here. > > If you want an atomic exchange then tmp = cur_hostmem should be inside > the lock. It will work because readers will grab either the hostmem_lock or the BQL, while writers will grab both. A kind of local/global lock, but I'm not sure it was intentional. :) It's simpler to just move the read inside the lock. Paolo