From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753280Ab3KCEF3 (ORCPT ); Sun, 3 Nov 2013 00:05:29 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:59466 "EHLO e7.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862Ab3KCEEi (ORCPT ); Sun, 3 Nov 2013 00:04:38 -0400 Date: Sat, 2 Nov 2013 10:28:40 -0700 From: "Paul E. McKenney" To: Victor Kaplansky Cc: Anton Blanchard , Benjamin Herrenschmidt , Frederic Weisbecker , LKML , Linux PPC dev , Mathieu Desnoyers , Michael Ellerman , Michael Neuling , Oleg Nesterov , Peter Zijlstra Subject: Re: perf events ring buffer memory barrier on powerpc Message-ID: <20131102172840.GA3947@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <20131028132634.GO19466@laptop.lan> <20131028163418.GD4126@linux.vnet.ibm.com> <20131028201735.GA15629@redhat.com> <20131030092725.GL4126@linux.vnet.ibm.com> <20131030112526.GI16117@laptop.programming.kicks-ass.net> <20131031064015.GV4126@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13110304-5806-0000-0000-0000234D10CE Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 01, 2013 at 04:25:42PM +0200, Victor Kaplansky wrote: > "Paul E. McKenney" wrote on 10/31/2013 > 08:40:15 AM: > > > > void ubuf_read(void) > > > { > > > u64 head, tail; > > > > > > tail = ACCESS_ONCE(ubuf->tail); > > > head = ACCESS_ONCE(ubuf->head); > > > > > > /* > > > * Ensure we read the buffer boundaries before the actual buffer > > > * data... > > > */ > > > smp_rmb(); /* C, matches with B */ > > > > > > while (tail != head) { > > > obj = ubuf->data + tail; > > > /* process obj */ > > > tail += obj->size; > > > tail %= ubuf->size; > > > } > > > > > > /* > > > * Ensure all data reads are complete before we issue the > > > * ubuf->tail update; once that update hits, kbuf_write() can > > > * observe and overwrite data. > > > */ > > > smp_mb(); /* D, matches with A */ > > > > > > ubuf->tail = tail; > > > } > > > > Could we replace A and C with an smp_read_barrier_depends()? > > > > C, yes, given that you have ACCESS_ONCE() on the fetch from ->tail > > and that the value fetch from ->tail feeds into the address used for > > the "obj =" assignment. > > No! You must to have a full smp_rmb() at C. The race on the reader side > is not between fetch of @tail and read from address pointed by @tail. > The real race here is between a fetch of @head and read of obj from > memory pointed by @tail. I believe you are in fact correct, good catch. Thanx, Paul