diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2010-02-22 20:04:45 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-02-25 03:40:59 -0500 |
commit | 632ee200130899252508c478ad0e808222573fbc (patch) | |
tree | e3f44ca9daf2a2da2186419f703bc9cec8faa058 /include/linux/srcu.h | |
parent | 996de8c6fe95c5a9fc524241cc8f142ef0605d3d (diff) |
rcu: Introduce lockdep-based checking to RCU read-side primitives
Inspection is proving insufficient to catch all RCU misuses,
which is understandable given that rcu_dereference() might be
protected by any of four different flavors of RCU (RCU, RCU-bh,
RCU-sched, and SRCU), and might also/instead be protected by any
of a number of locking primitives. It is therefore time to
enlist the aid of lockdep.
This set of patches is inspired by earlier work by Peter
Zijlstra and Thomas Gleixner, and takes the following approach:
o Set up separate lockdep classes for RCU, RCU-bh, and RCU-sched.
o Set up separate lockdep classes for each instance of SRCU.
o Create primitives that check for being in an RCU read-side
critical section. These return exact answers if lockdep is
fully enabled, but if unsure, report being in an RCU read-side
critical section. (We want to avoid false positives!)
The primitives are:
For RCU: rcu_read_lock_held(void)
For RCU-bh: rcu_read_lock_bh_held(void)
For RCU-sched: rcu_read_lock_sched_held(void)
For SRCU: srcu_read_lock_held(struct srcu_struct *sp)
o Add rcu_dereference_check(), which takes a second argument
in which one places a boolean expression based on the above
primitives and/or lockdep_is_held().
o A new kernel configuration parameter, CONFIG_PROVE_RCU, enables
rcu_dereference_check(). This depends on CONFIG_PROVE_LOCKING,
and should be quite helpful during the transition period while
CONFIG_PROVE_RCU-unaware patches are in flight.
The existing rcu_dereference() primitive does no checking, but
upcoming patches will change that.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: laijs@cn.fujitsu.com
Cc: dipankar@in.ibm.com
Cc: mathieu.desnoyers@polymtl.ca
Cc: josh@joshtriplett.org
Cc: dvhltc@us.ibm.com
Cc: niv@us.ibm.com
Cc: peterz@infradead.org
Cc: rostedt@goodmis.org
Cc: Valdis.Kletnieks@vt.edu
Cc: dhowells@redhat.com
LKML-Reference: <1266887105-1528-1-git-send-email-paulmck@linux.vnet.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include/linux/srcu.h')
-rw-r--r-- | include/linux/srcu.h | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/include/linux/srcu.h b/include/linux/srcu.h index 4765d97dcafb..adbe1670b366 100644 --- a/include/linux/srcu.h +++ b/include/linux/srcu.h | |||
@@ -35,6 +35,9 @@ struct srcu_struct { | |||
35 | int completed; | 35 | int completed; |
36 | struct srcu_struct_array *per_cpu_ref; | 36 | struct srcu_struct_array *per_cpu_ref; |
37 | struct mutex mutex; | 37 | struct mutex mutex; |
38 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
39 | struct lockdep_map dep_map; | ||
40 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
38 | }; | 41 | }; |
39 | 42 | ||
40 | #ifndef CONFIG_PREEMPT | 43 | #ifndef CONFIG_PREEMPT |
@@ -43,12 +46,92 @@ struct srcu_struct { | |||
43 | #define srcu_barrier() | 46 | #define srcu_barrier() |
44 | #endif /* #else #ifndef CONFIG_PREEMPT */ | 47 | #endif /* #else #ifndef CONFIG_PREEMPT */ |
45 | 48 | ||
49 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
50 | |||
51 | int __init_srcu_struct(struct srcu_struct *sp, const char *name, | ||
52 | struct lock_class_key *key); | ||
53 | |||
54 | #define init_srcu_struct(sp) \ | ||
55 | ({ \ | ||
56 | static struct lock_class_key __srcu_key; \ | ||
57 | \ | ||
58 | __init_srcu_struct((sp), #sp, &__srcu_key); \ | ||
59 | }) | ||
60 | |||
61 | # define srcu_read_acquire(sp) \ | ||
62 | lock_acquire(&(sp)->dep_map, 0, 0, 2, 1, NULL, _THIS_IP_) | ||
63 | # define srcu_read_release(sp) \ | ||
64 | lock_release(&(sp)->dep_map, 1, _THIS_IP_) | ||
65 | |||
66 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
67 | |||
46 | int init_srcu_struct(struct srcu_struct *sp); | 68 | int init_srcu_struct(struct srcu_struct *sp); |
69 | |||
70 | # define srcu_read_acquire(sp) do { } while (0) | ||
71 | # define srcu_read_release(sp) do { } while (0) | ||
72 | |||
73 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
74 | |||
47 | void cleanup_srcu_struct(struct srcu_struct *sp); | 75 | void cleanup_srcu_struct(struct srcu_struct *sp); |
48 | int srcu_read_lock(struct srcu_struct *sp) __acquires(sp); | 76 | int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp); |
49 | void srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp); | 77 | void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp); |
50 | void synchronize_srcu(struct srcu_struct *sp); | 78 | void synchronize_srcu(struct srcu_struct *sp); |
51 | void synchronize_srcu_expedited(struct srcu_struct *sp); | 79 | void synchronize_srcu_expedited(struct srcu_struct *sp); |
52 | long srcu_batches_completed(struct srcu_struct *sp); | 80 | long srcu_batches_completed(struct srcu_struct *sp); |
53 | 81 | ||
82 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
83 | |||
84 | /** | ||
85 | * srcu_read_lock_held - might we be in SRCU read-side critical section? | ||
86 | * | ||
87 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in | ||
88 | * an SRCU read-side critical section. In absence of CONFIG_PROVE_LOCKING, | ||
89 | * this assumes we are in an SRCU read-side critical section unless it can | ||
90 | * prove otherwise. | ||
91 | */ | ||
92 | static inline int srcu_read_lock_held(struct srcu_struct *sp) | ||
93 | { | ||
94 | if (debug_locks) | ||
95 | return lock_is_held(&sp->dep_map); | ||
96 | return 1; | ||
97 | } | ||
98 | |||
99 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
100 | |||
101 | static inline int srcu_read_lock_held(struct srcu_struct *sp) | ||
102 | { | ||
103 | return 1; | ||
104 | } | ||
105 | |||
106 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
107 | |||
108 | /** | ||
109 | * srcu_read_lock - register a new reader for an SRCU-protected structure. | ||
110 | * @sp: srcu_struct in which to register the new reader. | ||
111 | * | ||
112 | * Enter an SRCU read-side critical section. Note that SRCU read-side | ||
113 | * critical sections may be nested. | ||
114 | */ | ||
115 | static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp) | ||
116 | { | ||
117 | int retval = __srcu_read_lock(sp); | ||
118 | |||
119 | srcu_read_acquire(sp); | ||
120 | return retval; | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * srcu_read_unlock - unregister a old reader from an SRCU-protected structure. | ||
125 | * @sp: srcu_struct in which to unregister the old reader. | ||
126 | * @idx: return value from corresponding srcu_read_lock(). | ||
127 | * | ||
128 | * Exit an SRCU read-side critical section. | ||
129 | */ | ||
130 | static inline void srcu_read_unlock(struct srcu_struct *sp, int idx) | ||
131 | __releases(sp) | ||
132 | { | ||
133 | srcu_read_release(sp); | ||
134 | __srcu_read_unlock(sp, idx); | ||
135 | } | ||
136 | |||
54 | #endif | 137 | #endif |