From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, Zach Brown <zach.brown@oracle.com>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: [RFC/T PATCH 07/12] lockdep: non-recursive validation
Date: Tue, 17 Jul 2007 19:34:35 +0200 [thread overview]
Message-ID: <20070717173758.272328000@chello.nl> (raw)
In-Reply-To: 20070717173428.355522000@chello.nl
[-- Attachment #1: lockdep-norecursion.patch --]
[-- Type: text/plain, Size: 4116 bytes --]
Add a validation mode that diregards all recursive locking errors.
This is useful for locks like lock_page where there is a high degree
of nested locking.
Obviously it will not report a useful class of errors :-/
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
include/linux/lockdep.h | 15 ++++++++-------
kernel/lockdep.c | 15 ++++++++++++---
2 files changed, 20 insertions(+), 10 deletions(-)
Index: linux-2.6/include/linux/lockdep.h
===================================================================
--- linux-2.6.orig/include/linux/lockdep.h
+++ linux-2.6/include/linux/lockdep.h
@@ -286,7 +286,8 @@ extern void lockdep_init_map(struct lock
*
* 0: disabled
* 1: simple checks (freeing, held-at-exit-time, etc.)
- * 2: full validation
+ * 2: validation without recursion checks
+ * 3: full validation
*/
extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
int trylock, int read, int check, unsigned long ip);
@@ -426,7 +427,7 @@ static inline void print_irqtrace_events
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
-# define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i)
+# define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 3, i)
# else
# define spin_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i)
# endif
@@ -438,8 +439,8 @@ static inline void print_irqtrace_events
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
-# define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i)
-# define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 2, i)
+# define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 3, i)
+# define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 3, i)
# else
# define rwlock_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i)
# define rwlock_acquire_read(l, s, t, i) lock_acquire(l, s, t, 2, 1, i)
@@ -453,7 +454,7 @@ static inline void print_irqtrace_events
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
-# define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i)
+# define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 3, i)
# else
# define mutex_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i)
# endif
@@ -465,8 +466,8 @@ static inline void print_irqtrace_events
#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
-# define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 2, i)
-# define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 2, i)
+# define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 3, i)
+# define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 3, i)
# else
# define rwsem_acquire(l, s, t, i) lock_acquire(l, s, t, 0, 1, i)
# define rwsem_acquire_read(l, s, t, i) lock_acquire(l, s, t, 1, 1, i)
Index: linux-2.6/kernel/lockdep.c
===================================================================
--- linux-2.6.orig/kernel/lockdep.c
+++ linux-2.6/kernel/lockdep.c
@@ -2176,7 +2176,7 @@ static int __lock_acquire(struct lockdep
struct task_struct *curr = current;
struct lock_class *class = NULL;
struct held_lock *hlock;
- unsigned int depth, id;
+ unsigned int depth, id, first;
int chain_head = 0;
u64 chain_key;
@@ -2225,6 +2225,14 @@ static int __lock_acquire(struct lockdep
return 0;
hlock = curr->held_locks + depth;
+ if (check == 2 && depth > 0) {
+ struct held_lock *prev_hlock = NULL;
+
+ prev_hlock = curr->held_locks + depth - 1;
+ if (prev_hlock->class == class)
+ first = 0;
+ } else
+ first = 1;
hlock->class = class;
hlock->acquire_ip = ip;
@@ -2238,7 +2246,7 @@ static int __lock_acquire(struct lockdep
hlock->holdtime_stamp = sched_clock();
#endif
- if (check != 2)
+ if (check < 2)
goto out_calc_hash;
#ifdef CONFIG_TRACE_IRQFLAGS
/*
@@ -2347,7 +2355,8 @@ out_calc_hash:
* graph_lock for us)
*/
#ifdef CONFIG_PROVE_LOCKING
- if (!trylock && (check == 2) && lookup_chain_cache(chain_key, class)) {
+ if (!trylock && (check >= 2 && first) &&
+ lookup_chain_cache(chain_key, class)) {
/*
* Check whether last held lock:
*
--
next prev parent reply other threads:[~2007-07-17 15:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-17 17:34 [RFC/T PATCH 00/12] lockdep: annotate lock_page Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 01/12] lockdep: annotate journal_start() Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 02/12] mm: trylock_page Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 03/12] mm: remove raw SetPageLocked() usage Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 04/12] mm: remove raw ClearPageLocked() usage Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 05/12] lockdep: add initial lockdep support for lock_page Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 06/12] lockdep: lock_page: handle IO-completions Peter Zijlstra
2007-07-17 17:34 ` Peter Zijlstra [this message]
2007-07-17 17:34 ` [RFC/T PATCH 08/12] lockdep: lock_page: recursion Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 09/12] lockdep: increase MAX_LOCK_DEPTH Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 10/12] lockdep: fs: per file-system type lock_page class Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 11/12] lockdep: lock_page: use per fs-type " Peter Zijlstra
2007-07-17 17:34 ` [RFC/T PATCH 12/12] mm: set_page_mapping() Peter Zijlstra
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=20070717173758.272328000@chello.nl \
--to=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=zach.brown@oracle.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