Skip to content

Commit 19b4a8d

Browse files
committed
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 ...
2 parents 3cfef95 + 048b718 commit 19b4a8d

27 files changed

Lines changed: 1489 additions & 659 deletions

‎Documentation/RCU/NMI-RCU.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ not to return until all ongoing NMI handlers exit. It is therefore safe
9595
to free up the handler's data as soon as synchronize_sched() returns.
9696

9797
Important note: for this to work, the architecture in question must
98-
invoke irq_enter() and irq_exit() on NMI entry and exit, respectively.
98+
invoke nmi_enter() and nmi_exit() on NMI entry and exit, respectively.
9999

100100

101101
Answer to Quick Quiz
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
Lockdep-RCU was added to the Linux kernel in early 2010
2+
(http://lwn.net/Articles/371986/). This facility checks for some common
3+
misuses of the RCU API, most notably using one of the rcu_dereference()
4+
family to access an RCU-protected pointer without the proper protection.
5+
When such misuse is detected, an lockdep-RCU splat is emitted.
6+
7+
The usual cause of a lockdep-RCU slat is someone accessing an
8+
RCU-protected data structure without either (1) being in the right kind of
9+
RCU read-side critical section or (2) holding the right update-side lock.
10+
This problem can therefore be serious: it might result in random memory
11+
overwriting or worse. There can of course be false positives, this
12+
being the real world and all that.
13+
14+
So let's look at an example RCU lockdep splat from 3.0-rc5, one that
15+
has long since been fixed:
16+
17+
===============================
18+
[ INFO: suspicious RCU usage. ]
19+
-------------------------------
20+
block/cfq-iosched.c:2776 suspicious rcu_dereference_protected() usage!
21+
22+
other info that might help us debug this:
23+
24+
25+
rcu_scheduler_active = 1, debug_locks = 0
26+
3 locks held by scsi_scan_6/1552:
27+
#0: (&shost->scan_mutex){+.+.+.}, at: [<ffffffff8145efca>]
28+
scsi_scan_host_selected+0x5a/0x150
29+
#1: (&eq->sysfs_lock){+.+...}, at: [<ffffffff812a5032>]
30+
elevator_exit+0x22/0x60
31+
#2: (&(&q->__queue_lock)->rlock){-.-...}, at: [<ffffffff812b6233>]
32+
cfq_exit_queue+0x43/0x190
33+
34+
stack backtrace:
35+
Pid: 1552, comm: scsi_scan_6 Not tainted 3.0.0-rc5 #17
36+
Call 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+
63+
Line 2776 of block/cfq-iosched.c in v3.0-rc5 is as follows:
64+
65+
if (rcu_dereference(ioc->ioc_data) == cic) {
66+
67+
This form says that it must be in a plain vanilla RCU read-side critical
68+
section, but the "other info" list above shows that this is not the
69+
case. Instead, we hold three locks, one of which might be RCU related.
70+
And maybe that lock really does protect this reference. If so, the fix
71+
is to inform RCU, perhaps by changing __cfq_exit_single_io_context() to
72+
take the struct request_queue "q" from cfq_exit_queue() as an argument,
73+
which 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+
78+
With this change, there would be no lockdep-RCU splat emitted if this
79+
code was invoked either from within an RCU read-side critical section
80+
or with the ->queue_lock held. In particular, this would have suppressed
81+
the above lockdep-RCU splat because ->queue_lock is held (see #2 in the
82+
list above).
83+
84+
On the other hand, perhaps we really do need an RCU read-side critical
85+
section. In this case, the critical section must span the use of the
86+
return value from rcu_dereference(), or at least until there is some
87+
reference count incremented or some such. One way to handle this is to
88+
add 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+
98+
With this change, the rcu_dereference() is always within an RCU
99+
read-side critical section, which again would have suppressed the
100+
above lockdep-RCU splat.
101+
102+
But in this particular case, we don't actually deference the pointer
103+
returned from rcu_dereference(). Instead, that pointer is just compared
104+
to the cic pointer, which means that the rcu_dereference() can be replaced
105+
by rcu_access_pointer() as follows:
106+
107+
if (rcu_access_pointer(ioc->ioc_data) == cic) {
108+
109+
Because it is legal to invoke rcu_access_pointer() without protection,
110+
this change would also suppress the above lockdep-RCU splat.

‎Documentation/RCU/lockdep.txt‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,27 @@ checking of rcu_dereference() primitives:
3232
srcu_dereference(p, sp):
3333
Check for SRCU read-side critical section.
3434
rcu_dereference_check(p, c):
35-
Use explicit check expression "c". This is useful in
36-
code that is invoked by both readers and updaters.
37-
rcu_dereference_raw(p)
35+
Use explicit check expression "c" along with
36+
rcu_read_lock_held(). This is useful in code that is
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.
42+
rcu_dereference_sched_check(p, c):
43+
Use explicit check expression "c" along with
44+
rcu_read_lock_sched_held(). This is useful in code that
45+
is invoked by both RCU-sched readers and updaters.
46+
srcu_dereference_check(p, c):
47+
Use explicit check expression "c" along with
48+
srcu_read_lock_held()(). This is useful in code that
49+
is invoked by both SRCU readers and updaters.
50+
rcu_dereference_index_check(p, c):
51+
Use explicit check expression "c", but the caller
52+
must supply one of the rcu_read_lock_held() functions.
53+
This is useful in code that uses RCU-protected arrays
54+
that is invoked by both RCU readers and updaters.
55+
rcu_dereference_raw(p):
3856
Don't check. (Use sparingly, if at all.)
3957
rcu_dereference_protected(p, c):
4058
Use explicit check expression "c", and omit all barriers
@@ -48,21 +66,19 @@ checking of rcu_dereference() primitives:
4866
value of the pointer itself, for example, against NULL.
4967

5068
The rcu_dereference_check() check expression can be any boolean
51-
expression, but would normally include one of the rcu_read_lock_held()
52-
family of functions and a lockdep expression. However, any boolean
53-
expression can be used. For a moderately ornate example, consider
54-
the following:
69+
expression, but would normally include a lockdep expression. However,
70+
any boolean expression can be used. For a moderately ornate example,
71+
consider the following:
5572

5673
file = rcu_dereference_check(fdt->fd[fd],
57-
rcu_read_lock_held() ||
5874
lockdep_is_held(&files->file_lock) ||
5975
atomic_read(&files->count) == 1);
6076

6177
This expression picks up the pointer "fdt->fd[fd]" in an RCU-safe manner,
6278
and, if CONFIG_PROVE_RCU is configured, verifies that this expression
6379
is used in:
6480

65-
1. An RCU read-side critical section, or
81+
1. An RCU read-side critical section (implicit), or
6682
2. with files->file_lock held, or
6783
3. on an unshared files_struct.
6884

‎Documentation/RCU/torture.txt‎

Lines changed: 102 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fqs_holdoff Holdoff time (in microseconds) between consecutive calls
4242
fqs_stutter Wait time (in seconds) between consecutive bursts
4343
of calls to force_quiescent_state().
4444

45-
irqreaders Says to invoke RCU readers from irq level. This is currently
45+
irqreader Says to invoke RCU readers from irq level. This is currently
4646
done via timers. Defaults to "1" for variants of RCU that
4747
permit this. (Or, more accurately, variants of RCU that do
4848
-not- permit this know to ignore this variable.)
@@ -79,19 +79,68 @@ stutter The length of time to run the test before pausing for this
7979
Specifying "stutter=0" causes the test to run continuously
8080
without pausing, which is the old default behavior.
8181

82+
test_boost Whether or not to test the ability of RCU to do priority
83+
boosting. Defaults to "test_boost=1", which performs
84+
RCU priority-inversion testing only if the selected
85+
RCU implementation supports priority boosting. Specifying
86+
"test_boost=0" never performs RCU priority-inversion
87+
testing. Specifying "test_boost=2" performs RCU
88+
priority-inversion testing even if the selected RCU
89+
implementation does not support RCU priority boosting,
90+
which can be used to test rcutorture's ability to
91+
carry out RCU priority-inversion testing.
92+
93+
test_boost_interval
94+
The number of seconds in an RCU priority-inversion test
95+
cycle. Defaults to "test_boost_interval=7". It is
96+
usually wise for this value to be relatively prime to
97+
the value selected for "stutter".
98+
99+
test_boost_duration
100+
The number of seconds to do RCU priority-inversion testing
101+
within any given "test_boost_interval". Defaults to
102+
"test_boost_duration=4".
103+
82104
test_no_idle_hz Whether or not to test the ability of RCU to operate in
83105
a kernel that disables the scheduling-clock interrupt to
84106
idle CPUs. Boolean parameter, "1" to test, "0" otherwise.
85107
Defaults to omitting this test.
86108

87-
torture_type The type of RCU to test: "rcu" for the rcu_read_lock() API,
88-
"rcu_sync" for rcu_read_lock() with synchronous reclamation,
89-
"rcu_bh" for the rcu_read_lock_bh() API, "rcu_bh_sync" for
90-
rcu_read_lock_bh() with synchronous reclamation, "srcu" for
91-
the "srcu_read_lock()" API, "sched" for the use of
92-
preempt_disable() together with synchronize_sched(),
93-
and "sched_expedited" for the use of preempt_disable()
94-
with synchronize_sched_expedited().
109+
torture_type The type of RCU to test, with string values as follows:
110+
111+
"rcu": rcu_read_lock(), rcu_read_unlock() and call_rcu().
112+
113+
"rcu_sync": rcu_read_lock(), rcu_read_unlock(), and
114+
synchronize_rcu().
115+
116+
"rcu_expedited": rcu_read_lock(), rcu_read_unlock(), and
117+
synchronize_rcu_expedited().
118+
119+
"rcu_bh": rcu_read_lock_bh(), rcu_read_unlock_bh(), and
120+
call_rcu_bh().
121+
122+
"rcu_bh_sync": rcu_read_lock_bh(), rcu_read_unlock_bh(),
123+
and synchronize_rcu_bh().
124+
125+
"rcu_bh_expedited": rcu_read_lock_bh(), rcu_read_unlock_bh(),
126+
and synchronize_rcu_bh_expedited().
127+
128+
"srcu": srcu_read_lock(), srcu_read_unlock() and
129+
synchronize_srcu().
130+
131+
"srcu_expedited": srcu_read_lock(), srcu_read_unlock() and
132+
synchronize_srcu_expedited().
133+
134+
"sched": preempt_disable(), preempt_enable(), and
135+
call_rcu_sched().
136+
137+
"sched_sync": preempt_disable(), preempt_enable(), and
138+
synchronize_sched().
139+
140+
"sched_expedited": preempt_disable(), preempt_enable(), and
141+
synchronize_sched_expedited().
142+
143+
Defaults to "rcu".
95144

96145
verbose Enable debug printk()s. Default is disabled.
97146

@@ -100,39 +149,68 @@ OUTPUT
100149

101150
The statistics output is as follows:
102151

103-
rcu-torture: --- Start of test: nreaders=16 stat_interval=0 verbose=0
104-
rcu-torture: rtc: 0000000000000000 ver: 1916 tfle: 0 rta: 1916 rtaf: 0 rtf: 1915
105-
rcu-torture: Reader Pipe: 1466408 9747 0 0 0 0 0 0 0 0 0
106-
rcu-torture: Reader Batch: 1464477 11678 0 0 0 0 0 0 0 0
107-
rcu-torture: Free-Block Circulation: 1915 1915 1915 1915 1915 1915 1915 1915 1915 1915 0
108-
rcu-torture: --- End of test
152+
rcu-torture:--- Start of test: nreaders=16 nfakewriters=4 stat_interval=30 verbose=0 test_no_idle_hz=1 shuffle_interval=3 stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 fqs_stutter=3 test_boost=1/0 test_boost_interval=7 test_boost_duration=4
153+
rcu-torture: rtc: (null) ver: 155441 tfle: 0 rta: 155441 rtaf: 8884 rtf: 155440 rtmbe: 0 rtbke: 0 rtbre: 0 rtbf: 0 rtb: 0 nt: 3055767
154+
rcu-torture: Reader Pipe: 727860534 34213 0 0 0 0 0 0 0 0 0
155+
rcu-torture: Reader Batch: 727877838 17003 0 0 0 0 0 0 0 0 0
156+
rcu-torture: Free-Block Circulation: 155440 155440 155440 155440 155440 155440 155440 155440 155440 155440 0
157+
rcu-torture:--- End of test: SUCCESS: nreaders=16 nfakewriters=4 stat_interval=30 verbose=0 test_no_idle_hz=1 shuffle_interval=3 stutter=5 irqreader=1 fqs_duration=0 fqs_holdoff=0 fqs_stutter=3 test_boost=1/0 test_boost_interval=7 test_boost_duration=4
109158

110159
The command "dmesg | grep torture:" will extract this information on
111160
most systems. On more esoteric configurations, it may be necessary to
112161
use other commands to access the output of the printk()s used by
113162
the RCU torture test. The printk()s use KERN_ALERT, so they should
114163
be evident. ;-)
115164

165+
The first and last lines show the rcutorture module parameters, and the
166+
last line shows either "SUCCESS" or "FAILURE", based on rcutorture's
167+
automatic determination as to whether RCU operated correctly.
168+
116169
The entries are as follows:
117170

118171
o "rtc": The hexadecimal address of the structure currently visible
119172
to readers.
120173

121-
o "ver": The number of times since boot that the rcutw writer task
174+
o "ver": The number of times since boot that the RCU writer task
122175
has changed the structure visible to readers.
123176

124177
o "tfle": If non-zero, indicates that the "torture freelist"
125-
containing structure to be placed into the "rtc" area is empty.
178+
containing structures to be placed into the "rtc" area is empty.
126179
This condition is important, since it can fool you into thinking
127180
that RCU is working when it is not. :-/
128181

129182
o "rta": Number of structures allocated from the torture freelist.
130183

131184
o "rtaf": Number of allocations from the torture freelist that have
132-
failed due to the list being empty.
185+
failed due to the list being empty. It is not unusual for this
186+
to be non-zero, but it is bad for it to be a large fraction of
187+
the value indicated by "rta".
133188

134189
o "rtf": Number of frees into the torture freelist.
135190

191+
o "rtmbe": A non-zero value indicates that rcutorture believes that
192+
rcu_assign_pointer() and rcu_dereference() are not working
193+
correctly. This value should be zero.
194+
195+
o "rtbke": rcutorture was unable to create the real-time kthreads
196+
used to force RCU priority inversion. This value should be zero.
197+
198+
o "rtbre": Although rcutorture successfully created the kthreads
199+
used to force RCU priority inversion, it was unable to set them
200+
to the real-time priority level of 1. This value should be zero.
201+
202+
o "rtbf": The number of times that RCU priority boosting failed
203+
to resolve RCU priority inversion.
204+
205+
o "rtb": The number of times that rcutorture attempted to force
206+
an RCU priority inversion condition. If you are testing RCU
207+
priority boosting via the "test_boost" module parameter, this
208+
value should be non-zero.
209+
210+
o "nt": The number of times rcutorture ran RCU read-side code from
211+
within a timer handler. This value should be non-zero only
212+
if you specified the "irqreader" module parameter.
213+
136214
o "Reader Pipe": Histogram of "ages" of structures seen by readers.
137215
If any entries past the first two are non-zero, RCU is broken.
138216
And rcutorture prints the error flag string "!!!" to make sure
@@ -162,26 +240,15 @@ o "Free-Block Circulation": Shows the number of torture structures
162240
somehow gets incremented farther than it should.
163241

164242
Different implementations of RCU can provide implementation-specific
165-
additional information. For example, SRCU provides the following:
243+
additional information. For example, SRCU provides the following
244+
additional line:
166245

167-
srcu-torture: rtc: f8cf46a8 ver: 355 tfle: 0 rta: 356 rtaf: 0 rtf: 346 rtmbe: 0
168-
srcu-torture: Reader Pipe: 559738 939 0 0 0 0 0 0 0 0 0
169-
srcu-torture: Reader Batch: 560434 243 0 0 0 0 0 0 0 0
170-
srcu-torture: Free-Block Circulation: 355 354 353 352 351 350 349 348 347 346 0
171246
srcu-torture: per-CPU(idx=1): 0(0,1) 1(0,1) 2(0,0) 3(0,1)
172247

173-
The first four lines are similar to those for RCU. The last line shows
174-
the per-CPU counter state. The numbers in parentheses are the values
175-
of the "old" and "current" counters for the corresponding CPU. The
176-
"idx" value maps the "old" and "current" values to the underlying array,
177-
and is useful for debugging.
178-
179-
Similarly, sched_expedited RCU provides the following:
180-
181-
sched_expedited-torture: rtc: d0000000016c1880 ver: 1090796 tfle: 0 rta: 1090796 rtaf: 0 rtf: 1090787 rtmbe: 0 nt: 27713319
182-
sched_expedited-torture: Reader Pipe: 12660320201 95875 0 0 0 0 0 0 0 0 0
183-
sched_expedited-torture: Reader Batch: 12660424885 0 0 0 0 0 0 0 0 0 0
184-
sched_expedited-torture: Free-Block Circulation: 1090795 1090795 1090794 1090793 1090792 1090791 1090790 1090789 1090788 1090787 0
248+
This line shows the per-CPU counter state. The numbers in parentheses are
249+
the values of the "old" and "current" counters for the corresponding CPU.
250+
The "idx" value maps the "old" and "current" values to the underlying
251+
array, and is useful for debugging.
185252

186253

187254
USAGE

0 commit comments

Comments
 (0)