From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755177AbcEWUPP (ORCPT ); Mon, 23 May 2016 16:15:15 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:35512 "EHLO e34.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752910AbcEWUPM (ORCPT ); Mon, 23 May 2016 16:15:12 -0400 X-IBM-Helo: d03dlp03.boulder.ibm.com X-IBM-MailFrom: paulmck@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Mon, 23 May 2016 13:15:02 -0700 From: "Paul E. McKenney" To: Davidlohr Bueso Cc: Jason Low , Peter Hurley , jason.low2@hp.com, Waiman Long , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Dave Chinner , Scott J Norton , Douglas Hatch Subject: Re: [PATCH v4 2/5] locking/rwsem: Protect all writes to owner by WRITE_ONCE Message-ID: <20160523201502.GN3825@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1463534783-38814-1-git-send-email-Waiman.Long@hpe.com> <1463534783-38814-3-git-send-email-Waiman.Long@hpe.com> <20160518140436.GA6273@linux-uzut.site> <1463592095.3369.10.camel@j-VirtualBox> <573CB496.4010707@hpe.com> <1463601515.2587.24.camel@j-VirtualBox> <574086FE.6080807@hurleysoftware.com> <1464029181.2479.21.camel@j-VirtualBox> <20160523194416.up365sfbm7f55kbq@linux-uzut.site> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160523194416.up365sfbm7f55kbq@linux-uzut.site> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16052320-0017-0000-0000-00002F71FB64 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2016 at 12:44:16PM -0700, Davidlohr Bueso wrote: > On Mon, 23 May 2016, Jason Low wrote: > > >On Sat, 2016-05-21 at 09:04 -0700, Peter Hurley wrote: > >>On 05/18/2016 12:58 PM, Jason Low wrote: > >>> It should be fine to use the standard READ_ONCE here, even if it's just > >>> for documentation, as it's probably not going to cost anything in > >>> practice. It would be better to avoid adding any special macros for this > >>> which may just add more complexity. > >> > >>See, I don't understand this line of reasoning at all. > >> > >>I read this as "it's ok to be non-optimal here where were spinning CPU > >>time but not ok to be non-optimal generally elsewhere where it's > >>way less important like at init time". > > > >So I think there is a difference between using it during init time and > >using it here where we're spinning. During init time, initializing the > >owner field locklessly is normal. No other thread should be concurrently > >be writing to the field, since the structure is just getting > >initialized, so there are no surprises there. > > > >Our access of the owner field in this function is special in that we're > >using a bit of "lockless magic" to read and write to a field that gets > >concurrently accessed without any serialization. Since we're not taking > >the wait_lock in a scenario where we'd normally would take a lock, it > >would be good to have this documented. > > > >>And by the way, it's not just "here" but _everywhere_. > >>What about reading ->on_cpu locklessly? > > > >Sure, we could also use READ_ONCE when reading ->on_cpu :) > > Locking wise we should be covered with ->on_cpu as we're always under rcu_read_lock > (barrier, preempt_disable). But I'm not sure if this rule applies throughout the > scheduler, however, like it does in, say thread_group_cputime(). cpu_clock_sample() > (from posix timers) seems to mix and match being done under rcu. So ultimately I > think you're right. But rcu_read_lock() does not exclude updates, which is one reason why pointer reads use rcu_dereference() rather than normal assignments. So I do not believe that rcu_read_lock() is helping you in this case. That said, it is a bit hard to imagine the compiler tearing a load from an int... But compilers have uncovered weaknesses in my imagination more than once in the past. Thanx, Paul