From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ZqJ-0007Rz-0i for qemu-devel@nongnu.org; Thu, 17 Dec 2015 09:47:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9ZqE-0001RS-UE for qemu-devel@nongnu.org; Thu, 17 Dec 2015 09:47:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58013) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ZqE-0001R3-Oy for qemu-devel@nongnu.org; Thu, 17 Dec 2015 09:47:38 -0500 Date: Thu, 17 Dec 2015 16:47:32 +0200 From: "Michael S. Tsirkin" Message-ID: <20151217164428-mutt-send-email-mst@redhat.com> References: <1450347930-16275-1-git-send-email-mst@redhat.com> <20151217105827.GB6375@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151217105827.GB6375@twins.programming.kicks-ass.net> Subject: Re: [Qemu-devel] [PATCH] virtio: use smp_load_acquire/smp_store_release List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Zijlstra Cc: qemu-devel@nongnu.org, Jason Wang , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org On Thu, Dec 17, 2015 at 11:58:27AM +0100, Peter Zijlstra wrote: > On Thu, Dec 17, 2015 at 12:29:03PM +0200, Michael S. Tsirkin wrote: > > +static inline __virtio16 virtio_load_acquire(bool weak_barriers, __virtio16 *p) > > +{ > > + if (!weak_barriers) { > > + rmb(); > > + return READ_ONCE(*p); > > + } > > +#ifdef CONFIG_SMP > > + return smp_load_acquire(p); > > +#else > > + dma_rmb(); > > + return READ_ONCE(*p); > > +#endif > > +} > > This too is wrong. Look for example at arm. > > dma_rmb() is dmb(osh), while the smp_mb() used by smp_load_acquire() is > dmb(ish). They order completely different types of memory accesses. > > Also, load_acquire() is first load, then barrier, and an ACQUIRE barrier > at that, not a READ barrier. Yes - it just so happens that READ barrier is enough for where I use it for virtio. I really just need virtio_load_acquire that fences reads, I don't care what happens to writes. Given the confusion, maybe virtio_load_acquire is a bad name though. Donnu what a good name would be. virtio_load_acquire_rmb and virtio_store_release_wmb? > So your #else branch should look something like: > > var = READ_ONCE(*p); > dma_mb(); > return var; >