From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757294AbbCGJkt (ORCPT ); Sat, 7 Mar 2015 04:40:49 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:51535 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755060AbbCGJkh (ORCPT ); Sat, 7 Mar 2015 04:40:37 -0500 Date: Sat, 7 Mar 2015 10:21:26 +0100 From: Peter Zijlstra To: Jason Low Cc: Linus Torvalds , Ingo Molnar , Davidlohr Bueso , Tim Chen , "Paul E. McKenney" , Michel Lespinasse , Sasha Levin , LKML , Dave Jones , Ming Lei Subject: Re: [PATCH] locking/rwsem: Fix lock optimistic spinning when owner is not running Message-ID: <20150307092126.GO23367@worktop.ger.corp.intel.com> References: <1425714331.2475.388.camel@j-VirtualBox> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1425714331.2475.388.camel@j-VirtualBox> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 06, 2015 at 11:45:31PM -0800, Jason Low wrote: > static noinline > bool rwsem_spin_on_owner(struct rw_semaphore *sem, struct task_struct *owner) > { > long count; > > rcu_read_lock(); > + while (sem->owner == owner) { > + /* > + * Ensure we emit the owner->on_cpu, dereference _after_ > + * checking sem->owner still matches owner, if that fails, > + * owner might point to free()d memory, if it still matches, > + * the rcu_read_lock() ensures the memory stays valid. > + */ > + barrier(); > + > + /* abort spinning when need_resched or owner is not running */ > + if (!owner->on_cpu || need_resched()) { > rcu_read_unlock(); > return false; > } Thanks, looks good; do we want to change the mutex code (again) to more closely resemble this too? It still has the while (true) instead of the while(lock->owner != owner).