History

Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip

* 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (44 commits) rcu: Fix accelerated GPs for last non-dynticked CPU rcu: Make non-RCU_PROVE_LOCKING rcu_read_lock_sched_held() understand boot rcu: Fix accelerated grace periods for last non-dynticked CPU rcu: Export rcu_scheduler_active rcu: Make rcu_read_lock_sched_held() take boot time into account rcu: Make lockdep_rcu_dereference() message less alarmist sched, cgroups: Fix module export rcu: Add RCU_CPU_STALL_VERBOSE to dump detailed per-task information rcu: Fix rcutorture mod_timer argument to delay one jiffy rcu: Fix deadlock in TREE_PREEMPT_RCU CPU stall detection rcu: Convert to raw_spinlocks rcu: Stop overflowing signed integers rcu: Use canonical URL for Mathieu's dissertation rcu: Accelerate grace period if last non-dynticked CPU rcu: Fix citation of Mathieu's dissertation rcu: Documentation update for CONFIG_PROVE_RCU security: Apply lockdep-based checking to rcu_dereference() uses idr: Apply lockdep-based diagnostics to rcu_dereference() uses radix-tree: Disable RCU lockdep checking in radix tree vfs: Abstract rcu_dereference_check for files-fdtable use ...

Linus Torvalds committed 16 years ago

Commit 642c4c72 parents f91b22c 71da81355 files · +1346 −448Browse files

Unified · Split

55 files
  1. Documentation/RCU/00-INDEX +8 −2
  2. Documentation/RCU/RTFP.txt +57 −4
  3. Documentation/RCU/checklist.txt +126 −82
  4. Documentation/RCU/lockdep.txt +67 −0
  5. Documentation/RCU/rcu.txt +3 −45
  6. Documentation/RCU/stallwarn.txt +58 −0
  7. Documentation/RCU/torture.txt +12 −0
  8. Documentation/RCU/whatisRCU.txt +10 −6
  9. Documentation/filesystems/dentry-locking.txt +2 −1
  10. MAINTAINERS +7 −6
  11. fs/file.c +1 −1
  12. fs/proc/array.c +2 −0
  13. fs/proc/base.c +5 −1
  14. include/linux/cgroup.h +4 −1
  15. include/linux/cpumask.h +14 −0
  16. include/linux/cred.h +1 −1
  17. include/linux/fdtable.h +9 −2
  18. include/linux/lockdep.h +4 −0
  19. include/linux/rculist.h +7 −7
  20. include/linux/rculist_nulls.h +2 −2
  21. include/linux/rcupdate.h +150 −15
  22. include/linux/rcutiny.h +12 −4
  23. include/linux/rcutree.h +3 −1
  24. include/linux/rtnetlink.h +3 −0
  25. include/linux/srcu.h +93 −2
  26. include/net/addrconf.h +3 −1
  27. init/Kconfig +16 −0
  28. init/main.c +2 −0
  29. kernel/cgroup.c +15 −0
  30. kernel/exit.c +11 −3
  31. kernel/fork.c +1 −0
  32. kernel/lockdep.c +18 −0
  33. kernel/notifier.c +3 −3
  34. kernel/pid.c +1 −1
  35. kernel/rcupdate.c +29 −0
  36. kernel/rcutorture.c +89 −5
  37. kernel/rcutree.c +134 −134
  38. kernel/rcutree.h +34 −27
  39. kernel/rcutree_plugin.h +205 −24
  40. kernel/rcutree_trace.c +7 −7
  41. kernel/sched.c +8 −3
  42. kernel/srcu.c +34 −18
  43. lib/Kconfig.debug +25 −1
  44. lib/debug_locks.c +1 −0
  45. lib/idr.c +4 −4
  46. lib/radix-tree.c +12 −12
  47. net/core/dev.c +1 −1
  48. net/core/filter.c +3 −3
  49. net/core/rtnetlink.c +8 −0
  50. net/core/sock.c +2 −1
  51. net/decnet/dn_route.c +7 −7
  52. net/ipv4/route.c +7 −7
  53. net/packet/af_packet.c +1 −1
  54. security/keys/gc.c +2 −1
  55. security/keys/keyring.c +3 −1
Documentation/RCU/00-INDEX+8−2
@@ -6,16 +6,22 @@ checklist.txt · 5 unmodified lines
66 - Review Checklist for RCU Patches
77 listRCU.txt
88 - Using RCU to Protect Read-Mostly Linked Lists
9+lockdep.txt
10+ - RCU and lockdep checking
911 NMI-RCU.txt
1012 - Using RCU to Protect Dynamic NMI Handlers
13+rcubarrier.txt
14+ - RCU and Unloadable Modules
15+rculist_nulls.txt
16+ - RCU list primitives for use with SLAB_DESTROY_BY_RCU
1117 rcuref.txt
1218 - Reference-count design for elements of lists/arrays protected by RCU
1319 rcu.txt
1420 - RCU Concepts
15−rcubarrier.txt
16− - Unloading modules that use RCU callbacks
1721 RTFP.txt
1822 - List of RCU papers (bibliography) going back to 1980.
23+stallwarn.txt
24+ - RCU CPU stall warnings (CONFIG_RCU_CPU_STALL_DETECTOR)
1925 torture.txt
2026 - RCU Torture Test Operation (CONFIG_RCU_TORTURE_TEST)
2127 trace.txt
Documentation/RCU/RTFP.txt+57−4
@@ -25,10 +25,10 @@ to be referencing the data structure. However, this mechanism was not · 24 unmodified lines
2525 optimized for modern computer systems, which is not surprising given
2626 that these overheads were not so expensive in the mid-80s. Nonetheless,
2727 passive serialization appears to be the first deferred-destruction
28−mechanism to be used in production. Furthermore, the relevant patent has
29−lapsed, so this approach may be used in non-GPL software, if desired.
30−(In contrast, use of RCU is permitted only in software licensed under
31−GPL. Sorry!!!)
28+mechanism to be used in production. Furthermore, the relevant patent
29+has lapsed, so this approach may be used in non-GPL software, if desired.
30+(In contrast, implementation of RCU is permitted only in software licensed
31+under either GPL or LGPL. Sorry!!!)
3232
3333 In 1990, Pugh [Pugh90] noted that explicitly tracking which threads
3434 were reading a given data structure permitted deferred free to operate
@@ -150,6 +150,18 @@ preemptible RCU [PaulEMcKenney2007PreemptibleRCU], and the three-part · 115 unmodified lines
150150 LWN "What is RCU?" series [PaulEMcKenney2007WhatIsRCUFundamentally,
151151 PaulEMcKenney2008WhatIsRCUUsage, and PaulEMcKenney2008WhatIsRCUAPI].
152152
153+2008 saw a journal paper on real-time RCU [DinakarGuniguntala2008IBMSysJ],
154+a history of how Linux changed RCU more than RCU changed Linux
155+[PaulEMcKenney2008RCUOSR], and a design overview of hierarchical RCU
156+[PaulEMcKenney2008HierarchicalRCU].
157+
158+2009 introduced user-level RCU algorithms [PaulEMcKenney2009MaliciousURCU],
159+which Mathieu Desnoyers is now maintaining [MathieuDesnoyers2009URCU]
160+[MathieuDesnoyersPhD]. TINY_RCU [PaulEMcKenney2009BloatWatchRCU] made
161+its appearance, as did expedited RCU [PaulEMcKenney2009expeditedRCU].
162+The problem of resizeable RCU-protected hash tables may now be on a path
163+to a solution [JoshTriplett2009RPHash].
164+
153165 Bibtex Entries
154166
155167 @article{Kung80
@@ -730,6 +742,11 @@ Revised: · 574 unmodified lines
730742 "
731743 }
732744
745+#
746+# "What is RCU?" LWN series.
747+#
748+########################################################################
749+
733750 @article{DinakarGuniguntala2008IBMSysJ
734751 ,author="D. Guniguntala and P. E. McKenney and J. Triplett and J. Walpole"
735752 ,title="The read-copy-update mechanism for supporting real-time applications on shared-memory multiprocessor systems with {Linux}"
@@ -820,3 +837,39 @@ Revised: · 84 unmodified lines
820837 Uniprocessor assumptions allow simplified RCU implementation.
821838 "
822839 }
840+
841+@unpublished{PaulEMcKenney2009expeditedRCU
842+,Author="Paul E. McKenney"
843+,Title="[{PATCH} -tip 0/3] expedited 'big hammer' {RCU} grace periods"
844+,month="June"
845+,day="25"
846+,year="2009"
847+,note="Available:
848+\url{http://lkml.org/lkml/2009/6/25/306}
849+[Viewed August 16, 2009]"
850+,annotation="
851+ First posting of expedited RCU to be accepted into -tip.
852+"
853+}
854+
855+@unpublished{JoshTriplett2009RPHash
856+,Author="Josh Triplett"
857+,Title="Scalable concurrent hash tables via relativistic programming"
858+,month="September"
859+,year="2009"
860+,note="Linux Plumbers Conference presentation"
861+,annotation="
862+ RP fun with hash tables.
863+"
864+}
865+
866+@phdthesis{MathieuDesnoyersPhD
867+, title = "Low-Impact Operating System Tracing"
868+, author = "Mathieu Desnoyers"
869+, school = "Ecole Polytechnique de Montr\'{e}al"
870+, month = "December"
871+, year = 2009
872+,note="Available:
873+\url{http://www.lttng.org/pub/thesis/desnoyers-dissertation-2009-12.pdf}
874+[Viewed December 9, 2009]"
875+}
Documentation/RCU/checklist.txt+126−82
@@ -8,13 +8,12 @@ would cause. This list is based on experiences reviewing such patches · 7 unmodified lines
88 over a rather long period of time, but improvements are always welcome!
99
1010 0. Is RCU being applied to a read-mostly situation? If the data
11− structure is updated more than about 10% of the time, then
12− you should strongly consider some other approach, unless
13− detailed performance measurements show that RCU is nonetheless
14− the right tool for the job. Yes, you might think of RCU
15− as simply cutting overhead off of the readers and imposing it
16− on the writers. That is exactly why normal uses of RCU will
17− do much more reading than updating.
11+ structure is updated more than about 10% of the time, then you
12+ should strongly consider some other approach, unless detailed
13+ performance measurements show that RCU is nonetheless the right
14+ tool for the job. Yes, RCU does reduce read-side overhead by
15+ increasing write-side overhead, which is exactly why normal uses
16+ of RCU will do much more reading than updating.
1817
1918 Another exception is where performance is not an issue, and RCU
2019 provides a simpler implementation. An example of this situation
@@ -35,13 +34,13 @@ over a rather long period of time, but improvements are always welcome! · 14 unmodified lines
3534
3635 If you choose #b, be prepared to describe how you have handled
3736 memory barriers on weakly ordered machines (pretty much all of
38− them -- even x86 allows reads to be reordered), and be prepared
39− to explain why this added complexity is worthwhile. If you
40− choose #c, be prepared to explain how this single task does not
41− become a major bottleneck on big multiprocessor machines (for
42− example, if the task is updating information relating to itself
43− that other tasks can read, there by definition can be no
44− bottleneck).
37+ them -- even x86 allows later loads to be reordered to precede
38+ earlier stores), and be prepared to explain why this added
39+ complexity is worthwhile. If you choose #c, be prepared to
40+ explain how this single task does not become a major bottleneck on
41+ big multiprocessor machines (for example, if the task is updating
42+ information relating to itself that other tasks can read, there
43+ by definition can be no bottleneck).
4544
4645 2. Do the RCU read-side critical sections make proper use of
4746 rcu_read_lock() and friends? These primitives are needed
@@ -51,8 +50,10 @@ over a rather long period of time, but improvements are always welcome! · 3 unmodified lines
5150 actuarial risk of your kernel.
5251
5352 As a rough rule of thumb, any dereference of an RCU-protected
54− pointer must be covered by rcu_read_lock() or rcu_read_lock_bh()
55− or by the appropriate update-side lock.
53+ pointer must be covered by rcu_read_lock(), rcu_read_lock_bh(),
54+ rcu_read_lock_sched(), or by the appropriate update-side lock.
55+ Disabling of preemption can serve as rcu_read_lock_sched(), but
56+ is less readable.
5657
5758 3. Does the update code tolerate concurrent accesses?
5859
@@ -62,25 +63,27 @@ over a rather long period of time, but improvements are always welcome! · 3 unmodified lines
6263 of ways to handle this concurrency, depending on the situation:
6364
6465 a. Use the RCU variants of the list and hlist update
65− primitives to add, remove, and replace elements on an
66− RCU-protected list. Alternatively, use the RCU-protected
67− trees that have been added to the Linux kernel.
66+ primitives to add, remove, and replace elements on
67+ an RCU-protected list. Alternatively, use the other
68+ RCU-protected data structures that have been added to
69+ the Linux kernel.
6870
6971 This is almost always the best approach.
7072
7173 b. Proceed as in (a) above, but also maintain per-element
7274 locks (that are acquired by both readers and writers)
7375 that guard per-element state. Of course, fields that
74− the readers refrain from accessing can be guarded by the
75− update-side lock.
76+ the readers refrain from accessing can be guarded by
77+ some other lock acquired only by updaters, if desired.
7678
7779 This works quite well, also.
7880
7981 c. Make updates appear atomic to readers. For example,
80− pointer updates to properly aligned fields will appear
81− atomic, as will individual atomic primitives. Operations
82− performed under a lock and sequences of multiple atomic
83− primitives will -not- appear to be atomic.
82+ pointer updates to properly aligned fields will
83+ appear atomic, as will individual atomic primitives.
84+ Sequences of perations performed under a lock will -not-
85+ appear to be atomic to RCU readers, nor will sequences
86+ of multiple atomic primitives.
8487
8588 This can work, but is starting to get a bit tricky.
8689
@@ -98,9 +101,9 @@ over a rather long period of time, but improvements are always welcome! · 11 unmodified lines
98101 a new structure containing updated values.
99102
100103 4. Weakly ordered CPUs pose special challenges. Almost all CPUs
101− are weakly ordered -- even i386 CPUs allow reads to be reordered.
102− RCU code must take all of the following measures to prevent
103− memory-corruption problems:
104+ are weakly ordered -- even x86 CPUs allow later loads to be
105+ reordered to precede earlier stores. RCU code must take all of
106+ the following measures to prevent memory-corruption problems:
104107
105108 a. Readers must maintain proper ordering of their memory
106109 accesses. The rcu_dereference() primitive ensures that
@@ -113,14 +116,25 @@ over a rather long period of time, but improvements are always welcome! · 6 unmodified lines
113116 The rcu_dereference() primitive is also an excellent
114117 documentation aid, letting the person reading the code
115118 know exactly which pointers are protected by RCU.
116−
117− The rcu_dereference() primitive is used by the various
118− "_rcu()" list-traversal primitives, such as the
119− list_for_each_entry_rcu(). Note that it is perfectly
120− legal (if redundant) for update-side code to use
121− rcu_dereference() and the "_rcu()" list-traversal
122− primitives. This is particularly useful in code
123− that is common to readers and updaters.
119+ Please note that compilers can also reorder code, and
120+ they are becoming increasingly aggressive about doing
121+ just that. The rcu_dereference() primitive therefore
122+ also prevents destructive compiler optimizations.
123+
124+ The rcu_dereference() primitive is used by the
125+ various "_rcu()" list-traversal primitives, such
126+ as the list_for_each_entry_rcu(). Note that it is
127+ perfectly legal (if redundant) for update-side code to
128+ use rcu_dereference() and the "_rcu()" list-traversal
129+ primitives. This is particularly useful in code that
130+ is common to readers and updaters. However, lockdep
131+ will complain if you access rcu_dereference() outside
132+ of an RCU read-side critical section. See lockdep.txt
133+ to learn what to do about this.
134+
135+ Of course, neither rcu_dereference() nor the "_rcu()"
136+ list-traversal primitives can substitute for a good
137+ concurrency design coordinating among multiple updaters.
124138
125139 b. If the list macros are being used, the list_add_tail_rcu()
126140 and list_add_rcu() primitives must be used in order
@@ -135,11 +149,14 @@ over a rather long period of time, but improvements are always welcome! · 8 unmodified lines
135149 readers. Similarly, if the hlist macros are being used,
136150 the hlist_del_rcu() primitive is required.
137151
138− The list_replace_rcu() primitive may be used to
139− replace an old structure with a new one in an
140− RCU-protected list.
152+ The list_replace_rcu() and hlist_replace_rcu() primitives
153+ may be used to replace an old structure with a new one
154+ in their respective types of RCU-protected lists.
155+
156+ d. Rules similar to (4b) and (4c) apply to the "hlist_nulls"
157+ type of RCU-protected linked lists.
141158
142− d. Updates must ensure that initialization of a given
159+ e. Updates must ensure that initialization of a given
143160 structure happens before pointers to that structure are
144161 publicized. Use the rcu_assign_pointer() primitive
145162 when publicizing a pointer to a structure that can
@@ -151,16 +168,31 @@ over a rather long period of time, but improvements are always welcome! · 5 unmodified lines
151168 it cannot block.
152169
153170 6. Since synchronize_rcu() can block, it cannot be called from
154− any sort of irq context. Ditto for synchronize_sched() and
155− synchronize_srcu().
156−
157−7. If the updater uses call_rcu(), then the corresponding readers
158− must use rcu_read_lock() and rcu_read_unlock(). If the updater
159− uses call_rcu_bh(), then the corresponding readers must use
160− rcu_read_lock_bh() and rcu_read_unlock_bh(). If the updater
161− uses call_rcu_sched(), then the corresponding readers must
162− disable preemption. Mixing things up will result in confusion
163− and broken kernels.
171+ any sort of irq context. The same rule applies for
172+ synchronize_rcu_bh(), synchronize_sched(), synchronize_srcu(),
173+ synchronize_rcu_expedited(), synchronize_rcu_bh_expedited(),
174+ synchronize_sched_expedite(), and synchronize_srcu_expedited().
175+
176+ The expedited forms of these primitives have the same semantics
177+ as the non-expedited forms, but expediting is both expensive
178+ and unfriendly to real-time workloads. Use of the expedited
179+ primitives should be restricted to rare configuration-change
180+ operations that would not normally be undertaken while a real-time
181+ workload is running.
182+
183+7. If the updater uses call_rcu() or synchronize_rcu(), then the
184+ corresponding readers must use rcu_read_lock() and
185+ rcu_read_unlock(). If the updater uses call_rcu_bh() or
186+ synchronize_rcu_bh(), then the corresponding readers must
187+ use rcu_read_lock_bh() and rcu_read_unlock_bh(). If the
188+ updater uses call_rcu_sched() or synchronize_sched(), then
189+ the corresponding readers must disable preemption, possibly
190+ by calling rcu_read_lock_sched() and rcu_read_unlock_sched().
191+ If the updater uses synchronize_srcu(), the the corresponding
192+ readers must use srcu_read_lock() and srcu_read_unlock(),
193+ and with the same srcu_struct. The rules for the expedited
194+ primitives are the same as for their non-expedited counterparts.
195+ Mixing things up will result in confusion and broken kernels.
164196
165197 One exception to this rule: rcu_read_lock() and rcu_read_unlock()
166198 may be substituted for rcu_read_lock_bh() and rcu_read_unlock_bh()
@@ -212,6 +244,8 @@ over a rather long period of time, but improvements are always welcome! · 45 unmodified lines
212244 e. Periodically invoke synchronize_rcu(), permitting a limited
213245 number of updates per grace period.
214246
247+ The same cautions apply to call_rcu_bh() and call_rcu_sched().
248+
215249 9. All RCU list-traversal primitives, which include
216250 rcu_dereference(), list_for_each_entry_rcu(),
217251 list_for_each_continue_rcu(), and list_for_each_safe_rcu(),
@@ -219,7 +253,9 @@ over a rather long period of time, but improvements are always welcome! · 1 unmodified line
219253 must be protected by appropriate update-side locks. RCU
220254 read-side critical sections are delimited by rcu_read_lock()
221255 and rcu_read_unlock(), or by similar primitives such as
222− rcu_read_lock_bh() and rcu_read_unlock_bh().
256+ rcu_read_lock_bh() and rcu_read_unlock_bh(), in which case
257+ the matching rcu_dereference() primitive must be used in order
258+ to keep lockdep happy, in this case, rcu_dereference_bh().
223259
224260 The reason that it is permissible to use RCU list-traversal
225261 primitives when the update-side lock is held is that doing so
@@ -229,7 +265,8 @@ over a rather long period of time, but improvements are always welcome! · 3 unmodified lines
229265 10. Conversely, if you are in an RCU read-side critical section,
230266 and you don't hold the appropriate update-side lock, you -must-
231267 use the "_rcu()" variants of the list macros. Failing to do so
232− will break Alpha and confuse people reading your code.
268+ will break Alpha, cause aggressive compilers to generate bad code,
269+ and confuse people trying to read your code.
233270
234271 11. Note that synchronize_rcu() -only- guarantees to wait until
235272 all currently executing rcu_read_lock()-protected RCU read-side
@@ -239,15 +276,21 @@ over a rather long period of time, but improvements are always welcome! · 3 unmodified lines
239276 rcu_read_lock()-protected read-side critical sections, do -not-
240277 use synchronize_rcu().
241278
242− If you want to wait for some of these other things, you might
243− instead need to use synchronize_irq() or synchronize_sched().
279+ Similarly, disabling preemption is not an acceptable substitute
280+ for rcu_read_lock(). Code that attempts to use preemption
281+ disabling where it should be using rcu_read_lock() will break
282+ in real-time kernel builds.
283+
284+ If you want to wait for interrupt handlers, NMI handlers, and
285+ code under the influence of preempt_disable(), you instead
286+ need to use synchronize_irq() or synchronize_sched().
244287
245288 12. Any lock acquired by an RCU callback must be acquired elsewhere
246289 with softirq disabled, e.g., via spin_lock_irqsave(),
247290 spin_lock_bh(), etc. Failing to disable irq on a given
248− acquisition of that lock will result in deadlock as soon as the
249− RCU callback happens to interrupt that acquisition's critical
250− section.
291+ acquisition of that lock will result in deadlock as soon as
292+ the RCU softirq handler happens to run your RCU callback while
293+ interrupting that acquisition's critical section.
251294
252295 13. RCU callbacks can be and are executed in parallel. In many cases,
253296 the callback code simply wrappers around kfree(), so that this
@@ -265,29 +308,30 @@ over a rather long period of time, but improvements are always welcome! · 11 unmodified lines
265308 not the case, a self-spawning RCU callback would prevent the
266309 victim CPU from ever going offline.)
267310
268−14. SRCU (srcu_read_lock(), srcu_read_unlock(), and synchronize_srcu())
269− may only be invoked from process context. Unlike other forms of
270− RCU, it -is- permissible to block in an SRCU read-side critical
271− section (demarked by srcu_read_lock() and srcu_read_unlock()),
272− hence the "SRCU": "sleepable RCU". Please note that if you
273− don't need to sleep in read-side critical sections, you should
274− be using RCU rather than SRCU, because RCU is almost always
275− faster and easier to use than is SRCU.
311+14. SRCU (srcu_read_lock(), srcu_read_unlock(), srcu_dereference(),
312+ synchronize_srcu(), and synchronize_srcu_expedited()) may only
313+ be invoked from process context. Unlike other forms of RCU, it
314+ -is- permissible to block in an SRCU read-side critical section
315+ (demarked by srcu_read_lock() and srcu_read_unlock()), hence the
316+ "SRCU": "sleepable RCU". Please note that if you don't need
317+ to sleep in read-side critical sections, you should be using
318+ RCU rather than SRCU, because RCU is almost always faster and
319+ easier to use than is SRCU.
276320
277321 Also unlike other forms of RCU, explicit initialization
278322 and cleanup is required via init_srcu_struct() and
279323 cleanup_srcu_struct(). These are passed a "struct srcu_struct"
280324 that defines the scope of a given SRCU domain. Once initialized,
281325 the srcu_struct is passed to srcu_read_lock(), srcu_read_unlock()
282− and synchronize_srcu(). A given synchronize_srcu() waits only
283− for SRCU read-side critical sections governed by srcu_read_lock()
284− and srcu_read_unlock() calls that have been passd the same
285− srcu_struct. This property is what makes sleeping read-side
286− critical sections tolerable -- a given subsystem delays only
287− its own updates, not those of other subsystems using SRCU.
288− Therefore, SRCU is less prone to OOM the system than RCU would
289− be if RCU's read-side critical sections were permitted to
290− sleep.
326+ synchronize_srcu(), and synchronize_srcu_expedited(). A given
327+ synchronize_srcu() waits only for SRCU read-side critical
328+ sections governed by srcu_read_lock() and srcu_read_unlock()
329+ calls that have been passed the same srcu_struct. This property
330+ is what makes sleeping read-side critical sections tolerable --
331+ a given subsystem delays only its own updates, not those of other
332+ subsystems using SRCU. Therefore, SRCU is less prone to OOM the
333+ system than RCU would be if RCU's read-side critical sections
334+ were permitted to sleep.
291335
292336 The ability to sleep in read-side critical sections does not
293337 come for free. First, corresponding srcu_read_lock() and
@@ -311,12 +355,12 @@ over a rather long period of time, but improvements are always welcome! · 17 unmodified lines
311355 destructive operation, and -only- -then- invoke call_rcu(),
312356 synchronize_rcu(), or friends.
313357
314− Because these primitives only wait for pre-existing readers,
315− it is the caller's responsibility to guarantee safety to
316− any subsequent readers.
358+ Because these primitives only wait for pre-existing readers, it
359+ is the caller's responsibility to guarantee that any subsequent
360+ readers will execute safely.
317361
318−16. The various RCU read-side primitives do -not- contain memory
319− barriers. The CPU (and in some cases, the compiler) is free
320− to reorder code into and out of RCU read-side critical sections.
321− It is the responsibility of the RCU update-side primitives to
322− deal with this.
362+16. The various RCU read-side primitives do -not- necessarily contain
363+ memory barriers. You should therefore plan for the CPU
364+ and the compiler to freely reorder code into and out of RCU
365+ read-side critical sections. It is the responsibility of the
366+ RCU update-side primitives to deal with this.
Documentation/RCU/lockdep.txt+67−0
@@ -0,0 +1,67 @@
1+RCU and lockdep checking
2+
3+All flavors of RCU have lockdep checking available, so that lockdep is
4+aware of when each task enters and leaves any flavor of RCU read-side
5+critical section. Each flavor of RCU is tracked separately (but note
6+that this is not the case in 2.6.32 and earlier). This allows lockdep's
7+tracking to include RCU state, which can sometimes help when debugging
8+deadlocks and the like.
9+
10+In addition, RCU provides the following primitives that check lockdep's
11+state:
12+
13+ rcu_read_lock_held() for normal RCU.
14+ rcu_read_lock_bh_held() for RCU-bh.
15+ rcu_read_lock_sched_held() for RCU-sched.
16+ srcu_read_lock_held() for SRCU.
17+
18+These functions are conservative, and will therefore return 1 if they
19+aren't certain (for example, if CONFIG_DEBUG_LOCK_ALLOC is not set).
20+This prevents things like WARN_ON(!rcu_read_lock_held()) from giving false
21+positives when lockdep is disabled.
22+
23+In addition, a separate kernel config parameter CONFIG_PROVE_RCU enables
24+checking of rcu_dereference() primitives:
25+
26+ rcu_dereference(p):
27+ Check for RCU read-side critical section.
28+ rcu_dereference_bh(p):
29+ Check for RCU-bh read-side critical section.
30+ rcu_dereference_sched(p):
31+ Check for RCU-sched read-side critical section.
32+ srcu_dereference(p, sp):
33+ Check for SRCU read-side critical section.
34+ rcu_dereference_check(p, c):
35+ Use explicit check expression "c".
36+ rcu_dereference_raw(p)
37+ Don't check. (Use sparingly, if at all.)
38+
39+The rcu_dereference_check() check expression can be any boolean
40+expression, but would normally include one of the rcu_read_lock_held()
41+family of functions and a lockdep expression. However, any boolean
42+expression can be used. For a moderately ornate example, consider
43+the following:
44+
45+ file = rcu_dereference_check(fdt->fd[fd],
46+ rcu_read_lock_held() ||
47+ lockdep_is_held(&files->file_lock) ||
48+ atomic_read(&files->count) == 1);
49+
50+This expression picks up the pointer "fdt->fd[fd]" in an RCU-safe manner,
51+and, if CONFIG_PROVE_RCU is configured, verifies that this expression
52+is used in:
53+
54+1. An RCU read-side critical section, or
55+2. with files->file_lock held, or
56+3. on an unshared files_struct.
57+
58+In case (1), the pointer is picked up in an RCU-safe manner for vanilla
59+RCU read-side critical sections, in case (2) the ->file_lock prevents
60+any change from taking place, and finally, in case (3) the current task
61+is the only task accessing the file_struct, again preventing any change
62+from taking place.
63+
64+There are currently only "universal" versions of the rcu_assign_pointer()
65+and RCU list-/tree-traversal primitives, which do not (yet) check for
66+being in an RCU read-side critical section. In the future, separate
67+versions of these primitives might be created.
Documentation/RCU/rcu.txt+3−45
@@ -75,6 +75,8 @@ o I hear that RCU is patented? What is with that? · 74 unmodified lines
7575 search for the string "Patent" in RTFP.txt to find them.
7676 Of these, one was allowed to lapse by the assignee, and the
7777 others have been contributed to the Linux kernel under GPL.
78+ There are now also LGPL implementations of user-level RCU
79+ available (http://lttng.org/?q=node/18).
7880
7981 o I hear that RCU needs work in order to support realtime kernels?
8082
@@ -91,48 +93,4 @@ o Where can I find more information on RCU? · 10 unmodified lines
9193
9294 o What are all these files in this directory?
9395
94−
95− NMI-RCU.txt
96−
97− Describes how to use RCU to implement dynamic
98− NMI handlers, which can be revectored on the fly,
99− without rebooting.
100−
101− RTFP.txt
102−
103− List of RCU-related publications and web sites.
104−
105− UP.txt
106−
107− Discussion of RCU usage in UP kernels.
108−
109− arrayRCU.txt
110−
111− Describes how to use RCU to protect arrays, with
112− resizeable arrays whose elements reference other
113− data structures being of the most interest.
114−
115− checklist.txt
116−
117− Lists things to check for when inspecting code that
118− uses RCU.
119−
120− listRCU.txt
121−
122− Describes how to use RCU to protect linked lists.
123− This is the simplest and most common use of RCU
124− in the Linux kernel.
125−
126− rcu.txt
127−
128− You are reading it!
129−
130− rcuref.txt
131−
132− Describes how to combine use of reference counts
133− with RCU.
134−
135− whatisRCU.txt
136−
137− Overview of how the RCU implementation works. Along
138− the way, presents a conceptual view of RCU.
96+ See 00-INDEX for the list.
Documentation/RCU/stallwarn.txt+58−0
@@ -0,0 +1,58 @@
1+Using RCU's CPU Stall Detector
2+
3+The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables
4+RCU's CPU stall detector, which detects conditions that unduly delay
5+RCU grace periods. The stall detector's idea of what constitutes
6+"unduly delayed" is controlled by a pair of C preprocessor macros:
7+
8+RCU_SECONDS_TILL_STALL_CHECK
9+
10+ This macro defines the period of time that RCU will wait from
11+ the beginning of a grace period until it issues an RCU CPU
12+ stall warning. It is normally ten seconds.
13+
14+RCU_SECONDS_TILL_STALL_RECHECK
15+
16+ This macro defines the period of time that RCU will wait after
17+ issuing a stall warning until it issues another stall warning.
18+ It is normally set to thirty seconds.
19+
20+RCU_STALL_RAT_DELAY
21+
22+ The CPU stall detector tries to make the offending CPU rat on itself,
23+ as this often gives better-quality stack traces. However, if
24+ the offending CPU does not detect its own stall in the number
25+ of jiffies specified by RCU_STALL_RAT_DELAY, then other CPUs will
26+ complain. This is normally set to two jiffies.
27+
28+The following problems can result in an RCU CPU stall warning:
29+
30+o A CPU looping in an RCU read-side critical section.
31+
32+o A CPU looping with interrupts disabled.
33+
34+o A CPU looping with preemption disabled.
35+
36+o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
37+ without invoking schedule().
38+
39+o A bug in the RCU implementation.
40+
41+o A hardware failure. This is quite unlikely, but has occurred
42+ at least once in a former life. A CPU failed in a running system,
43+ becoming unresponsive, but not causing an immediate crash.
44+ This resulted in a series of RCU CPU stall warnings, eventually
45+ leading the realization that the CPU had failed.
46+
47+The RCU, RCU-sched, and RCU-bh implementations have CPU stall warning.
48+SRCU does not do so directly, but its calls to synchronize_sched() will
49+result in RCU-sched detecting any CPU stalls that might be occurring.
50+
51+To diagnose the cause of the stall, inspect the stack traces. The offending
52+function will usually be near the top of the stack. If you have a series
53+of stall warnings from a single extended stall, comparing the stack traces
54+can often help determine where the stall is occurring, which will usually
55+be in the function nearest the top of the stack that stays the same from
56+trace to trace.
57+
58+RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE.
Documentation/RCU/torture.txt+12−0
@@ -30,6 +30,18 @@ MODULE PARAMETERS · 29 unmodified lines
3030
3131 This module has the following parameters:
3232
33+fqs_duration Duration (in microseconds) of artificially induced bursts
34+ of force_quiescent_state() invocations. In RCU
35+ implementations having force_quiescent_state(), these
36+ bursts help force races between forcing a given grace
37+ period and that grace period ending on its own.
38+
39+fqs_holdoff Holdoff time (in microseconds) between consecutive calls
40+ to force_quiescent_state() within a burst.
41+
42+fqs_stutter Wait time (in seconds) between consecutive bursts
43+ of calls to force_quiescent_state().
44+
3345 irqreaders Says to invoke RCU readers from irq level. This is currently
3446 done via timers. Defaults to "1" for variants of RCU that
3547 permit this. (Or, more accurately, variants of RCU that do
Documentation/RCU/whatisRCU.txt+10−6
@@ -323,14 +323,17 @@ used as follows: · 322 unmodified lines
323323 Defer Protect
324324
325325 a. synchronize_rcu() rcu_read_lock() / rcu_read_unlock()
326− call_rcu()
326+ call_rcu() rcu_dereference()
327327
328328 b. call_rcu_bh() rcu_read_lock_bh() / rcu_read_unlock_bh()
329+ rcu_dereference_bh()
329330
330−c. synchronize_sched() preempt_disable() / preempt_enable()
331+c. synchronize_sched() rcu_read_lock_sched() / rcu_read_unlock_sched()
332+ preempt_disable() / preempt_enable()
331333 local_irq_save() / local_irq_restore()
332334 hardirq enter / hardirq exit
333335 NMI enter / NMI exit
336+ rcu_dereference_sched()
334337
335338 These three mechanisms are used as follows:
336339
@@ -780,9 +783,8 @@ Linux-kernel source code, but it helps to have a full list of the · 443 unmodified lines
780783 APIs, since there does not appear to be a way to categorize them
781784 in docbook. Here is the list, by category.
782785
783−RCU pointer/list traversal:
786+RCU list traversal:
784787
785− rcu_dereference
786788 list_for_each_entry_rcu
787789 hlist_for_each_entry_rcu
788790 hlist_nulls_for_each_entry_rcu
@@ -808,7 +810,7 @@ RCU: Critical sections Grace period Barrier · 19 unmodified lines
808810
809811 rcu_read_lock synchronize_net rcu_barrier
810812 rcu_read_unlock synchronize_rcu
811− synchronize_rcu_expedited
813+ rcu_dereference synchronize_rcu_expedited
812814 call_rcu
813815
814816
@@ -816,7 +818,7 @@ bh: Critical sections Grace period Barrier · 1 unmodified line
816818
817819 rcu_read_lock_bh call_rcu_bh rcu_barrier_bh
818820 rcu_read_unlock_bh synchronize_rcu_bh
819− synchronize_rcu_bh_expedited
821+ rcu_dereference_bh synchronize_rcu_bh_expedited
820822
821823
822824 sched: Critical sections Grace period Barrier
@@ -825,12 +827,14 @@ sched: Critical sections Grace period Barrier · 2 unmodified lines
825827 rcu_read_unlock_sched call_rcu_sched
826828 [preempt_disable] synchronize_sched_expedited
827829 [and friends]
830+ rcu_dereference_sched
828831
829832
830833 SRCU: Critical sections Grace period Barrier
831834
832835 srcu_read_lock synchronize_srcu N/A
833836 srcu_read_unlock synchronize_srcu_expedited
837+ srcu_dereference
834838
835839 SRCU: Initialization/cleanup
836840 init_srcu_struct
Documentation/filesystems/dentry-locking.txt+2−1
@@ -62,7 +62,8 @@ changes are : · 61 unmodified lines
6262 2. Insertion of a dentry into the hash table is done using
6363 hlist_add_head_rcu() which take care of ordering the writes - the
6464 writes to the dentry must be visible before the dentry is
65− inserted. This works in conjunction with hlist_for_each_rcu() while
65+ inserted. This works in conjunction with hlist_for_each_rcu(),
66+ which has since been replaced by hlist_for_each_entry_rcu(), while
6667 walking the hash chain. The only requirement is that all
6768 initialization to the dentry must be done before
6869 hlist_add_head_rcu() since we don't have dcache_lock protection
MAINTAINERS+7−6
@@ -4544,7 +4544,7 @@ F: drivers/net/wireless/ray* · 4543 unmodified lines
45444544 RCUTORTURE MODULE
45454545 M: Josh Triplett <josh@freedesktop.org>
45464546 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
4547−S: Maintained
4547+S: Supported
45484548 F: Documentation/RCU/torture.txt
45494549 F: kernel/rcutorture.c
45504550
@@ -4569,11 +4569,12 @@ M: Dipankar Sarma <dipankar@in.ibm.com> · 18 unmodified lines
45694569 M: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
45704570 W: http://www.rdrop.com/users/paulmck/rclock/
45714571 S: Supported
4572−F: Documentation/RCU/rcu.txt
4573−F: Documentation/RCU/rcuref.txt
4574−F: include/linux/rcupdate.h
4575−F: include/linux/srcu.h
4576−F: kernel/rcupdate.c
4572+F: Documentation/RCU/
4573+F: include/linux/rcu*
4574+F: include/linux/srcu*
4575+F: kernel/rcu*
4576+F: kernel/srcu*
4577+X: kernel/rcutorture.c
45774578
45784579 REAL TIME CLOCK DRIVER
45794580 M: Paul Gortmaker <p_gortmaker@yahoo.com>
fs/file.c+1−1
@@ -478,7 +478,7 @@ repeat: · 477 unmodified lines
478478 error = fd;
479479 #if 1
480480 /* Sanity check */
481− if (rcu_dereference(fdt->fd[fd]) != NULL) {
481+ if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
482482 printk(KERN_WARNING "alloc_fd: slot %d not NULL!\n", fd);
483483 rcu_assign_pointer(fdt->fd[fd], NULL);
484484 }
fs/proc/array.c+2−0
@@ -270,7 +270,9 @@ static inline void task_sig(struct seq_file *m, struct task_struct *p) · 269 unmodified lines
270270 blocked = p->blocked;
271271 collect_sigign_sigcatch(p, &ignored, &caught);
272272 num_threads = atomic_read(&p->signal->count);
273+ rcu_read_lock(); /* FIXME: is this correct? */
273274 qsize = atomic_read(&__task_cred(p)->user->sigpending);
275+ rcu_read_unlock();
274276 qlim = p->signal->rlim[RLIMIT_SIGPENDING].rlim_cur;
275277 unlock_task_sighand(p, &flags);
276278 }
fs/proc/base.c+5−1
@@ -1095,8 +1095,12 @@ static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, · 1094 unmodified lines
10951095 if (!capable(CAP_AUDIT_CONTROL))
10961096 return -EPERM;
10971097
1098− if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
1098+ rcu_read_lock();
1099+ if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) {
1100+ rcu_read_unlock();
10991101 return -EPERM;
1102+ }
1103+ rcu_read_unlock();
11001104
11011105 if (count >= PAGE_SIZE)
11021106 count = PAGE_SIZE - 1;
include/linux/cgroup.h+4−1
@@ -28,6 +28,7 @@ struct css_id; · 27 unmodified lines
2828 extern int cgroup_init_early(void);
2929 extern int cgroup_init(void);
3030 extern void cgroup_lock(void);
31+extern int cgroup_lock_is_held(void);
3132 extern bool cgroup_lock_live_group(struct cgroup *cgrp);
3233 extern void cgroup_unlock(void);
3334 extern void cgroup_fork(struct task_struct *p);
@@ -486,7 +487,9 @@ static inline struct cgroup_subsys_state *cgroup_subsys_state( · 452 unmodified lines
486487 static inline struct cgroup_subsys_state *task_subsys_state(
487488 struct task_struct *task, int subsys_id)
488489 {
489− return rcu_dereference(task->cgroups->subsys[subsys_id]);
490+ return rcu_dereference_check(task->cgroups->subsys[subsys_id],
491+ rcu_read_lock_held() ||
492+ cgroup_lock_is_held());
490493 }
491494
492495 static inline struct cgroup* task_cgroup(struct task_struct *task,
include/linux/cpumask.h+14−0
@@ -143,6 +143,8 @@ static inline unsigned int cpumask_any_but(const struct cpumask *mask, · 142 unmodified lines
143143
144144 #define for_each_cpu(cpu, mask) \
145145 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
146+#define for_each_cpu_not(cpu, mask) \
147+ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
146148 #define for_each_cpu_and(cpu, mask, and) \
147149 for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)and)
148150 #else
@@ -202,6 +204,18 @@ int cpumask_any_but(const struct cpumask *mask, unsigned int cpu); · 53 unmodified lines
202204 (cpu) = cpumask_next((cpu), (mask)), \
203205 (cpu) < nr_cpu_ids;)
204206
207+/**
208+ * for_each_cpu_not - iterate over every cpu in a complemented mask
209+ * @cpu: the (optionally unsigned) integer iterator
210+ * @mask: the cpumask pointer
211+ *
212+ * After the loop, cpu is >= nr_cpu_ids.
213+ */
214+#define for_each_cpu_not(cpu, mask) \
215+ for ((cpu) = -1; \
216+ (cpu) = cpumask_next_zero((cpu), (mask)), \
217+ (cpu) < nr_cpu_ids;)
218+
205219 /**
206220 * for_each_cpu_and - iterate over every cpu in both masks
207221 * @cpu: the (optionally unsigned) integer iterator
include/linux/cred.h+1−1
@@ -280,7 +280,7 @@ static inline void put_cred(const struct cred *_cred) · 279 unmodified lines
280280 * task or by holding tasklist_lock to prevent it from being unlinked.
281281 */
282282 #define __task_cred(task) \
283− ((const struct cred *)(rcu_dereference((task)->real_cred)))
283+ ((const struct cred *)(rcu_dereference_check((task)->real_cred, rcu_read_lock_held() || lockdep_is_held(&tasklist_lock))))
284284
285285 /**
286286 * get_task_cred - Get another task's objective credentials
include/linux/fdtable.h+9−2
@@ -57,7 +57,14 @@ struct files_struct { · 56 unmodified lines
5757 struct file * fd_array[NR_OPEN_DEFAULT];
5858 };
5959
60−#define files_fdtable(files) (rcu_dereference((files)->fdt))
60+#define rcu_dereference_check_fdtable(files, fdtfd) \
61+ (rcu_dereference_check((fdtfd), \
62+ rcu_read_lock_held() || \
63+ lockdep_is_held(&(files)->file_lock) || \
64+ atomic_read(&(files)->count) == 1))
65+
66+#define files_fdtable(files) \
67+ (rcu_dereference_check_fdtable((files), (files)->fdt))
6168
6269 struct file_operations;
6370 struct vfsmount;
@@ -78,7 +85,7 @@ static inline struct file * fcheck_files(struct files_struct *files, unsigned in · 14 unmodified lines
7885 struct fdtable *fdt = files_fdtable(files);
7986
8087 if (fd < fdt->max_fds)
81− file = rcu_dereference(fdt->fd[fd]);
88+ file = rcu_dereference_check_fdtable(files, fdt->fd[fd]);
8289 return file;
8390 }
8491
include/linux/lockdep.h+4−0
@@ -534,4 +534,8 @@ do { \ · 533 unmodified lines
534534 # define might_lock_read(lock) do { } while (0)
535535 #endif
536536
537+#ifdef CONFIG_PROVE_RCU
538+extern void lockdep_rcu_dereference(const char *file, const int line);
539+#endif
540+
537541 #endif /* __LINUX_LOCKDEP_H */
include/linux/rculist.h+7−7
@@ -208,7 +208,7 @@ static inline void list_splice_init_rcu(struct list_head *list, · 207 unmodified lines
208208 * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
209209 */
210210 #define list_entry_rcu(ptr, type, member) \
211− container_of(rcu_dereference(ptr), type, member)
211+ container_of(rcu_dereference_raw(ptr), type, member)
212212
213213 /**
214214 * list_first_entry_rcu - get the first element from a list
@@ -225,9 +225,9 @@ static inline void list_splice_init_rcu(struct list_head *list, · 10 unmodified lines
225225 list_entry_rcu((ptr)->next, type, member)
226226
227227 #define __list_for_each_rcu(pos, head) \
228− for (pos = rcu_dereference((head)->next); \
228+ for (pos = rcu_dereference_raw((head)->next); \
229229 pos != (head); \
230− pos = rcu_dereference(pos->next))
230+ pos = rcu_dereference_raw(pos->next))
231231
232232 /**
233233 * list_for_each_entry_rcu - iterate over rcu list of given type
@@ -257,9 +257,9 @@ static inline void list_splice_init_rcu(struct list_head *list, · 23 unmodified lines
257257 * as long as the traversal is guarded by rcu_read_lock().
258258 */
259259 #define list_for_each_continue_rcu(pos, head) \
260− for ((pos) = rcu_dereference((pos)->next); \
260+ for ((pos) = rcu_dereference_raw((pos)->next); \
261261 prefetch((pos)->next), (pos) != (head); \
262− (pos) = rcu_dereference((pos)->next))
262+ (pos) = rcu_dereference_raw((pos)->next))
263263
264264 /**
265265 * list_for_each_entry_continue_rcu - continue iteration over list of given type
@@ -418,10 +418,10 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, · 152 unmodified lines
418418 * as long as the traversal is guarded by rcu_read_lock().
419419 */
420420 #define hlist_for_each_entry_rcu(tpos, pos, head, member) \
421− for (pos = rcu_dereference((head)->first); \
421+ for (pos = rcu_dereference_raw((head)->first); \
422422 pos && ({ prefetch(pos->next); 1; }) && \
423423 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
424− pos = rcu_dereference(pos->next))
424+ pos = rcu_dereference_raw(pos->next))
425425
426426 #endif /* __KERNEL__ */
427427 #endif
include/linux/rculist_nulls.h+2−2
@@ -101,10 +101,10 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n, · 100 unmodified lines
101101 *
102102 */
103103 #define hlist_nulls_for_each_entry_rcu(tpos, pos, head, member) \
104− for (pos = rcu_dereference((head)->first); \
104+ for (pos = rcu_dereference_raw((head)->first); \
105105 (!is_a_nulls(pos)) && \
106106 ({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1; }); \
107− pos = rcu_dereference(pos->next))
107+ pos = rcu_dereference_raw(pos->next))
108108
109109 #endif
110110 #endif
include/linux/rcupdate.h+150−15
@@ -62,6 +62,8 @@ extern int sched_expedited_torture_stats(char *page); · 61 unmodified lines
6262
6363 /* Internal to kernel */
6464 extern void rcu_init(void);
65+extern int rcu_scheduler_active;
66+extern void rcu_scheduler_starting(void);
6567
6668 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
6769 #include <linux/rcutree.h>
@@ -78,14 +80,120 @@ extern void rcu_init(void); · 10 unmodified lines
7880 } while (0)
7981
8082 #ifdef CONFIG_DEBUG_LOCK_ALLOC
83+
8184 extern struct lockdep_map rcu_lock_map;
82−# define rcu_read_acquire() \
83− lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
85+# define rcu_read_acquire() \
86+ lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
8487 # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
85−#else
86−# define rcu_read_acquire() do { } while (0)
87−# define rcu_read_release() do { } while (0)
88−#endif
88+
89+extern struct lockdep_map rcu_bh_lock_map;
90+# define rcu_read_acquire_bh() \
91+ lock_acquire(&rcu_bh_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
92+# define rcu_read_release_bh() lock_release(&rcu_bh_lock_map, 1, _THIS_IP_)
93+
94+extern struct lockdep_map rcu_sched_lock_map;
95+# define rcu_read_acquire_sched() \
96+ lock_acquire(&rcu_sched_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
97+# define rcu_read_release_sched() \
98+ lock_release(&rcu_sched_lock_map, 1, _THIS_IP_)
99+
100+/**
101+ * rcu_read_lock_held - might we be in RCU read-side critical section?
102+ *
103+ * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in
104+ * an RCU read-side critical section. In absence of CONFIG_PROVE_LOCKING,
105+ * this assumes we are in an RCU read-side critical section unless it can
106+ * prove otherwise.
107+ */
108+static inline int rcu_read_lock_held(void)
109+{
110+ if (debug_locks)
111+ return lock_is_held(&rcu_lock_map);
112+ return 1;
113+}
114+
115+/**
116+ * rcu_read_lock_bh_held - might we be in RCU-bh read-side critical section?
117+ *
118+ * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in
119+ * an RCU-bh read-side critical section. In absence of CONFIG_PROVE_LOCKING,
120+ * this assumes we are in an RCU-bh read-side critical section unless it can
121+ * prove otherwise.
122+ */
123+static inline int rcu_read_lock_bh_held(void)
124+{
125+ if (debug_locks)
126+ return lock_is_held(&rcu_bh_lock_map);
127+ return 1;
128+}
129+
130+/**
131+ * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section?
132+ *
133+ * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in an
134+ * RCU-sched read-side critical section. In absence of CONFIG_PROVE_LOCKING,
135+ * this assumes we are in an RCU-sched read-side critical section unless it
136+ * can prove otherwise. Note that disabling of preemption (including
137+ * disabling irqs) counts as an RCU-sched read-side critical section.
138+ */
139+static inline int rcu_read_lock_sched_held(void)
140+{
141+ int lockdep_opinion = 0;
142+
143+ if (debug_locks)
144+ lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
145+ return lockdep_opinion || preempt_count() != 0 || !rcu_scheduler_active;
146+}
147+
148+#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
149+
150+# define rcu_read_acquire() do { } while (0)
151+# define rcu_read_release() do { } while (0)
152+# define rcu_read_acquire_bh() do { } while (0)
153+# define rcu_read_release_bh() do { } while (0)
154+# define rcu_read_acquire_sched() do { } while (0)
155+# define rcu_read_release_sched() do { } while (0)
156+
157+static inline int rcu_read_lock_held(void)
158+{
159+ return 1;
160+}
161+
162+static inline int rcu_read_lock_bh_held(void)
163+{
164+ return 1;
165+}
166+
167+static inline int rcu_read_lock_sched_held(void)
168+{
169+ return preempt_count() != 0 || !rcu_scheduler_active;
170+}
171+
172+#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
173+
174+#ifdef CONFIG_PROVE_RCU
175+
176+/**
177+ * rcu_dereference_check - rcu_dereference with debug checking
178+ *
179+ * Do an rcu_dereference(), but check that the context is correct.
180+ * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to
181+ * ensure that the rcu_dereference_check() executes within an RCU
182+ * read-side critical section. It is also possible to check for
183+ * locks being held, for example, by using lockdep_is_held().
184+ */
185+#define rcu_dereference_check(p, c) \
186+ ({ \
187+ if (debug_locks && !(c)) \
188+ lockdep_rcu_dereference(__FILE__, __LINE__); \
189+ rcu_dereference_raw(p); \
190+ })
191+
192+#else /* #ifdef CONFIG_PROVE_RCU */
193+
194+#define rcu_dereference_check(p, c) rcu_dereference_raw(p)
195+
196+#endif /* #else #ifdef CONFIG_PROVE_RCU */
89197
90198 /**
91199 * rcu_read_lock - mark the beginning of an RCU read-side critical section.
@@ -160,7 +268,7 @@ static inline void rcu_read_lock_bh(void) · 68 unmodified lines
160268 {
161269 __rcu_read_lock_bh();
162270 __acquire(RCU_BH);
163− rcu_read_acquire();
271+ rcu_read_acquire_bh();
164272 }
165273
166274 /*
@@ -170,7 +278,7 @@ static inline void rcu_read_lock_bh(void) · 3 unmodified lines
170278 */
171279 static inline void rcu_read_unlock_bh(void)
172280 {
173− rcu_read_release();
281+ rcu_read_release_bh();
174282 __release(RCU_BH);
175283 __rcu_read_unlock_bh();
176284 }
@@ -188,7 +296,7 @@ static inline void rcu_read_lock_sched(void) · 11 unmodified lines
188296 {
189297 preempt_disable();
190298 __acquire(RCU_SCHED);
191− rcu_read_acquire();
299+ rcu_read_acquire_sched();
192300 }
193301
194302 /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
@@ -205,7 +313,7 @@ static inline notrace void rcu_read_lock_sched_notrace(void) · 10 unmodified lines
205313 */
206314 static inline void rcu_read_unlock_sched(void)
207315 {
208− rcu_read_release();
316+ rcu_read_release_sched();
209317 __release(RCU_SCHED);
210318 preempt_enable();
211319 }
@@ -219,21 +327,48 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) · 7 unmodified lines
219327
220328
221329 /**
222− * rcu_dereference - fetch an RCU-protected pointer in an
223− * RCU read-side critical section. This pointer may later
224− * be safely dereferenced.
330+ * rcu_dereference_raw - fetch an RCU-protected pointer
331+ *
332+ * The caller must be within some flavor of RCU read-side critical
333+ * section, or must be otherwise preventing the pointer from changing,
334+ * for example, by holding an appropriate lock. This pointer may later
335+ * be safely dereferenced. It is the caller's responsibility to have
336+ * done the right thing, as this primitive does no checking of any kind.
225337 *
226338 * Inserts memory barriers on architectures that require them
227339 * (currently only the Alpha), and, more importantly, documents
228340 * exactly which pointers are protected by RCU.
229341 */
230−
231−#define rcu_dereference(p) ({ \
342+#define rcu_dereference_raw(p) ({ \
232343 typeof(p) _________p1 = ACCESS_ONCE(p); \
233344 smp_read_barrier_depends(); \
234345 (_________p1); \
235346 })
236347
348+/**
349+ * rcu_dereference - fetch an RCU-protected pointer, checking for RCU
350+ *
351+ * Makes rcu_dereference_check() do the dirty work.
352+ */
353+#define rcu_dereference(p) \
354+ rcu_dereference_check(p, rcu_read_lock_held())
355+
356+/**
357+ * rcu_dereference_bh - fetch an RCU-protected pointer, checking for RCU-bh
358+ *
359+ * Makes rcu_dereference_check() do the dirty work.
360+ */
361+#define rcu_dereference_bh(p) \
362+ rcu_dereference_check(p, rcu_read_lock_bh_held())
363+
364+/**
365+ * rcu_dereference_sched - fetch RCU-protected pointer, checking for RCU-sched
366+ *
367+ * Makes rcu_dereference_check() do the dirty work.
368+ */
369+#define rcu_dereference_sched(p) \
370+ rcu_dereference_check(p, rcu_read_lock_sched_held())
371+
237372 /**
238373 * rcu_assign_pointer - assign (publicize) a pointer to a newly
239374 * initialized structure that will be dereferenced by RCU read-side
include/linux/rcutiny.h+12−4
@@ -62,6 +62,18 @@ static inline long rcu_batches_completed_bh(void) · 61 unmodified lines
6262
6363 extern int rcu_expedited_torture_stats(char *page);
6464
65+static inline void rcu_force_quiescent_state(void)
66+{
67+}
68+
69+static inline void rcu_bh_force_quiescent_state(void)
70+{
71+}
72+
73+static inline void rcu_sched_force_quiescent_state(void)
74+{
75+}
76+
6577 #define synchronize_rcu synchronize_sched
6678
6779 static inline void synchronize_rcu_expedited(void)
@@ -93,10 +105,6 @@ static inline void rcu_exit_nohz(void) · 25 unmodified lines
93105
94106 #endif /* #else #ifdef CONFIG_NO_HZ */
95107
96−static inline void rcu_scheduler_starting(void)
97−{
98−}
99−
100108 static inline void exit_rcu(void)
101109 {
102110 }
include/linux/rcutree.h+3−1
@@ -35,7 +35,6 @@ struct notifier_block; · 34 unmodified lines
3535 extern void rcu_sched_qs(int cpu);
3636 extern void rcu_bh_qs(int cpu);
3737 extern int rcu_needs_cpu(int cpu);
38−extern void rcu_scheduler_starting(void);
3938 extern int rcu_expedited_torture_stats(char *page);
4039
4140 #ifdef CONFIG_TREE_PREEMPT_RCU
@@ -99,6 +98,9 @@ extern void rcu_check_callbacks(int cpu, int user); · 57 unmodified lines
9998 extern long rcu_batches_completed(void);
10099 extern long rcu_batches_completed_bh(void);
101100 extern long rcu_batches_completed_sched(void);
101+extern void rcu_force_quiescent_state(void);
102+extern void rcu_bh_force_quiescent_state(void);
103+extern void rcu_sched_force_quiescent_state(void);
102104
103105 #ifdef CONFIG_NO_HZ
104106 void rcu_enter_nohz(void);
include/linux/rtnetlink.h+3−0
@@ -735,6 +735,9 @@ extern void rtnl_lock(void); · 734 unmodified lines
735735 extern void rtnl_unlock(void);
736736 extern int rtnl_trylock(void);
737737 extern int rtnl_is_locked(void);
738+#ifdef CONFIG_PROVE_LOCKING
739+extern int lockdep_rtnl_is_held(void);
740+#endif /* #ifdef CONFIG_PROVE_LOCKING */
738741
739742 extern void rtnetlink_init(void);
740743 extern void __rtnl_unlock(void);
include/linux/srcu.h+93−2
@@ -35,6 +35,9 @@ struct srcu_struct { · 34 unmodified lines
3535 int completed;
3636 struct srcu_struct_array *per_cpu_ref;
3737 struct mutex mutex;
38+#ifdef CONFIG_DEBUG_LOCK_ALLOC
39+ struct lockdep_map dep_map;
40+#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
3841 };
3942
4043 #ifndef CONFIG_PREEMPT
@@ -43,12 +46,100 @@ struct srcu_struct { · 2 unmodified lines
4346 #define srcu_barrier()
4447 #endif /* #else #ifndef CONFIG_PREEMPT */
4548
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+
4668 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+
4775 void cleanup_srcu_struct(struct srcu_struct *sp);
48−int srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
49−void srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
76+int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
77+void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
5078 void synchronize_srcu(struct srcu_struct *sp);
5179 void synchronize_srcu_expedited(struct srcu_struct *sp);
5280 long srcu_batches_completed(struct srcu_struct *sp);
5381
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_dereference - fetch SRCU-protected pointer with checking
110+ *
111+ * Makes rcu_dereference_check() do the dirty work.
112+ */
113+#define srcu_dereference(p, sp) \
114+ rcu_dereference_check(p, srcu_read_lock_held(sp))
115+
116+/**
117+ * srcu_read_lock - register a new reader for an SRCU-protected structure.
118+ * @sp: srcu_struct in which to register the new reader.
119+ *
120+ * Enter an SRCU read-side critical section. Note that SRCU read-side
121+ * critical sections may be nested.
122+ */
123+static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp)
124+{
125+ int retval = __srcu_read_lock(sp);
126+
127+ srcu_read_acquire(sp);
128+ return retval;
129+}
130+
131+/**
132+ * srcu_read_unlock - unregister a old reader from an SRCU-protected structure.
133+ * @sp: srcu_struct in which to unregister the old reader.
134+ * @idx: return value from corresponding srcu_read_lock().
135+ *
136+ * Exit an SRCU read-side critical section.
137+ */
138+static inline void srcu_read_unlock(struct srcu_struct *sp, int idx)
139+ __releases(sp)
140+{
141+ srcu_read_release(sp);
142+ __srcu_read_unlock(sp, idx);
143+}
144+
54145 #endif
include/net/addrconf.h+3−1
@@ -177,7 +177,9 @@ extern int unregister_inet6addr_notifier(struct notifier_block *nb); · 176 unmodified lines
177177 static inline struct inet6_dev *
178178 __in6_dev_get(struct net_device *dev)
179179 {
180− return rcu_dereference(dev->ip6_ptr);
180+ return rcu_dereference_check(dev->ip6_ptr,
181+ rcu_read_lock_held() ||
182+ lockdep_rtnl_is_held());
181183 }
182184
183185 static inline struct inet6_dev *
init/Kconfig+16−0
@@ -396,6 +396,22 @@ config RCU_FANOUT_EXACT · 395 unmodified lines
396396
397397 Say N if unsure.
398398
399+config RCU_FAST_NO_HZ
400+ bool "Accelerate last non-dyntick-idle CPU's grace periods"
401+ depends on TREE_RCU && NO_HZ && SMP
402+ default n
403+ help
404+ This option causes RCU to attempt to accelerate grace periods
405+ in order to allow the final CPU to enter dynticks-idle state
406+ more quickly. On the other hand, this option increases the
407+ overhead of the dynticks-idle checking, particularly on systems
408+ with large numbers of CPUs.
409+
410+ Say Y if energy efficiency is critically important, particularly
411+ if you have relatively few CPUs.
412+
413+ Say N if you are unsure.
414+
399415 config TREE_RCU_TRACE
400416 def_bool RCU_TRACE && ( TREE_RCU || TREE_PREEMPT_RCU )
401417 select DEBUG_FS
init/main.c+2−0
@@ -416,7 +416,9 @@ static noinline void __init_refok rest_init(void) · 415 unmodified lines
416416 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
417417 numa_default_policy();
418418 pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
419+ rcu_read_lock();
419420 kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
421+ rcu_read_unlock();
420422 unlock_kernel();
421423
422424 /*
kernel/cgroup.c+15−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 */
2424
2525 #include <linux/cgroup.h>
26+#include <linux/module.h>
2627 #include <linux/ctype.h>
2728 #include <linux/errno.h>
2829 #include <linux/fs.h>
@@ -166,6 +167,20 @@ static DEFINE_SPINLOCK(hierarchy_id_lock); · 137 unmodified lines
166167 */
167168 static int need_forkexit_callback __read_mostly;
168169
170+#ifdef CONFIG_PROVE_LOCKING
171+int cgroup_lock_is_held(void)
172+{
173+ return lockdep_is_held(&cgroup_mutex);
174+}
175+#else /* #ifdef CONFIG_PROVE_LOCKING */
176+int cgroup_lock_is_held(void)
177+{
178+ return mutex_is_locked(&cgroup_mutex);
179+}
180+#endif /* #else #ifdef CONFIG_PROVE_LOCKING */
181+
182+EXPORT_SYMBOL_GPL(cgroup_lock_is_held);
183+
169184 /* convenient tests for these bits */
170185 inline int cgroup_is_removed(const struct cgroup *cgrp)
171186 {
kernel/exit.c+11−3
@@ -85,7 +85,9 @@ static void __exit_signal(struct task_struct *tsk) · 84 unmodified lines
8585 BUG_ON(!sig);
8686 BUG_ON(!atomic_read(&sig->count));
8787
88− sighand = rcu_dereference(tsk->sighand);
88+ sighand = rcu_dereference_check(tsk->sighand,
89+ rcu_read_lock_held() ||
90+ lockdep_is_held(&tasklist_lock));
8991 spin_lock(&sighand->siglock);
9092
9193 posix_cpu_timers_exit(tsk);
@@ -170,8 +172,10 @@ void release_task(struct task_struct * p) · 78 unmodified lines
170172 repeat:
171173 tracehook_prepare_release_task(p);
172174 /* don't need to get the RCU readlock here - the process is dead and
173− * can't be modifying its own credentials */
175+ * can't be modifying its own credentials. But shut RCU-lockdep up */
176+ rcu_read_lock();
174177 atomic_dec(&__task_cred(p)->user->processes);
178+ rcu_read_unlock();
175179
176180 proc_flush_task(p);
177181
@@ -473,9 +477,11 @@ static void close_files(struct files_struct * files) · 295 unmodified lines
473477 /*
474478 * It is safe to dereference the fd table without RCU or
475479 * ->file_lock because this is the last reference to the
476− * files structure.
480+ * files structure. But use RCU to shut RCU-lockdep up.
477481 */
482+ rcu_read_lock();
478483 fdt = files_fdtable(files);
484+ rcu_read_unlock();
479485 for (;;) {
480486 unsigned long set;
481487 i = j * __NFDBITS;
@@ -521,10 +527,12 @@ void put_files_struct(struct files_struct *files) · 39 unmodified lines
521527 * at the end of the RCU grace period. Otherwise,
522528 * you can free files immediately.
523529 */
530+ rcu_read_lock();
524531 fdt = files_fdtable(files);
525532 if (fdt != &files->fdtab)
526533 kmem_cache_free(files_cachep, files);
527534 free_fdtable(fdt);
535+ rcu_read_unlock();
528536 }
529537 }
530538
kernel/fork.c+1−0
@@ -86,6 +86,7 @@ int max_threads; /* tunable limit on nr_threads */ · 85 unmodified lines
8686 DEFINE_PER_CPU(unsigned long, process_counts) = 0;
8787
8888 __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
89+EXPORT_SYMBOL_GPL(tasklist_lock);
8990
9091 int nr_processes(void)
9192 {
kernel/lockdep.c+18−0
@@ -3809,3 +3809,21 @@ void lockdep_sys_exit(void) · 3808 unmodified lines
38093809 lockdep_print_held_locks(curr);
38103810 }
38113811 }
3812+
3813+void lockdep_rcu_dereference(const char *file, const int line)
3814+{
3815+ struct task_struct *curr = current;
3816+
3817+ if (!debug_locks_off())
3818+ return;
3819+ printk("\n===================================================\n");
3820+ printk( "[ INFO: suspicious rcu_dereference_check() usage. ]\n");
3821+ printk( "---------------------------------------------------\n");
3822+ printk("%s:%d invoked rcu_dereference_check() without protection!\n",
3823+ file, line);
3824+ printk("\nother info that might help us debug this:\n\n");
3825+ lockdep_print_held_locks(curr);
3826+ printk("\nstack backtrace:\n");
3827+ dump_stack();
3828+}
3829+EXPORT_SYMBOL_GPL(lockdep_rcu_dereference);
kernel/notifier.c+3−3
@@ -78,10 +78,10 @@ static int __kprobes notifier_call_chain(struct notifier_block **nl, · 77 unmodified lines
7878 int ret = NOTIFY_DONE;
7979 struct notifier_block *nb, *next_nb;
8080
81− nb = rcu_dereference(*nl);
81+ nb = rcu_dereference_raw(*nl);
8282
8383 while (nb && nr_to_call) {
84− next_nb = rcu_dereference(nb->next);
84+ next_nb = rcu_dereference_raw(nb->next);
8585
8686 #ifdef CONFIG_DEBUG_NOTIFIERS
8787 if (unlikely(!func_ptr_is_kernel_text(nb->notifier_call))) {
@@ -309,7 +309,7 @@ int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, · 221 unmodified lines
309309 * racy then it does not matter what the result of the test
310310 * is, we re-check the list after having taken the lock anyway:
311311 */
312− if (rcu_dereference(nh->head)) {
312+ if (rcu_dereference_raw(nh->head)) {
313313 down_read(&nh->rwsem);
314314 ret = notifier_call_chain(&nh->head, val, v, nr_to_call,
315315 nr_calls);
kernel/pid.c+1−1
@@ -367,7 +367,7 @@ struct task_struct *pid_task(struct pid *pid, enum pid_type type) · 366 unmodified lines
367367 struct task_struct *result = NULL;
368368 if (pid) {
369369 struct hlist_node *first;
370− first = rcu_dereference(pid->tasks[type].first);
370+ first = rcu_dereference_check(pid->tasks[type].first, rcu_read_lock_held() || lockdep_is_held(&tasklist_lock));
371371 if (first)
372372 result = hlist_entry(first, struct task_struct, pids[(type)].node);
373373 }
kernel/rcupdate.c+29−0
@@ -44,14 +44,43 @@ · 43 unmodified lines
4444 #include <linux/cpu.h>
4545 #include <linux/mutex.h>
4646 #include <linux/module.h>
47+#include <linux/kernel_stat.h>
4748
4849 #ifdef CONFIG_DEBUG_LOCK_ALLOC
4950 static struct lock_class_key rcu_lock_key;
5051 struct lockdep_map rcu_lock_map =
5152 STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);
5253 EXPORT_SYMBOL_GPL(rcu_lock_map);
54+
55+static struct lock_class_key rcu_bh_lock_key;
56+struct lockdep_map rcu_bh_lock_map =
57+ STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_bh", &rcu_bh_lock_key);
58+EXPORT_SYMBOL_GPL(rcu_bh_lock_map);
59+
60+static struct lock_class_key rcu_sched_lock_key;
61+struct lockdep_map rcu_sched_lock_map =
62+ STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_sched", &rcu_sched_lock_key);
63+EXPORT_SYMBOL_GPL(rcu_sched_lock_map);
5364 #endif
5465
66+int rcu_scheduler_active __read_mostly;
67+EXPORT_SYMBOL_GPL(rcu_scheduler_active);
68+
69+/*
70+ * This function is invoked towards the end of the scheduler's initialization
71+ * process. Before this is called, the idle task might contain
72+ * RCU read-side critical sections (during which time, this idle
73+ * task is booting the system). After this function is called, the
74+ * idle tasks are prohibited from containing RCU read-side critical
75+ * sections.
76+ */
77+void rcu_scheduler_starting(void)
78+{
79+ WARN_ON(num_online_cpus() != 1);
80+ WARN_ON(nr_context_switches() > 0);
81+ rcu_scheduler_active = 1;
82+}
83+
5584 /*
5685 * Awaken the corresponding synchronize_rcu() instance now that a
5786 * grace period has elapsed.
kernel/rcutorture.c+89−5
@@ -61,6 +61,9 @@ static int test_no_idle_hz; /* Test RCU's support for tickless idle CPUs. */ · 60 unmodified lines
6161 static int shuffle_interval = 3; /* Interval between shuffles (in sec)*/
6262 static int stutter = 5; /* Start/stop testing interval (in sec) */
6363 static int irqreader = 1; /* RCU readers from irq (timers). */
64+static int fqs_duration = 0; /* Duration of bursts (us), 0 to disable. */
65+static int fqs_holdoff = 0; /* Hold time within burst (us). */
66+static int fqs_stutter = 3; /* Wait time between bursts (s). */
6467 static char *torture_type = "rcu"; /* What RCU implementation to torture. */
6568
6669 module_param(nreaders, int, 0444);
@@ -79,6 +82,12 @@ module_param(stutter, int, 0444); · 12 unmodified lines
7982 MODULE_PARM_DESC(stutter, "Number of seconds to run/halt test");
8083 module_param(irqreader, int, 0444);
8184 MODULE_PARM_DESC(irqreader, "Allow RCU readers from irq handlers");
85+module_param(fqs_duration, int, 0444);
86+MODULE_PARM_DESC(fqs_duration, "Duration of fqs bursts (us)");
87+module_param(fqs_holdoff, int, 0444);
88+MODULE_PARM_DESC(fqs_holdoff, "Holdoff time within fqs bursts (us)");
89+module_param(fqs_stutter, int, 0444);
90+MODULE_PARM_DESC(fqs_stutter, "Wait time between fqs bursts (s)");
8291 module_param(torture_type, charp, 0444);
8392 MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, srcu)");
8493
@@ -99,6 +108,7 @@ static struct task_struct **reader_tasks; · 14 unmodified lines
99108 static struct task_struct *stats_task;
100109 static struct task_struct *shuffler_task;
101110 static struct task_struct *stutter_task;
111+static struct task_struct *fqs_task;
102112
103113 #define RCU_TORTURE_PIPE_LEN 10
104114
@@ -263,6 +273,7 @@ struct rcu_torture_ops { · 158 unmodified lines
263273 void (*deferred_free)(struct rcu_torture *p);
264274 void (*sync)(void);
265275 void (*cb_barrier)(void);
276+ void (*fqs)(void);
266277 int (*stats)(char *page);
267278 int irq_capable;
268279 char *name;
@@ -347,6 +358,7 @@ static struct rcu_torture_ops rcu_ops = { · 78 unmodified lines
347358 .deferred_free = rcu_torture_deferred_free,
348359 .sync = synchronize_rcu,
349360 .cb_barrier = rcu_barrier,
361+ .fqs = rcu_force_quiescent_state,
350362 .stats = NULL,
351363 .irq_capable = 1,
352364 .name = "rcu"
@@ -388,6 +400,7 @@ static struct rcu_torture_ops rcu_sync_ops = { · 35 unmodified lines
388400 .deferred_free = rcu_sync_torture_deferred_free,
389401 .sync = synchronize_rcu,
390402 .cb_barrier = NULL,
403+ .fqs = rcu_force_quiescent_state,
391404 .stats = NULL,
392405 .irq_capable = 1,
393406 .name = "rcu_sync"
@@ -403,6 +416,7 @@ static struct rcu_torture_ops rcu_expedited_ops = { · 9 unmodified lines
403416 .deferred_free = rcu_sync_torture_deferred_free,
404417 .sync = synchronize_rcu_expedited,
405418 .cb_barrier = NULL,
419+ .fqs = rcu_force_quiescent_state,
406420 .stats = NULL,
407421 .irq_capable = 1,
408422 .name = "rcu_expedited"
@@ -465,6 +479,7 @@ static struct rcu_torture_ops rcu_bh_ops = { · 56 unmodified lines
465479 .deferred_free = rcu_bh_torture_deferred_free,
466480 .sync = rcu_bh_torture_synchronize,
467481 .cb_barrier = rcu_barrier_bh,
482+ .fqs = rcu_bh_force_quiescent_state,
468483 .stats = NULL,
469484 .irq_capable = 1,
470485 .name = "rcu_bh"
@@ -480,6 +495,7 @@ static struct rcu_torture_ops rcu_bh_sync_ops = { · 9 unmodified lines
480495 .deferred_free = rcu_sync_torture_deferred_free,
481496 .sync = rcu_bh_torture_synchronize,
482497 .cb_barrier = NULL,
498+ .fqs = rcu_bh_force_quiescent_state,
483499 .stats = NULL,
484500 .irq_capable = 1,
485501 .name = "rcu_bh_sync"
@@ -621,6 +637,7 @@ static struct rcu_torture_ops sched_ops = { · 135 unmodified lines
621637 .deferred_free = rcu_sched_torture_deferred_free,
622638 .sync = sched_torture_synchronize,
623639 .cb_barrier = rcu_barrier_sched,
640+ .fqs = rcu_sched_force_quiescent_state,
624641 .stats = NULL,
625642 .irq_capable = 1,
626643 .name = "sched"
@@ -636,6 +653,7 @@ static struct rcu_torture_ops sched_sync_ops = { · 9 unmodified lines
636653 .deferred_free = rcu_sync_torture_deferred_free,
637654 .sync = sched_torture_synchronize,
638655 .cb_barrier = NULL,
656+ .fqs = rcu_sched_force_quiescent_state,
639657 .stats = NULL,
640658 .name = "sched_sync"
641659 };
@@ -650,11 +668,44 @@ static struct rcu_torture_ops sched_expedited_ops = { · 8 unmodified lines
650668 .deferred_free = rcu_sync_torture_deferred_free,
651669 .sync = synchronize_sched_expedited,
652670 .cb_barrier = NULL,
671+ .fqs = rcu_sched_force_quiescent_state,
653672 .stats = rcu_expedited_torture_stats,
654673 .irq_capable = 1,
655674 .name = "sched_expedited"
656675 };
657676
677+/*
678+ * RCU torture force-quiescent-state kthread. Repeatedly induces
679+ * bursts of calls to force_quiescent_state(), increasing the probability
680+ * of occurrence of some important types of race conditions.
681+ */
682+static int
683+rcu_torture_fqs(void *arg)
684+{
685+ unsigned long fqs_resume_time;
686+ int fqs_burst_remaining;
687+
688+ VERBOSE_PRINTK_STRING("rcu_torture_fqs task started");
689+ do {
690+ fqs_resume_time = jiffies + fqs_stutter * HZ;
691+ while (jiffies - fqs_resume_time > LONG_MAX) {
692+ schedule_timeout_interruptible(1);
693+ }
694+ fqs_burst_remaining = fqs_duration;
695+ while (fqs_burst_remaining > 0) {
696+ cur_ops->fqs();
697+ udelay(fqs_holdoff);
698+ fqs_burst_remaining -= fqs_holdoff;
699+ }
700+ rcu_stutter_wait("rcu_torture_fqs");
701+ } while (!kthread_should_stop() && fullstop == FULLSTOP_DONTSTOP);
702+ VERBOSE_PRINTK_STRING("rcu_torture_fqs task stopping");
703+ rcutorture_shutdown_absorb("rcu_torture_fqs");
704+ while (!kthread_should_stop())
705+ schedule_timeout_uninterruptible(1);
706+ return 0;
707+}
708+
658709 /*
659710 * RCU torture writer kthread. Repeatedly substitutes a new structure
660711 * for that pointed to by rcu_torture_current, freeing the old structure
@@ -745,7 +796,11 @@ static void rcu_torture_timer(unsigned long unused) · 84 unmodified lines
745796
746797 idx = cur_ops->readlock();
747798 completed = cur_ops->completed();
748− p = rcu_dereference(rcu_torture_current);
799+ p = rcu_dereference_check(rcu_torture_current,
800+ rcu_read_lock_held() ||
801+ rcu_read_lock_bh_held() ||
802+ rcu_read_lock_sched_held() ||
803+ srcu_read_lock_held(&srcu_ctl));
749804 if (p == NULL) {
750805 /* Leave because rcu_torture_writer is not yet underway */
751806 cur_ops->readunlock(idx);
@@ -798,11 +853,15 @@ rcu_torture_reader(void *arg) · 46 unmodified lines
798853 do {
799854 if (irqreader && cur_ops->irq_capable) {
800855 if (!timer_pending(&t))
801− mod_timer(&t, 1);
856+ mod_timer(&t, jiffies + 1);
802857 }
803858 idx = cur_ops->readlock();
804859 completed = cur_ops->completed();
805− p = rcu_dereference(rcu_torture_current);
860+ p = rcu_dereference_check(rcu_torture_current,
861+ rcu_read_lock_held() ||
862+ rcu_read_lock_bh_held() ||
863+ rcu_read_lock_sched_held() ||
864+ srcu_read_lock_held(&srcu_ctl));
806865 if (p == NULL) {
807866 /* Wait for rcu_torture_writer to get underway */
808867 cur_ops->readunlock(idx);
@@ -1030,10 +1089,11 @@ rcu_torture_print_module_parms(char *tag) · 221 unmodified lines
10301089 printk(KERN_ALERT "%s" TORTURE_FLAG
10311090 "--- %s: nreaders=%d nfakewriters=%d "
10321091 "stat_interval=%d verbose=%d test_no_idle_hz=%d "
1033− "shuffle_interval=%d stutter=%d irqreader=%d\n",
1092+ "shuffle_interval=%d stutter=%d irqreader=%d "
1093+ "fqs_duration=%d fqs_holdoff=%d fqs_stutter=%d\n",
10341094 torture_type, tag, nrealreaders, nfakewriters,
10351095 stat_interval, verbose, test_no_idle_hz, shuffle_interval,
1036− stutter, irqreader);
1096+ stutter, irqreader, fqs_duration, fqs_holdoff, fqs_stutter);
10371097 }
10381098
10391099 static struct notifier_block rcutorture_nb = {
@@ -1109,6 +1169,12 @@ rcu_torture_cleanup(void) · 69 unmodified lines
11091169 }
11101170 stats_task = NULL;
11111171
1172+ if (fqs_task) {
1173+ VERBOSE_PRINTK_STRING("Stopping rcu_torture_fqs task");
1174+ kthread_stop(fqs_task);
1175+ }
1176+ fqs_task = NULL;
1177+
11121178 /* Wait for all RCU callbacks to fire. */
11131179
11141180 if (cur_ops->cb_barrier != NULL)
@@ -1154,6 +1220,11 @@ rcu_torture_init(void) · 39 unmodified lines
11541220 mutex_unlock(&fullstop_mutex);
11551221 return -EINVAL;
11561222 }
1223+ if (cur_ops->fqs == NULL && fqs_duration != 0) {
1224+ printk(KERN_ALERT "rcu-torture: ->fqs NULL and non-zero "
1225+ "fqs_duration, fqs disabled.\n");
1226+ fqs_duration = 0;
1227+ }
11571228 if (cur_ops->init)
11581229 cur_ops->init(); /* no "goto unwind" prior to this point!!! */
11591230
@@ -1282,6 +1353,19 @@ rcu_torture_init(void) · 122 unmodified lines
12821353 goto unwind;
12831354 }
12841355 }
1356+ if (fqs_duration < 0)
1357+ fqs_duration = 0;
1358+ if (fqs_duration) {
1359+ /* Create the stutter thread */
1360+ fqs_task = kthread_run(rcu_torture_fqs, NULL,
1361+ "rcu_torture_fqs");
1362+ if (IS_ERR(fqs_task)) {
1363+ firsterr = PTR_ERR(fqs_task);
1364+ VERBOSE_PRINTK_ERRSTRING("Failed to create fqs");
1365+ fqs_task = NULL;
1366+ goto unwind;
1367+ }
1368+ }
12851369 register_reboot_notifier(&rcutorture_nb);
12861370 mutex_unlock(&fullstop_mutex);
12871371 return 0;
kernel/rcutree.c+134−134
@@ -46,7 +46,6 @@ · 45 unmodified lines
4646 #include <linux/cpu.h>
4747 #include <linux/mutex.h>
4848 #include <linux/time.h>
49−#include <linux/kernel_stat.h>
5049
5150 #include "rcutree.h"
5251
@@ -66,11 +65,11 @@ static struct lock_class_key rcu_node_class[NUM_RCU_LVLS]; · 13 unmodified lines
6665 .signaled = RCU_GP_IDLE, \
6766 .gpnum = -300, \
6867 .completed = -300, \
69− .onofflock = __SPIN_LOCK_UNLOCKED(&name.onofflock), \
68+ .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&name.onofflock), \
7069 .orphan_cbs_list = NULL, \
7170 .orphan_cbs_tail = &name.orphan_cbs_list, \
7271 .orphan_qlen = 0, \
73− .fqslock = __SPIN_LOCK_UNLOCKED(&name.fqslock), \
72+ .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&name.fqslock), \
7473 .n_force_qs = 0, \
7574 .n_force_qs_ngp = 0, \
7675 }
@@ -81,9 +80,6 @@ DEFINE_PER_CPU(struct rcu_data, rcu_sched_data); · 4 unmodified lines
8180 struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state);
8281 DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
8382
84−static int rcu_scheduler_active __read_mostly;
85−
86−
8783 /*
8884 * Return true if an RCU grace period is in progress. The ACCESS_ONCE()s
8985 * permit this function to be invoked without holding the root rcu_node
@@ -156,6 +152,24 @@ long rcu_batches_completed_bh(void) · 66 unmodified lines
156152 }
157153 EXPORT_SYMBOL_GPL(rcu_batches_completed_bh);
158154
155+/*
156+ * Force a quiescent state for RCU BH.
157+ */
158+void rcu_bh_force_quiescent_state(void)
159+{
160+ force_quiescent_state(&rcu_bh_state, 0);
161+}
162+EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
163+
164+/*
165+ * Force a quiescent state for RCU-sched.
166+ */
167+void rcu_sched_force_quiescent_state(void)
168+{
169+ force_quiescent_state(&rcu_sched_state, 0);
170+}
171+EXPORT_SYMBOL_GPL(rcu_sched_force_quiescent_state);
172+
159173 /*
160174 * Does the CPU have callbacks ready to be invoked?
161175 */
@@ -439,10 +453,10 @@ static void print_other_cpu_stall(struct rcu_state *rsp) · 277 unmodified lines
439453
440454 /* Only let one CPU complain about others per time interval. */
441455
442− spin_lock_irqsave(&rnp->lock, flags);
456+ raw_spin_lock_irqsave(&rnp->lock, flags);
443457 delta = jiffies - rsp->jiffies_stall;
444458 if (delta < RCU_STALL_RAT_DELAY || !rcu_gp_in_progress(rsp)) {
445− spin_unlock_irqrestore(&rnp->lock, flags);
459+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
446460 return;
447461 }
448462 rsp->jiffies_stall = jiffies + RCU_SECONDS_TILL_STALL_RECHECK;
@@ -452,13 +466,15 @@ static void print_other_cpu_stall(struct rcu_state *rsp) · 3 unmodified lines
452466 * due to CPU offlining.
453467 */
454468 rcu_print_task_stall(rnp);
455− spin_unlock_irqrestore(&rnp->lock, flags);
469+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
456470
457471 /* OK, time to rat on our buddy... */
458472
459473 printk(KERN_ERR "INFO: RCU detected CPU stalls:");
460474 rcu_for_each_leaf_node(rsp, rnp) {
475+ raw_spin_lock_irqsave(&rnp->lock, flags);
461476 rcu_print_task_stall(rnp);
477+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
462478 if (rnp->qsmask == 0)
463479 continue;
464480 for (cpu = 0; cpu <= rnp->grphi - rnp->grplo; cpu++)
@@ -469,6 +485,10 @@ static void print_other_cpu_stall(struct rcu_state *rsp) · 4 unmodified lines
469485 smp_processor_id(), (long)(jiffies - rsp->gp_start));
470486 trigger_all_cpu_backtrace();
471487
488+ /* If so configured, complain about tasks blocking the grace period. */
489+
490+ rcu_print_detail_task_stall(rsp);
491+
472492 force_quiescent_state(rsp, 0); /* Kick them all. */
473493 }
474494
@@ -481,11 +501,11 @@ static void print_cpu_stall(struct rcu_state *rsp) · 6 unmodified lines
481501 smp_processor_id(), jiffies - rsp->gp_start);
482502 trigger_all_cpu_backtrace();
483503
484− spin_lock_irqsave(&rnp->lock, flags);
485− if ((long)(jiffies - rsp->jiffies_stall) >= 0)
504+ raw_spin_lock_irqsave(&rnp->lock, flags);
505+ if (ULONG_CMP_GE(jiffies, rsp->jiffies_stall))
486506 rsp->jiffies_stall =
487507 jiffies + RCU_SECONDS_TILL_STALL_RECHECK;
488− spin_unlock_irqrestore(&rnp->lock, flags);
508+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
489509
490510 set_need_resched(); /* kick ourselves to get things going. */
491511 }
@@ -545,12 +565,12 @@ static void note_new_gpnum(struct rcu_state *rsp, struct rcu_data *rdp) · 53 unmodified lines
545565 local_irq_save(flags);
546566 rnp = rdp->mynode;
547567 if (rdp->gpnum == ACCESS_ONCE(rnp->gpnum) || /* outside lock. */
548− !spin_trylock(&rnp->lock)) { /* irqs already off, retry later. */
568+ !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
549569 local_irq_restore(flags);
550570 return;
551571 }
552572 __note_new_gpnum(rsp, rnp, rdp);
553− spin_unlock_irqrestore(&rnp->lock, flags);
573+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
554574 }
555575
556576 /*
@@ -609,12 +629,12 @@ rcu_process_gp_end(struct rcu_state *rsp, struct rcu_data *rdp) · 52 unmodified lines
609629 local_irq_save(flags);
610630 rnp = rdp->mynode;
611631 if (rdp->completed == ACCESS_ONCE(rnp->completed) || /* outside lock. */
612− !spin_trylock(&rnp->lock)) { /* irqs already off, retry later. */
632+ !raw_spin_trylock(&rnp->lock)) { /* irqs already off, so later. */
613633 local_irq_restore(flags);
614634 return;
615635 }
616636 __rcu_process_gp_end(rsp, rnp, rdp);
617− spin_unlock_irqrestore(&rnp->lock, flags);
637+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
618638 }
619639
620640 /*
@@ -659,12 +679,14 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) · 38 unmodified lines
659679 struct rcu_data *rdp = rsp->rda[smp_processor_id()];
660680 struct rcu_node *rnp = rcu_get_root(rsp);
661681
662− if (!cpu_needs_another_gp(rsp, rdp)) {
682+ if (!cpu_needs_another_gp(rsp, rdp) || rsp->fqs_active) {
683+ if (cpu_needs_another_gp(rsp, rdp))
684+ rsp->fqs_need_gp = 1;
663685 if (rnp->completed == rsp->completed) {
664− spin_unlock_irqrestore(&rnp->lock, flags);
686+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
665687 return;
666688 }
667− spin_unlock(&rnp->lock); /* irqs remain disabled. */
689+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
668690
669691 /*
670692 * Propagate new ->completed value to rcu_node structures
@@ -672,9 +694,9 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) · 1 unmodified line
672694 * of the next grace period to process their callbacks.
673695 */
674696 rcu_for_each_node_breadth_first(rsp, rnp) {
675− spin_lock(&rnp->lock); /* irqs already disabled. */
697+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
676698 rnp->completed = rsp->completed;
677− spin_unlock(&rnp->lock); /* irqs remain disabled. */
699+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
678700 }
679701 local_irq_restore(flags);
680702 return;
@@ -695,15 +717,15 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) · 14 unmodified lines
695717 rnp->completed = rsp->completed;
696718 rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state OK. */
697719 rcu_start_gp_per_cpu(rsp, rnp, rdp);
698− spin_unlock_irqrestore(&rnp->lock, flags);
720+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
699721 return;
700722 }
701723
702− spin_unlock(&rnp->lock); /* leave irqs disabled. */
724+ raw_spin_unlock(&rnp->lock); /* leave irqs disabled. */
703725
704726
705727 /* Exclude any concurrent CPU-hotplug operations. */
706− spin_lock(&rsp->onofflock); /* irqs already disabled. */
728+ raw_spin_lock(&rsp->onofflock); /* irqs already disabled. */
707729
708730 /*
709731 * Set the quiescent-state-needed bits in all the rcu_node
@@ -723,21 +745,21 @@ rcu_start_gp(struct rcu_state *rsp, unsigned long flags) · 13 unmodified lines
723745 * irqs disabled.
724746 */
725747 rcu_for_each_node_breadth_first(rsp, rnp) {
726− spin_lock(&rnp->lock); /* irqs already disabled. */
748+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
727749 rcu_preempt_check_blocked_tasks(rnp);
728750 rnp->qsmask = rnp->qsmaskinit;
729751 rnp->gpnum = rsp->gpnum;
730752 rnp->completed = rsp->completed;
731753 if (rnp == rdp->mynode)
732754 rcu_start_gp_per_cpu(rsp, rnp, rdp);
733− spin_unlock(&rnp->lock); /* irqs remain disabled. */
755+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
734756 }
735757
736758 rnp = rcu_get_root(rsp);
737− spin_lock(&rnp->lock); /* irqs already disabled. */
759+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
738760 rsp->signaled = RCU_SIGNAL_INIT; /* force_quiescent_state now OK. */
739− spin_unlock(&rnp->lock); /* irqs remain disabled. */
740− spin_unlock_irqrestore(&rsp->onofflock, flags);
761+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
762+ raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
741763 }
742764
743765 /*
@@ -776,14 +798,14 @@ rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp, · 32 unmodified lines
776798 if (!(rnp->qsmask & mask)) {
777799
778800 /* Our bit has already been cleared, so done. */
779− spin_unlock_irqrestore(&rnp->lock, flags);
801+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
780802 return;
781803 }
782804 rnp->qsmask &= ~mask;
783805 if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) {
784806
785807 /* Other bits still set at this level, so done. */
786− spin_unlock_irqrestore(&rnp->lock, flags);
808+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
787809 return;
788810 }
789811 mask = rnp->grpmask;
@@ -793,10 +815,10 @@ rcu_report_qs_rnp(unsigned long mask, struct rcu_state *rsp, · 3 unmodified lines
793815
794816 break;
795817 }
796− spin_unlock_irqrestore(&rnp->lock, flags);
818+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
797819 rnp_c = rnp;
798820 rnp = rnp->parent;
799− spin_lock_irqsave(&rnp->lock, flags);
821+ raw_spin_lock_irqsave(&rnp->lock, flags);
800822 WARN_ON_ONCE(rnp_c->qsmask);
801823 }
802824
@@ -825,7 +847,7 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long las · 22 unmodified lines
825847 struct rcu_node *rnp;
826848
827849 rnp = rdp->mynode;
828− spin_lock_irqsave(&rnp->lock, flags);
850+ raw_spin_lock_irqsave(&rnp->lock, flags);
829851 if (lastcomp != rnp->completed) {
830852
831853 /*
@@ -837,12 +859,12 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp, long las · 5 unmodified lines
837859 * race occurred.
838860 */
839861 rdp->passed_quiesc = 0; /* try again later! */
840− spin_unlock_irqrestore(&rnp->lock, flags);
862+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
841863 return;
842864 }
843865 mask = rdp->grpmask;
844866 if ((rnp->qsmask & mask) == 0) {
845− spin_unlock_irqrestore(&rnp->lock, flags);
867+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
846868 } else {
847869 rdp->qs_pending = 0;
848870
@@ -906,7 +928,7 @@ static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) · 57 unmodified lines
906928
907929 if (rdp->nxtlist == NULL)
908930 return; /* irqs disabled, so comparison is stable. */
909− spin_lock(&rsp->onofflock); /* irqs already disabled. */
931+ raw_spin_lock(&rsp->onofflock); /* irqs already disabled. */
910932 *rsp->orphan_cbs_tail = rdp->nxtlist;
911933 rsp->orphan_cbs_tail = rdp->nxttail[RCU_NEXT_TAIL];
912934 rdp->nxtlist = NULL;
@@ -914,7 +936,7 @@ static void rcu_send_cbs_to_orphanage(struct rcu_state *rsp) · 1 unmodified line
914936 rdp->nxttail[i] = &rdp->nxtlist;
915937 rsp->orphan_qlen += rdp->qlen;
916938 rdp->qlen = 0;
917− spin_unlock(&rsp->onofflock); /* irqs remain disabled. */
939+ raw_spin_unlock(&rsp->onofflock); /* irqs remain disabled. */
918940 }
919941
920942 /*
@@ -925,10 +947,10 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) · 4 unmodified lines
925947 unsigned long flags;
926948 struct rcu_data *rdp;
927949
928− spin_lock_irqsave(&rsp->onofflock, flags);
950+ raw_spin_lock_irqsave(&rsp->onofflock, flags);
929951 rdp = rsp->rda[smp_processor_id()];
930952 if (rsp->orphan_cbs_list == NULL) {
931− spin_unlock_irqrestore(&rsp->onofflock, flags);
953+ raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
932954 return;
933955 }
934956 *rdp->nxttail[RCU_NEXT_TAIL] = rsp->orphan_cbs_list;
@@ -937,7 +959,7 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp) · 2 unmodified lines
937959 rsp->orphan_cbs_list = NULL;
938960 rsp->orphan_cbs_tail = &rsp->orphan_cbs_list;
939961 rsp->orphan_qlen = 0;
940− spin_unlock_irqrestore(&rsp->onofflock, flags);
962+ raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
941963 }
942964
943965 /*
@@ -953,23 +975,23 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) · 9 unmodified lines
953975 struct rcu_node *rnp;
954976
955977 /* Exclude any attempts to start a new grace period. */
956− spin_lock_irqsave(&rsp->onofflock, flags);
978+ raw_spin_lock_irqsave(&rsp->onofflock, flags);
957979
958980 /* Remove the outgoing CPU from the masks in the rcu_node hierarchy. */
959981 rnp = rdp->mynode; /* this is the outgoing CPU's rnp. */
960982 mask = rdp->grpmask; /* rnp->grplo is constant. */
961983 do {
962− spin_lock(&rnp->lock); /* irqs already disabled. */
984+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
963985 rnp->qsmaskinit &= ~mask;
964986 if (rnp->qsmaskinit != 0) {
965987 if (rnp != rdp->mynode)
966− spin_unlock(&rnp->lock); /* irqs remain disabled. */
988+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
967989 break;
968990 }
969991 if (rnp == rdp->mynode)
970992 need_report = rcu_preempt_offline_tasks(rsp, rnp, rdp);
971993 else
972− spin_unlock(&rnp->lock); /* irqs remain disabled. */
994+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
973995 mask = rnp->grpmask;
974996 rnp = rnp->parent;
975997 } while (rnp != NULL);
@@ -980,12 +1002,12 @@ static void __rcu_offline_cpu(int cpu, struct rcu_state *rsp) · 4 unmodified lines
9801002 * because invoking rcu_report_unblock_qs_rnp() with ->onofflock
9811003 * held leads to deadlock.
9821004 */
983− spin_unlock(&rsp->onofflock); /* irqs remain disabled. */
1005+ raw_spin_unlock(&rsp->onofflock); /* irqs remain disabled. */
9841006 rnp = rdp->mynode;
9851007 if (need_report & RCU_OFL_TASKS_NORM_GP)
9861008 rcu_report_unblock_qs_rnp(rnp, flags);
9871009 else
988− spin_unlock_irqrestore(&rnp->lock, flags);
1010+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
9891011 if (need_report & RCU_OFL_TASKS_EXP_GP)
9901012 rcu_report_exp_rnp(rsp, rnp);
9911013
@@ -1144,11 +1166,9 @@ void rcu_check_callbacks(int cpu, int user) · 152 unmodified lines
11441166 /*
11451167 * Scan the leaf rcu_node structures, processing dyntick state for any that
11461168 * have not yet encountered a quiescent state, using the function specified.
1147− * Returns 1 if the current grace period ends while scanning (possibly
1148− * because we made it end).
1169+ * The caller must have suppressed start of new grace periods.
11491170 */
1150−static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp,
1151− int (*f)(struct rcu_data *))
1171+static void force_qs_rnp(struct rcu_state *rsp, int (*f)(struct rcu_data *))
11521172 {
11531173 unsigned long bit;
11541174 int cpu;
@@ -1158,13 +1178,13 @@ static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp, · 3 unmodified lines
11581178
11591179 rcu_for_each_leaf_node(rsp, rnp) {
11601180 mask = 0;
1161− spin_lock_irqsave(&rnp->lock, flags);
1162− if (rnp->completed != lastcomp) {
1163− spin_unlock_irqrestore(&rnp->lock, flags);
1164− return 1;
1181+ raw_spin_lock_irqsave(&rnp->lock, flags);
1182+ if (!rcu_gp_in_progress(rsp)) {
1183+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
1184+ return;
11651185 }
11661186 if (rnp->qsmask == 0) {
1167− spin_unlock_irqrestore(&rnp->lock, flags);
1187+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
11681188 continue;
11691189 }
11701190 cpu = rnp->grplo;
@@ -1173,15 +1193,14 @@ static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp, · 2 unmodified lines
11731193 if ((rnp->qsmask & bit) != 0 && f(rsp->rda[cpu]))
11741194 mask |= bit;
11751195 }
1176− if (mask != 0 && rnp->completed == lastcomp) {
1196+ if (mask != 0) {
11771197
11781198 /* rcu_report_qs_rnp() releases rnp->lock. */
11791199 rcu_report_qs_rnp(mask, rsp, rnp, flags);
11801200 continue;
11811201 }
1182− spin_unlock_irqrestore(&rnp->lock, flags);
1202+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
11831203 }
1184− return 0;
11851204 }
11861205
11871206 /*
@@ -1191,32 +1210,26 @@ static int rcu_process_dyntick(struct rcu_state *rsp, long lastcomp, · 3 unmodified lines
11911210 static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
11921211 {
11931212 unsigned long flags;
1194− long lastcomp;
11951213 struct rcu_node *rnp = rcu_get_root(rsp);
1196− u8 signaled;
1197− u8 forcenow;
11981214
11991215 if (!rcu_gp_in_progress(rsp))
12001216 return; /* No grace period in progress, nothing to force. */
1201− if (!spin_trylock_irqsave(&rsp->fqslock, flags)) {
1217+ if (!raw_spin_trylock_irqsave(&rsp->fqslock, flags)) {
12021218 rsp->n_force_qs_lh++; /* Inexact, can lose counts. Tough! */
12031219 return; /* Someone else is already on the job. */
12041220 }
1205− if (relaxed &&
1206− (long)(rsp->jiffies_force_qs - jiffies) >= 0)
1207− goto unlock_ret; /* no emergency and done recently. */
1221+ if (relaxed && ULONG_CMP_GE(rsp->jiffies_force_qs, jiffies))
1222+ goto unlock_fqs_ret; /* no emergency and done recently. */
12081223 rsp->n_force_qs++;
1209− spin_lock(&rnp->lock);
1210− lastcomp = rsp->gpnum - 1;
1211− signaled = rsp->signaled;
1224+ raw_spin_lock(&rnp->lock); /* irqs already disabled */
12121225 rsp->jiffies_force_qs = jiffies + RCU_JIFFIES_TILL_FORCE_QS;
12131226 if(!rcu_gp_in_progress(rsp)) {
12141227 rsp->n_force_qs_ngp++;
1215− spin_unlock(&rnp->lock);
1216− goto unlock_ret; /* no GP in progress, time updated. */
1228+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1229+ goto unlock_fqs_ret; /* no GP in progress, time updated. */
12171230 }
1218− spin_unlock(&rnp->lock);
1219− switch (signaled) {
1231+ rsp->fqs_active = 1;
1232+ switch (rsp->signaled) {
12201233 case RCU_GP_IDLE:
12211234 case RCU_GP_INIT:
12221235
@@ -1224,45 +1237,38 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed) · 1 unmodified line
12241237
12251238 case RCU_SAVE_DYNTICK:
12261239
1240+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
12271241 if (RCU_SIGNAL_INIT != RCU_SAVE_DYNTICK)
12281242 break; /* So gcc recognizes the dead code. */
12291243
12301244 /* Record dyntick-idle state. */
1231− if (rcu_process_dyntick(rsp, lastcomp,
1232− dyntick_save_progress_counter))
1233− goto unlock_ret;
1234− /* fall into next case. */
1235−
1236− case RCU_SAVE_COMPLETED:
1237−
1238− /* Update state, record completion counter. */
1239− forcenow = 0;
1240− spin_lock(&rnp->lock);
1241− if (lastcomp + 1 == rsp->gpnum &&
1242− lastcomp == rsp->completed &&
1243− rsp->signaled == signaled) {
1245+ force_qs_rnp(rsp, dyntick_save_progress_counter);
1246+ raw_spin_lock(&rnp->lock); /* irqs already disabled */
1247+ if (rcu_gp_in_progress(rsp))
12441248 rsp->signaled = RCU_FORCE_QS;
1245− rsp->completed_fqs = lastcomp;
1246− forcenow = signaled == RCU_SAVE_COMPLETED;
1247− }
1248− spin_unlock(&rnp->lock);
1249− if (!forcenow)
1250− break;
1251− /* fall into next case. */
1249+ break;
12521250
12531251 case RCU_FORCE_QS:
12541252
12551253 /* Check dyntick-idle state, send IPI to laggarts. */
1256− if (rcu_process_dyntick(rsp, rsp->completed_fqs,
1257− rcu_implicit_dynticks_qs))
1258− goto unlock_ret;
1254+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1255+ force_qs_rnp(rsp, rcu_implicit_dynticks_qs);
12591256
12601257 /* Leave state in case more forcing is required. */
12611258
1259+ raw_spin_lock(&rnp->lock); /* irqs already disabled */
12621260 break;
12631261 }
1264−unlock_ret:
1265− spin_unlock_irqrestore(&rsp->fqslock, flags);
1262+ rsp->fqs_active = 0;
1263+ if (rsp->fqs_need_gp) {
1264+ raw_spin_unlock(&rsp->fqslock); /* irqs remain disabled */
1265+ rsp->fqs_need_gp = 0;
1266+ rcu_start_gp(rsp, flags); /* releases rnp->lock */
1267+ return;
1268+ }
1269+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
1270+unlock_fqs_ret:
1271+ raw_spin_unlock_irqrestore(&rsp->fqslock, flags);
12661272 }
12671273
12681274 #else /* #ifdef CONFIG_SMP */
@@ -1290,7 +1296,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) · 21 unmodified lines
12901296 * If an RCU GP has gone long enough, go check for dyntick
12911297 * idle CPUs and, if needed, send resched IPIs.
12921298 */
1293− if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)
1299+ if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies))
12941300 force_quiescent_state(rsp, 1);
12951301
12961302 /*
@@ -1304,7 +1310,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp) · 7 unmodified lines
13041310
13051311 /* Does this CPU require a not-yet-started grace period? */
13061312 if (cpu_needs_another_gp(rsp, rdp)) {
1307− spin_lock_irqsave(&rcu_get_root(rsp)->lock, flags);
1313+ raw_spin_lock_irqsave(&rcu_get_root(rsp)->lock, flags);
13081314 rcu_start_gp(rsp, flags); /* releases above lock */
13091315 }
13101316
@@ -1335,6 +1341,9 @@ static void rcu_process_callbacks(struct softirq_action *unused) · 24 unmodified lines
13351341 * grace-period manipulations above.
13361342 */
13371343 smp_mb(); /* See above block comment. */
1344+
1345+ /* If we are last CPU on way to dyntick-idle mode, accelerate it. */
1346+ rcu_needs_cpu_flush();
13381347 }
13391348
13401349 static void
@@ -1369,7 +1378,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), · 28 unmodified lines
13691378 unsigned long nestflag;
13701379 struct rcu_node *rnp_root = rcu_get_root(rsp);
13711380
1372− spin_lock_irqsave(&rnp_root->lock, nestflag);
1381+ raw_spin_lock_irqsave(&rnp_root->lock, nestflag);
13731382 rcu_start_gp(rsp, nestflag); /* releases rnp_root->lock. */
13741383 }
13751384
@@ -1387,7 +1396,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu), · 11 unmodified lines
13871396 force_quiescent_state(rsp, 0);
13881397 rdp->n_force_qs_snap = rsp->n_force_qs;
13891398 rdp->qlen_last_fqs_check = rdp->qlen;
1390− } else if ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)
1399+ } else if (ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies))
13911400 force_quiescent_state(rsp, 1);
13921401 local_irq_restore(flags);
13931402 }
@@ -1520,7 +1529,7 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp) · 126 unmodified lines
15201529
15211530 /* Has an RCU GP gone long enough to send resched IPIs &c? */
15221531 if (rcu_gp_in_progress(rsp) &&
1523− ((long)(ACCESS_ONCE(rsp->jiffies_force_qs) - jiffies) < 0)) {
1532+ ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs), jiffies)) {
15241533 rdp->n_rp_need_fqs++;
15251534 return 1;
15261535 }
@@ -1545,10 +1554,9 @@ static int rcu_pending(int cpu) · 18 unmodified lines
15451554 /*
15461555 * Check to see if any future RCU-related work will need to be done
15471556 * by the current CPU, even if none need be done immediately, returning
1548− * 1 if so. This function is part of the RCU implementation; it is -not-
1549− * an exported member of the RCU API.
1557+ * 1 if so.
15501558 */
1551−int rcu_needs_cpu(int cpu)
1559+static int rcu_needs_cpu_quick_check(int cpu)
15521560 {
15531561 /* RCU callbacks either ready or pending? */
15541562 return per_cpu(rcu_sched_data, cpu).nxtlist ||
@@ -1556,21 +1564,6 @@ int rcu_needs_cpu(int cpu) · 1 unmodified line
15561564 rcu_preempt_needs_cpu(cpu);
15571565 }
15581566
1559−/*
1560− * This function is invoked towards the end of the scheduler's initialization
1561− * process. Before this is called, the idle task might contain
1562− * RCU read-side critical sections (during which time, this idle
1563− * task is booting the system). After this function is called, the
1564− * idle tasks are prohibited from containing RCU read-side critical
1565− * sections.
1566− */
1567−void rcu_scheduler_starting(void)
1568−{
1569− WARN_ON(num_online_cpus() != 1);
1570− WARN_ON(nr_context_switches() > 0);
1571− rcu_scheduler_active = 1;
1572−}
1573−
15741567 static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL};
15751568 static atomic_t rcu_barrier_cpu_count;
15761569 static DEFINE_MUTEX(rcu_barrier_mutex);
@@ -1659,7 +1652,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) · 82 unmodified lines
16591652 struct rcu_node *rnp = rcu_get_root(rsp);
16601653
16611654 /* Set up local state, ensuring consistent view of global state. */
1662− spin_lock_irqsave(&rnp->lock, flags);
1655+ raw_spin_lock_irqsave(&rnp->lock, flags);
16631656 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
16641657 rdp->nxtlist = NULL;
16651658 for (i = 0; i < RCU_NEXT_SIZE; i++)
@@ -1669,7 +1662,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp) · 3 unmodified lines
16691662 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
16701663 #endif /* #ifdef CONFIG_NO_HZ */
16711664 rdp->cpu = cpu;
1672− spin_unlock_irqrestore(&rnp->lock, flags);
1665+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
16731666 }
16741667
16751668 /*
@@ -1687,7 +1680,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) · 11 unmodified lines
16871680 struct rcu_node *rnp = rcu_get_root(rsp);
16881681
16891682 /* Set up local state, ensuring consistent view of global state. */
1690− spin_lock_irqsave(&rnp->lock, flags);
1683+ raw_spin_lock_irqsave(&rnp->lock, flags);
16911684 rdp->passed_quiesc = 0; /* We could be racing with new GP, */
16921685 rdp->qs_pending = 1; /* so set up to respond to current GP. */
16931686 rdp->beenonline = 1; /* We have now been online. */
@@ -1695,7 +1688,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) · 1 unmodified line
16951688 rdp->qlen_last_fqs_check = 0;
16961689 rdp->n_force_qs_snap = rsp->n_force_qs;
16971690 rdp->blimit = blimit;
1698− spin_unlock(&rnp->lock); /* irqs remain disabled. */
1691+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
16991692
17001693 /*
17011694 * A new grace period might start here. If so, we won't be part
@@ -1703,14 +1696,14 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) · 1 unmodified line
17031696 */
17041697
17051698 /* Exclude any attempts to start a new GP on large systems. */
1706− spin_lock(&rsp->onofflock); /* irqs already disabled. */
1699+ raw_spin_lock(&rsp->onofflock); /* irqs already disabled. */
17071700
17081701 /* Add CPU to rcu_node bitmasks. */
17091702 rnp = rdp->mynode;
17101703 mask = rdp->grpmask;
17111704 do {
17121705 /* Exclude any attempts to start a new GP on small systems. */
1713− spin_lock(&rnp->lock); /* irqs already disabled. */
1706+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
17141707 rnp->qsmaskinit |= mask;
17151708 mask = rnp->grpmask;
17161709 if (rnp == rdp->mynode) {
@@ -1718,11 +1711,11 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptable) · 1 unmodified line
17181711 rdp->completed = rnp->completed;
17191712 rdp->passed_quiesc_completed = rnp->completed - 1;
17201713 }
1721− spin_unlock(&rnp->lock); /* irqs already disabled. */
1714+ raw_spin_unlock(&rnp->lock); /* irqs already disabled. */
17221715 rnp = rnp->parent;
17231716 } while (rnp != NULL && !(rnp->qsmaskinit & mask));
17241717
1725− spin_unlock_irqrestore(&rsp->onofflock, flags);
1718+ raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
17261719 }
17271720
17281721 static void __cpuinit rcu_online_cpu(int cpu)
@@ -1806,11 +1799,17 @@ static void __init rcu_init_levelspread(struct rcu_state *rsp) · 77 unmodified lines
18061799 */
18071800 static void __init rcu_init_one(struct rcu_state *rsp)
18081801 {
1802+ static char *buf[] = { "rcu_node_level_0",
1803+ "rcu_node_level_1",
1804+ "rcu_node_level_2",
1805+ "rcu_node_level_3" }; /* Match MAX_RCU_LVLS */
18091806 int cpustride = 1;
18101807 int i;
18111808 int j;
18121809 struct rcu_node *rnp;
18131810
1811+ BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */
1812+
18141813 /* Initialize the level-tracking arrays. */
18151814
18161815 for (i = 1; i < NUM_RCU_LVLS; i++)
@@ -1823,8 +1822,9 @@ static void __init rcu_init_one(struct rcu_state *rsp) · 6 unmodified lines
18231822 cpustride *= rsp->levelspread[i];
18241823 rnp = rsp->level[i];
18251824 for (j = 0; j < rsp->levelcnt[i]; j++, rnp++) {
1826− spin_lock_init(&rnp->lock);
1827− lockdep_set_class(&rnp->lock, &rcu_node_class[i]);
1825+ raw_spin_lock_init(&rnp->lock);
1826+ lockdep_set_class_and_name(&rnp->lock,
1827+ &rcu_node_class[i], buf[i]);
18281828 rnp->gpnum = 0;
18291829 rnp->qsmask = 0;
18301830 rnp->qsmaskinit = 0;
@@ -1876,7 +1876,7 @@ do { \ · 45 unmodified lines
18761876
18771877 void __init rcu_init(void)
18781878 {
1879− int i;
1879+ int cpu;
18801880
18811881 rcu_bootup_announce();
18821882 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
@@ -1896,8 +1896,8 @@ void __init rcu_init(void) · 13 unmodified lines
18961896 * or the scheduler are operational.
18971897 */
18981898 cpu_notifier(rcu_cpu_notify, 0);
1899− for_each_online_cpu(i)
1900− rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)i);
1899+ for_each_online_cpu(cpu)
1900+ rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
19011901 }
19021902
19031903 #include "rcutree_plugin.h"
kernel/rcutree.h+34−27
@@ -90,12 +90,12 @@ struct rcu_dynticks { · 89 unmodified lines
9090 * Definition for node within the RCU grace-period-detection hierarchy.
9191 */
9292 struct rcu_node {
93− spinlock_t lock; /* Root rcu_node's lock protects some */
93+ raw_spinlock_t lock; /* Root rcu_node's lock protects some */
9494 /* rcu_state fields as well as following. */
95− long gpnum; /* Current grace period for this node. */
95+ unsigned long gpnum; /* Current grace period for this node. */
9696 /* This will either be equal to or one */
9797 /* behind the root rcu_node's gpnum. */
98− long completed; /* Last grace period completed for this node. */
98+ unsigned long completed; /* Last GP completed for this node. */
9999 /* This will either be equal to or one */
100100 /* behind the root rcu_node's gpnum. */
101101 unsigned long qsmask; /* CPUs or groups that need to switch in */
@@ -161,11 +161,11 @@ struct rcu_node { · 59 unmodified lines
161161 /* Per-CPU data for read-copy update. */
162162 struct rcu_data {
163163 /* 1) quiescent-state and grace-period handling : */
164− long completed; /* Track rsp->completed gp number */
164+ unsigned long completed; /* Track rsp->completed gp number */
165165 /* in order to detect GP end. */
166− long gpnum; /* Highest gp number that this CPU */
166+ unsigned long gpnum; /* Highest gp number that this CPU */
167167 /* is aware of having started. */
168− long passed_quiesc_completed;
168+ unsigned long passed_quiesc_completed;
169169 /* Value of completed at time of qs. */
170170 bool passed_quiesc; /* User-mode/idle loop etc. */
171171 bool qs_pending; /* Core waits for quiesc state. */
@@ -221,14 +221,14 @@ struct rcu_data { · 49 unmodified lines
221221 unsigned long resched_ipi; /* Sent a resched IPI. */
222222
223223 /* 5) __rcu_pending() statistics. */
224− long n_rcu_pending; /* rcu_pending() calls since boot. */
225− long n_rp_qs_pending;
226− long n_rp_cb_ready;
227− long n_rp_cpu_needs_gp;
228− long n_rp_gp_completed;
229− long n_rp_gp_started;
230− long n_rp_need_fqs;
231− long n_rp_need_nothing;
224+ unsigned long n_rcu_pending; /* rcu_pending() calls since boot. */
225+ unsigned long n_rp_qs_pending;
226+ unsigned long n_rp_cb_ready;
227+ unsigned long n_rp_cpu_needs_gp;
228+ unsigned long n_rp_gp_completed;
229+ unsigned long n_rp_gp_started;
230+ unsigned long n_rp_need_fqs;
231+ unsigned long n_rp_need_nothing;
232232
233233 int cpu;
234234 };
@@ -237,12 +237,11 @@ struct rcu_data { · 2 unmodified lines
237237 #define RCU_GP_IDLE 0 /* No grace period in progress. */
238238 #define RCU_GP_INIT 1 /* Grace period being initialized. */
239239 #define RCU_SAVE_DYNTICK 2 /* Need to scan dyntick state. */
240−#define RCU_SAVE_COMPLETED 3 /* Need to save rsp->completed. */
241−#define RCU_FORCE_QS 4 /* Need to force quiescent state. */
240+#define RCU_FORCE_QS 3 /* Need to force quiescent state. */
242241 #ifdef CONFIG_NO_HZ
243242 #define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK
244243 #else /* #ifdef CONFIG_NO_HZ */
245−#define RCU_SIGNAL_INIT RCU_SAVE_COMPLETED
244+#define RCU_SIGNAL_INIT RCU_FORCE_QS
246245 #endif /* #else #ifdef CONFIG_NO_HZ */
247246
248247 #define RCU_JIFFIES_TILL_FORCE_QS 3 /* for rsp->jiffies_force_qs */
@@ -256,6 +255,9 @@ struct rcu_data { · 7 unmodified lines
256255
257256 #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
258257
258+#define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
259+#define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
260+
259261 /*
260262 * RCU global state, including node hierarchy. This hierarchy is
261263 * represented in "heap" form in a dense array. The root (first level)
@@ -277,12 +279,19 @@ struct rcu_state { · 15 unmodified lines
277279
278280 u8 signaled ____cacheline_internodealigned_in_smp;
279281 /* Force QS state. */
280− long gpnum; /* Current gp number. */
281− long completed; /* # of last completed gp. */
282+ u8 fqs_active; /* force_quiescent_state() */
283+ /* is running. */
284+ u8 fqs_need_gp; /* A CPU was prevented from */
285+ /* starting a new grace */
286+ /* period because */
287+ /* force_quiescent_state() */
288+ /* was running. */
289+ unsigned long gpnum; /* Current gp number. */
290+ unsigned long completed; /* # of last completed gp. */
282291
283292 /* End of fields guarded by root rcu_node's lock. */
284293
285− spinlock_t onofflock; /* exclude on/offline and */
294+ raw_spinlock_t onofflock; /* exclude on/offline and */
286295 /* starting new GP. Also */
287296 /* protects the following */
288297 /* orphan_cbs fields. */
@@ -292,10 +301,8 @@ struct rcu_state { · 3 unmodified lines
292301 /* going offline. */
293302 struct rcu_head **orphan_cbs_tail; /* And tail pointer. */
294303 long orphan_qlen; /* Number of orphaned cbs. */
295− spinlock_t fqslock; /* Only one task forcing */
304+ raw_spinlock_t fqslock; /* Only one task forcing */
296305 /* quiescent states. */
297− long completed_fqs; /* Value of completed @ snap. */
298− /* Protected by fqslock. */
299306 unsigned long jiffies_force_qs; /* Time at which to invoke */
300307 /* force_quiescent_state(). */
301308 unsigned long n_force_qs; /* Number of calls to */
@@ -319,8 +326,6 @@ struct rcu_state { · 17 unmodified lines
319326 #define RCU_OFL_TASKS_EXP_GP 0x2 /* Tasks blocking expedited */
320327 /* GP were moved to root. */
321328
322−#ifdef RCU_TREE_NONCORE
323−
324329 /*
325330 * RCU implementation internal declarations:
326331 */
@@ -335,7 +340,7 @@ extern struct rcu_state rcu_preempt_state; · 8 unmodified lines
335340 DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data);
336341 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
337342
338−#else /* #ifdef RCU_TREE_NONCORE */
343+#ifndef RCU_TREE_NONCORE
339344
340345 /* Forward declarations for rcutree_plugin.h */
341346 static void rcu_bootup_announce(void);
@@ -347,6 +352,7 @@ static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, · 5 unmodified lines
347352 unsigned long flags);
348353 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
349354 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
355+static void rcu_print_detail_task_stall(struct rcu_state *rsp);
350356 static void rcu_print_task_stall(struct rcu_node *rnp);
351357 #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
352358 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
@@ -367,5 +373,6 @@ static int rcu_preempt_needs_cpu(int cpu); · 14 unmodified lines
367373 static void __cpuinit rcu_preempt_init_percpu_data(int cpu);
368374 static void rcu_preempt_send_cbs_to_orphanage(void);
369375 static void __init __rcu_init_preempt(void);
376+static void rcu_needs_cpu_flush(void);
370377
371−#endif /* #else #ifdef RCU_TREE_NONCORE */
378+#endif /* #ifndef RCU_TREE_NONCORE */
kernel/rcutree_plugin.h+205−24
@@ -61,6 +61,15 @@ long rcu_batches_completed(void) · 60 unmodified lines
6161 }
6262 EXPORT_SYMBOL_GPL(rcu_batches_completed);
6363
64+/*
65+ * Force a quiescent state for preemptible RCU.
66+ */
67+void rcu_force_quiescent_state(void)
68+{
69+ force_quiescent_state(&rcu_preempt_state, 0);
70+}
71+EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
72+
6473 /*
6574 * Record a preemptable-RCU quiescent state for the specified CPU. Note
6675 * that this just means that the task currently running on the CPU is
@@ -102,7 +111,7 @@ static void rcu_preempt_note_context_switch(int cpu) · 35 unmodified lines
102111 /* Possibly blocking in an RCU read-side critical section. */
103112 rdp = rcu_preempt_state.rda[cpu];
104113 rnp = rdp->mynode;
105− spin_lock_irqsave(&rnp->lock, flags);
114+ raw_spin_lock_irqsave(&rnp->lock, flags);
106115 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
107116 t->rcu_blocked_node = rnp;
108117
@@ -123,7 +132,7 @@ static void rcu_preempt_note_context_switch(int cpu) · 14 unmodified lines
123132 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
124133 phase = (rnp->gpnum + !(rnp->qsmask & rdp->grpmask)) & 0x1;
125134 list_add(&t->rcu_node_entry, &rnp->blocked_tasks[phase]);
126− spin_unlock_irqrestore(&rnp->lock, flags);
135+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
127136 }
128137
129138 /*
@@ -180,7 +189,7 @@ static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags) · 50 unmodified lines
180189 struct rcu_node *rnp_p;
181190
182191 if (rnp->qsmask != 0 || rcu_preempted_readers(rnp)) {
183− spin_unlock_irqrestore(&rnp->lock, flags);
192+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
184193 return; /* Still need more quiescent states! */
185194 }
186195
@@ -197,8 +206,8 @@ static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags) · 10 unmodified lines
197206
198207 /* Report up the rest of the hierarchy. */
199208 mask = rnp->grpmask;
200− spin_unlock(&rnp->lock); /* irqs remain disabled. */
201− spin_lock(&rnp_p->lock); /* irqs already disabled. */
209+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
210+ raw_spin_lock(&rnp_p->lock); /* irqs already disabled. */
202211 rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
203212 }
204213
@@ -248,10 +257,10 @@ static void rcu_read_unlock_special(struct task_struct *t) · 43 unmodified lines
248257 */
249258 for (;;) {
250259 rnp = t->rcu_blocked_node;
251− spin_lock(&rnp->lock); /* irqs already disabled. */
260+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
252261 if (rnp == t->rcu_blocked_node)
253262 break;
254− spin_unlock(&rnp->lock); /* irqs remain disabled. */
263+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
255264 }
256265 empty = !rcu_preempted_readers(rnp);
257266 empty_exp = !rcu_preempted_readers_exp(rnp);
@@ -265,7 +274,7 @@ static void rcu_read_unlock_special(struct task_struct *t) · 7 unmodified lines
265274 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock.
266275 */
267276 if (empty)
268− spin_unlock_irqrestore(&rnp->lock, flags);
277+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
269278 else
270279 rcu_report_unblock_qs_rnp(rnp, flags);
271280
@@ -295,29 +304,73 @@ void __rcu_read_unlock(void) · 23 unmodified lines
295304 if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
296305 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
297306 rcu_read_unlock_special(t);
307+#ifdef CONFIG_PROVE_LOCKING
308+ WARN_ON_ONCE(ACCESS_ONCE(t->rcu_read_lock_nesting) < 0);
309+#endif /* #ifdef CONFIG_PROVE_LOCKING */
298310 }
299311 EXPORT_SYMBOL_GPL(__rcu_read_unlock);
300312
301313 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
302314
315+#ifdef CONFIG_RCU_CPU_STALL_VERBOSE
316+
317+/*
318+ * Dump detailed information for all tasks blocking the current RCU
319+ * grace period on the specified rcu_node structure.
320+ */
321+static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
322+{
323+ unsigned long flags;
324+ struct list_head *lp;
325+ int phase;
326+ struct task_struct *t;
327+
328+ if (rcu_preempted_readers(rnp)) {
329+ raw_spin_lock_irqsave(&rnp->lock, flags);
330+ phase = rnp->gpnum & 0x1;
331+ lp = &rnp->blocked_tasks[phase];
332+ list_for_each_entry(t, lp, rcu_node_entry)
333+ sched_show_task(t);
334+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
335+ }
336+}
337+
338+/*
339+ * Dump detailed information for all tasks blocking the current RCU
340+ * grace period.
341+ */
342+static void rcu_print_detail_task_stall(struct rcu_state *rsp)
343+{
344+ struct rcu_node *rnp = rcu_get_root(rsp);
345+
346+ rcu_print_detail_task_stall_rnp(rnp);
347+ rcu_for_each_leaf_node(rsp, rnp)
348+ rcu_print_detail_task_stall_rnp(rnp);
349+}
350+
351+#else /* #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
352+
353+static void rcu_print_detail_task_stall(struct rcu_state *rsp)
354+{
355+}
356+
357+#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_VERBOSE */
358+
303359 /*
304360 * Scan the current list of tasks blocked within RCU read-side critical
305361 * sections, printing out the tid of each.
306362 */
307363 static void rcu_print_task_stall(struct rcu_node *rnp)
308364 {
309− unsigned long flags;
310365 struct list_head *lp;
311366 int phase;
312367 struct task_struct *t;
313368
314369 if (rcu_preempted_readers(rnp)) {
315− spin_lock_irqsave(&rnp->lock, flags);
316370 phase = rnp->gpnum & 0x1;
317371 lp = &rnp->blocked_tasks[phase];
318372 list_for_each_entry(t, lp, rcu_node_entry)
319373 printk(" P%d", t->pid);
320− spin_unlock_irqrestore(&rnp->lock, flags);
321374 }
322375 }
323376
@@ -388,11 +441,11 @@ static int rcu_preempt_offline_tasks(struct rcu_state *rsp, · 64 unmodified lines
388441 lp_root = &rnp_root->blocked_tasks[i];
389442 while (!list_empty(lp)) {
390443 tp = list_entry(lp->next, typeof(*tp), rcu_node_entry);
391− spin_lock(&rnp_root->lock); /* irqs already disabled */
444+ raw_spin_lock(&rnp_root->lock); /* irqs already disabled */
392445 list_del(&tp->rcu_node_entry);
393446 tp->rcu_blocked_node = rnp_root;
394447 list_add(&tp->rcu_node_entry, lp_root);
395− spin_unlock(&rnp_root->lock); /* irqs remain disabled */
448+ raw_spin_unlock(&rnp_root->lock); /* irqs remain disabled */
396449 }
397450 }
398451 return retval;
@@ -516,7 +569,7 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) · 117 unmodified lines
516569 unsigned long flags;
517570 unsigned long mask;
518571
519− spin_lock_irqsave(&rnp->lock, flags);
572+ raw_spin_lock_irqsave(&rnp->lock, flags);
520573 for (;;) {
521574 if (!sync_rcu_preempt_exp_done(rnp))
522575 break;
@@ -525,12 +578,12 @@ static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp) · 2 unmodified lines
525578 break;
526579 }
527580 mask = rnp->grpmask;
528− spin_unlock(&rnp->lock); /* irqs remain disabled */
581+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
529582 rnp = rnp->parent;
530− spin_lock(&rnp->lock); /* irqs already disabled */
583+ raw_spin_lock(&rnp->lock); /* irqs already disabled */
531584 rnp->expmask &= ~mask;
532585 }
533− spin_unlock_irqrestore(&rnp->lock, flags);
586+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
534587 }
535588
536589 /*
@@ -545,11 +598,11 @@ sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp) · 8 unmodified lines
545598 {
546599 int must_wait;
547600
548− spin_lock(&rnp->lock); /* irqs already disabled */
601+ raw_spin_lock(&rnp->lock); /* irqs already disabled */
549602 list_splice_init(&rnp->blocked_tasks[0], &rnp->blocked_tasks[2]);
550603 list_splice_init(&rnp->blocked_tasks[1], &rnp->blocked_tasks[3]);
551604 must_wait = rcu_preempted_readers_exp(rnp);
552− spin_unlock(&rnp->lock); /* irqs remain disabled */
605+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
553606 if (!must_wait)
554607 rcu_report_exp_rnp(rsp, rnp);
555608 }
@@ -594,13 +647,13 @@ void synchronize_rcu_expedited(void) · 38 unmodified lines
594647 /* force all RCU readers onto blocked_tasks[]. */
595648 synchronize_sched_expedited();
596649
597− spin_lock_irqsave(&rsp->onofflock, flags);
650+ raw_spin_lock_irqsave(&rsp->onofflock, flags);
598651
599652 /* Initialize ->expmask for all non-leaf rcu_node structures. */
600653 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
601− spin_lock(&rnp->lock); /* irqs already disabled. */
654+ raw_spin_lock(&rnp->lock); /* irqs already disabled. */
602655 rnp->expmask = rnp->qsmaskinit;
603− spin_unlock(&rnp->lock); /* irqs remain disabled. */
656+ raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
604657 }
605658
606659 /* Snapshot current state of ->blocked_tasks[] lists. */
@@ -609,7 +662,7 @@ void synchronize_rcu_expedited(void) · 2 unmodified lines
609662 if (NUM_RCU_NODES > 1)
610663 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
611664
612− spin_unlock_irqrestore(&rsp->onofflock, flags);
665+ raw_spin_unlock_irqrestore(&rsp->onofflock, flags);
613666
614667 /* Wait for snapshotted ->blocked_tasks[] lists to drain. */
615668 rnp = rcu_get_root(rsp);
@@ -712,6 +765,16 @@ long rcu_batches_completed(void) · 96 unmodified lines
712765 }
713766 EXPORT_SYMBOL_GPL(rcu_batches_completed);
714767
768+/*
769+ * Force a quiescent state for RCU, which, because there is no preemptible
770+ * RCU, becomes the same as rcu-sched.
771+ */
772+void rcu_force_quiescent_state(void)
773+{
774+ rcu_sched_force_quiescent_state();
775+}
776+EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
777+
715778 /*
716779 * Because preemptable RCU does not exist, we never have to check for
717780 * CPUs being in quiescent states.
@@ -734,13 +797,21 @@ static int rcu_preempted_readers(struct rcu_node *rnp) · 16 unmodified lines
734797 /* Because preemptible RCU does not exist, no quieting of tasks. */
735798 static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
736799 {
737− spin_unlock_irqrestore(&rnp->lock, flags);
800+ raw_spin_unlock_irqrestore(&rnp->lock, flags);
738801 }
739802
740803 #endif /* #ifdef CONFIG_HOTPLUG_CPU */
741804
742805 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
743806
807+/*
808+ * Because preemptable RCU does not exist, we never have to check for
809+ * tasks blocked within RCU read-side critical sections.
810+ */
811+static void rcu_print_detail_task_stall(struct rcu_state *rsp)
812+{
813+}
814+
744815 /*
745816 * Because preemptable RCU does not exist, we never have to check for
746817 * tasks blocked within RCU read-side critical sections.
@@ -884,3 +955,113 @@ static void __init __rcu_init_preempt(void) · 137 unmodified lines
884955 }
885956
886957 #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */
958+
959+#if !defined(CONFIG_RCU_FAST_NO_HZ)
960+
961+/*
962+ * Check to see if any future RCU-related work will need to be done
963+ * by the current CPU, even if none need be done immediately, returning
964+ * 1 if so. This function is part of the RCU implementation; it is -not-
965+ * an exported member of the RCU API.
966+ *
967+ * Because we have preemptible RCU, just check whether this CPU needs
968+ * any flavor of RCU. Do not chew up lots of CPU cycles with preemption
969+ * disabled in a most-likely vain attempt to cause RCU not to need this CPU.
970+ */
971+int rcu_needs_cpu(int cpu)
972+{
973+ return rcu_needs_cpu_quick_check(cpu);
974+}
975+
976+/*
977+ * Check to see if we need to continue a callback-flush operations to
978+ * allow the last CPU to enter dyntick-idle mode. But fast dyntick-idle
979+ * entry is not configured, so we never do need to.
980+ */
981+static void rcu_needs_cpu_flush(void)
982+{
983+}
984+
985+#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
986+
987+#define RCU_NEEDS_CPU_FLUSHES 5
988+static DEFINE_PER_CPU(int, rcu_dyntick_drain);
989+static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
990+
991+/*
992+ * Check to see if any future RCU-related work will need to be done
993+ * by the current CPU, even if none need be done immediately, returning
994+ * 1 if so. This function is part of the RCU implementation; it is -not-
995+ * an exported member of the RCU API.
996+ *
997+ * Because we are not supporting preemptible RCU, attempt to accelerate
998+ * any current grace periods so that RCU no longer needs this CPU, but
999+ * only if all other CPUs are already in dynticks-idle mode. This will
1000+ * allow the CPU cores to be powered down immediately, as opposed to after
1001+ * waiting many milliseconds for grace periods to elapse.
1002+ *
1003+ * Because it is not legal to invoke rcu_process_callbacks() with irqs
1004+ * disabled, we do one pass of force_quiescent_state(), then do a
1005+ * raise_softirq() to cause rcu_process_callbacks() to be invoked later.
1006+ * The per-cpu rcu_dyntick_drain variable controls the sequencing.
1007+ */
1008+int rcu_needs_cpu(int cpu)
1009+{
1010+ int c = 0;
1011+ int thatcpu;
1012+
1013+ /* Don't bother unless we are the last non-dyntick-idle CPU. */
1014+ for_each_cpu_not(thatcpu, nohz_cpu_mask)
1015+ if (thatcpu != cpu) {
1016+ per_cpu(rcu_dyntick_drain, cpu) = 0;
1017+ per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
1018+ return rcu_needs_cpu_quick_check(cpu);
1019+ }
1020+
1021+ /* Check and update the rcu_dyntick_drain sequencing. */
1022+ if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1023+ /* First time through, initialize the counter. */
1024+ per_cpu(rcu_dyntick_drain, cpu) = RCU_NEEDS_CPU_FLUSHES;
1025+ } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
1026+ /* We have hit the limit, so time to give up. */
1027+ per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
1028+ return rcu_needs_cpu_quick_check(cpu);
1029+ }
1030+
1031+ /* Do one step pushing remaining RCU callbacks through. */
1032+ if (per_cpu(rcu_sched_data, cpu).nxtlist) {
1033+ rcu_sched_qs(cpu);
1034+ force_quiescent_state(&rcu_sched_state, 0);
1035+ c = c || per_cpu(rcu_sched_data, cpu).nxtlist;
1036+ }
1037+ if (per_cpu(rcu_bh_data, cpu).nxtlist) {
1038+ rcu_bh_qs(cpu);
1039+ force_quiescent_state(&rcu_bh_state, 0);
1040+ c = c || per_cpu(rcu_bh_data, cpu).nxtlist;
1041+ }
1042+
1043+ /* If RCU callbacks are still pending, RCU still needs this CPU. */
1044+ if (c) {
1045+ raise_softirq(RCU_SOFTIRQ);
1046+ per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
1047+ }
1048+ return c;
1049+}
1050+
1051+/*
1052+ * Check to see if we need to continue a callback-flush operations to
1053+ * allow the last CPU to enter dyntick-idle mode.
1054+ */
1055+static void rcu_needs_cpu_flush(void)
1056+{
1057+ int cpu = smp_processor_id();
1058+ unsigned long flags;
1059+
1060+ if (per_cpu(rcu_dyntick_drain, cpu) <= 0)
1061+ return;
1062+ local_irq_save(flags);
1063+ (void)rcu_needs_cpu(cpu);
1064+ local_irq_restore(flags);
1065+}
1066+
1067+#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
kernel/rcutree_trace.c+7−7
@@ -50,7 +50,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) · 49 unmodified lines
5050 {
5151 if (!rdp->beenonline)
5252 return;
53− seq_printf(m, "%3d%cc=%ld g=%ld pq=%d pqc=%ld qp=%d",
53+ seq_printf(m, "%3d%cc=%lu g=%lu pq=%d pqc=%lu qp=%d",
5454 rdp->cpu,
5555 cpu_is_offline(rdp->cpu) ? '!' : ' ',
5656 rdp->completed, rdp->gpnum,
@@ -105,7 +105,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp) · 48 unmodified lines
105105 {
106106 if (!rdp->beenonline)
107107 return;
108− seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d",
108+ seq_printf(m, "%d,%s,%lu,%lu,%d,%lu,%d",
109109 rdp->cpu,
110110 cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
111111 rdp->completed, rdp->gpnum,
@@ -155,13 +155,13 @@ static const struct file_operations rcudata_csv_fops = { · 43 unmodified lines
155155
156156 static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
157157 {
158− long gpnum;
158+ unsigned long gpnum;
159159 int level = 0;
160160 int phase;
161161 struct rcu_node *rnp;
162162
163163 gpnum = rsp->gpnum;
164− seq_printf(m, "c=%ld g=%ld s=%d jfq=%ld j=%x "
164+ seq_printf(m, "c=%lu g=%lu s=%d jfq=%ld j=%x "
165165 "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld\n",
166166 rsp->completed, gpnum, rsp->signaled,
167167 (long)(rsp->jiffies_force_qs - jiffies),
@@ -215,12 +215,12 @@ static const struct file_operations rcuhier_fops = { · 47 unmodified lines
215215 static int show_rcugp(struct seq_file *m, void *unused)
216216 {
217217 #ifdef CONFIG_TREE_PREEMPT_RCU
218− seq_printf(m, "rcu_preempt: completed=%ld gpnum=%ld\n",
218+ seq_printf(m, "rcu_preempt: completed=%ld gpnum=%lu\n",
219219 rcu_preempt_state.completed, rcu_preempt_state.gpnum);
220220 #endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
221− seq_printf(m, "rcu_sched: completed=%ld gpnum=%ld\n",
221+ seq_printf(m, "rcu_sched: completed=%ld gpnum=%lu\n",
222222 rcu_sched_state.completed, rcu_sched_state.gpnum);
223− seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n",
223+ seq_printf(m, "rcu_bh: completed=%ld gpnum=%lu\n",
224224 rcu_bh_state.completed, rcu_bh_state.gpnum);
225225 return 0;
226226 }
kernel/sched.c+8−3
@@ -645,6 +645,11 @@ static inline int cpu_of(struct rq *rq) · 644 unmodified lines
645645 #endif
646646 }
647647
648+#define rcu_dereference_check_sched_domain(p) \
649+ rcu_dereference_check((p), \
650+ rcu_read_lock_sched_held() || \
651+ lockdep_is_held(&sched_domains_mutex))
652+
648653 /*
649654 * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
650655 * See detach_destroy_domains: synchronize_sched for details.
@@ -653,7 +658,7 @@ static inline int cpu_of(struct rq *rq) · 2 unmodified lines
653658 * preempt-disabled sections.
654659 */
655660 #define for_each_domain(cpu, __sd) \
656− for (__sd = rcu_dereference(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)
661+ for (__sd = rcu_dereference_check_sched_domain(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)
657662
658663 #define cpu_rq(cpu) (&per_cpu(runqueues, (cpu)))
659664 #define this_rq() (&__get_cpu_var(runqueues))
@@ -1531,7 +1536,7 @@ static unsigned long target_load(int cpu, int type) · 871 unmodified lines
15311536
15321537 static struct sched_group *group_of(int cpu)
15331538 {
1534− struct sched_domain *sd = rcu_dereference(cpu_rq(cpu)->sd);
1539+ struct sched_domain *sd = rcu_dereference_sched(cpu_rq(cpu)->sd);
15351540
15361541 if (!sd)
15371542 return NULL;
@@ -4888,7 +4893,7 @@ static void run_rebalance_domains(struct softirq_action *h) · 3350 unmodified lines
48884893
48894894 static inline int on_null_domain(int cpu)
48904895 {
4891− return !rcu_dereference(cpu_rq(cpu)->sd);
4896+ return !rcu_dereference_sched(cpu_rq(cpu)->sd);
48924897 }
48934898
48944899 /*
kernel/srcu.c+34−18
@@ -34,6 +34,30 @@ · 33 unmodified lines
3434 #include <linux/smp.h>
3535 #include <linux/srcu.h>
3636
37+static int init_srcu_struct_fields(struct srcu_struct *sp)
38+{
39+ sp->completed = 0;
40+ mutex_init(&sp->mutex);
41+ sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array);
42+ return sp->per_cpu_ref ? 0 : -ENOMEM;
43+}
44+
45+#ifdef CONFIG_DEBUG_LOCK_ALLOC
46+
47+int __init_srcu_struct(struct srcu_struct *sp, const char *name,
48+ struct lock_class_key *key)
49+{
50+#ifdef CONFIG_DEBUG_LOCK_ALLOC
51+ /* Don't re-initialize a lock while it is held. */
52+ debug_check_no_locks_freed((void *)sp, sizeof(*sp));
53+ lockdep_init_map(&sp->dep_map, name, key, 0);
54+#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
55+ return init_srcu_struct_fields(sp);
56+}
57+EXPORT_SYMBOL_GPL(__init_srcu_struct);
58+
59+#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
60+
3761 /**
3862 * init_srcu_struct - initialize a sleep-RCU structure
3963 * @sp: structure to initialize.
@@ -44,13 +68,12 @@ · 4 unmodified lines
4468 */
4569 int init_srcu_struct(struct srcu_struct *sp)
4670 {
47− sp->completed = 0;
48− mutex_init(&sp->mutex);
49− sp->per_cpu_ref = alloc_percpu(struct srcu_struct_array);
50− return (sp->per_cpu_ref ? 0 : -ENOMEM);
71+ return init_srcu_struct_fields(sp);
5172 }
5273 EXPORT_SYMBOL_GPL(init_srcu_struct);
5374
75+#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
76+
5477 /*
5578 * srcu_readers_active_idx -- returns approximate number of readers
5679 * active on the specified rank of per-CPU counters.
@@ -100,15 +123,12 @@ void cleanup_srcu_struct(struct srcu_struct *sp) · 43 unmodified lines
100123 }
101124 EXPORT_SYMBOL_GPL(cleanup_srcu_struct);
102125
103−/**
104− * srcu_read_lock - register a new reader for an SRCU-protected structure.
105− * @sp: srcu_struct in which to register the new reader.
106− *
126+/*
107127 * Counts the new reader in the appropriate per-CPU element of the
108128 * srcu_struct. Must be called from process context.
109129 * Returns an index that must be passed to the matching srcu_read_unlock().
110130 */
111−int srcu_read_lock(struct srcu_struct *sp)
131+int __srcu_read_lock(struct srcu_struct *sp)
112132 {
113133 int idx;
114134
@@ -120,31 +140,27 @@ int srcu_read_lock(struct srcu_struct *sp) · 5 unmodified lines
120140 preempt_enable();
121141 return idx;
122142 }
123−EXPORT_SYMBOL_GPL(srcu_read_lock);
143+EXPORT_SYMBOL_GPL(__srcu_read_lock);
124144
125−/**
126− * srcu_read_unlock - unregister a old reader from an SRCU-protected structure.
127− * @sp: srcu_struct in which to unregister the old reader.
128− * @idx: return value from corresponding srcu_read_lock().
129− *
145+/*
130146 * Removes the count for the old reader from the appropriate per-CPU
131147 * element of the srcu_struct. Note that this may well be a different
132148 * CPU than that which was incremented by the corresponding srcu_read_lock().
133149 * Must be called from process context.
134150 */
135−void srcu_read_unlock(struct srcu_struct *sp, int idx)
151+void __srcu_read_unlock(struct srcu_struct *sp, int idx)
136152 {
137153 preempt_disable();
138154 srcu_barrier(); /* ensure compiler won't misorder critical section. */
139155 per_cpu_ptr(sp->per_cpu_ref, smp_processor_id())->c[idx]--;
140156 preempt_enable();
141157 }
142−EXPORT_SYMBOL_GPL(srcu_read_unlock);
158+EXPORT_SYMBOL_GPL(__srcu_read_unlock);
143159
144160 /*
145161 * Helper function for synchronize_srcu() and synchronize_srcu_expedited().
146162 */
147−void __synchronize_srcu(struct srcu_struct *sp, void (*sync_func)(void))
163+static void __synchronize_srcu(struct srcu_struct *sp, void (*sync_func)(void))
148164 {
149165 int idx;
150166
lib/Kconfig.debug+25−1
@@ -499,6 +499,18 @@ config PROVE_LOCKING · 498 unmodified lines
499499
500500 For more details, see Documentation/lockdep-design.txt.
501501
502+config PROVE_RCU
503+ bool "RCU debugging: prove RCU correctness"
504+ depends on PROVE_LOCKING
505+ default n
506+ help
507+ This feature enables lockdep extensions that check for correct
508+ use of RCU APIs. This is currently under development. Say Y
509+ if you want to debug RCU usage or help work on the PROVE_RCU
510+ feature.
511+
512+ Say N if you are unsure.
513+
502514 config LOCKDEP
503515 bool
504516 depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
@@ -765,10 +777,22 @@ config RCU_CPU_STALL_DETECTOR · 260 unmodified lines
765777 CPUs are delaying the current grace period, but only when
766778 the grace period extends for excessive time periods.
767779
768− Say Y if you want RCU to perform such checks.
780+ Say N if you want to disable such checks.
781+
782+ Say Y if you are unsure.
783+
784+config RCU_CPU_STALL_VERBOSE
785+ bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR"
786+ depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU
787+ default n
788+ help
789+ This option causes RCU to printk detailed per-task information
790+ for any tasks that are stalling the current RCU grace period.
769791
770792 Say N if you are unsure.
771793
794+ Say Y if you want to enable such checks.
795+
772796 config KPROBES_SANITY_TEST
773797 bool "Kprobes sanity tests"
774798 depends on DEBUG_KERNEL
lib/debug_locks.c+1−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 * shut up after that.
2424 */
2525 int debug_locks = 1;
26+EXPORT_SYMBOL_GPL(debug_locks);
2627
2728 /*
2829 * The locking-testsuite uses <debug_locks_silent> to get a
lib/idr.c+4−4
@@ -504,7 +504,7 @@ void *idr_find(struct idr *idp, int id) · 503 unmodified lines
504504 int n;
505505 struct idr_layer *p;
506506
507− p = rcu_dereference(idp->top);
507+ p = rcu_dereference_raw(idp->top);
508508 if (!p)
509509 return NULL;
510510 n = (p->layer+1) * IDR_BITS;
@@ -519,7 +519,7 @@ void *idr_find(struct idr *idp, int id) · 8 unmodified lines
519519 while (n > 0 && p) {
520520 n -= IDR_BITS;
521521 BUG_ON(n != p->layer*IDR_BITS);
522− p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]);
522+ p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
523523 }
524524 return((void *)p);
525525 }
@@ -552,7 +552,7 @@ int idr_for_each(struct idr *idp, · 26 unmodified lines
552552 struct idr_layer **paa = &pa[0];
553553
554554 n = idp->layers * IDR_BITS;
555− p = rcu_dereference(idp->top);
555+ p = rcu_dereference_raw(idp->top);
556556 max = 1 << n;
557557
558558 id = 0;
@@ -560,7 +560,7 @@ int idr_for_each(struct idr *idp, · 1 unmodified line
560560 while (n > 0 && p) {
561561 n -= IDR_BITS;
562562 *paa++ = p;
563− p = rcu_dereference(p->ary[(id >> n) & IDR_MASK]);
563+ p = rcu_dereference_raw(p->ary[(id >> n) & IDR_MASK]);
564564 }
565565
566566 if (p) {
lib/radix-tree.c+12−12
@@ -364,7 +364,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root, · 363 unmodified lines
364364 unsigned int height, shift;
365365 struct radix_tree_node *node, **slot;
366366
367− node = rcu_dereference(root->rnode);
367+ node = rcu_dereference_raw(root->rnode);
368368 if (node == NULL)
369369 return NULL;
370370
@@ -384,7 +384,7 @@ static void *radix_tree_lookup_element(struct radix_tree_root *root, · 13 unmodified lines
384384 do {
385385 slot = (struct radix_tree_node **)
386386 (node->slots + ((index>>shift) & RADIX_TREE_MAP_MASK));
387− node = rcu_dereference(*slot);
387+ node = rcu_dereference_raw(*slot);
388388 if (node == NULL)
389389 return NULL;
390390
@@ -568,7 +568,7 @@ int radix_tree_tag_get(struct radix_tree_root *root, · 177 unmodified lines
568568 if (!root_tag_get(root, tag))
569569 return 0;
570570
571− node = rcu_dereference(root->rnode);
571+ node = rcu_dereference_raw(root->rnode);
572572 if (node == NULL)
573573 return 0;
574574
@@ -602,7 +602,7 @@ int radix_tree_tag_get(struct radix_tree_root *root, · 27 unmodified lines
602602 BUG_ON(ret && saw_unset_tag);
603603 return !!ret;
604604 }
605− node = rcu_dereference(node->slots[offset]);
605+ node = rcu_dereference_raw(node->slots[offset]);
606606 shift -= RADIX_TREE_MAP_SHIFT;
607607 height--;
608608 }
@@ -711,7 +711,7 @@ __lookup(struct radix_tree_node *slot, void ***results, unsigned long index, · 102 unmodified lines
711711 }
712712
713713 shift -= RADIX_TREE_MAP_SHIFT;
714− slot = rcu_dereference(slot->slots[i]);
714+ slot = rcu_dereference_raw(slot->slots[i]);
715715 if (slot == NULL)
716716 goto out;
717717 }
@@ -758,7 +758,7 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results, · 40 unmodified lines
758758 unsigned long cur_index = first_index;
759759 unsigned int ret;
760760
761− node = rcu_dereference(root->rnode);
761+ node = rcu_dereference_raw(root->rnode);
762762 if (!node)
763763 return 0;
764764
@@ -787,7 +787,7 @@ radix_tree_gang_lookup(struct radix_tree_root *root, void **results, · 22 unmodified lines
787787 slot = *(((void ***)results)[ret + i]);
788788 if (!slot)
789789 continue;
790− results[ret + nr_found] = rcu_dereference(slot);
790+ results[ret + nr_found] = rcu_dereference_raw(slot);
791791 nr_found++;
792792 }
793793 ret += nr_found;
@@ -826,7 +826,7 @@ radix_tree_gang_lookup_slot(struct radix_tree_root *root, void ***results, · 32 unmodified lines
826826 unsigned long cur_index = first_index;
827827 unsigned int ret;
828828
829− node = rcu_dereference(root->rnode);
829+ node = rcu_dereference_raw(root->rnode);
830830 if (!node)
831831 return 0;
832832
@@ -915,7 +915,7 @@ __lookup_tag(struct radix_tree_node *slot, void ***results, unsigned long index, · 82 unmodified lines
915915 }
916916 }
917917 shift -= RADIX_TREE_MAP_SHIFT;
918− slot = rcu_dereference(slot->slots[i]);
918+ slot = rcu_dereference_raw(slot->slots[i]);
919919 if (slot == NULL)
920920 break;
921921 }
@@ -951,7 +951,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results, · 29 unmodified lines
951951 if (!root_tag_get(root, tag))
952952 return 0;
953953
954− node = rcu_dereference(root->rnode);
954+ node = rcu_dereference_raw(root->rnode);
955955 if (!node)
956956 return 0;
957957
@@ -980,7 +980,7 @@ radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results, · 22 unmodified lines
980980 slot = *(((void ***)results)[ret + i]);
981981 if (!slot)
982982 continue;
983− results[ret + nr_found] = rcu_dereference(slot);
983+ results[ret + nr_found] = rcu_dereference_raw(slot);
984984 nr_found++;
985985 }
986986 ret += nr_found;
@@ -1020,7 +1020,7 @@ radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results, · 33 unmodified lines
10201020 if (!root_tag_get(root, tag))
10211021 return 0;
10221022
1023− node = rcu_dereference(root->rnode);
1023+ node = rcu_dereference_raw(root->rnode);
10241024 if (!node)
10251025 return 0;
10261026
net/core/dev.c+1−1
@@ -2041,7 +2041,7 @@ gso: · 2040 unmodified lines
20412041 rcu_read_lock_bh();
20422042
20432043 txq = dev_pick_tx(dev, skb);
2044− q = rcu_dereference(txq->qdisc);
2044+ q = rcu_dereference_bh(txq->qdisc);
20452045
20462046 #ifdef CONFIG_NET_CLS_ACT
20472047 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS);
net/core/filter.c+3−3
@@ -86,7 +86,7 @@ int sk_filter(struct sock *sk, struct sk_buff *skb) · 85 unmodified lines
8686 return err;
8787
8888 rcu_read_lock_bh();
89− filter = rcu_dereference(sk->sk_filter);
89+ filter = rcu_dereference_bh(sk->sk_filter);
9090 if (filter) {
9191 unsigned int pkt_len = sk_run_filter(skb, filter->insns,
9292 filter->len);
@@ -521,7 +521,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk) · 428 unmodified lines
521521 }
522522
523523 rcu_read_lock_bh();
524− old_fp = rcu_dereference(sk->sk_filter);
524+ old_fp = rcu_dereference_bh(sk->sk_filter);
525525 rcu_assign_pointer(sk->sk_filter, fp);
526526 rcu_read_unlock_bh();
527527
@@ -536,7 +536,7 @@ int sk_detach_filter(struct sock *sk) · 8 unmodified lines
536536 struct sk_filter *filter;
537537
538538 rcu_read_lock_bh();
539− filter = rcu_dereference(sk->sk_filter);
539+ filter = rcu_dereference_bh(sk->sk_filter);
540540 if (filter) {
541541 rcu_assign_pointer(sk->sk_filter, NULL);
542542 sk_filter_delayed_uncharge(sk, filter);
net/core/rtnetlink.c+8−0
@@ -89,6 +89,14 @@ int rtnl_is_locked(void) · 88 unmodified lines
8989 }
9090 EXPORT_SYMBOL(rtnl_is_locked);
9191
92+#ifdef CONFIG_PROVE_LOCKING
93+int lockdep_rtnl_is_held(void)
94+{
95+ return lockdep_is_held(&rtnl_mutex);
96+}
97+EXPORT_SYMBOL(lockdep_rtnl_is_held);
98+#endif /* #ifdef CONFIG_PROVE_LOCKING */
99+
92100 static struct rtnl_link *rtnl_msg_handlers[NPROTO];
93101
94102 static inline int rtm_msgindex(int msgtype)
net/core/sock.c+2−1
@@ -1073,7 +1073,8 @@ static void __sk_free(struct sock *sk) · 1072 unmodified lines
10731073 if (sk->sk_destruct)
10741074 sk->sk_destruct(sk);
10751075
1076− filter = rcu_dereference(sk->sk_filter);
1076+ filter = rcu_dereference_check(sk->sk_filter,
1077+ atomic_read(&sk->sk_wmem_alloc) == 0);
10771078 if (filter) {
10781079 sk_filter_uncharge(sk, filter);
10791080 rcu_assign_pointer(sk->sk_filter, NULL);
net/decnet/dn_route.c+7−7
@@ -1155,8 +1155,8 @@ static int __dn_route_output_key(struct dst_entry **pprt, const struct flowi *fl · 1154 unmodified lines
11551155
11561156 if (!(flags & MSG_TRYHARD)) {
11571157 rcu_read_lock_bh();
1158− for(rt = rcu_dereference(dn_rt_hash_table[hash].chain); rt;
1159− rt = rcu_dereference(rt->u.dst.dn_next)) {
1158+ for (rt = rcu_dereference_bh(dn_rt_hash_table[hash].chain); rt;
1159+ rt = rcu_dereference_bh(rt->u.dst.dn_next)) {
11601160 if ((flp->fld_dst == rt->fl.fld_dst) &&
11611161 (flp->fld_src == rt->fl.fld_src) &&
11621162 (flp->mark == rt->fl.mark) &&
@@ -1618,9 +1618,9 @@ int dn_cache_dump(struct sk_buff *skb, struct netlink_callback *cb) · 455 unmodified lines
16181618 if (h > s_h)
16191619 s_idx = 0;
16201620 rcu_read_lock_bh();
1621− for(rt = rcu_dereference(dn_rt_hash_table[h].chain), idx = 0;
1621+ for(rt = rcu_dereference_bh(dn_rt_hash_table[h].chain), idx = 0;
16221622 rt;
1623− rt = rcu_dereference(rt->u.dst.dn_next), idx++) {
1623+ rt = rcu_dereference_bh(rt->u.dst.dn_next), idx++) {
16241624 if (idx < s_idx)
16251625 continue;
16261626 skb_dst_set(skb, dst_clone(&rt->u.dst));
@@ -1654,12 +1654,12 @@ static struct dn_route *dn_rt_cache_get_first(struct seq_file *seq) · 27 unmodified lines
16541654
16551655 for(s->bucket = dn_rt_hash_mask; s->bucket >= 0; --s->bucket) {
16561656 rcu_read_lock_bh();
1657− rt = dn_rt_hash_table[s->bucket].chain;
1657+ rt = rcu_dereference_bh(dn_rt_hash_table[s->bucket].chain);
16581658 if (rt)
16591659 break;
16601660 rcu_read_unlock_bh();
16611661 }
1662− return rcu_dereference(rt);
1662+ return rt;
16631663 }
16641664
16651665 static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_route *rt)
@@ -1674,7 +1674,7 @@ static struct dn_route *dn_rt_cache_get_next(struct seq_file *seq, struct dn_rou · 8 unmodified lines
16741674 rcu_read_lock_bh();
16751675 rt = dn_rt_hash_table[s->bucket].chain;
16761676 }
1677− return rcu_dereference(rt);
1677+ return rcu_dereference_bh(rt);
16781678 }
16791679
16801680 static void *dn_rt_cache_seq_start(struct seq_file *seq, loff_t *pos)
net/ipv4/route.c+7−7
@@ -287,12 +287,12 @@ static struct rtable *rt_cache_get_first(struct seq_file *seq) · 286 unmodified lines
287287 if (!rt_hash_table[st->bucket].chain)
288288 continue;
289289 rcu_read_lock_bh();
290− r = rcu_dereference(rt_hash_table[st->bucket].chain);
290+ r = rcu_dereference_bh(rt_hash_table[st->bucket].chain);
291291 while (r) {
292292 if (dev_net(r->u.dst.dev) == seq_file_net(seq) &&
293293 r->rt_genid == st->genid)
294294 return r;
295− r = rcu_dereference(r->u.dst.rt_next);
295+ r = rcu_dereference_bh(r->u.dst.rt_next);
296296 }
297297 rcu_read_unlock_bh();
298298 }
@@ -314,7 +314,7 @@ static struct rtable *__rt_cache_get_next(struct seq_file *seq, · 15 unmodified lines
314314 rcu_read_lock_bh();
315315 r = rt_hash_table[st->bucket].chain;
316316 }
317− return rcu_dereference(r);
317+ return rcu_dereference_bh(r);
318318 }
319319
320320 static struct rtable *rt_cache_get_next(struct seq_file *seq,
@@ -2689,8 +2689,8 @@ int __ip_route_output_key(struct net *net, struct rtable **rp, · 2368 unmodified lines
26892689 hash = rt_hash(flp->fl4_dst, flp->fl4_src, flp->oif, rt_genid(net));
26902690
26912691 rcu_read_lock_bh();
2692− for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
2693− rth = rcu_dereference(rth->u.dst.rt_next)) {
2692+ for (rth = rcu_dereference_bh(rt_hash_table[hash].chain); rth;
2693+ rth = rcu_dereference_bh(rth->u.dst.rt_next)) {
26942694 if (rth->fl.fl4_dst == flp->fl4_dst &&
26952695 rth->fl.fl4_src == flp->fl4_src &&
26962696 rth->fl.iif == 0 &&
@@ -3008,8 +3008,8 @@ int ip_rt_dump(struct sk_buff *skb, struct netlink_callback *cb) · 311 unmodified lines
30083008 if (!rt_hash_table[h].chain)
30093009 continue;
30103010 rcu_read_lock_bh();
3011− for (rt = rcu_dereference(rt_hash_table[h].chain), idx = 0; rt;
3012− rt = rcu_dereference(rt->u.dst.rt_next), idx++) {
3011+ for (rt = rcu_dereference_bh(rt_hash_table[h].chain), idx = 0; rt;
3012+ rt = rcu_dereference_bh(rt->u.dst.rt_next), idx++) {
30133013 if (!net_eq(dev_net(rt->u.dst.dev), net) || idx < s_idx)
30143014 continue;
30153015 if (rt_is_expired(rt))
net/packet/af_packet.c+1−1
@@ -508,7 +508,7 @@ static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk, · 507 unmodified lines
508508 struct sk_filter *filter;
509509
510510 rcu_read_lock_bh();
511− filter = rcu_dereference(sk->sk_filter);
511+ filter = rcu_dereference_bh(sk->sk_filter);
512512 if (filter != NULL)
513513 res = sk_run_filter(skb, filter->insns, filter->len);
514514 rcu_read_unlock_bh();
security/keys/gc.c+2−1
@@ -77,7 +77,8 @@ static bool key_gc_keyring(struct key *keyring, time_t limit) · 76 unmodified lines
7777 goto dont_gc;
7878
7979 /* scan the keyring looking for dead keys */
80− klist = rcu_dereference(keyring->payload.subscriptions);
80+ klist = rcu_dereference_check(keyring->payload.subscriptions,
81+ lockdep_is_held(&key_serial_lock));
8182 if (!klist)
8283 goto dont_gc;
8384
security/keys/keyring.c+3−1
@@ -151,7 +151,9 @@ static void keyring_destroy(struct key *keyring) · 150 unmodified lines
151151 write_unlock(&keyring_name_lock);
152152 }
153153
154− klist = rcu_dereference(keyring->payload.subscriptions);
154+ klist = rcu_dereference_check(keyring->payload.subscriptions,
155+ rcu_read_lock_held() ||
156+ atomic_read(&keyring->usage) == 0);
155157 if (klist) {
156158 for (loop = klist->nkeys - 1; loop >= 0; loop--)
157159 key_put(klist->keys[loop]);