[PATCH 2/8] lockdep: reader-in-writer recursion

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Gautham R Shenoy
Date: Tuesday, April 29, 2008 - 5:58 am

Subject: lockdep: reader-in-writer recursion

From: Peter Zijlstra <a.p.zijlstra@chello.nl>

Create a read mode that allows for reader-in-writer recursion

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Gautham R Shenoy <ego@in.ibm.com>
---

 include/linux/lockdep.h |    1 +
 kernel/lockdep.c        |    9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 4c4d236..36e254f 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -291,6 +291,7 @@ extern void lockdep_init_map(struct lockdep_map *lock, const char *name,
  *   0: exclusive (write) acquire
  *   1: read-acquire (no recursion allowed)
  *   2: read-acquire with same-instance recursion allowed
+ *   3: 2 + reader in writer recursion
  *
  * Values for check:
  *
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 94b0f4f..3859259 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -1280,6 +1280,13 @@ check_deadlock(struct task_struct *curr, struct held_lock *next,
 		 */
 		if ((read == 2) && prev->read)
 			return 2;
+		/*
+		 * Allow read-after-write recursion of the same
+		 * lock class (i.e. write_lock(lock)+read_lock(lock)):
+		 */
+		if (read == 3)
+			return 2;
+
 		return print_deadlock_bug(curr, prev, next);
 	}
 	return 1;
@@ -1559,7 +1566,7 @@ static int validate_chain(struct task_struct *curr, struct lockdep_map *lock,
 		 * If we are the first recursive read, don't jump over our
 		 * dependency.
 		 */
-		if (hlock->read == 2 && ret != 2)
+		if (hlock->read >= 2 && ret != 2)
 			hlock->read = 1;
 		/*
 		 * Add dependency only if this lock is not the head
-- 
Thanks and Regards
gautham
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 1/8] lockdep: fix recursive read lock validation, Gautham R Shenoy, (Tue Apr 29, 5:57 am)
[PATCH 2/8] lockdep: reader-in-writer recursion, Gautham R Shenoy, (Tue Apr 29, 5:58 am)
[PATCH 3/8] lockdep: fix fib_hash softirq inversion, Gautham R Shenoy, (Tue Apr 29, 6:00 am)
[PATCH 4/8] net: af_netlink: deadlock, Gautham R Shenoy, (Tue Apr 29, 6:01 am)
[PATCH 5/8] cpu: cpu-hotplug deadlock, Gautham R Shenoy, (Tue Apr 29, 6:02 am)
[PATCH 6/8] lockdep: annotate cpu_hotplug, Gautham R Shenoy, (Tue Apr 29, 6:02 am)
[PATCH 7/8] cpu_hotplug: Introduce try_get_online_cpus(), Gautham R Shenoy, (Tue Apr 29, 6:03 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Bart Van Assche, (Tue Apr 29, 6:16 am)
Re: Hans Reiser, reiserfs developer, linux-os (Dick Johnson), (Tue Apr 29, 6:19 am)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Oleg Nesterov, (Tue Apr 29, 7:33 am)
Re: [PATCH 3/8] lockdep: fix fib_hash softirq inversion, Peter Zijlstra, (Tue Apr 29, 7:45 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Bart Van Assche, (Tue Apr 29, 8:03 am)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Peter Zijlstra, (Tue Apr 29, 8:09 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Bart Van Assche, (Tue Apr 29, 9:03 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Bart Van Assche, (Tue Apr 29, 9:29 am)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Oleg Nesterov, (Tue Apr 29, 9:45 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Peter Zijlstra, (Tue Apr 29, 10:04 am)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Peter Zijlstra, (Tue Apr 29, 10:31 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Bart Van Assche, (Tue Apr 29, 10:45 am)
Re: [PATCH 1/8] lockdep: fix recursive read lock validation, Peter Zijlstra, (Tue Apr 29, 10:58 am)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Gautham R Shenoy, (Tue Apr 29, 10:37 pm)
Re: [PATCH 5/8] cpu: cpu-hotplug deadlock, Oleg Nesterov, (Wed Apr 30, 4:43 am)