public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@sgi.com>
To: Rik van Riel <riel@conectiva.com.br>
Cc: linux-kernel@vger.kernel.org, jmacd@namesys.com,
	phillips@arcor.de, rml@tech9.net
Subject: Re: [PATCH] lock assertion macros for 2.5.30
Date: Thu, 8 Aug 2002 10:23:35 -0700	[thread overview]
Message-ID: <20020808172335.GA29509@sgi.com> (raw)
In-Reply-To: <Pine.LNX.4.44L.0208071918440.23404-100000@imladris.surriel.com>

On Wed, Aug 07, 2002 at 07:19:21PM -0300, Rik van Riel wrote:
> Looks good to me. Would be even better if you removed MUST_NOT_HOLD ;)

Ok, here's yet another version.  I've removed the conversion of the
scsi layer's ASSERT_LOCK macros as well as the silly version of
MUST_NOT_HOLD.  Other things people seem interested in:
  o sleeping function assertions
  o lock ordering enforcement
  o lock recursion detection
  o more assertion checks in other parts of the kernel

Should any of the above be included in this patch?  If so, I can try
to hack one or more of them together, otherwise maybe this is ok to go
in?

Thanks,
Jesse


diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/fs/inode.c linux-2.5.30-lockassert/fs/inode.c
--- linux-2.5.30/fs/inode.c	Thu Aug  1 14:16:45 2002
+++ linux-2.5.30-lockassert/fs/inode.c	Thu Aug  8 10:03:13 2002
@@ -193,6 +193,8 @@
  */
 void __iget(struct inode * inode)
 {
+	MUST_HOLD(&inode_lock);
+
 	if (atomic_read(&inode->i_count)) {
 		atomic_inc(&inode->i_count);
 		return;
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/asm-i386/semaphore.h linux-2.5.30-lockassert/include/asm-i386/semaphore.h
--- linux-2.5.30/include/asm-i386/semaphore.h	Thu Aug  1 14:16:16 2002
+++ linux-2.5.30-lockassert/include/asm-i386/semaphore.h	Thu Aug  8 10:03:13 2002
@@ -40,6 +40,7 @@
 #include <asm/atomic.h>
 #include <linux/wait.h>
 #include <linux/rwsem.h>
+#include <linux/config.h>
 
 struct semaphore {
 	atomic_t count;
@@ -55,6 +56,12 @@
 		, (int)&(name).__magic
 #else
 # define __SEM_DEBUG_INIT(name)
+#endif
+
+#ifdef CONFIG_DEBUG_SPINLOCK
+# define MUST_HOLD_SEM(sem)		do { BUG_ON(atomic_read(&((sem)->count))); } while(0)
+#else
+# define MUST_HOLD_SEM(sem)		do { } while(0)
 #endif
 
 #define __SEMAPHORE_INITIALIZER(name,count) \
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/asm-i386/spinlock.h linux-2.5.30-lockassert/include/asm-i386/spinlock.h
--- linux-2.5.30/include/asm-i386/spinlock.h	Thu Aug  1 14:16:14 2002
+++ linux-2.5.30-lockassert/include/asm-i386/spinlock.h	Thu Aug  8 10:03:13 2002
@@ -157,6 +157,7 @@
 #define RW_LOCK_UNLOCKED (rwlock_t) { RW_LOCK_BIAS RWLOCK_MAGIC_INIT }
 
 #define rwlock_init(x)	do { *(x) = RW_LOCK_UNLOCKED; } while(0)
+#define rwlock_is_locked(x) ((x)->lock != RW_LOCK_BIAS)
 
 /*
  * On x86, we implement read-write locks as a 32-bit counter
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/asm-ia64/semaphore.h linux-2.5.30-lockassert/include/asm-ia64/semaphore.h
--- linux-2.5.30/include/asm-ia64/semaphore.h	Thu Aug  1 14:16:24 2002
+++ linux-2.5.30-lockassert/include/asm-ia64/semaphore.h	Thu Aug  8 10:03:13 2002
@@ -6,6 +6,7 @@
  * Copyright (C) 1998-2000 David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
+#include <linux/config.h>
 #include <linux/wait.h>
 #include <linux/rwsem.h>
 
@@ -24,6 +25,12 @@
 # define __SEM_DEBUG_INIT(name)		, (long) &(name).__magic
 #else
 # define __SEM_DEBUG_INIT(name)
+#endif
+
+#ifdef CONFIG_DEBUG_SPINLOCK
+# define MUST_HOLD_SEM(sem)		do { BUG_ON(atomic_read(&((sem)->count)); } while(0)
+#else
+# define MUST_HOLD_SEM(sem)		do { } while(0)
 #endif
 
 #define __SEMAPHORE_INITIALIZER(name,count)					\
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/asm-ia64/spinlock.h linux-2.5.30-lockassert/include/asm-ia64/spinlock.h
--- linux-2.5.30/include/asm-ia64/spinlock.h	Thu Aug  1 14:16:06 2002
+++ linux-2.5.30-lockassert/include/asm-ia64/spinlock.h	Thu Aug  8 10:03:13 2002
@@ -109,6 +109,7 @@
 #define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
 
 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
+#define rwlock_is_locked(x) ((x)->read_counter != 0 || (x)->write_lock != 0)
 
 #define _raw_read_lock(rw)							\
 do {										\
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/linux/rwsem-spinlock.h linux-2.5.30-lockassert/include/linux/rwsem-spinlock.h
--- linux-2.5.30/include/linux/rwsem-spinlock.h	Thu Aug  1 14:16:28 2002
+++ linux-2.5.30-lockassert/include/linux/rwsem-spinlock.h	Thu Aug  8 10:03:13 2002
@@ -46,6 +46,12 @@
 #define __RWSEM_DEBUG_INIT	/* */
 #endif
 
+#ifdef CONFIG_DEBUG_SPINLOCK
+#define MUST_HOLD_RWSEM(sem)		BUG_ON(!(sem)->activity))
+#else
+#define MUST_HOLD_RWSEM(sem)		do { } while (0)
+#endif
+
 #define __RWSEM_INITIALIZER(name) \
 { 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT }
 
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/linux/rwsem.h linux-2.5.30-lockassert/include/linux/rwsem.h
--- linux-2.5.30/include/linux/rwsem.h	Thu Aug  1 14:16:18 2002
+++ linux-2.5.30-lockassert/include/linux/rwsem.h	Thu Aug  8 10:03:13 2002
@@ -7,6 +7,7 @@
 #ifndef _LINUX_RWSEM_H
 #define _LINUX_RWSEM_H
 
+#include <linux/config.h>
 #include <linux/linkage.h>
 
 #define RWSEM_DEBUG 0
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/include/linux/spinlock.h linux-2.5.30-lockassert/include/linux/spinlock.h
--- linux-2.5.30/include/linux/spinlock.h	Thu Aug  1 14:16:25 2002
+++ linux-2.5.30-lockassert/include/linux/spinlock.h	Thu Aug  8 10:04:23 2002
@@ -117,7 +117,19 @@
 #define _raw_write_lock(lock)	(void)(lock) /* Not "unused variable". */
 #define _raw_write_unlock(lock)	do { } while(0)
 
-#endif /* !SMP */
+#endif /* !CONFIG_SMP */
+
+/*
+ * Simple lock assertions for debugging and documenting where locks need
+ * to be held.
+ */
+#if defined(CONFIG_DEBUG_SPINLOCK) && defined(CONFIG_SMP)
+#define MUST_HOLD(lock)			BUG_ON(!spin_is_locked(lock))
+#define MUST_HOLD_RW(lock)		BUG_ON(!rwlock_is_locked(lock))
+#else
+#define MUST_HOLD(lock)			do { } while(0)
+#define MUST_HOLD_RW(lock)		do { } while(0)
+#endif /* CONFIG_DEBUG_SPINLOCK && CONFIG_SMP */
 
 #ifdef CONFIG_PREEMPT
 
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/kernel/acct.c linux-2.5.30-lockassert/kernel/acct.c
--- linux-2.5.30/kernel/acct.c	Thu Aug  1 14:16:27 2002
+++ linux-2.5.30-lockassert/kernel/acct.c	Thu Aug  8 10:03:13 2002
@@ -160,6 +160,8 @@
 {
 	struct file *old_acct = NULL;
 
+	MUST_HOLD(&acct_globals.lock);
+
 	if (acct_globals.file) {
 		old_acct = acct_globals.file;
 		del_timer(&acct_globals.timer);
diff -Naur -X /home/jbarnes/dontdiff linux-2.5.30/kernel/printk.c linux-2.5.30-lockassert/kernel/printk.c
--- linux-2.5.30/kernel/printk.c	Thu Aug  1 14:16:25 2002
+++ linux-2.5.30-lockassert/kernel/printk.c	Thu Aug  8 10:03:13 2002
@@ -337,6 +337,8 @@
 	unsigned long cur_index, start_print;
 	static int msg_level = -1;
 
+	MUST_HOLD_SEM(&console_sem);
+
 	if (((long)(start - end)) > 0)
 		BUG();
 

  reply	other threads:[~2002-08-08 17:20 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07 20:51 [PATCH] lock assertion macros for 2.5.30 Jesse Barnes
2002-08-07 21:02 ` Rik van Riel
2002-08-07 21:08   ` Jesse Barnes
2002-08-07 21:21     ` Rik van Riel
2002-08-07 21:39       ` Jesse Barnes
2002-08-07 21:44         ` Rik van Riel
2002-08-08  7:58         ` Marcin Dalecki
2002-08-08 11:09           ` Daniel Phillips
2002-08-07 22:15       ` Jesse Barnes
2002-08-07 22:19         ` Rik van Riel
2002-08-08 17:23           ` Jesse Barnes [this message]
2002-08-08 17:36             ` Rik van Riel
2002-08-08 17:39               ` Jesse Barnes
2002-08-09  2:56                 ` Daniel Phillips
2002-08-12 21:03                   ` [PATCH] lock assertion macros for 2.5.31 Jesse Barnes
     [not found]                     ` <3D5829B9.D281B855@zip.com.au>
     [not found]                       ` <20020812223645.GB40343@sgi.com>
     [not found]                         ` <3D5840E9.89C8680C@zip.com.au>
2002-08-21 18:26                           ` Jesse Barnes
2002-08-21 18:40                             ` Andrew Morton
2002-08-21 18:46                               ` Jesse Barnes
2002-08-09  3:04             ` [PATCH] lock assertion macros for 2.5.30 Daniel Phillips
2002-08-09  4:12               ` Bernd Eckenfels
2002-08-07 22:30         ` Daniel Phillips
2002-08-07 22:41           ` Roman Zippel
2002-08-08  0:07           ` Thunder from the hill
2002-08-07 21:37     ` Oliver Xymoron
2002-08-08 12:55       ` Joshua MacDonald
2002-08-08 13:23         ` Jens Axboe
2002-08-08  6:00     ` Jens Axboe
2002-08-08 17:08       ` Jesse Barnes
2002-08-08 17:31         ` Rik van Riel
2002-08-08 17:35           ` Jesse Barnes
2002-08-08 17:43           ` Joshua MacDonald
2002-08-08 17:47             ` Rik van Riel
     [not found] <0C01A29FBAE24448A792F5C68F5EA47D2D4437@nasdaq.ms.ensim.com>
2002-08-08 18:52 ` Paul Menage
2002-08-08 19:00   ` Rik van Riel

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=20020808172335.GA29509@sgi.com \
    --to=jbarnes@sgi.com \
    --cc=jmacd@namesys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@arcor.de \
    --cc=riel@conectiva.com.br \
    --cc=rml@tech9.net \
    /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