From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751419AbcEIHM1 (ORCPT ); Mon, 9 May 2016 03:12:27 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:42321 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbcEIHM0 (ORCPT ); Mon, 9 May 2016 03:12:26 -0400 Date: Mon, 9 May 2016 09:12:20 +0200 From: Peter Zijlstra To: Peter Hurley Cc: Davidlohr Bueso , mingo@kernel.org, tglx@linutronix.de, Waiman.Long@hpe.com, jason.low2@hp.com, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 1/4] locking/rwsem: Avoid stale ->count for rwsem_down_write_failed() Message-ID: <20160509071220.GB3430@twins.programming.kicks-ass.net> References: <1462769770-29363-1-git-send-email-dave@stgolabs.net> <1462769770-29363-2-git-send-email-dave@stgolabs.net> <573021D5.4070406@hurleysoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <573021D5.4070406@hurleysoftware.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 08, 2016 at 10:36:21PM -0700, Peter Hurley wrote: > On 05/08/2016 09:56 PM, Davidlohr Bueso wrote: > > The field is obviously updated w.o the lock and needs a READ_ONCE > > while waiting for lock holder(s) to go away, just like we do with > > all other ->count accesses. > > This isn't actually fixing a bug because it's passed through > several full barriers which will force reloading from sem->count. > > I think the patch is ok if you want it just for consistency anyway, > but please change $subject and changelog. Agreed, and note that the READ_ONCE does prohibit load-tearing, while the current code does not. So in that respect the patched code is more strict. But yes, the current code does not allow using a stale value of sem->count() because, as PeterH notes, we've just passed through at least the full memory barrier implied by set_current_state().