From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754508AbbAaJ3g (ORCPT ); Sat, 31 Jan 2015 04:29:36 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:32997 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754141AbbAaJ3c (ORCPT ); Sat, 31 Jan 2015 04:29:32 -0500 Date: Sat, 31 Jan 2015 10:29:21 +0100 From: Peter Zijlstra To: Davidlohr Bueso Cc: Ingo Molnar , "Paul E. McKenney" , Jason Low , Michel Lespinasse , Tim Chen , linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 4/5] locking/rwsem: Avoid deceiving lock spinners Message-ID: <20150131092921.GB32343@twins.programming.kicks-ass.net> References: <1422609267-15102-1-git-send-email-dave@stgolabs.net> <1422609267-15102-5-git-send-email-dave@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1422609267-15102-5-git-send-email-dave@stgolabs.net> 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 Fri, Jan 30, 2015 at 01:14:26AM -0800, Davidlohr Bueso wrote: > +++ b/kernel/locking/rwsem-xadd.c > @@ -337,21 +337,30 @@ static inline bool owner_running(struct rw_semaphore *sem, > static noinline > bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner) > { > + long count; > + > rcu_read_lock(); > while (owner_running(sem, owner)) { > + /* abort spinning when need_resched */ > + if (need_resched()) { > + rcu_read_unlock(); > + return false; > + } > > cpu_relax_lowlatency(); > } > rcu_read_unlock(); > > + if (READ_ONCE(sem->owner)) > + return true; /* new owner, continue spinning */ > + Same concern as Tim; also the mutex code seems to terminate the spin when owner changes. And I think we want to have writers behave similar to mutexes, no? Does it make sense to change things to allow owner changes from NULL, but not to NULL? > /* > + * When the owner is not set, the lock could be free or > + * held by readers. Check the counter to verify the > + * state. > */ > - return sem->owner == NULL; > + count = READ_ONCE(sem->count); > + return (count == 0 || count == RWSEM_WAITING_BIAS); > }