From: William Lee Irwin III <wli@holomorphy.com>
To: Robert Love <rml@tech9.net>
Cc: Pete Zaitcev <zaitcev@redhat.com>, linux-kernel@vger.kernel.org
Subject: Re: interrupt checks for spinlocks
Date: Sun, 3 Nov 2002 19:22:15 -0800 [thread overview]
Message-ID: <20021104032215.GW23425@holomorphy.com> (raw)
In-Reply-To: <1036378887.750.96.camel@phantasy>
On Sun, Nov 03, 2002 at 10:01:24PM -0500, Robert Love wrote:
> You can do #1, but you need to figure out if your interrupt is the only
> interrupt using the lock or not (possibly hard).
> In other words, a lock unique to your interrupt handler does not need to
> disable interrupts (since only that handler can grab the lock and it is
> disabled).
> If other handlers can grab the lock, interrupts need to be disabled.
> So a test of irqs_disabled() would show a false-positive in the first
> case. No easy way to tell..
> Robert Love
Attempt #1:
===== include/linux/spinlock.h 1.18 vs edited =====
--- 1.18/include/linux/spinlock.h Sun Aug 25 10:25:45 2002
+++ edited/include/linux/spinlock.h Sun Nov 3 19:21:44 2002
@@ -38,6 +38,44 @@
#include <asm/spinlock.h>
/*
+ * if a lock is ever taken in interrupt context, it must always be
+ * taken with interrupts disabled. If a locking call is made that
+ * unconditionally disables and then re-enables interrupts, it must
+ * be made with interrupts enabled.
+ */
+#ifndef irq_tainted_lock
+#define irq_tainted_lock(lock) 0
+#endif
+
+#ifndef irq_taint_lock
+#define irq_taint_lock(lock) do { } while (0)
+#define
+
+#ifndef CONFIG_DEBUG_SPINLOCK
+#define check_spinlock_irq(lock) do { } while (0)
+#define check_spinlock_irqs_disabled(lock) do { } while (0)
+#else
+#define check_spinlock_irq(lock) \
+ do { \
+ if (irqs_disabled()) { \
+ printk("spinlock taken unconditionally " \
+ "re-enabling interrupts\n"); \
+ dump_stack(); \
+ } \
+ } while (0)
+#define check_spinlock_irqs_disabled(lock) \
+ do { \
+ if (in_interrupt()) \
+ irq_taint_lock(lock); \
+ else if (irq_tainted_lock(lock)) { \
+ printk("spinlock taken in process context " \
+ "without disabling interrupts\n"); \
+ dump_stack(); \
+ } \
+ } while (0)
+#endif
+
+/*
* !CONFIG_SMP and spin_lock_init not previously defined
* (e.g. by including include/asm/spinlock.h)
*/
@@ -87,6 +125,7 @@
*/
#define spin_lock(lock) \
do { \
+ check_spinlock_irqs_disabled(lock); \
preempt_disable(); \
_raw_spin_lock(lock); \
} while(0)
@@ -102,6 +141,7 @@
#define read_lock(lock) \
do { \
+ check_spinlock_irqs_disabled(lock); \
preempt_disable(); \
_raw_read_lock(lock); \
} while(0)
@@ -114,6 +154,7 @@
#define write_lock(lock) \
do { \
+ check_spinlock_irqs_disabled(lock); \
preempt_disable(); \
_raw_write_lock(lock); \
} while(0)
@@ -136,6 +177,7 @@
#define spin_lock_irq(lock) \
do { \
+ check_spinlock_irq(lock); \
local_irq_disable(); \
preempt_disable(); \
_raw_spin_lock(lock); \
@@ -157,6 +199,7 @@
#define read_lock_irq(lock) \
do { \
+ check_spinlock_irq(lock); \
local_irq_disable(); \
preempt_disable(); \
_raw_read_lock(lock); \
@@ -178,6 +221,7 @@
#define write_lock_irq(lock) \
do { \
+ check_spinlock_irq(lock); \
local_irq_disable(); \
preempt_disable(); \
_raw_write_lock(lock); \
next prev parent reply other threads:[~2002-11-04 3:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1036362421.16883.linux-kernel2news@redhat.com>
[not found] ` <200211040028.gA40S8600593@devserv.devel.redhat.com>
[not found] ` <20021104002813.GZ16347@holomorphy.com>
2002-11-04 0:42 ` interrupt checks for spinlocks Pete Zaitcev
2002-11-04 0:53 ` William Lee Irwin III
2002-11-04 1:18 ` Robert Love
2002-11-04 1:42 ` William Lee Irwin III
2002-11-04 3:01 ` Robert Love
2002-11-04 3:04 ` William Lee Irwin III
2002-11-04 3:22 ` William Lee Irwin III [this message]
2002-11-04 3:36 ` Zwane Mwaikambo
2002-11-03 22:08 William Lee Irwin III
2002-11-04 0:15 ` Davide Libenzi
2002-11-04 0:39 ` William Lee Irwin III
2002-11-04 1:39 ` Davide Libenzi
2002-11-04 1:39 ` William Lee Irwin III
2002-11-04 5:18 ` Randy.Dunlap
2002-11-04 15:47 ` Davide Libenzi
2002-11-04 13:31 ` Alan Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20021104032215.GW23425@holomorphy.com \
--to=wli@holomorphy.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rml@tech9.net \
--cc=zaitcev@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox