From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcXsJ-0000qs-MW for qemu-devel@nongnu.org; Wed, 15 May 2013 05:19:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcXsG-0006Sx-9o for qemu-devel@nongnu.org; Wed, 15 May 2013 05:19:55 -0400 Received: from mx3-phx2.redhat.com ([209.132.183.24]:53827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcXsG-0006Sq-2K for qemu-devel@nongnu.org; Wed, 15 May 2013 05:19:52 -0400 Date: Wed, 15 May 2013 05:19:48 -0400 (EDT) From: Paolo Bonzini Message-ID: <154112326.1807249.1368609588959.JavaMail.root@redhat.com> In-Reply-To: References: <1368415264-10800-1-git-send-email-qemulist@gmail.com> <1368415264-10800-3-git-send-email-qemulist@gmail.com> <5190B2FD.7090008@redhat.com> <51920512.3090708@redhat.com> <519345AB.3030208@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH 2/2] mem: prepare address_space listener rcu style List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: liu ping fan Cc: Peter Maydell , Anthony Liguori , "Michael S. Tsirkin" , Jan Kiszka , qemu-devel@nongnu.org, Stefan Hajnoczi > > > rcu_read_lock(); > > > map = rcu_dereference(d->cur_map) > > > if (unlikely(d->prev_map!=map) { > > > d->root = map->root; > > > d->pgtbl = map->pgtbl; > > > } > > > ...... > > > rcu_read_unlock(); > > > > > > Then it can avoid ABA problem. > > > > I don't see the assignment of prev_map, which is where the ABA problem > > arises. If you do this: > rcu_read_lock(); > map = rcu_derefenrence(d->cur_map) > if (unlikely(d->prev_map!=map) { > d->root = map->root; > d->pgtbl = map->pgtbl; > d->prev_map = map; > } > .... > rcu_read_unlock(); It can happen. The problem is that prev_map can change _after_ the rcu_read_unlock. It is the same as your previous solution. Please just use the load-and-check idiom. I'll post my RCU implementation as soon as I finish the documentation. Paolo