Commit a3b0a79f authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Paul E. McKenney

docs: RCU: Convert lockdep-splat.txt to ReST

- Add a SPDX header;
- Add a document title;
- Some whitespace fixes and new line breaks;
- Mark literal blocks as such;
- Add it to RCU/index.rst.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: default avatarPaul E. McKenney <paulmck@kernel.org>
parent 6b05dfac
...@@ -11,6 +11,7 @@ RCU concepts ...@@ -11,6 +11,7 @@ RCU concepts
arrayRCU arrayRCU
checklist checklist
lockdep-splat
rcubarrier rcubarrier
rcu_dereference rcu_dereference
whatisRCU whatisRCU
......
.. SPDX-License-Identifier: GPL-2.0
=================
Lockdep-RCU Splat
=================
Lockdep-RCU was added to the Linux kernel in early 2010 Lockdep-RCU was added to the Linux kernel in early 2010
(http://lwn.net/Articles/371986/). This facility checks for some common (http://lwn.net/Articles/371986/). This facility checks for some common
misuses of the RCU API, most notably using one of the rcu_dereference() misuses of the RCU API, most notably using one of the rcu_dereference()
...@@ -12,28 +18,27 @@ overwriting or worse. There can of course be false positives, this ...@@ -12,28 +18,27 @@ overwriting or worse. There can of course be false positives, this
being the real world and all that. being the real world and all that.
So let's look at an example RCU lockdep splat from 3.0-rc5, one that So let's look at an example RCU lockdep splat from 3.0-rc5, one that
has long since been fixed: has long since been fixed::
=============================
WARNING: suspicious RCU usage
-----------------------------
block/cfq-iosched.c:2776 suspicious rcu_dereference_protected() usage!
other info that might help us debug this: =============================
WARNING: suspicious RCU usage
-----------------------------
block/cfq-iosched.c:2776 suspicious rcu_dereference_protected() usage!
other info that might help us debug this::
rcu_scheduler_active = 1, debug_locks = 0 rcu_scheduler_active = 1, debug_locks = 0
3 locks held by scsi_scan_6/1552: 3 locks held by scsi_scan_6/1552:
#0: (&shost->scan_mutex){+.+.}, at: [<ffffffff8145efca>] #0: (&shost->scan_mutex){+.+.}, at: [<ffffffff8145efca>]
scsi_scan_host_selected+0x5a/0x150 scsi_scan_host_selected+0x5a/0x150
#1: (&eq->sysfs_lock){+.+.}, at: [<ffffffff812a5032>] #1: (&eq->sysfs_lock){+.+.}, at: [<ffffffff812a5032>]
elevator_exit+0x22/0x60 elevator_exit+0x22/0x60
#2: (&(&q->__queue_lock)->rlock){-.-.}, at: [<ffffffff812b6233>] #2: (&(&q->__queue_lock)->rlock){-.-.}, at: [<ffffffff812b6233>]
cfq_exit_queue+0x43/0x190 cfq_exit_queue+0x43/0x190
stack backtrace: stack backtrace:
Pid: 1552, comm: scsi_scan_6 Not tainted 3.0.0-rc5 #17 Pid: 1552, comm: scsi_scan_6 Not tainted 3.0.0-rc5 #17
Call Trace: Call Trace:
[<ffffffff810abb9b>] lockdep_rcu_dereference+0xbb/0xc0 [<ffffffff810abb9b>] lockdep_rcu_dereference+0xbb/0xc0
[<ffffffff812b6139>] __cfq_exit_single_io_context+0xe9/0x120 [<ffffffff812b6139>] __cfq_exit_single_io_context+0xe9/0x120
[<ffffffff812b626c>] cfq_exit_queue+0x7c/0x190 [<ffffffff812b626c>] cfq_exit_queue+0x7c/0x190
...@@ -60,7 +65,7 @@ Call Trace: ...@@ -60,7 +65,7 @@ Call Trace:
[<ffffffff81097510>] ? __kthread_init_worker+0x70/0x70 [<ffffffff81097510>] ? __kthread_init_worker+0x70/0x70
[<ffffffff817db150>] ? gs_change+0xb/0xb [<ffffffff817db150>] ? gs_change+0xb/0xb
Line 2776 of block/cfq-iosched.c in v3.0-rc5 is as follows: Line 2776 of block/cfq-iosched.c in v3.0-rc5 is as follows::
if (rcu_dereference(ioc->ioc_data) == cic) { if (rcu_dereference(ioc->ioc_data) == cic) {
...@@ -70,7 +75,7 @@ case. Instead, we hold three locks, one of which might be RCU related. ...@@ -70,7 +75,7 @@ case. Instead, we hold three locks, one of which might be RCU related.
And maybe that lock really does protect this reference. If so, the fix And maybe that lock really does protect this reference. If so, the fix
is to inform RCU, perhaps by changing __cfq_exit_single_io_context() to is to inform RCU, perhaps by changing __cfq_exit_single_io_context() to
take the struct request_queue "q" from cfq_exit_queue() as an argument, take the struct request_queue "q" from cfq_exit_queue() as an argument,
which would permit us to invoke rcu_dereference_protected as follows: which would permit us to invoke rcu_dereference_protected as follows::
if (rcu_dereference_protected(ioc->ioc_data, if (rcu_dereference_protected(ioc->ioc_data,
lockdep_is_held(&q->queue_lock)) == cic) { lockdep_is_held(&q->queue_lock)) == cic) {
...@@ -85,7 +90,7 @@ On the other hand, perhaps we really do need an RCU read-side critical ...@@ -85,7 +90,7 @@ On the other hand, perhaps we really do need an RCU read-side critical
section. In this case, the critical section must span the use of the section. In this case, the critical section must span the use of the
return value from rcu_dereference(), or at least until there is some return value from rcu_dereference(), or at least until there is some
reference count incremented or some such. One way to handle this is to reference count incremented or some such. One way to handle this is to
add rcu_read_lock() and rcu_read_unlock() as follows: add rcu_read_lock() and rcu_read_unlock() as follows::
rcu_read_lock(); rcu_read_lock();
if (rcu_dereference(ioc->ioc_data) == cic) { if (rcu_dereference(ioc->ioc_data) == cic) {
...@@ -102,7 +107,7 @@ above lockdep-RCU splat. ...@@ -102,7 +107,7 @@ above lockdep-RCU splat.
But in this particular case, we don't actually dereference the pointer But in this particular case, we don't actually dereference the pointer
returned from rcu_dereference(). Instead, that pointer is just compared returned from rcu_dereference(). Instead, that pointer is just compared
to the cic pointer, which means that the rcu_dereference() can be replaced to the cic pointer, which means that the rcu_dereference() can be replaced
by rcu_access_pointer() as follows: by rcu_access_pointer() as follows::
if (rcu_access_pointer(ioc->ioc_data) == cic) { if (rcu_access_pointer(ioc->ioc_data) == cic) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment