From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753022Ab3C0Imj (ORCPT ); Wed, 27 Mar 2013 04:42:39 -0400 Received: from merlin.infradead.org ([205.233.59.134]:43957 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777Ab3C0Imh (ORCPT ); Wed, 27 Mar 2013 04:42:37 -0400 Message-ID: <1364373750.5053.54.camel@laptop> Subject: Re: [PATCH -mm -next] ipc,sem: fix lockdep false positive From: Peter Zijlstra To: Rik van Riel Cc: Michel Lespinasse , Sasha Levin , torvalds@linux-foundation.org, davidlohr.bueso@hp.com, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, hhuang@redhat.com, jason.low2@hp.com, lwoodman@redhat.com, chegu_vinod@hp.com, Dave Jones , benisty.e@gmail.com, Ingo Molnar Date: Wed, 27 Mar 2013 09:42:30 +0100 In-Reply-To: <5151BC78.3030306@surriel.com> References: <1363809337-29718-1-git-send-email-riel@surriel.com> <5150B1C2.8090607@oracle.com> <20130325163844.042a45ba@annuminas.surriel.com> <1364303965.5053.29.camel@laptop> <1364308023.5053.40.camel@laptop> <5151BC78.3030306@surriel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.6.2-0ubuntu0.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2013-03-26 at 11:19 -0400, Rik van Riel wrote: > > Maybe something like: > > > > void sma_lock(struct sem_array *sma) /* global */ > > { > > int i; > > > > sma->global_locked = 1; > > smp_wmb(); /* can we merge with the LOCK ? */ > > spin_lock(&sma->global_lock); > > > > /* wait for all local locks to go away */ > > for (i = 0; i < sma->sem_nsems; i++) > > spin_unlock_wait(&sem->sem_base[i]->lock); > > } > > > > void sma_lock_one(struct sem_array *sma, int nr) /* local */ > > { > > smp_rmb(); /* pairs with wmb in sma_lock() */ > > if (unlikely(sma->global_locked)) { /* wait for global lock */ > > while (sma->global_locked) > > spin_unlock_wait(&sma->global_lock); > > } > > spin_lock(&sma->sem_base[nr]->lock); > > } I since realized there's an ordering problem with ->global_locked, we need to use spin_is_locked() or somesuch. Two competing sma_lock() operations will screw over the separate variable. > > > This still has the problem of a non-preemptible section of > O(sem_nsems) > > (with the avg wait-time on the local lock). Could we make the global > > lock a sleeping lock? > > Not without breaking your scheme above :) How would making sma->global_lock a mutex wreck anything?