Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752879Ab3FXTM7 (ORCPT ); Mon, 24 Jun 2013 15:12:59 -0400 Received: from mga09.intel.com ([134.134.136.24]:13569 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752522Ab3FXTM6 (ORCPT ); Mon, 24 Jun 2013 15:12:58 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,930,1363158000"; d="scan'208";a="334806657" Subject: Re: [PATCH 2/2] rwsem: do optimistic spinning for writer lock acquisition From: Tim Chen To: Peter Hurley Cc: Davidlohr Bueso , Alex Shi , Michel Lespinasse , Ingo Molnar , Andrew Morton , Andrea Arcangeli , Andi Kleen , Matthew R Wilcox , Dave Hansen , Peter Zijlstra , Rik van Riel , linux-kernel@vger.kernel.org, linux-mm In-Reply-To: <51C894C3.4040407@hurleysoftware.com> References: <1371858700.22432.5.camel@schen9-DESK> <51C558E2.1040108@hurleysoftware.com> <1372017836.1797.14.camel@buesod1.americas.hpqcorp.net> <1372093876.22432.34.camel@schen9-DESK> <51C894C3.4040407@hurleysoftware.com> Content-Type: text/plain; charset="UTF-8" Date: Mon, 24 Jun 2013 12:13:00 -0700 Message-ID: <1372101180.22432.58.camel@schen9-DESK> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-1.fc14) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1579 Lines: 51 On Mon, 2013-06-24 at 14:49 -0400, Peter Hurley wrote: > On 06/24/2013 01:11 PM, Tim Chen wrote: > > On Sun, 2013-06-23 at 13:03 -0700, Davidlohr Bueso wrote: > >> On Sat, 2013-06-22 at 03:57 -0400, Peter Hurley wrote: > >>> On 06/21/2013 07:51 PM, Tim Chen wrote: > >>>> > >>>> +static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem) > >>>> +{ > >>>> + int retval = true; > >>>> + > >>>> + /* Spin only if active writer running */ > >>>> + if (!sem->owner) > >>>> + return false; > >>>> + > >>>> + rcu_read_lock(); > >>>> + if (sem->owner) > >>>> + retval = sem->owner->on_cpu; > >>> ^^^^^^^^^^^^^^^^^^ > >>> > >>> Why is this a safe dereference? Could not another cpu have just > >>> dropped the sem (and thus set sem->owner to NULL and oops)? > >>> > > > > The rcu read lock should protect against sem->owner being NULL. > > It doesn't. > > Here's the comment from mutex_spin_on_owner(): > > /* > * Look out! "owner" is an entirely speculative pointer > * access and not reliable. > */ > In mutex_spin_on_owner, after rcu_read_lock, the owner_running() function de-references the owner pointer. The rcu_read_lock prevents owner from getting freed. The comment's intention is to warn that owner->on_cpu may not be reliable. I'm using similar logic in rw-sem. Tim -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/