From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from e28smtp09.in.ibm.com (e28smtp09.in.ibm.com [122.248.162.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e28smtp09.in.ibm.com", Issuer "GeoTrust SSL CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id CB4892C02EC for ; Mon, 11 Feb 2013 23:58:13 +1100 (EST) Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Feb 2013 18:26:31 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 122D9E004E for ; Mon, 11 Feb 2013 18:28:55 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1BCw4Yj32243810 for ; Mon, 11 Feb 2013 18:28:04 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1BCw47h015239 for ; Mon, 11 Feb 2013 23:58:06 +1100 Message-ID: <5118EA6A.9040002@linux.vnet.ibm.com> Date: Mon, 11 Feb 2013 18:26:10 +0530 From: "Srivatsa S. Bhat" MIME-Version: 1.0 To: David Howells Subject: Re: [PATCH v5 01/45] percpu_rwlock: Introduce the global reader-writer lock backend References: <20130122073315.13822.27093.stgit@srivatsabhat.in.ibm.com> <20130122073210.13822.50434.stgit@srivatsabhat.in.ibm.com> <30708.1360586491@warthog.procyon.org.uk> In-Reply-To: <30708.1360586491@warthog.procyon.org.uk> Content-Type: text/plain; charset=ISO-8859-1 Cc: linux-doc@vger.kernel.org, peterz@infradead.org, fweisbec@gmail.com, linux-kernel@vger.kernel.org, mingo@kernel.org, linux-arch@vger.kernel.org, linux@arm.linux.org.uk, xiaoguangrong@linux.vnet.ibm.com, wangyun@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, nikunj@linux.vnet.ibm.com, linux-pm@vger.kernel.org, rusty@rustcorp.com.au, rostedt@goodmis.org, rjw@sisk.pl, namhyung@kernel.org, tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, oleg@redhat.com, sbw@mit.edu, tj@kernel.org, akpm@linux-foundation.org, linuxppc-dev@lists.ozlabs.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 02/11/2013 06:11 PM, David Howells wrote: > Srivatsa S. Bhat wrote: > >> We can use global rwlocks as shown below safely, without fear of deadlocks: >> >> Readers: >> >> CPU 0 CPU 1 >> ------ ------ >> >> 1. spin_lock(&random_lock); read_lock(&my_rwlock); >> >> >> 2. read_lock(&my_rwlock); spin_lock(&random_lock); > > The lock order on CPU 0 is unsafe if CPU2 can do: > > write_lock(&my_rwlock); > spin_lock(&random_lock); > > and on CPU 1 if CPU2 can do: > > spin_lock(&random_lock); > write_lock(&my_rwlock); > Right.. > I presume you were specifically excluding these situations? > Yes.. Those cases are simple to find out and fix (by changing the lock ordering). My main problem was with CPU 0 and CPU 1 as shown above.. ... and using a global rwlock helps ease that part out. Regards, Srivatsa S. Bhat