aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-26 10:26:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-26 10:26:53 -0400
commit19b4a8d520a6e0176dd52aaa429261ad4fcaa545 (patch)
tree6dcf5a780718fc50b9cd79cc803daa7c7e080a02
parent3cfef9524677a4ecb392d6fbffe6ebce6302f1d4 (diff)
parent048b718029033af117870d3da47da12995be14a3 (diff)
Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
* 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (45 commits) rcu: Move propagation of ->completed from rcu_start_gp() to rcu_report_qs_rsp() rcu: Remove rcu_needs_cpu_flush() to avoid false quiescent states rcu: Wire up RCU_BOOST_PRIO for rcutree rcu: Make rcu_torture_boost() exit loops at end of test rcu: Make rcu_torture_fqs() exit loops at end of test rcu: Permit rt_mutex_unlock() with irqs disabled rcu: Avoid having just-onlined CPU resched itself when RCU is idle rcu: Suppress NMI backtraces when stall ends before dump rcu: Prohibit grace periods during early boot rcu: Simplify unboosting checks rcu: Prevent early boot set_need_resched() from __rcu_pending() rcu: Dump local stack if cannot dump all CPUs' stacks rcu: Move __rcu_read_unlock()'s barrier() within if-statement rcu: Improve rcu_assign_pointer() and RCU_INIT_POINTER() documentation rcu: Make rcu_assign_pointer() unconditionally insert a memory barrier rcu: Make rcu_implicit_dynticks_qs() locals be correct size rcu: Eliminate in_irq() checks in rcu_enter_nohz() nohz: Remove nohz_cpu_mask rcu: Document interpretation of RCU-lockdep splats rcu: Allow rcutorture's stat_interval parameter to be changed at runtime ...
-rw-r--r--Documentation/RCU/NMI-RCU.txt2
-rw-r--r--Documentation/RCU/lockdep-splat.txt110
-rw-r--r--Documentation/RCU/lockdep.txt34
-rw-r--r--Documentation/RCU/torture.txt137
-rw-r--r--Documentation/RCU/trace.txt38
-rw-r--r--include/linux/lockdep.h2
-rw-r--r--include/linux/rcupdate.h300
-rw-r--r--include/linux/rcutiny.h20
-rw-r--r--include/linux/rcutree.h2
-rw-r--r--include/linux/sched.h4
-rw-r--r--include/linux/types.h10
-rw-r--r--include/trace/events/rcu.h459
-rw-r--r--init/Kconfig6
-rw-r--r--kernel/lockdep.c84
-rw-r--r--kernel/pid.c4
-rw-r--r--kernel/rcu.h85
-rw-r--r--kernel/rcupdate.c26
-rw-r--r--kernel/rcutiny.c117
-rw-r--r--kernel/rcutiny_plugin.h134
-rw-r--r--kernel/rcutorture.c77
-rw-r--r--kernel/rcutree.c290
-rw-r--r--kernel/rcutree.h17
-rw-r--r--kernel/rcutree_plugin.h150
-rw-r--r--kernel/rcutree_trace.c13
-rw-r--r--kernel/rtmutex.c8
-rw-r--r--kernel/sched.c13
-rw-r--r--kernel/time/tick-sched.c6
27 files changed, 1489 insertions, 659 deletions
diff --git a/Documentation/RCU/NMI-RCU.txt b/Documentation/RCU/NMI-RCU.txt
index bf82851a0e57..687777f83b23 100644
--- a/Documentation/RCU/NMI-RCU.txt
+++ b/Documentation/RCU/NMI-RCU.txt
@@ -95,7 +95,7 @@ not to return until all ongoing NMI handlers exit. It is therefore safe
95to free up the handler's data as soon as synchronize_sched() returns. 95to free up the handler's data as soon as synchronize_sched() returns.
96 96
97Important note: for this to work, the architecture in question must 97Important note: for this to work, the architecture in question must
98invoke irq_enter() and irq_exit() on NMI entry and exit, respectively. 98invoke nmi_enter() and nmi_exit() on NMI entry and exit, respectively.
99 99
100 100
101Answer to Quick Quiz 101Answer to Quick Quiz
diff --git a/Documentation/RCU/lockdep-splat.txt b/Documentation/RCU/lockdep-splat.txt
new file mode 100644
index 000000000000..bf9061142827
--- /dev/null
+++ b/Documentation/RCU/lockdep-splat.txt
@@ -0,0 +1,110 @@
1Lockdep-RCU was added to the Linux kernel in early 2010
2(http://lwn.net/Articles/371986/). This facility checks for some common
3misuses of the RCU API, most notably using one of the rcu_dereference()
4family to access an RCU-protected pointer without the proper protection.
5When such misuse is detected, an lockdep-RCU splat is emitted.
6
7The usual cause of a lockdep-RCU slat is someone accessing an
8RCU-protected data structure without either (1) being in the right kind of
9RCU read-side critical section or (2) holding the right update-side lock.
10This problem can therefore be serious: it might result in random memory
11overwriting or worse. There can of course be false positives, this
12being the real world and all that.
13
14So let's look at an example RCU lockdep splat from 3.0-rc5, one that
15has long since been fixed:
16
17===============================
18[ INFO: suspicious RCU usage. ]
19-------------------------------
20block/cfq-iosched.c:2776 suspicious rcu_dereference_protected() usage!
21
22other info that might help us debug this:
23
24
25rcu_scheduler_active = 1, debug_locks = 0
263 locks held by scsi_scan_6/1552:
27 #0: (&shost->scan_mutex){+.+.+.}, at: [<ffffffff8145efca>]
28scsi_scan_host_selected+0x5a/0x150
29 #1: (&eq->sysfs_lock){+.+...}, at: [<ffffffff812a5032>]
30elevator_exit+0x22/0x60
31 #2: (&(&q->__queue_lock)->rlock){-.-...}, at: [<ffffffff812b6233>]
32cfq_exit_queue+0x43/0x190
33
34stack backtrace:
35Pid: 1552, comm: scsi_scan_6 Not tainted 3.0.0-rc5 #17
36Call Trace:
37 [<ffffffff810abb9b>] lockdep_rcu_dereference+0xbb/0xc0
38 [<ffffffff812b6139>] __cfq_exit_single_io_context+0xe9/0x120
39 [<ffffffff812b626c>] cfq_exit_queue+0x7c/0x190
40 [<ffffffff812a5046>] elevator_exit+0x36/0x60
41 [<ffffffff812a802a>] blk_cleanup_queue+0x4a/0x60
42 [<ffffffff8145cc09>] scsi_free_queue+0x9/0x10
43 [<ffffffff81460944>] __scsi_remove_device+0x84/0xd0
44 [<ffffffff8145dca3>] scsi_probe_and_add_lun+0x353/0xb10
45 [<ffffffff817da069>] ? error_exit+0x29/0xb0
46 [<ffffffff817d98ed>] ? _raw_spin_unlock_irqrestore+0x3d/0x80
47 [<ffffffff8145e722>] __scsi_scan_target+0x112/0x680
48 [<ffffffff812c690d>] ? trace_hardirqs_off_thunk+0x3a/0x3c
49 [<ffffffff817da069>] ? error_exit+0x29/0xb0
50 [<ffffffff812bcc60>] ? kobject_del+0x40/0x40
51 [<ffffffff8145ed16>] scsi_scan_channel+0x86/0xb0
52 [<ffffffff8145f0b0>] scsi_scan_host_selected+0x140/0x150
53 [<ffffffff8145f149>] do_scsi_scan_host+0x89/0x90
54 [<ffffffff8145f170>] do_scan_async+0x20/0x160
55 [<ffffffff8145f150>] ? do_scsi_scan_host+0x90/0x90
56 [<ffffffff810975b6>] kthread+0xa6/0xb0
57 [<ffffffff817db154>] kernel_thread_helper+0x4/0x10
58 [<ffffffff81066430>] ? finish_task_switch+0x80/0x110
59 [<ffffffff817d9c04>] ? retint_restore_args+0xe/0xe
60 [<ffffffff81097510>] ? __init_kthread_worker+0x70/0x70
61 [<ffffffff817db150>] ? gs_change+0xb/0xb
62
63Line 2776 of block/cfq-iosched.c in v3.0-rc5 is as follows:
64
65 if (rcu_dereference(ioc->ioc_data) == cic) {
66
67This form says that it must be in a plain vanilla RCU read-side critical
68section, but the "other info" list above shows that this is not the
69case. Instead, we hold three locks, one of which might be RCU related.
70And maybe that lock really does protect this reference. If so, the fix
71is to inform RCU, perhaps by changing __cfq_exit_single_io_context() to
72take the struct request_queue "q" from cfq_exit_queue() as an argument,
73which would permit us to invoke rcu_dereference_protected as follows:
74
75 if (rcu_dereference_protected(ioc->ioc_data,
76 lockdep_is_held(&q->queue_lock)) == cic) {
77
78With this change, there would be no lockdep-RCU splat emitted if this
79code was invoked either from within an RCU read-side critical section
80or with the ->queue_lock held. In particular, this would have suppressed
81the above lockdep-RCU splat because ->queue_lock is held (see #2 in the
82list above).
83
84On the other hand, perhaps we really do need an RCU read-side critical
85section. In this case, the critical section must span the use of the
86return value from rcu_dereference(), or at least until there is some
87reference count incremented or some such. One way to handle this is to
88add rcu_read_lock() and rcu_read_unlock() as follows:
89
90 rcu_read_lock();
91 if (rcu_dereference(ioc->ioc_data) == cic) {
92 spin_lock(&ioc->lock);
93 rcu_assign_pointer(ioc->ioc_data, NULL);
94 spin_unlock(&ioc->lock);
95 }
96 rcu_read_unlock();
97
98With this change, the rcu_dereference() is always within an RCU
99read-side critical section, which again would have suppressed the
100above lockdep-RCU splat.
101
102But in this particular case, we don't actually deference the pointer
103returned from rcu_dereference(). Instead, that pointer is just compared
104to the cic pointer, which means that the rcu_dereference() can be replaced
105by rcu_access_pointer() as follows:
106
107 if (rcu_access_pointer(ioc->ioc_data) == cic) {
108
109Because it is legal to invoke rcu_access_pointer() without protection,
110this change would also suppress the above lockdep-RCU splat.
diff --git a/Documentation/RCU/lockdep.txt b/Documentation/RCU/lockdep.txt
index d7a49b2f6994..a102d4b3724b 100644
--- a/Documentation/RCU/lockdep.txt
+++ b/Documentation/RCU/lockdep.txt
@@ -32,9 +32,27 @@ checking of rcu_dereference() primitives:
32 srcu_dereference(p, sp): 32 srcu_dereference(p, sp):
33 Check for SRCU read-side critical section. 33 Check for SRCU read-side critical section.
34 rcu_dereference_check(p, c): 34 rcu_dereference_check(p, c):
35 Use explicit check expression "c". This is useful in 35 Use explicit check expression "c" along with
36 code that is invoked by both readers and updaters. 36 rcu_read_lock_held(). This is useful in code that is
37 rcu_dereference_raw(p) 37 invoked by both RCU readers and updaters.
38 rcu_dereference_bh_check(p, c):
39 Use explicit check expression "c" along with
40 rcu_read_lock_bh_held(). This is useful in code that
41 is invoked by both RCU-bh readers and updaters.