From mboxrd@z Thu Jan 1 00:00:00 1970 Received: with ECARTIS (v1.0.0; list linux-mips); Wed, 25 Jan 2006 11:50:43 +0000 (GMT) Received: from mail.ocs.com.au ([202.147.117.210]:61892 "EHLO mail.ocs.com.au") by ftp.linux-mips.org with ESMTP id S8133488AbWAYLuY (ORCPT ); Wed, 25 Jan 2006 11:50:24 +0000 Received: from ocs3.ocs.com.au (ocs3.ocs.com.au [192.168.255.3]) by mail.ocs.com.au (Postfix) with ESMTP id BC5E1E0B206; Wed, 25 Jan 2006 22:54:43 +1100 (EST) Received: by ocs3.ocs.com.au (Postfix, from userid 16331) id 969732E79; Wed, 25 Jan 2006 22:54:43 +1100 (EST) Received: from ocs3.ocs.com.au (localhost [127.0.0.1]) by ocs3.ocs.com.au (Postfix) with ESMTP id 918D78017F; Wed, 25 Jan 2006 22:54:43 +1100 (EST) X-Mailer: exmh version 2.7.0 06/18/2004 with nmh-1.1-RC1 From: Keith Owens To: mita@miraclelinux.com (Akinobu Mita) cc: linux-kernel@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Russell King , Ian Molton , dev-etrax@axis.com, David Howells , Yoshinori Sato , Linus Torvalds , linux-ia64@vger.kernel.org, Hirokazu Takata , linux-m68k@lists.linux-m68k.org, Greg Ungerer , linux-mips@linux-mips.org, parisc-linux@parisc-linux.org, linuxppc-dev@ozlabs.org, linux390@de.ibm.com, linuxsh-dev@lists.sourceforge.net, linuxsh-shmedia-dev@lists.sourceforge.net, sparclinux@vger.kernel.org, ultralinux@vger.kernel.org, Miles Bader , Andi Kleen , Chris Zankel Subject: Re: [PATCH 3/6] C-language equivalents of include/asm-*/bitops.h In-reply-to: Your message of "Wed, 25 Jan 2006 20:32:06 +0900." <20060125113206.GD18584@miraclelinux.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 25 Jan 2006 22:54:43 +1100 Message-ID: <24086.1138190083@ocs3.ocs.com.au> Return-Path: X-Envelope-To: <"|/home/ecartis/ecartis -s linux-mips"> (uid 0) X-Orcpt: rfc822;linux-mips@linux-mips.org Original-Recipient: rfc822;linux-mips@linux-mips.org X-archive-position: 10133 X-ecartis-version: Ecartis v1.0.0 Sender: linux-mips-bounce@linux-mips.org Errors-to: linux-mips-bounce@linux-mips.org X-original-sender: kaos@sgi.com Precedence: bulk X-list: linux-mips Akinobu Mita (on Wed, 25 Jan 2006 20:32:06 +0900) wrote: >o generic {,test_and_}{set,clear,change}_bit() (atomic bitops) ... >+static __inline__ void set_bit(int nr, volatile unsigned long *addr) >+{ >+ unsigned long mask = BITOP_MASK(nr); >+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); >+ unsigned long flags; >+ >+ _atomic_spin_lock_irqsave(p, flags); >+ *p |= mask; >+ _atomic_spin_unlock_irqrestore(p, flags); >+} Be very, very careful about using these generic *_bit() routines if the architecture supports non-maskable interrupts. NMI events can occur at any time, including when interrupts have been disabled by *_irqsave(). So you can get NMI events occurring while a *_bit fucntion is holding a spin lock. If the NMI handler also wants to do bit manipulation (and they do) then you can get a deadlock between the original caller of *_bit() and the NMI handler. Doing any work that requires spinlocks in an NMI handler is just asking for deadlock problems. The generic *_bit() routines add a hidden spinlock behind what was previously a safe operation. I would even say that any arch that supports any type of NMI event _must_ define its own bit routines that do not rely on your _atomic_spin_lock_irqsave() and its hash of spinlocks. From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ocs.com.au ([202.147.117.210]:61892 "EHLO mail.ocs.com.au") by ftp.linux-mips.org with ESMTP id S8133488AbWAYLuY (ORCPT ); Wed, 25 Jan 2006 11:50:24 +0000 From: Keith Owens Subject: Re: [PATCH 3/6] C-language equivalents of include/asm-*/bitops.h In-reply-to: Your message of "Wed, 25 Jan 2006 20:32:06 +0900." <20060125113206.GD18584@miraclelinux.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 25 Jan 2006 22:54:43 +1100 Message-ID: <24086.1138190083@ocs3.ocs.com.au> Return-Path: Sender: linux-mips-bounce@linux-mips.org Errors-to: linux-mips-bounce@linux-mips.org To: Akinobu Mita Cc: linux-kernel@vger.kernel.org, Richard Henderson , Ivan Kokshaysky , Russell King , Ian Molton , dev-etrax@axis.com, David Howells , Yoshinori Sato , Linus Torvalds , linux-ia64@vger.kernel.org, Hirokazu Takata , linux-m68k@lists.linux-m68k.org, Greg Ungerer , linux-mips@linux-mips.org, parisc-linux@parisc-linux.org, linuxppc-dev@ozlabs.org, linux390@de.ibm.com, linuxsh-dev@lists.sourceforge.net, linuxsh-shmedia-dev@lists.sourceforge.net, sparclinux@vger.kernel.org, ultralinux@vger.kernel.org, Miles Bader , Andi Kleen , Chris Zankel Message-ID: <20060125115443.N7loHf77W_PsKz_ceLrNuLJzn8OkWZvkS2k1NAk5pYs@z> Akinobu Mita (on Wed, 25 Jan 2006 20:32:06 +0900) wrote: >o generic {,test_and_}{set,clear,change}_bit() (atomic bitops) ... >+static __inline__ void set_bit(int nr, volatile unsigned long *addr) >+{ >+ unsigned long mask = BITOP_MASK(nr); >+ unsigned long *p = ((unsigned long *)addr) + BITOP_WORD(nr); >+ unsigned long flags; >+ >+ _atomic_spin_lock_irqsave(p, flags); >+ *p |= mask; >+ _atomic_spin_unlock_irqrestore(p, flags); >+} Be very, very careful about using these generic *_bit() routines if the architecture supports non-maskable interrupts. NMI events can occur at any time, including when interrupts have been disabled by *_irqsave(). So you can get NMI events occurring while a *_bit fucntion is holding a spin lock. If the NMI handler also wants to do bit manipulation (and they do) then you can get a deadlock between the original caller of *_bit() and the NMI handler. Doing any work that requires spinlocks in an NMI handler is just asking for deadlock problems. The generic *_bit() routines add a hidden spinlock behind what was previously a safe operation. I would even say that any arch that supports any type of NMI event _must_ define its own bit routines that do not rely on your _atomic_spin_lock_irqsave() and its hash of spinlocks.