Merge branches 'doc.2021.01.06a', 'fixes.2021.01.04b', 'kfree_rcu.2021.01.04a', ...
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 22 Jan 2021 23:26:44 +0000 (15:26 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 22 Jan 2021 23:26:44 +0000 (15:26 -0800)
doc.2021.01.06a: Documentation updates.
fixes.2021.01.04b: Miscellaneous fixes.
kfree_rcu.2021.01.04a: kfree_rcu() updates.
mmdumpobj.2021.01.22a: Dump allocation point for memory blocks.
nocb.2021.01.06a: RCU callback offload updates and cblist segment lengths.
rt.2021.01.04a: Real-time updates.
stall.2021.01.06a: RCU CPU stall warning updates.
torture.2021.01.12a: Torture-test updates and polling SRCU grace-period API.
tortureall.2021.01.06a: Torture-test script updates.

52 files changed:
Documentation/RCU/Design/Expedited-Grace-Periods/Expedited-Grace-Periods.rst
Documentation/RCU/Design/Requirements/Requirements.rst
Documentation/RCU/checklist.rst
Documentation/RCU/rcubarrier.rst
Documentation/RCU/stallwarn.rst
Documentation/RCU/whatisRCU.rst
Documentation/admin-guide/kernel-parameters.txt
include/linux/list.h
include/linux/mm.h
include/linux/rcupdate.h
include/linux/slab.h
include/linux/srcu.h
include/linux/srcutiny.h
include/linux/torture.h
include/linux/vmalloc.h
init/main.c
kernel/locking/locktorture.c
kernel/rcu/Kconfig
kernel/rcu/rcu.h
kernel/rcu/rcutorture.c
kernel/rcu/refscale.c
kernel/rcu/srcutiny.c
kernel/rcu/srcutree.c
kernel/rcu/tasks.h
kernel/rcu/tree.c
kernel/rcu/tree_exp.h
kernel/rcu/tree_plugin.h
kernel/rcu/tree_stall.h
kernel/rcu/update.c
kernel/scftorture.c
kernel/sched/core.c
kernel/torture.c
lib/percpu-refcount.c
mm/slab.c
mm/slab.h
mm/slab_common.c
mm/slob.c
mm/slub.c
mm/util.c
mm/vmalloc.c
tools/testing/selftests/rcutorture/bin/config2csv.sh [new file with mode: 0755]
tools/testing/selftests/rcutorture/bin/console-badness.sh
tools/testing/selftests/rcutorture/bin/functions.sh
tools/testing/selftests/rcutorture/bin/kvm-find-errors.sh
tools/testing/selftests/rcutorture/bin/kvm-recheck.sh
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh
tools/testing/selftests/rcutorture/bin/kvm.sh
tools/testing/selftests/rcutorture/bin/parse-build.sh
tools/testing/selftests/rcutorture/bin/parse-console.sh
tools/testing/selftests/rcutorture/bin/torture.sh [new file with mode: 0755]
tools/testing/selftests/rcutorture/configs/rcu/RUDE01.boot
tools/testing/selftests/rcutorture/configs/rcu/TASKS01.boot

index 72f0f6fbd53c08e147362ea520456f20f11a0c8f..6f89cf1e567d099aa3c4f963a7b8c628fe19a062 100644 (file)
@@ -38,7 +38,7 @@ sections.
 RCU-preempt Expedited Grace Periods
 ===================================
 
-``CONFIG_PREEMPT=y`` kernels implement RCU-preempt.
+``CONFIG_PREEMPTION=y`` kernels implement RCU-preempt.
 The overall flow of the handling of a given CPU by an RCU-preempt
 expedited grace period is shown in the following diagram:
 
@@ -112,7 +112,7 @@ things.
 RCU-sched Expedited Grace Periods
 ---------------------------------
 
-``CONFIG_PREEMPT=n`` kernels implement RCU-sched. The overall flow of
+``CONFIG_PREEMPTION=n`` kernels implement RCU-sched. The overall flow of
 the handling of a given CPU by an RCU-sched expedited grace period is
 shown in the following diagram:
 
index e8c84fcc050716af8f19f326962e5c11b392fa41..0da9133fa13ab675ff624868560fdbfbd98e3953 100644 (file)
@@ -72,13 +72,13 @@ understanding of this guarantee.
 
 RCU's grace-period guarantee allows updaters to wait for the completion
 of all pre-existing RCU read-side critical sections. An RCU read-side
-critical section begins with the marker ``rcu_read_lock()`` and ends
-with the marker ``rcu_read_unlock()``. These markers may be nested, and
+critical section begins with the marker rcu_read_lock() and ends
+with the marker rcu_read_unlock(). These markers may be nested, and
 RCU treats a nested set as one big RCU read-side critical section.
-Production-quality implementations of ``rcu_read_lock()`` and
-``rcu_read_unlock()`` are extremely lightweight, and in fact have
+Production-quality implementations of rcu_read_lock() and
+rcu_read_unlock() are extremely lightweight, and in fact have
 exactly zero overhead in Linux kernels built for production use with
-``CONFIG_PREEMPT=n``.
+``CONFIG_PREEMPTION=n``.
 
 This guarantee allows ordering to be enforced with extremely low
 overhead to readers, for example:
@@ -102,12 +102,12 @@ overhead to readers, for example:
       15   WRITE_ONCE(y, 1);
       16 }
 
-Because the ``synchronize_rcu()`` on line 14 waits for all pre-existing
-readers, any instance of ``thread0()`` that loads a value of zero from
-``x`` must complete before ``thread1()`` stores to ``y``, so that
+Because the synchronize_rcu() on line 14 waits for all pre-existing
+readers, any instance of thread0() that loads a value of zero from
+``x`` must complete before thread1() stores to ``y``, so that
 instance must also load a value of zero from ``y``. Similarly, any
-instance of ``thread0()`` that loads a value of one from ``y`` must have
-started after the ``synchronize_rcu()`` started, and must therefore also
+instance of thread0() that loads a value of one from ``y`` must have
+started after the synchronize_rcu() started, and must therefore also
 load a value of one from ``x``. Therefore, the outcome:
 
    ::
@@ -121,14 +121,14 @@ cannot happen.
 +-----------------------------------------------------------------------+
 | Wait a minute! You said that updaters can make useful forward         |
 | progress concurrently with readers, but pre-existing readers will     |
-| block ``synchronize_rcu()``!!!                                        |
+| block synchronize_rcu()!!!                                            |
 | Just who are you trying to fool???                                    |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
 | First, if updaters do not wish to be blocked by readers, they can use |
-| ``call_rcu()`` or ``kfree_rcu()``, which will be discussed later.     |
-| Second, even when using ``synchronize_rcu()``, the other update-side  |
+| call_rcu() or kfree_rcu(), which will be discussed later.             |
+| Second, even when using synchronize_rcu(), the other update-side      |
 | code does run concurrently with readers, whether pre-existing or not. |
 +-----------------------------------------------------------------------+
 
@@ -170,34 +170,34 @@ recovery from node failure, more or less as follows:
       29   WRITE_ONCE(state, STATE_NORMAL);
       30 }
 
-The RCU read-side critical section in ``do_something_dlm()`` works with
-the ``synchronize_rcu()`` in ``start_recovery()`` to guarantee that
-``do_something()`` never runs concurrently with ``recovery()``, but with
-little or no synchronization overhead in ``do_something_dlm()``.
+The RCU read-side critical section in do_something_dlm() works with
+the synchronize_rcu() in start_recovery() to guarantee that
+do_something() never runs concurrently with recovery(), but with
+little or no synchronization overhead in do_something_dlm().
 
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| Why is the ``synchronize_rcu()`` on line 28 needed?                   |
+| Why is the synchronize_rcu() on line 28 needed?                       |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
 | Without that extra grace period, memory reordering could result in    |
-| ``do_something_dlm()`` executing ``do_something()`` concurrently with |
-| the last bits of ``recovery()``.                                      |
+| do_something_dlm() executing do_something() concurrently with         |
+| the last bits of recovery().                                          |
 +-----------------------------------------------------------------------+
 
 In order to avoid fatal problems such as deadlocks, an RCU read-side
-critical section must not contain calls to ``synchronize_rcu()``.
+critical section must not contain calls to synchronize_rcu().
 Similarly, an RCU read-side critical section must not contain anything
 that waits, directly or indirectly, on completion of an invocation of
-``synchronize_rcu()``.
+synchronize_rcu().
 
 Although RCU's grace-period guarantee is useful in and of itself, with
 `quite a few use cases <https://lwn.net/Articles/573497/>`__, it would
 be good to be able to use RCU to coordinate read-side access to linked
 data structures. For this, the grace-period guarantee is not sufficient,
-as can be seen in function ``add_gp_buggy()`` below. We will look at the
+as can be seen in function add_gp_buggy() below. We will look at the
 reader's code later, but in the meantime, just think of the reader as
 locklessly picking up the ``gp`` pointer, and, if the value loaded is
 non-\ ``NULL``, locklessly accessing the ``->a`` and ``->b`` fields.
@@ -256,8 +256,8 @@ Publish/Subscribe Guarantee
 
 RCU's publish-subscribe guarantee allows data to be inserted into a
 linked data structure without disrupting RCU readers. The updater uses
-``rcu_assign_pointer()`` to insert the new data, and readers use
-``rcu_dereference()`` to access data, whether new or old. The following
+rcu_assign_pointer() to insert the new data, and readers use
+rcu_dereference() to access data, whether new or old. The following
 shows an example of insertion:
 
    ::
@@ -279,7 +279,7 @@ shows an example of insertion:
       15   return true;
       16 }
 
-The ``rcu_assign_pointer()`` on line 13 is conceptually equivalent to a
+The rcu_assign_pointer() on line 13 is conceptually equivalent to a
 simple assignment statement, but also guarantees that its assignment
 will happen after the two assignments in lines 11 and 12, similar to the
 C11 ``memory_order_release`` store operation. It also prevents any
@@ -289,7 +289,7 @@ number of “interesting” compiler optimizations, for example, the use of
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| But ``rcu_assign_pointer()`` does nothing to prevent the two          |
+| But rcu_assign_pointer() does nothing to prevent the two              |
 | assignments to ``p->a`` and ``p->b`` from being reordered. Can't that |
 | also cause problems?                                                  |
 +-----------------------------------------------------------------------+
@@ -303,7 +303,7 @@ number of “interesting” compiler optimizations, for example, the use of
 
 It is tempting to assume that the reader need not do anything special to
 control its accesses to the RCU-protected data, as shown in
-``do_something_gp_buggy()`` below:
+do_something_gp_buggy() below:
 
    ::
 
@@ -321,11 +321,10 @@ control its accesses to the RCU-protected data, as shown in
       12 }
 
 However, this temptation must be resisted because there are a
-surprisingly large number of ways that the compiler (to say nothing of
-`DEC Alpha CPUs <https://h71000.www7.hp.com/wizard/wiz_2637.html>`__)
-can trip this code up. For but one example, if the compiler were short
-of registers, it might choose to refetch from ``gp`` rather than keeping
-a separate copy in ``p`` as follows:
+surprisingly large number of ways that the compiler (or weak ordering
+CPUs like the DEC Alpha) can trip this code up. For but one example, if
+the compiler were short of registers, it might choose to refetch from
+``gp`` rather than keeping a separate copy in ``p`` as follows:
 
    ::
 
@@ -345,7 +344,7 @@ If this function ran concurrently with a series of updates that replaced
 the current structure with a new one, the fetches of ``gp->a`` and
 ``gp->b`` might well come from two different structures, which could
 cause serious confusion. To prevent this (and much else besides),
-``do_something_gp()`` uses ``rcu_dereference()`` to fetch from ``gp``:
+do_something_gp() uses rcu_dereference() to fetch from ``gp``:
 
    ::
 
@@ -362,21 +361,21 @@ cause serious confusion. To prevent this (and much else besides),
       11   return false;
       12 }
 
-The ``rcu_dereference()`` uses volatile casts and (for DEC Alpha) memory
+The rcu_dereference() uses volatile casts and (for DEC Alpha) memory
 barriers in the Linux kernel. Should a `high-quality implementation of
 C11 ``memory_order_consume``
 [PDF] <http://www.rdrop.com/users/paulmck/RCU/consume.2015.07.13a.pdf>`__
-ever appear, then ``rcu_dereference()`` could be implemented as a
+ever appear, then rcu_dereference() could be implemented as a
 ``memory_order_consume`` load. Regardless of the exact implementation, a
-pointer fetched by ``rcu_dereference()`` may not be used outside of the
+pointer fetched by rcu_dereference() may not be used outside of the
 outermost RCU read-side critical section containing that
-``rcu_dereference()``, unless protection of the corresponding data
+rcu_dereference(), unless protection of the corresponding data
 element has been passed from RCU to some other synchronization
 mechanism, most commonly locking or `reference
 counting <https://www.kernel.org/doc/Documentation/RCU/rcuref.txt>`__.
 
-In short, updaters use ``rcu_assign_pointer()`` and readers use
-``rcu_dereference()``, and these two RCU API elements work together to
+In short, updaters use rcu_assign_pointer() and readers use
+rcu_dereference(), and these two RCU API elements work together to
 ensure that readers have a consistent view of newly added data elements.
 
 Of course, it is also necessary to remove elements from RCU-protected
@@ -388,9 +387,9 @@ data structures, for example, using the following process:
    the newly removed data element).
 #. At this point, only the updater has a reference to the newly removed
    data element, so it can safely reclaim the data element, for example,
-   by passing it to ``kfree()``.
+   by passing it to kfree().
 
-This process is implemented by ``remove_gp_synchronous()``:
+This process is implemented by remove_gp_synchronous():
 
    ::
 
@@ -413,16 +412,16 @@ This process is implemented by ``remove_gp_synchronous()``:
 
 This function is straightforward, with line 13 waiting for a grace
 period before line 14 frees the old data element. This waiting ensures
-that readers will reach line 7 of ``do_something_gp()`` before the data
-element referenced by ``p`` is freed. The ``rcu_access_pointer()`` on
-line 6 is similar to ``rcu_dereference()``, except that:
+that readers will reach line 7 of do_something_gp() before the data
+element referenced by ``p`` is freed. The rcu_access_pointer() on
+line 6 is similar to rcu_dereference(), except that:
 
-#. The value returned by ``rcu_access_pointer()`` cannot be
+#. The value returned by rcu_access_pointer() cannot be
    dereferenced. If you want to access the value pointed to as well as
-   the pointer itself, use ``rcu_dereference()`` instead of
-   ``rcu_access_pointer()``.
-#. The call to ``rcu_access_pointer()`` need not be protected. In
-   contrast, ``rcu_dereference()`` must either be within an RCU
+   the pointer itself, use rcu_dereference() instead of
+   rcu_access_pointer().
+#. The call to rcu_access_pointer() need not be protected. In
+   contrast, rcu_dereference() must either be within an RCU
    read-side critical section or in a code segment where the pointer
    cannot change, for example, in code protected by the corresponding
    update-side lock.
@@ -430,13 +429,13 @@ line 6 is similar to ``rcu_dereference()``, except that:
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| Without the ``rcu_dereference()`` or the ``rcu_access_pointer()``,    |
+| Without the rcu_dereference() or the rcu_access_pointer(),            |
 | what destructive optimizations might the compiler make use of?        |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
-| Let's start with what happens to ``do_something_gp()`` if it fails to |
-| use ``rcu_dereference()``. It could reuse a value formerly fetched    |
+| Let's start with what happens to do_something_gp() if it fails to     |
+| use rcu_dereference(). It could reuse a value formerly fetched        |
 | from this same pointer. It could also fetch the pointer from ``gp``   |
 | in a byte-at-a-time manner, resulting in *load tearing*, in turn      |
 | resulting a bytewise mash-up of two distinct pointer values. It might |
@@ -445,15 +444,15 @@ line 6 is similar to ``rcu_dereference()``, except that:
 | update has changed the pointer to match the wrong guess. Too bad      |
 | about any dereferences that returned pre-initialization garbage in    |
 | the meantime!                                                         |
-| For ``remove_gp_synchronous()``, as long as all modifications to      |
+| For remove_gp_synchronous(), as long as all modifications to          |
 | ``gp`` are carried out while holding ``gp_lock``, the above           |
 | optimizations are harmless. However, ``sparse`` will complain if you  |
 | define ``gp`` with ``__rcu`` and then access it without using either  |
-| ``rcu_access_pointer()`` or ``rcu_dereference()``.                    |
+| rcu_access_pointer() or rcu_dereference().                            |
 +-----------------------------------------------------------------------+
 
 In short, RCU's publish-subscribe guarantee is provided by the
-combination of ``rcu_assign_pointer()`` and ``rcu_dereference()``. This
+combination of rcu_assign_pointer() and rcu_dereference(). This
 guarantee allows data elements to be safely added to RCU-protected
 linked data structures without disrupting RCU readers. This guarantee
 can be used in combination with the grace-period guarantee to also allow
@@ -462,9 +461,9 @@ again without disrupting RCU readers.
 
 This guarantee was only partially premeditated. DYNIX/ptx used an
 explicit memory barrier for publication, but had nothing resembling
-``rcu_dereference()`` for subscription, nor did it have anything
+rcu_dereference() for subscription, nor did it have anything
 resembling the dependency-ordering barrier that was later subsumed
-into ``rcu_dereference()`` and later still into ``READ_ONCE()``. The
+into rcu_dereference() and later still into READ_ONCE(). The
 need for these operations made itself known quite suddenly at a
 late-1990s meeting with the DEC Alpha architects, back in the days when
 DEC was still a free-standing company. It took the Alpha architects a
@@ -474,7 +473,7 @@ documentation did not make this point clear. More recent work with the C
 and C++ standards committees have provided much education on tricks and
 traps from the compiler. In short, compilers were much less tricky in
 the early 1990s, but in 2015, don't even think about omitting
-``rcu_dereference()``!
+rcu_dereference()!
 
 Memory-Barrier Guarantees
 ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -484,31 +483,31 @@ demonstrates the need for RCU's stringent memory-ordering guarantees on
 systems with more than one CPU:
 
 #. Each CPU that has an RCU read-side critical section that begins
-   before ``synchronize_rcu()`` starts is guaranteed to execute a full
+   before synchronize_rcu() starts is guaranteed to execute a full
    memory barrier between the time that the RCU read-side critical
-   section ends and the time that ``synchronize_rcu()`` returns. Without
+   section ends and the time that synchronize_rcu() returns. Without
    this guarantee, a pre-existing RCU read-side critical section might
    hold a reference to the newly removed ``struct foo`` after the
-   ``kfree()`` on line 14 of ``remove_gp_synchronous()``.
+   kfree() on line 14 of remove_gp_synchronous().
 #. Each CPU that has an RCU read-side critical section that ends after
-   ``synchronize_rcu()`` returns is guaranteed to execute a full memory
-   barrier between the time that ``synchronize_rcu()`` begins and the
+   synchronize_rcu() returns is guaranteed to execute a full memory
+   barrier between the time that synchronize_rcu() begins and the
    time that the RCU read-side critical section begins. Without this
    guarantee, a later RCU read-side critical section running after the
-   ``kfree()`` on line 14 of ``remove_gp_synchronous()`` might later run
-   ``do_something_gp()`` and find the newly deleted ``struct foo``.
-#. If the task invoking ``synchronize_rcu()`` remains on a given CPU,
+   kfree() on line 14 of remove_gp_synchronous() might later run
+   do_something_gp() and find the newly deleted ``struct foo``.
+#. If the task invoking synchronize_rcu() remains on a given CPU,
    then that CPU is guaranteed to execute a full memory barrier sometime
-   during the execution of ``synchronize_rcu()``. This guarantee ensures
-   that the ``kfree()`` on line 14 of ``remove_gp_synchronous()`` really
+   during the execution of synchronize_rcu(). This guarantee ensures
+   that the kfree() on line 14 of remove_gp_synchronous() really
    does execute after the removal on line 11.
-#. If the task invoking ``synchronize_rcu()`` migrates among a group of
+#. If the task invoking synchronize_rcu() migrates among a group of
    CPUs during that invocation, then each of the CPUs in that group is
    guaranteed to execute a full memory barrier sometime during the
-   execution of ``synchronize_rcu()``. This guarantee also ensures that
-   the ``kfree()`` on line 14 of ``remove_gp_synchronous()`` really does
+   execution of synchronize_rcu(). This guarantee also ensures that
+   the kfree() on line 14 of remove_gp_synchronous() really does
    execute after the removal on line 11, but also in the case where the
-   thread executing the ``synchronize_rcu()`` migrates in the meantime.
+   thread executing the synchronize_rcu() migrates in the meantime.
 
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
@@ -516,19 +515,19 @@ systems with more than one CPU:
 | Given that multiple CPUs can start RCU read-side critical sections at |
 | any time without any ordering whatsoever, how can RCU possibly tell   |
 | whether or not a given RCU read-side critical section starts before a |
-| given instance of ``synchronize_rcu()``?                              |
+| given instance of synchronize_rcu()?                                  |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
 | If RCU cannot tell whether or not a given RCU read-side critical      |
-| section starts before a given instance of ``synchronize_rcu()``, then |
+| section starts before a given instance of synchronize_rcu(), then     |
 | it must assume that the RCU read-side critical section started first. |
-| In other words, a given instance of ``synchronize_rcu()`` can avoid   |
+| In other words, a given instance of synchronize_rcu() can avoid       |
 | waiting on a given RCU read-side critical section only if it can      |
-| prove that ``synchronize_rcu()`` started first.                       |
-| A related question is “When ``rcu_read_lock()`` doesn't generate any  |
+| prove that synchronize_rcu() started first.                           |
+| A related question is “When rcu_read_lock() doesn't generate any      |
 | code, why does it matter how it relates to a grace period?” The       |
-| answer is that it is not the relationship of ``rcu_read_lock()``      |
+| answer is that it is not the relationship of rcu_read_lock()          |
 | itself that is important, but rather the relationship of the code     |
 | within the enclosed RCU read-side critical section to the code        |
 | preceding and following the grace period. If we take this viewpoint,  |
@@ -556,14 +555,14 @@ systems with more than one CPU:
 | Yes, they really are required. To see why the first guarantee is      |
 | required, consider the following sequence of events:                  |
 |                                                                       |
-| #. CPU 1: ``rcu_read_lock()``                                         |
+| #. CPU 1: rcu_read_lock()                                             |
 | #. CPU 1: ``q = rcu_dereference(gp); /* Very likely to return p. */`` |
 | #. CPU 0: ``list_del_rcu(p);``                                        |
-| #. CPU 0: ``synchronize_rcu()`` starts.                               |
+| #. CPU 0: synchronize_rcu() starts.                                   |
 | #. CPU 1: ``do_something_with(q->a);``                                |
 |    ``/* No smp_mb(), so might happen after kfree(). */``              |
-| #. CPU 1: ``rcu_read_unlock()``                                       |
-| #. CPU 0: ``synchronize_rcu()`` returns.                              |
+| #. CPU 1: rcu_read_unlock()                                           |
+| #. CPU 0: synchronize_rcu() returns.                                  |
 | #. CPU 0: ``kfree(p);``                                               |
 |                                                                       |
 | Therefore, there absolutely must be a full memory barrier between the |
@@ -574,14 +573,14 @@ systems with more than one CPU:
 | is roughly similar:                                                   |
 |                                                                       |
 | #. CPU 0: ``list_del_rcu(p);``                                        |
-| #. CPU 0: ``synchronize_rcu()`` starts.                               |
-| #. CPU 1: ``rcu_read_lock()``                                         |
+| #. CPU 0: synchronize_rcu() starts.                                   |
+| #. CPU 1: rcu_read_lock()                                             |
 | #. CPU 1: ``q = rcu_dereference(gp);``                                |
 |    ``/* Might return p if no memory barrier. */``                     |
-| #. CPU 0: ``synchronize_rcu()`` returns.                              |
+| #. CPU 0: synchronize_rcu() returns.                                  |
 | #. CPU 0: ``kfree(p);``                                               |
 | #. CPU 1: ``do_something_with(q->a); /* Boom!!! */``                  |
-| #. CPU 1: ``rcu_read_unlock()``                                       |
+| #. CPU 1: rcu_read_unlock()                                           |
 |                                                                       |
 | And similarly, without a memory barrier between the beginning of the  |
 | grace period and the beginning of the RCU read-side critical section, |
@@ -597,7 +596,7 @@ systems with more than one CPU:
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| You claim that ``rcu_read_lock()`` and ``rcu_read_unlock()`` generate |
+| You claim that rcu_read_lock() and rcu_read_unlock() generate         |
 | absolutely no code in some kernel builds. This means that the         |
 | compiler might arbitrarily rearrange consecutive RCU read-side        |
 | critical sections. Given such rearrangement, if a given RCU read-side |
@@ -607,11 +606,11 @@ systems with more than one CPU:
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
-| In cases where ``rcu_read_lock()`` and ``rcu_read_unlock()`` generate |
+| In cases where rcu_read_lock() and rcu_read_unlock() generate         |
 | absolutely no code, RCU infers quiescent states only at special       |
 | locations, for example, within the scheduler. Because calls to        |
-| ``schedule()`` had better prevent calling-code accesses to shared     |
-| variables from being rearranged across the call to ``schedule()``, if |
+| schedule() had better prevent calling-code accesses to shared         |
+| variables from being rearranged across the call to schedule(), if     |
 | RCU detects the end of a given RCU read-side critical section, it     |
 | will necessarily detect the end of all prior RCU read-side critical   |
 | sections, no matter how aggressively the compiler scrambles the code. |
@@ -655,8 +654,8 @@ read-side critical section might search for a given data element, and
 then might acquire the update-side spinlock in order to update that
 element, all while remaining in that RCU read-side critical section. Of
 course, it is necessary to exit the RCU read-side critical section
-before invoking ``synchronize_rcu()``, however, this inconvenience can
-be avoided through use of the ``call_rcu()`` and ``kfree_rcu()`` API
+before invoking synchronize_rcu(), however, this inconvenience can
+be avoided through use of the call_rcu() and kfree_rcu() API
 members described later in this document.
 
 +-----------------------------------------------------------------------+
@@ -694,10 +693,10 @@ these non-guarantees were premeditated.
 Readers Impose Minimal Ordering
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Reader-side markers such as ``rcu_read_lock()`` and
-``rcu_read_unlock()`` provide absolutely no ordering guarantees except
+Reader-side markers such as rcu_read_lock() and
+rcu_read_unlock() provide absolutely no ordering guarantees except
 through their interaction with the grace-period APIs such as
-``synchronize_rcu()``. To see this, consider the following pair of
+synchronize_rcu(). To see this, consider the following pair of
 threads:
 
    ::
@@ -722,7 +721,7 @@ threads:
       18   rcu_read_unlock();
       19 }
 
-After ``thread0()`` and ``thread1()`` execute concurrently, it is quite
+After thread0() and thread1() execute concurrently, it is quite
 possible to have
 
    ::
@@ -730,7 +729,7 @@ possible to have
       (r1 == 1 && r2 == 0)
 
 (that is, ``y`` appears to have been assigned before ``x``), which would
-not be possible if ``rcu_read_lock()`` and ``rcu_read_unlock()`` had
+not be possible if rcu_read_lock() and rcu_read_unlock() had
 much in the way of ordering properties. But they do not, so the CPU is
 within its rights to do significant reordering. This is by design: Any
 significant ordering constraints would slow down these fast-path APIs.
@@ -742,14 +741,14 @@ significant ordering constraints would slow down these fast-path APIs.
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
-| No, the volatile casts in ``READ_ONCE()`` and ``WRITE_ONCE()``        |
+| No, the volatile casts in READ_ONCE() and WRITE_ONCE()                |
 | prevent the compiler from reordering in this particular case.         |
 +-----------------------------------------------------------------------+
 
 Readers Do Not Exclude Updaters
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Neither ``rcu_read_lock()`` nor ``rcu_read_unlock()`` exclude updates.
+Neither rcu_read_lock() nor rcu_read_unlock() exclude updates.
 All they do is to prevent grace periods from ending. The following
 example illustrates this:
 
@@ -775,19 +774,19 @@ example illustrates this:
       18   spin_unlock(&my_lock);
       19 }
 
-If the ``thread0()`` function's ``rcu_read_lock()`` excluded the
-``thread1()`` function's update, the ``WARN_ON()`` could never fire. But
-the fact is that ``rcu_read_lock()`` does not exclude much of anything
-aside from subsequent grace periods, of which ``thread1()`` has none, so
-the ``WARN_ON()`` can and does fire.
+If the thread0() function's rcu_read_lock() excluded the
+thread1() function's update, the WARN_ON() could never fire. But
+the fact is that rcu_read_lock() does not exclude much of anything
+aside from subsequent grace periods, of which thread1() has none, so
+the WARN_ON() can and does fire.
 
 Updaters Only Wait For Old Readers
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-It might be tempting to assume that after ``synchronize_rcu()``
+It might be tempting to assume that after synchronize_rcu()
 completes, there are no readers executing. This temptation must be
 avoided because new readers can start immediately after
-``synchronize_rcu()`` starts, and ``synchronize_rcu()`` is under no
+synchronize_rcu() starts, and synchronize_rcu() is under no
 obligation to wait for these new readers.
 
 +-----------------------------------------------------------------------+
@@ -799,10 +798,10 @@ obligation to wait for these new readers.
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
-| For no time at all. Even if ``synchronize_rcu()`` were to wait until  |
+| For no time at all. Even if synchronize_rcu() were to wait until      |
 | all readers had completed, a new reader might start immediately after |
-| ``synchronize_rcu()`` completed. Therefore, the code following        |
-| ``synchronize_rcu()`` can *never* rely on there being no readers.     |
+| synchronize_rcu() completed. Therefore, the code following            |
+| synchronize_rcu() can *never* rely on there being no readers.         |
 +-----------------------------------------------------------------------+
 
 Grace Periods Don't Partition Read-Side Critical Sections
@@ -892,12 +891,12 @@ period is known to end before the second grace period starts:
       28   rcu_read_unlock();
       29 }
 
-Here, if ``(r1 == 1)``, then ``thread0()``'s write to ``b`` must happen
-before the end of ``thread1()``'s grace period. If in addition
-``(r4 == 1)``, then ``thread3()``'s read from ``b`` must happen after
-the beginning of ``thread2()``'s grace period. If it is also the case
-that ``(r2 == 1)``, then the end of ``thread1()``'s grace period must
-precede the beginning of ``thread2()``'s grace period. This mean that
+Here, if ``(r1 == 1)``, then thread0()'s write to ``b`` must happen
+before the end of thread1()'s grace period. If in addition
+``(r4 == 1)``, then thread3()'s read from ``b`` must happen after
+the beginning of thread2()'s grace period. If it is also the case
+that ``(r2 == 1)``, then the end of thread1()'s grace period must
+precede the beginning of thread2()'s grace period. This mean that
 the two RCU read-side critical sections cannot overlap, guaranteeing
 that ``(r3 == 1)``. As a result, the outcome:
 
@@ -1076,8 +1075,8 @@ is captured by the following list of situations:
    b. Wait-free read-side primitives for real-time use.
 
 This focus on read-mostly situations means that RCU must interoperate
-with other synchronization primitives. For example, the ``add_gp()`` and
-``remove_gp_synchronous()`` examples discussed earlier use RCU to
+with other synchronization primitives. For example, the add_gp() and
+remove_gp_synchronous() examples discussed earlier use RCU to
 protect readers and locking to coordinate updaters. However, the need
 extends much farther, requiring that a variety of synchronization
 primitives be legal within RCU read-side critical sections, including
@@ -1104,11 +1103,11 @@ memory barriers.
 | sections.                                                             |
 | Note that it *is* legal for a normal RCU read-side critical section   |
 | to conditionally acquire a sleeping locks (as in                      |
-| ``mutex_trylock()``), but only as long as it does not loop            |
+| mutex_trylock()), but only as long as it does not loop                |
 | indefinitely attempting to conditionally acquire that sleeping locks. |
-| The key point is that things like ``mutex_trylock()`` either return   |
+| The key point is that things like mutex_trylock() either return       |
 | with the mutex held, or return an error indication if the mutex was   |
-| not immediately available. Either way, ``mutex_trylock()`` returns    |
+| not immediately available. Either way, mutex_trylock() returns        |
 | immediately without sleeping.                                         |
 +-----------------------------------------------------------------------+
 
@@ -1182,8 +1181,8 @@ and has become decreasingly so as memory sizes have expanded and memory
 costs have plummeted. However, as I learned from Matt Mackall's
 `bloatwatch <http://elinux.org/Linux_Tiny-FAQ>`__ efforts, memory
 footprint is critically important on single-CPU systems with
-non-preemptible (``CONFIG_PREEMPT=n``) kernels, and thus `tiny
-RCU <https://lkml.kernel.org/g/20090113221724.GA15307@linux.vnet.ibm.com>`__
+non-preemptible (``CONFIG_PREEMPTION=n``) kernels, and thus `tiny
+RCU <https://lore.kernel.org/r/20090113221724.GA15307@linux.vnet.ibm.com>`__
 was born. Josh Triplett has since taken over the small-memory banner
 with his `Linux kernel tinification <https://tiny.wiki.kernel.org/>`__
 project, which resulted in `SRCU <#Sleepable%20RCU>`__ becoming optional
@@ -1191,57 +1190,57 @@ for those kernels not needing it.
 
 The remaining performance requirements are, for the most part,
 unsurprising. For example, in keeping with RCU's read-side
-specialization, ``rcu_dereference()`` should have negligible overhead
+specialization, rcu_dereference() should have negligible overhead
 (for example, suppression of a few minor compiler optimizations).
-Similarly, in non-preemptible environments, ``rcu_read_lock()`` and
-``rcu_read_unlock()`` should have exactly zero overhead.
+Similarly, in non-preemptible environments, rcu_read_lock() and
+rcu_read_unlock() should have exactly zero overhead.
 
 In preemptible environments, in the case where the RCU read-side
 critical section was not preempted (as will be the case for the
-highest-priority real-time process), ``rcu_read_lock()`` and
-``rcu_read_unlock()`` should have minimal overhead. In particular, they
+highest-priority real-time process), rcu_read_lock() and
+rcu_read_unlock() should have minimal overhead. In particular, they
 should not contain atomic read-modify-write operations, memory-barrier
 instructions, preemption disabling, interrupt disabling, or backwards
 branches. However, in the case where the RCU read-side critical section
-was preempted, ``rcu_read_unlock()`` may acquire spinlocks and disable
+was preempted, rcu_read_unlock() may acquire spinlocks and disable
 interrupts. This is why it is better to nest an RCU read-side critical
 section within a preempt-disable region than vice versa, at least in
 cases where that critical section is short enough to avoid unduly
 degrading real-time latencies.
 
-The ``synchronize_rcu()`` grace-period-wait primitive is optimized for
+The synchronize_rcu() grace-period-wait primitive is optimized for
 throughput. It may therefore incur several milliseconds of latency in
 addition to the duration of the longest RCU read-side critical section.
 On the other hand, multiple concurrent invocations of
-``synchronize_rcu()`` are required to use batching optimizations so that
+synchronize_rcu() are required to use batching optimizations so that
 they can be satisfied by a single underlying grace-period-wait
 operation. For example, in the Linux kernel, it is not unusual for a
 single grace-period-wait operation to serve more than `1,000 separate
 invocations <https://www.usenix.org/conference/2004-usenix-annual-technical-conference/making-rcu-safe-deep-sub-millisecond-response>`__
-of ``synchronize_rcu()``, thus amortizing the per-invocation overhead
+of synchronize_rcu(), thus amortizing the per-invocation overhead
 down to nearly zero. However, the grace-period optimization is also
 required to avoid measurable degradation of real-time scheduling and
 interrupt latencies.
 
-In some cases, the multi-millisecond ``synchronize_rcu()`` latencies are
-unacceptable. In these cases, ``synchronize_rcu_expedited()`` may be
+In some cases, the multi-millisecond synchronize_rcu() latencies are
+unacceptable. In these cases, synchronize_rcu_expedited() may be
 used instead, reducing the grace-period latency down to a few tens of
 microseconds on small systems, at least in cases where the RCU read-side
 critical sections are short. There are currently no special latency
-requirements for ``synchronize_rcu_expedited()`` on large systems, but,
+requirements for synchronize_rcu_expedited() on large systems, but,
 consistent with the empirical nature of the RCU specification, that is
 subject to change. However, there most definitely are scalability
-requirements: A storm of ``synchronize_rcu_expedited()`` invocations on
+requirements: A storm of synchronize_rcu_expedited() invocations on
 4096 CPUs should at least make reasonable forward progress. In return
-for its shorter latencies, ``synchronize_rcu_expedited()`` is permitted
+for its shorter latencies, synchronize_rcu_expedited() is permitted
 to impose modest degradation of real-time latency on non-idle online
 CPUs. Here, “modest” means roughly the same latency degradation as a
 scheduling-clock interrupt.
 
 There are a number of situations where even
-``synchronize_rcu_expedited()``'s reduced grace-period latency is
-unacceptable. In these situations, the asynchronous ``call_rcu()`` can
-be used in place of ``synchronize_rcu()`` as follows:
+synchronize_rcu_expedited()'s reduced grace-period latency is
+unacceptable. In these situations, the asynchronous call_rcu() can
+be used in place of synchronize_rcu() as follows:
 
    ::
 
@@ -1275,19 +1274,19 @@ be used in place of ``synchronize_rcu()`` as follows:
       28 }
 
 A definition of ``struct foo`` is finally needed, and appears on
-lines 1-5. The function ``remove_gp_cb()`` is passed to ``call_rcu()``
+lines 1-5. The function remove_gp_cb() is passed to call_rcu()
 on line 25, and will be invoked after the end of a subsequent grace
-period. This gets the same effect as ``remove_gp_synchronous()``, but
+period. This gets the same effect as remove_gp_synchronous(), but
 without forcing the updater to wait for a grace period to elapse. The
-``call_rcu()`` function may be used in a number of situations where
-neither ``synchronize_rcu()`` nor ``synchronize_rcu_expedited()`` would
-be legal, including within preempt-disable code, ``local_bh_disable()``
+call_rcu() function may be used in a number of situations where
+neither synchronize_rcu() nor synchronize_rcu_expedited() would
+be legal, including within preempt-disable code, local_bh_disable()
 code, interrupt-disable code, and interrupt handlers. However, even
-``call_rcu()`` is illegal within NMI handlers and from idle and offline
-CPUs. The callback function (``remove_gp_cb()`` in this case) will be
+call_rcu() is illegal within NMI handlers and from idle and offline
+CPUs. The callback function (remove_gp_cb() in this case) will be
 executed within softirq (software interrupt) environment within the
 Linux kernel, either within a real softirq handler or under the
-protection of ``local_bh_disable()``. In both the Linux kernel and in
+protection of local_bh_disable(). In both the Linux kernel and in
 userspace, it is bad practice to write an RCU callback function that
 takes too long. Long-running operations should be relegated to separate
 threads or (in the Linux kernel) workqueues.
@@ -1295,23 +1294,23 @@ threads or (in the Linux kernel) workqueues.
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| Why does line 19 use ``rcu_access_pointer()``? After all,             |
-| ``call_rcu()`` on line 25 stores into the structure, which would      |
+| Why does line 19 use rcu_access_pointer()? After all,                 |
+| call_rcu() on line 25 stores into the structure, which would          |
 | interact badly with concurrent insertions. Doesn't this mean that     |
-| ``rcu_dereference()`` is required?                                    |
+| rcu_dereference() is required?                                        |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
 +-----------------------------------------------------------------------+
 | Presumably the ``->gp_lock`` acquired on line 18 excludes any         |
-| changes, including any insertions that ``rcu_dereference()`` would    |
+| changes, including any insertions that rcu_dereference() would        |
 | protect against. Therefore, any insertions will be delayed until      |
 | after ``->gp_lock`` is released on line 25, which in turn means that  |
-| ``rcu_access_pointer()`` suffices.                                    |
+| rcu_access_pointer() suffices.                                        |
 +-----------------------------------------------------------------------+
 
-However, all that ``remove_gp_cb()`` is doing is invoking ``kfree()`` on
+However, all that remove_gp_cb() is doing is invoking kfree() on
 the data element. This is a common idiom, and is supported by
-``kfree_rcu()``, which allows “fire and forget” operation as shown
+kfree_rcu(), which allows “fire and forget” operation as shown
 below:
 
    ::
@@ -1338,20 +1337,20 @@ below:
       20   return true;
       21 }
 
-Note that ``remove_gp_faf()`` simply invokes ``kfree_rcu()`` and
+Note that remove_gp_faf() simply invokes kfree_rcu() and
 proceeds, without any need to pay any further attention to the
-subsequent grace period and ``kfree()``. It is permissible to invoke
-``kfree_rcu()`` from the same environments as for ``call_rcu()``.
-Interestingly enough, DYNIX/ptx had the equivalents of ``call_rcu()``
-and ``kfree_rcu()``, but not ``synchronize_rcu()``. This was due to the
+subsequent grace period and kfree(). It is permissible to invoke
+kfree_rcu() from the same environments as for call_rcu().
+Interestingly enough, DYNIX/ptx had the equivalents of call_rcu()
+and kfree_rcu(), but not synchronize_rcu(). This was due to the
 fact that RCU was not heavily used within DYNIX/ptx, so the very few
-places that needed something like ``synchronize_rcu()`` simply
+places that needed something like synchronize_rcu() simply
 open-coded it.
 
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
-| Earlier it was claimed that ``call_rcu()`` and ``kfree_rcu()``        |
+| Earlier it was claimed that call_rcu() and kfree_rcu()                |
 | allowed updaters to avoid being blocked by readers. But how can that  |
 | be correct, given that the invocation of the callback and the freeing |
 | of the memory (respectively) must still wait for a grace period to    |
@@ -1363,16 +1362,16 @@ open-coded it.
 | definition would say that updates in garbage-collected languages      |
 | cannot complete until the next time the garbage collector runs, which |
 | does not seem at all reasonable. The key point is that in most cases, |
-| an updater using either ``call_rcu()`` or ``kfree_rcu()`` can proceed |
-| to the next update as soon as it has invoked ``call_rcu()`` or        |
-| ``kfree_rcu()``, without having to wait for a subsequent grace        |
+| an updater using either call_rcu() or kfree_rcu() can proceed         |
+| to the next update as soon as it has invoked call_rcu() or            |
+| kfree_rcu(), without having to wait for a subsequent grace            |
 | period.                                                               |
 +-----------------------------------------------------------------------+
 
 But what if the updater must wait for the completion of code to be
 executed after the end of the grace period, but has other tasks that can
 be carried out in the meantime? The polling-style
-``get_state_synchronize_rcu()`` and ``cond_synchronize_rcu()`` functions
+get_state_synchronize_rcu() and cond_synchronize_rcu() functions
 may be used for this purpose, as shown below:
 
    ::
@@ -1397,11 +1396,11 @@ may be used for this purpose, as shown below:
       18   return true;
       19 }
 
-On line 14, ``get_state_synchronize_rcu()`` obtains a “cookie” from RCU,
+On line 14, get_state_synchronize_rcu() obtains a “cookie” from RCU,
 then line 15 carries out other tasks, and finally, line 16 returns
 immediately if a grace period has elapsed in the meantime, but otherwise
 waits as required. The need for ``get_state_synchronize_rcu`` and
-``cond_synchronize_rcu()`` has appeared quite recently, so it is too
+cond_synchronize_rcu() has appeared quite recently, so it is too
 early to tell whether they will stand the test of time.
 
 RCU thus provides a range of tools to allow updaters to strike the
@@ -1421,8 +1420,8 @@ example, an infinite loop in an RCU read-side critical section must by
 definition prevent later grace periods from ever completing. For a more
 involved example, consider a 64-CPU system built with
 ``CONFIG_RCU_NOCB_CPU=y`` and booted with ``rcu_nocbs=1-63``, where
-CPUs 1 through 63 spin in tight loops that invoke ``call_rcu()``. Even
-if these tight loops also contain calls to ``cond_resched()`` (thus
+CPUs 1 through 63 spin in tight loops that invoke call_rcu(). Even
+if these tight loops also contain calls to cond_resched() (thus
 allowing grace periods to complete), CPU 0 simply will not be able to
 invoke callbacks as fast as the other 63 CPUs can register them, at
 least not until the system runs out of memory. In both of these
@@ -1435,21 +1434,21 @@ RCU takes the following steps to encourage timely completion of grace
 periods:
 
 #. If a grace period fails to complete within 100 milliseconds, RCU
-   causes future invocations of ``cond_resched()`` on the holdout CPUs
+   causes future invocations of cond_resched() on the holdout CPUs
    to provide an RCU quiescent state. RCU also causes those CPUs'
-   ``need_resched()`` invocations to return ``true``, but only after the
+   need_resched() invocations to return ``true``, but only after the
    corresponding CPU's next scheduling-clock.
 #. CPUs mentioned in the ``nohz_full`` kernel boot parameter can run
    indefinitely in the kernel without scheduling-clock interrupts, which
-   defeats the above ``need_resched()`` strategem. RCU will therefore
-   invoke ``resched_cpu()`` on any ``nohz_full`` CPUs still holding out
+   defeats the above need_resched() strategem. RCU will therefore
+   invoke resched_cpu() on any ``nohz_full`` CPUs still holding out
    after 109 milliseconds.
 #. In kernels built with ``CONFIG_RCU_BOOST=y``, if a given task that
    has been preempted within an RCU read-side critical section is
    holding out for more than 500 milliseconds, RCU will resort to
    priority boosting.
 #. If a CPU is still holding out 10 seconds into the grace period, RCU
-   will invoke ``resched_cpu()`` on it regardless of its ``nohz_full``
+   will invoke resched_cpu() on it regardless of its ``nohz_full``
    state.
 
 The above values are defaults for systems running with ``HZ=1000``. They
@@ -1460,7 +1459,7 @@ caution when changing them. Note that these forward-progress measures
 are provided only for RCU, not for `SRCU <#Sleepable%20RCU>`__ or `Tasks
 RCU <#Tasks%20RCU>`__.
 
-RCU takes the following steps in ``call_rcu()`` to encourage timely
+RCU takes the following steps in call_rcu() to encourage timely
 invocation of callbacks when any given non-\ ``rcu_nocbs`` CPU has
 10,000 callbacks, or has 10,000 more callbacks than it had the last time
 encouragement was provided:
@@ -1481,8 +1480,8 @@ RCU, not for `SRCU <#Sleepable%20RCU>`__ or `Tasks
 RCU <#Tasks%20RCU>`__. Even for RCU, callback-invocation forward
 progress for ``rcu_nocbs`` CPUs is much less well-developed, in part
 because workloads benefiting from ``rcu_nocbs`` CPUs tend to invoke
-``call_rcu()`` relatively infrequently. If workloads emerge that need
-both ``rcu_nocbs`` CPUs and high ``call_rcu()`` invocation rates, then
+call_rcu() relatively infrequently. If workloads emerge that need
+both ``rcu_nocbs`` CPUs and high call_rcu() invocation rates, then
 additional forward-progress work will be required.
 
 Composability
@@ -1496,11 +1495,11 @@ in fact may be nested arbitrarily deeply. In practice, as with all
 real-world implementations of composable constructs, there are
 limitations.
 
-Implementations of RCU for which ``rcu_read_lock()`` and
-``rcu_read_unlock()`` generate no code, such as Linux-kernel RCU when
-``CONFIG_PREEMPT=n``, can be nested arbitrarily deeply. After all, there
+Implementations of RCU for which rcu_read_lock() and
+rcu_read_unlock() generate no code, such as Linux-kernel RCU when
+``CONFIG_PREEMPTION=n``, can be nested arbitrarily deeply. After all, there
 is no overhead. Except that if all these instances of
-``rcu_read_lock()`` and ``rcu_read_unlock()`` are visible to the
+rcu_read_lock() and rcu_read_unlock() are visible to the
 compiler, compilation will eventually fail due to exhausting memory,
 mass storage, or user patience, whichever comes first. If the nesting is
 not visible to the compiler, as is the case with mutually recursive
@@ -1558,11 +1557,11 @@ argue that such workloads should instead use something other than RCU,
 the fact remains that RCU must handle such workloads gracefully. This
 requirement is another factor driving batching of grace periods, but it
 is also the driving force behind the checks for large numbers of queued
-RCU callbacks in the ``call_rcu()`` code path. Finally, high update
+RCU callbacks in the call_rcu() code path. Finally, high update
 rates should not delay RCU read-side critical sections, although some
 small read-side delays can occur when using
-``synchronize_rcu_expedited()``, courtesy of this function's use of
-``smp_call_function_single()``.
+synchronize_rcu_expedited(), courtesy of this function's use of
+smp_call_function_single().
 
 Although all three of these corner cases were understood in the early
 1990s, a simple user-level test consisting of ``close(open(path))`` in a
@@ -1583,48 +1582,48 @@ Software-Engineering Requirements
 Between Murphy's Law and “To err is human”, it is necessary to guard
 against mishaps and misuse:
 
-#. It is all too easy to forget to use ``rcu_read_lock()`` everywhere
+#. It is all too easy to forget to use rcu_read_lock() everywhere
    that it is needed, so kernels built with ``CONFIG_PROVE_RCU=y`` will
-   splat if ``rcu_dereference()`` is used outside of an RCU read-side
+   splat if rcu_dereference() is used outside of an RCU read-side
    critical section. Update-side code can use
-   ``rcu_dereference_protected()``, which takes a `lockdep
+   rcu_dereference_protected(), which takes a `lockdep
    expression <https://lwn.net/Articles/371986/>`__ to indicate what is
    providing the protection. If the indicated protection is not
    provided, a lockdep splat is emitted.
    Code shared between readers and updaters can use
-   ``rcu_dereference_check()``, which also takes a lockdep expression,
-   and emits a lockdep splat if neither ``rcu_read_lock()`` nor the
+   rcu_dereference_check(), which also takes a lockdep expression,
+   and emits a lockdep splat if neither rcu_read_lock() nor the
    indicated protection is in place. In addition,
-   ``rcu_dereference_raw()`` is used in those (hopefully rare) cases
+   rcu_dereference_raw() is used in those (hopefully rare) cases
    where the required protection cannot be easily described. Finally,
-   ``rcu_read_lock_held()`` is provided to allow a function to verify
+   rcu_read_lock_held() is provided to allow a function to verify
    that it has been invoked within an RCU read-side critical section. I
    was made aware of this set of requirements shortly after Thomas
    Gleixner audited a number of RCU uses.
 #. A given function might wish to check for RCU-related preconditions
    upon entry, before using any other RCU API. The
-   ``rcu_lockdep_assert()`` does this job, asserting the expression in
+   rcu_lockdep_assert() does this job, asserting the expression in
    kernels having lockdep enabled and doing nothing otherwise.
-#. It is also easy to forget to use ``rcu_assign_pointer()`` and
-   ``rcu_dereference()``, perhaps (incorrectly) substituting a simple
+#. It is also easy to forget to use rcu_assign_pointer() and
+   rcu_dereference(), perhaps (incorrectly) substituting a simple
    assignment. To catch this sort of error, a given RCU-protected
    pointer may be tagged with ``__rcu``, after which sparse will
    complain about simple-assignment accesses to that pointer. Arnd
    Bergmann made me aware of this requirement, and also supplied the
    needed `patch series <https://lwn.net/Articles/376011/>`__.
 #. Kernels built with ``CONFIG_DEBUG_OBJECTS_RCU_HEAD=y`` will splat if
-   a data element is passed to ``call_rcu()`` twice in a row, without a
+   a data element is passed to call_rcu() twice in a row, without a
    grace period in between. (This error is similar to a double free.)
    The corresponding ``rcu_head`` structures that are dynamically
    allocated are automatically tracked, but ``rcu_head`` structures
    allocated on the stack must be initialized with
-   ``init_rcu_head_on_stack()`` and cleaned up with
-   ``destroy_rcu_head_on_stack()``. Similarly, statically allocated
+   init_rcu_head_on_stack() and cleaned up with
+   destroy_rcu_head_on_stack(). Similarly, statically allocated
    non-stack ``rcu_head`` structures must be initialized with
-   ``init_rcu_head()`` and cleaned up with ``destroy_rcu_head()``.
+   init_rcu_head() and cleaned up with destroy_rcu_head().
    Mathieu Desnoyers made me aware of this requirement, and also
    supplied the needed
-   `patch <https://lkml.kernel.org/g/20100319013024.GA28456@Krystal>`__.
+   `patch <https://lore.kernel.org/r/20100319013024.GA28456@Krystal>`__.
 #. An infinite loop in an RCU read-side critical section will eventually
    trigger an RCU CPU stall warning splat, with the duration of
    “eventually” being controlled by the ``RCU_CPU_STALL_TIMEOUT``
@@ -1638,9 +1637,9 @@ against mishaps and misuse:
    ``rcupdate.rcu_cpu_stall_suppress`` to suppress the splats. This
    kernel parameter may also be set via ``sysfs``. Furthermore, RCU CPU
    stall warnings are counter-productive during sysrq dumps and during
-   panics. RCU therefore supplies the ``rcu_sysrq_start()`` and
-   ``rcu_sysrq_end()`` API members to be called before and after long
-   sysrq dumps. RCU also supplies the ``rcu_panic()`` notifier that is
+   panics. RCU therefore supplies the rcu_sysrq_start() and
+   rcu_sysrq_end() API members to be called before and after long
+   sysrq dumps. RCU also supplies the rcu_panic() notifier that is
    automatically invoked at the beginning of a panic to suppress further
    RCU CPU stall warnings.
 
@@ -1656,7 +1655,7 @@ against mishaps and misuse:
    synchronization mechanism, for example, reference counting.
 #. In kernels built with ``CONFIG_RCU_TRACE=y``, RCU-related information
    is provided via event tracing.
-#. Open-coded use of ``rcu_assign_pointer()`` and ``rcu_dereference()``
+#. Open-coded use of rcu_assign_pointer() and rcu_dereference()
    to create typical linked data structures can be surprisingly
    error-prone. Therefore, RCU-protected `linked
    lists <https://lwn.net/Articles/609973/#RCU%20List%20APIs>`__ and,
@@ -1665,12 +1664,11 @@ against mishaps and misuse:
    other special-purpose RCU-protected data structures are available in
    the Linux kernel and the userspace RCU library.
 #. Some linked structures are created at compile time, but still require
-   ``__rcu`` checking. The ``RCU_POINTER_INITIALIZER()`` macro serves
+   ``__rcu`` checking. The RCU_POINTER_INITIALIZER() macro serves
    this purpose.
-#. It is not necessary to use ``rcu_assign_pointer()`` when creating
+#. It is not necessary to use rcu_assign_pointer() when creating
    linked structures that are to be published via a single external
-   pointer. The ``RCU_INIT_POINTER()`` macro is provided for this task
-   and also for assigning ``NULL`` pointers at runtime.
+   pointer. The RCU_INIT_POINTER() macro is provided for this task.
 
 This not a hard-and-fast list: RCU's diagnostic capabilities will
 continue to be guided by the number and type of usage bugs found in
@@ -1716,7 +1714,7 @@ requires almost all of them be hidden behind a ``CONFIG_RCU_EXPERT``
 
 This all should be quite obvious, but the fact remains that Linus
 Torvalds recently had to
-`remind <https://lkml.kernel.org/g/CA+55aFy4wcCwaL4okTs8wXhGZ5h-ibecy_Meg9C4MNQrUnwMcg@mail.gmail.com>`__
+`remind <https://lore.kernel.org/r/CA+55aFy4wcCwaL4okTs8wXhGZ5h-ibecy_Meg9C4MNQrUnwMcg@mail.gmail.com>`__
 me of this requirement.
 
 Firmware Interface
@@ -1743,17 +1741,17 @@ Early Boot
 ~~~~~~~~~~
 
 The Linux kernel's boot sequence is an interesting process, and RCU is
-used early, even before ``rcu_init()`` is invoked. In fact, a number of
+used early, even before rcu_init() is invoked. In fact, a number of
 RCU's primitives can be used as soon as the initial task's
 ``task_struct`` is available and the boot CPU's per-CPU variables are
-set up. The read-side primitives (``rcu_read_lock()``,
-``rcu_read_unlock()``, ``rcu_dereference()``, and
-``rcu_access_pointer()``) will operate normally very early on, as will
-``rcu_assign_pointer()``.
+set up. The read-side primitives (rcu_read_lock(),
+rcu_read_unlock(), rcu_dereference(), and
+rcu_access_pointer()) will operate normally very early on, as will
+rcu_assign_pointer().
 
-Although ``call_rcu()`` may be invoked at any time during boot,
+Although call_rcu() may be invoked at any time during boot,
 callbacks are not guaranteed to be invoked until after all of RCU's
-kthreads have been spawned, which occurs at ``early_initcall()`` time.
+kthreads have been spawned, which occurs at early_initcall() time.
 This delay in callback invocation is due to the fact that RCU does not
 invoke callbacks until it is fully initialized, and this full
 initialization cannot occur until after the scheduler has initialized
@@ -1762,22 +1760,22 @@ it would be possible to invoke callbacks earlier, however, this is not a
 panacea because there would be severe restrictions on what operations
 those callbacks could invoke.
 
-Perhaps surprisingly, ``synchronize_rcu()`` and
-``synchronize_rcu_expedited()``, will operate normally during very early
+Perhaps surprisingly, synchronize_rcu() and
+synchronize_rcu_expedited(), will operate normally during very early
 boot, the reason being that there is only one CPU and preemption is
-disabled. This means that the call ``synchronize_rcu()`` (or friends)
+disabled. This means that the call synchronize_rcu() (or friends)
 itself is a quiescent state and thus a grace period, so the early-boot
 implementation can be a no-op.
 
 However, once the scheduler has spawned its first kthread, this early
-boot trick fails for ``synchronize_rcu()`` (as well as for
-``synchronize_rcu_expedited()``) in ``CONFIG_PREEMPT=y`` kernels. The
+boot trick fails for synchronize_rcu() (as well as for
+synchronize_rcu_expedited()) in ``CONFIG_PREEMPTION=y`` kernels. The
 reason is that an RCU read-side critical section might be preempted,
-which means that a subsequent ``synchronize_rcu()`` really does have to
+which means that a subsequent synchronize_rcu() really does have to
 wait for something, as opposed to simply returning immediately.
-Unfortunately, ``synchronize_rcu()`` can't do this until all of its
+Unfortunately, synchronize_rcu() can't do this until all of its
 kthreads are spawned, which doesn't happen until some time during
-``early_initcalls()`` time. But this is no excuse: RCU is nevertheless
+early_initcalls() time. But this is no excuse: RCU is nevertheless
 required to correctly handle synchronous grace periods during this time
 period. Once all of its kthreads are up and running, RCU starts running
 normally.
@@ -1820,7 +1818,7 @@ Interrupts and NMIs
 
 The Linux kernel has interrupts, and RCU read-side critical sections are
 legal within interrupt handlers and within interrupt-disabled regions of
-code, as are invocations of ``call_rcu()``.
+code, as are invocations of call_rcu().
 
 Some Linux-kernel architectures can enter an interrupt handler from
 non-idle process context, and then just never leave it, instead
@@ -1832,22 +1830,22 @@ way during a rewrite of RCU's dyntick-idle code.
 
 The Linux kernel has non-maskable interrupts (NMIs), and RCU read-side
 critical sections are legal within NMI handlers. Thankfully, RCU
-update-side primitives, including ``call_rcu()``, are prohibited within
+update-side primitives, including call_rcu(), are prohibited within
 NMI handlers.
 
 The name notwithstanding, some Linux-kernel architectures can have
 nested NMIs, which RCU must handle correctly. Andy Lutomirski `surprised
-me <https://lkml.kernel.org/r/CALCETrXLq1y7e_dKFPgou-FKHB6Pu-r8+t-6Ds+8=va7anBWDA@mail.gmail.com>`__
+me <https://lore.kernel.org/r/CALCETrXLq1y7e_dKFPgou-FKHB6Pu-r8+t-6Ds+8=va7anBWDA@mail.gmail.com>`__
 with this requirement; he also kindly surprised me with `an
-algorithm <https://lkml.kernel.org/r/CALCETrXSY9JpW3uE6H8WYk81sg56qasA2aqmjMPsq5dOtzso=g@mail.gmail.com>`__
+algorithm <https://lore.kernel.org/r/CALCETrXSY9JpW3uE6H8WYk81sg56qasA2aqmjMPsq5dOtzso=g@mail.gmail.com>`__
 that meets this requirement.
 
 Furthermore, NMI handlers can be interrupted by what appear to RCU to be
 normal interrupts. One way that this can happen is for code that
-directly invokes ``rcu_irq_enter()`` and ``rcu_irq_exit()`` to be called
+directly invokes rcu_irq_enter() and rcu_irq_exit() to be called
 from an NMI handler. This astonishing fact of life prompted the current
-code structure, which has ``rcu_irq_enter()`` invoking
-``rcu_nmi_enter()`` and ``rcu_irq_exit()`` invoking ``rcu_nmi_exit()``.
+code structure, which has rcu_irq_enter() invoking
+rcu_nmi_enter() and rcu_irq_exit() invoking rcu_nmi_exit().
 And yes, I also learned of this requirement the hard way.
 
 Loadable Modules
@@ -1857,45 +1855,45 @@ The Linux kernel has loadable modules, and these modules can also be
 unloaded. After a given module has been unloaded, any attempt to call
 one of its functions results in a segmentation fault. The module-unload
 functions must therefore cancel any delayed calls to loadable-module
-functions, for example, any outstanding ``mod_timer()`` must be dealt
-with via ``del_timer_sync()`` or similar.
+functions, for example, any outstanding mod_timer() must be dealt
+with via del_timer_sync() or similar.
 
 Unfortunately, there is no way to cancel an RCU callback; once you
-invoke ``call_rcu()``, the callback function is eventually going to be
+invoke call_rcu(), the callback function is eventually going to be
 invoked, unless the system goes down first. Because it is normally
 considered socially irresponsible to crash the system in response to a
 module unload request, we need some other way to deal with in-flight RCU
 callbacks.
 
-RCU therefore provides ``rcu_barrier()``, which waits until all
+RCU therefore provides rcu_barrier(), which waits until all
 in-flight RCU callbacks have been invoked. If a module uses
-``call_rcu()``, its exit function should therefore prevent any future
-invocation of ``call_rcu()``, then invoke ``rcu_barrier()``. In theory,
-the underlying module-unload code could invoke ``rcu_barrier()``
+call_rcu(), its exit function should therefore prevent any future
+invocation of call_rcu(), then invoke rcu_barrier(). In theory,
+the underlying module-unload code could invoke rcu_barrier()
 unconditionally, but in practice this would incur unacceptable
 latencies.
 
 Nikita Danilov noted this requirement for an analogous
 filesystem-unmount situation, and Dipankar Sarma incorporated
-``rcu_barrier()`` into RCU. The need for ``rcu_barrier()`` for module
+rcu_barrier() into RCU. The need for rcu_barrier() for module
 unloading became apparent later.
 
 .. important::
 
-   The ``rcu_barrier()`` function is not, repeat,
+   The rcu_barrier() function is not, repeat,
    *not*, obligated to wait for a grace period. It is instead only required
    to wait for RCU callbacks that have already been posted. Therefore, if
    there are no RCU callbacks posted anywhere in the system,
-   ``rcu_barrier()`` is within its rights to return immediately. Even if
-   there are callbacks posted, ``rcu_barrier()`` does not necessarily need
+   rcu_barrier() is within its rights to return immediately. Even if
+   there are callbacks posted, rcu_barrier() does not necessarily need
    to wait for a grace period.
 
 +-----------------------------------------------------------------------+
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
 | Wait a minute! Each RCU callbacks must wait for a grace period to     |
-| complete, and ``rcu_barrier()`` must wait for each pre-existing       |
-| callback to be invoked. Doesn't ``rcu_barrier()`` therefore need to   |
+| complete, and rcu_barrier() must wait for each pre-existing           |
+| callback to be invoked. Doesn't rcu_barrier() therefore need to       |
 | wait for a full grace period if there is even one callback posted     |
 | anywhere in the system?                                               |
 +-----------------------------------------------------------------------+
@@ -1904,14 +1902,14 @@ unloading became apparent later.
 | Absolutely not!!!                                                     |
 | Yes, each RCU callbacks must wait for a grace period to complete, but |
 | it might well be partly (or even completely) finished waiting by the  |
-| time ``rcu_barrier()`` is invoked. In that case, ``rcu_barrier()``    |
+| time rcu_barrier() is invoked. In that case, rcu_barrier()            |
 | need only wait for the remaining portion of the grace period to       |
 | elapse. So even if there are quite a few callbacks posted,            |
-| ``rcu_barrier()`` might well return quite quickly.                    |
+| rcu_barrier() might well return quite quickly.                        |
 |                                                                       |
 | So if you need to wait for a grace period as well as for all          |
 | pre-existing callbacks, you will need to invoke both                  |
-| ``synchronize_rcu()`` and ``rcu_barrier()``. If latency is a concern, |
+| synchronize_rcu() and rcu_barrier(). If latency is a concern,         |
 | you can always use workqueues to invoke them concurrently.            |
 +-----------------------------------------------------------------------+
 
@@ -1929,18 +1927,18 @@ The Linux-kernel CPU-hotplug implementation has notifiers that are used
 to allow the various kernel subsystems (including RCU) to respond
 appropriately to a given CPU-hotplug operation. Most RCU operations may
 be invoked from CPU-hotplug notifiers, including even synchronous
-grace-period operations such as (``synchronize_rcu()`` and
-``synchronize_rcu_expedited()``).  However, these synchronous operations
+grace-period operations such as (synchronize_rcu() and
+synchronize_rcu_expedited()).  However, these synchronous operations
 do block and therefore cannot be invoked from notifiers that execute via
-``stop_machine()``, specifically those between the ``CPUHP_AP_OFFLINE``
+stop_machine(), specifically those between the ``CPUHP_AP_OFFLINE``
 and ``CPUHP_AP_ONLINE`` states.
 
-In addition, all-callback-wait operations such as ``rcu_barrier()`` may
+In addition, all-callback-wait operations such as rcu_barrier() may
 not be invoked from any CPU-hotplug notifier.  This restriction is due
 to the fact that there are phases of CPU-hotplug operations where the
 outgoing CPU's callbacks will not be invoked until after the CPU-hotplug
 operation ends, which could also result in deadlock. Furthermore,
-``rcu_barrier()`` blocks CPU-hotplug operations during its execution,
+rcu_barrier() blocks CPU-hotplug operations during its execution,
 which results in another type of deadlock when invoked from a CPU-hotplug
 notifier.
 
@@ -1955,12 +1953,12 @@ if offline CPUs block an RCU grace period for too long.
 
 An offline CPU's quiescent state will be reported either:
 
-1.  As the CPU goes offline using RCU's hotplug notifier (``rcu_report_dead()``).
-2.  When grace period initialization (``rcu_gp_init()``) detects a
+1.  As the CPU goes offline using RCU's hotplug notifier (rcu_report_dead()).
+2.  When grace period initialization (rcu_gp_init()) detects a
     race either with CPU offlining or with a task unblocking on a leaf
     ``rcu_node`` structure whose CPUs are all offline.
 
-The CPU-online path (``rcu_cpu_starting()``) should never need to report
+The CPU-online path (rcu_cpu_starting()) should never need to report
 a quiescent state for an offline CPU.  However, as a debugging measure,
 it does emit a warning if a quiescent state was not already reported
 for that CPU.
@@ -1984,11 +1982,11 @@ room for further improvement.
 
 There is no longer any prohibition against holding any of
 scheduler's runqueue or priority-inheritance spinlocks across an
-``rcu_read_unlock()``, even if interrupts and preemption were enabled
+rcu_read_unlock(), even if interrupts and preemption were enabled
 somewhere within the corresponding RCU read-side critical section.
-Therefore, it is now perfectly legal to execute ``rcu_read_lock()``
+Therefore, it is now perfectly legal to execute rcu_read_lock()
 with preemption enabled, acquire one of the scheduler locks, and hold
-that lock across the matching ``rcu_read_unlock()``.
+that lock across the matching rcu_read_unlock().
 
 Similarly, the RCU flavor consolidation has removed the need for negative
 nesting.  The fact that interrupt-disabled regions of code act as RCU
@@ -1999,7 +1997,7 @@ Tracing and RCU
 ~~~~~~~~~~~~~~~
 
 It is possible to use tracing on RCU code, but tracing itself uses RCU.
-For this reason, ``rcu_dereference_raw_check()`` is provided for use
+For this reason, rcu_dereference_raw_check() is provided for use
 by tracing, which avoids the destructive recursion that could otherwise
 ensue. This API is also used by virtualization in some architectures,
 where RCU readers execute in environments in which tracing cannot be
@@ -2010,12 +2008,12 @@ Accesses to User Memory and RCU
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 The kernel needs to access user-space memory, for example, to access data
-referenced by system-call parameters.  The ``get_user()`` macro does this job.
+referenced by system-call parameters.  The get_user() macro does this job.
 
 However, user-space memory might well be paged out, which means that
-``get_user()`` might well page-fault and thus block while waiting for the
+get_user() might well page-fault and thus block while waiting for the
 resulting I/O to complete.  It would be a very bad thing for the compiler to
-reorder a ``get_user()`` invocation into an RCU read-side critical section.
+reorder a get_user() invocation into an RCU read-side critical section.
 
 For example, suppose that the source code looked like this:
 
@@ -2040,23 +2038,23 @@ the following:
        5 rcu_read_unlock();
        6 do_something_with(v, user_v);
 
-If the compiler did make this transformation in a ``CONFIG_PREEMPT=n`` kernel
-build, and if ``get_user()`` did page fault, the result would be a quiescent
+If the compiler did make this transformation in a ``CONFIG_PREEMPTION=n`` kernel
+build, and if get_user() did page fault, the result would be a quiescent
 state in the middle of an RCU read-side critical section.  This misplaced
 quiescent state could result in line 4 being a use-after-free access,
 which could be bad for your kernel's actuarial statistics.  Similar examples
-can be constructed with the call to ``get_user()`` preceding the
-``rcu_read_lock()``.
+can be constructed with the call to get_user() preceding the
+rcu_read_lock().
 
-Unfortunately, ``get_user()`` doesn't have any particular ordering properties,
+Unfortunately, get_user() doesn't have any particular ordering properties,
 and in some architectures the underlying ``asm`` isn't even marked
 ``volatile``.  And even if it was marked ``volatile``, the above access to
 ``p->value`` is not volatile, so the compiler would not have any reason to keep
 those two accesses in order.
 
-Therefore, the Linux-kernel definitions of ``rcu_read_lock()`` and
-``rcu_read_unlock()`` must act as compiler barriers, at least for outermost
-instances of ``rcu_read_lock()`` and ``rcu_read_unlock()`` within a nested set
+Therefore, the Linux-kernel definitions of rcu_read_lock() and
+rcu_read_unlock() must act as compiler barriers, at least for outermost
+instances of rcu_read_lock() and rcu_read_unlock() within a nested set
 of RCU read-side critical sections.
 
 Energy Efficiency
@@ -2071,26 +2069,26 @@ call.
 
 Because RCU avoids interrupting idle CPUs, it is illegal to execute an
 RCU read-side critical section on an idle CPU. (Kernels built with
-``CONFIG_PROVE_RCU=y`` will splat if you try it.) The ``RCU_NONIDLE()``
+``CONFIG_PROVE_RCU=y`` will splat if you try it.) The RCU_NONIDLE()
 macro and ``_rcuidle`` event tracing is provided to work around this
-restriction. In addition, ``rcu_is_watching()`` may be used to test
+restriction. In addition, rcu_is_watching() may be used to test
 whether or not it is currently legal to run RCU read-side critical
 sections on this CPU. I learned of the need for diagnostics on the one
-hand and ``RCU_NONIDLE()`` on the other while inspecting idle-loop code.
+hand and RCU_NONIDLE() on the other while inspecting idle-loop code.
 Steven Rostedt supplied ``_rcuidle`` event tracing, which is used quite
 heavily in the idle loop. However, there are some restrictions on the
-code placed within ``RCU_NONIDLE()``:
+code placed within RCU_NONIDLE():
 
 #. Blocking is prohibited. In practice, this is not a serious
    restriction given that idle tasks are prohibited from blocking to
    begin with.
-#. Although nesting ``RCU_NONIDLE()`` is permitted, they cannot nest
+#. Although nesting RCU_NONIDLE() is permitted, they cannot nest
    indefinitely deeply. However, given that they can be nested on the
    order of a million deep, even on 32-bit systems, this should not be a
    serious restriction. This nesting limit would probably be reached
    long after the compiler OOMed or the stack overflowed.
-#. Any code path that enters ``RCU_NONIDLE()`` must sequence out of that
-   same ``RCU_NONIDLE()``. For example, the following is grossly
+#. Any code path that enters RCU_NONIDLE() must sequence out of that
+   same RCU_NONIDLE(). For example, the following is grossly
    illegal:
 
       ::
@@ -2103,7 +2101,7 @@ code placed within ``RCU_NONIDLE()``:
 
 
    It is just as illegal to transfer control into the middle of
-   ``RCU_NONIDLE()``'s argument. Yes, in theory, you could transfer in
+   RCU_NONIDLE()'s argument. Yes, in theory, you could transfer in
    as long as you also transferred out, but in practice you could also
    expect to get sharply worded review comments.
 
@@ -2195,9 +2193,9 @@ scheduling-clock interrupt be enabled when RCU needs it to be:
    sections, and RCU believes this CPU to be idle, no problem. This
    sort of thing is used by some architectures for light-weight
    exception handlers, which can then avoid the overhead of
-   ``rcu_irq_enter()`` and ``rcu_irq_exit()`` at exception entry and
+   rcu_irq_enter() and rcu_irq_exit() at exception entry and
    exit, respectively. Some go further and avoid the entireties of
-   ``irq_enter()`` and ``irq_exit()``.
+   irq_enter() and irq_exit().
    Just make very sure you are running some of your tests with
    ``CONFIG_PROVE_RCU=y``, just in case one of your code paths was in
    fact joking about not doing RCU read-side critical sections.
@@ -2221,7 +2219,7 @@ scheduling-clock interrupt be enabled when RCU needs it to be:
 | **Quick Quiz**:                                                       |
 +-----------------------------------------------------------------------+
 | But what if my driver has a hardware interrupt handler that can run   |
-| for many seconds? I cannot invoke ``schedule()`` from an hardware     |
+| for many seconds? I cannot invoke schedule() from an hardware         |
 | interrupt handler, after all!                                         |
 +-----------------------------------------------------------------------+
 | **Answer**:                                                           |
@@ -2243,8 +2241,8 @@ Memory Efficiency
 
 Although small-memory non-realtime systems can simply use Tiny RCU, code
 size is only one aspect of memory efficiency. Another aspect is the size
-of the ``rcu_head`` structure used by ``call_rcu()`` and
-``kfree_rcu()``. Although this structure contains nothing more than a
+of the ``rcu_head`` structure used by call_rcu() and
+kfree_rcu(). Although this structure contains nothing more than a
 pair of pointers, it does appear in many RCU-protected data structures,
 including some that are size critical. The ``page`` structure is a case
 in point, as evidenced by the many occurrences of the ``union`` keyword
@@ -2254,7 +2252,7 @@ This need for memory efficiency is one reason that RCU uses hand-crafted
 singly linked lists to track the ``rcu_head`` structures that are
 waiting for a grace period to elapse. It is also the reason why
 ``rcu_head`` structures do not contain debug information, such as fields
-tracking the file and line of the ``call_rcu()`` or ``kfree_rcu()`` that
+tracking the file and line of the call_rcu() or kfree_rcu() that
 posted them. Although this information might appear in debug-only kernel
 builds at some point, in the meantime, the ``->func`` field will often
 provide the needed debug information.
@@ -2264,18 +2262,18 @@ more extreme measures. Returning to the ``page`` structure, the
 ``rcu_head`` field shares storage with a great many other structures
 that are used at various points in the corresponding page's lifetime. In
 order to correctly resolve certain `race
-conditions <https://lkml.kernel.org/g/1439976106-137226-1-git-send-email-kirill.shutemov@linux.intel.com>`__,
+conditions <https://lore.kernel.org/r/1439976106-137226-1-git-send-email-kirill.shutemov@linux.intel.com>`__,
 the Linux kernel's memory-management subsystem needs a particular bit to
 remain zero during all phases of grace-period processing, and that bit
 happens to map to the bottom bit of the ``rcu_head`` structure's
-``->next`` field. RCU makes this guarantee as long as ``call_rcu()`` is
-used to post the callback, as opposed to ``kfree_rcu()`` or some future
-“lazy” variant of ``call_rcu()`` that might one day be created for
+``->next`` field. RCU makes this guarantee as long as call_rcu() is
+used to post the callback, as opposed to kfree_rcu() or some future
+“lazy” variant of call_rcu() that might one day be created for
 energy-efficiency purposes.
 
 That said, there are limits. RCU requires that the ``rcu_head``
 structure be aligned to a two-byte boundary, and passing a misaligned
-``rcu_head`` structure to one of the ``call_rcu()`` family of functions
+``rcu_head`` structure to one of the call_rcu() family of functions
 will result in a splat. It is therefore necessary to exercise caution
 when packing structures containing fields of type ``rcu_head``. Why not
 a four-byte or even eight-byte alignment requirement? Because the m68k
@@ -2299,7 +2297,7 @@ hot code paths in performance-critical portions of the Linux kernel's
 networking, security, virtualization, and scheduling code paths. RCU
 must therefore use efficient implementations, especially in its
 read-side primitives. To that end, it would be good if preemptible RCU's
-implementation of ``rcu_read_lock()`` could be inlined, however, doing
+implementation of rcu_read_lock() could be inlined, however, doing
 this requires resolving ``#include`` issues with the ``task_struct``
 structure.
 
@@ -2312,23 +2310,23 @@ on the ``rcu_node`` structure. RCU is required to tolerate all CPUs
 continuously invoking any combination of RCU's runtime primitives with
 minimal per-operation overhead. In fact, in many cases, increasing load
 must *decrease* the per-operation overhead, witness the batching
-optimizations for ``synchronize_rcu()``, ``call_rcu()``,
-``synchronize_rcu_expedited()``, and ``rcu_barrier()``. As a general
+optimizations for synchronize_rcu(), call_rcu(),
+synchronize_rcu_expedited(), and rcu_barrier(). As a general
 rule, RCU must cheerfully accept whatever the rest of the Linux kernel
 decides to throw at it.
 
 The Linux kernel is used for real-time workloads, especially in
 conjunction with the `-rt
-patchset <https://rt.wiki.kernel.org/index.php/Main_Page>`__. The
+patchset <https://wiki.linuxfoundation.org/realtime/>`__. The
 real-time-latency response requirements are such that the traditional
 approach of disabling preemption across RCU read-side critical sections
-is inappropriate. Kernels built with ``CONFIG_PREEMPT=y`` therefore use
+is inappropriate. Kernels built with ``CONFIG_PREEMPTION=y`` therefore use
 an RCU implementation that allows RCU read-side critical sections to be
 preempted. This requirement made its presence known after users made it
 clear that an earlier `real-time
 patch <https://lwn.net/Articles/107930/>`__ did not meet their needs, in
 conjunction with some `RCU
-issues <https://lkml.kernel.org/g/20050318002026.GA2693@us.ibm.com>`__
+issues <https://lore.kernel.org/r/20050318002026.GA2693@us.ibm.com>`__
 encountered by a very early version of the -rt patchset.
 
 In addition, RCU must make do with a sub-100-microsecond real-time
@@ -2346,7 +2344,7 @@ number of race conditions.
 RCU must avoid degrading real-time response for CPU-bound threads,
 whether executing in usermode (which is one use case for
 ``CONFIG_NO_HZ_FULL=y``) or in the kernel. That said, CPU-bound loops in
-the kernel must execute ``cond_resched()`` at least once per few tens of
+the kernel must execute cond_resched() at least once per few tens of
 milliseconds in order to avoid receiving an IPI from RCU.
 
 Finally, RCU's status as a synchronization primitive means that any RCU
@@ -2412,7 +2410,7 @@ grace periods from ever ending. The result was an out-of-memory
 condition and a system hang.
 
 The solution was the creation of RCU-bh, which does
-``local_bh_disable()`` across its read-side critical sections, and which
+local_bh_disable() across its read-side critical sections, and which
 uses the transition from one type of softirq processing to another as a
 quiescent state in addition to context switch, idle, user mode, and
 offline. This means that RCU-bh grace periods can complete even when
@@ -2420,31 +2418,31 @@ some of the CPUs execute in softirq indefinitely, thus allowing
 algorithms based on RCU-bh to withstand network-based denial-of-service
 attacks.
 
-Because ``rcu_read_lock_bh()`` and ``rcu_read_unlock_bh()`` disable and
+Because rcu_read_lock_bh() and rcu_read_unlock_bh() disable and
 re-enable softirq handlers, any attempt to start a softirq handlers
 during the RCU-bh read-side critical section will be deferred. In this
-case, ``rcu_read_unlock_bh()`` will invoke softirq processing, which can
+case, rcu_read_unlock_bh() will invoke softirq processing, which can
 take considerable time. One can of course argue that this softirq
 overhead should be associated with the code following the RCU-bh
-read-side critical section rather than ``rcu_read_unlock_bh()``, but the
+read-side critical section rather than rcu_read_unlock_bh(), but the
 fact is that most profiling tools cannot be expected to make this sort
 of fine distinction. For example, suppose that a three-millisecond-long
 RCU-bh read-side critical section executes during a time of heavy
 networking load. There will very likely be an attempt to invoke at least
 one softirq handler during that three milliseconds, but any such
 invocation will be delayed until the time of the
-``rcu_read_unlock_bh()``. This can of course make it appear at first
-glance as if ``rcu_read_unlock_bh()`` was executing very slowly.
+rcu_read_unlock_bh(). This can of course make it appear at first
+glance as if rcu_read_unlock_bh() was executing very slowly.
 
 The `RCU-bh
 API <https://lwn.net/Articles/609973/#RCU%20Per-Flavor%20API%20Table>`__
-includes ``rcu_read_lock_bh()``, ``rcu_read_unlock_bh()``,
-``rcu_dereference_bh()``, ``rcu_dereference_bh_check()``,
-``synchronize_rcu_bh()``, ``synchronize_rcu_bh_expedited()``,
-``call_rcu_bh()``, ``rcu_barrier_bh()``, and
-``rcu_read_lock_bh_held()``. However, the update-side APIs are now
-simple wrappers for other RCU flavors, namely RCU-sched in
-CONFIG_PREEMPT=n kernels and RCU-preempt otherwise.
+includes rcu_read_lock_bh(), rcu_read_unlock_bh(), rcu_dereference_bh(),
+rcu_dereference_bh_check(), and rcu_read_lock_bh_held(). However, the
+old RCU-bh update-side APIs are now gone, replaced by synchronize_rcu(),
+synchronize_rcu_expedited(), call_rcu(), and rcu_barrier().  In addition,
+anything that disables bottom halves also marks an RCU-bh read-side
+critical section, including local_bh_disable() and local_bh_enable(),
+local_irq_save() and local_irq_restore(), and so on.
 
 Sched Flavor (Historical)
 ~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -2462,32 +2460,32 @@ not have this property, given that any point in the code outside of an
 RCU read-side critical section can be a quiescent state. Therefore,
 *RCU-sched* was created, which follows “classic” RCU in that an
 RCU-sched grace period waits for pre-existing interrupt and NMI
-handlers. In kernels built with ``CONFIG_PREEMPT=n``, the RCU and
+handlers. In kernels built with ``CONFIG_PREEMPTION=n``, the RCU and
 RCU-sched APIs have identical implementations, while kernels built with
-``CONFIG_PREEMPT=y`` provide a separate implementation for each.
+``CONFIG_PREEMPTION=y`` provide a separate implementation for each.
 
-Note well that in ``CONFIG_PREEMPT=y`` kernels,
-``rcu_read_lock_sched()`` and ``rcu_read_unlock_sched()`` disable and
+Note well that in ``CONFIG_PREEMPTION=y`` kernels,
+rcu_read_lock_sched() and rcu_read_unlock_sched() disable and
 re-enable preemption, respectively. This means that if there was a
 preemption attempt during the RCU-sched read-side critical section,
-``rcu_read_unlock_sched()`` will enter the scheduler, with all the
-latency and overhead entailed. Just as with ``rcu_read_unlock_bh()``,
-this can make it look as if ``rcu_read_unlock_sched()`` was executing
+rcu_read_unlock_sched() will enter the scheduler, with all the
+latency and overhead entailed. Just as with rcu_read_unlock_bh(),
+this can make it look as if rcu_read_unlock_sched() was executing
 very slowly. However, the highest-priority task won't be preempted, so
-that task will enjoy low-overhead ``rcu_read_unlock_sched()``
+that task will enjoy low-overhead rcu_read_unlock_sched()
 invocations.
 
 The `RCU-sched
 API <https://lwn.net/Articles/609973/#RCU%20Per-Flavor%20API%20Table>`__
-includes ``rcu_read_lock_sched()``, ``rcu_read_unlock_sched()``,
-``rcu_read_lock_sched_notrace()``, ``rcu_read_unlock_sched_notrace()``,
-``rcu_dereference_sched()``, ``rcu_dereference_sched_check()``,
-``synchronize_sched()``, ``synchronize_rcu_sched_expedited()``,
-``call_rcu_sched()``, ``rcu_barrier_sched()``, and
-``rcu_read_lock_sched_held()``. However, anything that disables
-preemption also marks an RCU-sched read-side critical section, including
-``preempt_disable()`` and ``preempt_enable()``, ``local_irq_save()`` and
-``local_irq_restore()``, and so on.
+includes rcu_read_lock_sched(), rcu_read_unlock_sched(),
+rcu_read_lock_sched_notrace(), rcu_read_unlock_sched_notrace(),
+rcu_dereference_sched(), rcu_dereference_sched_check(), and
+rcu_read_lock_sched_held().  However, the old RCU-sched update-side APIs
+are now gone, replaced by synchronize_rcu(), synchronize_rcu_expedited(),
+call_rcu(), and rcu_barrier().  In addition, anything that disables
+preemption also marks an RCU-sched read-side critical section,
+including preempt_disable() and preempt_enable(), local_irq_save()
+and local_irq_restore(), and so on.
 
 Sleepable RCU
 ~~~~~~~~~~~~~
@@ -2509,7 +2507,7 @@ this structure must be passed in to each SRCU function, for example,
 structure. The key benefit of these domains is that a slow SRCU reader
 in one domain does not delay an SRCU grace period in some other domain.
 That said, one consequence of these domains is that read-side code must
-pass a “cookie” from ``srcu_read_lock()`` to ``srcu_read_unlock()``, for
+pass a “cookie” from srcu_read_lock() to srcu_read_unlock(), for
 example, as follows:
 
    ::
@@ -2539,24 +2537,24 @@ period to elapse. For example, this results in a self-deadlock:
        6 srcu_read_unlock(&ss, idx);
 
 However, if line 5 acquired a mutex that was held across a
-``synchronize_srcu()`` for domain ``ss``, deadlock would still be
+synchronize_srcu() for domain ``ss``, deadlock would still be
 possible. Furthermore, if line 5 acquired a mutex that was held across a
-``synchronize_srcu()`` for some other domain ``ss1``, and if an
+synchronize_srcu() for some other domain ``ss1``, and if an
 ``ss1``-domain SRCU read-side critical section acquired another mutex
-that was held across as ``ss``-domain ``synchronize_srcu()``, deadlock
+that was held across as ``ss``-domain synchronize_srcu(), deadlock
 would again be possible. Such a deadlock cycle could extend across an
 arbitrarily large number of different SRCU domains. Again, with great
 power comes great responsibility.
 
 Unlike the other RCU flavors, SRCU read-side critical sections can run
 on idle and even offline CPUs. This ability requires that
-``srcu_read_lock()`` and ``srcu_read_unlock()`` contain memory barriers,
+srcu_read_lock() and srcu_read_unlock() contain memory barriers,
 which means that SRCU readers will run a bit slower than would RCU
-readers. It also motivates the ``smp_mb__after_srcu_read_unlock()`` API,
-which, in combination with ``srcu_read_unlock()``, guarantees a full
+readers. It also motivates the smp_mb__after_srcu_read_unlock() API,
+which, in combination with srcu_read_unlock(), guarantees a full
 memory barrier.
 
-Also unlike other RCU flavors, ``synchronize_srcu()`` may **not** be
+Also unlike other RCU flavors, synchronize_srcu() may **not** be
 invoked from CPU-hotplug notifiers, due to the fact that SRCU grace
 periods make use of timers and the possibility of timers being
 temporarily “stranded” on the outgoing CPU. This stranding of timers
@@ -2565,7 +2563,7 @@ the CPU-hotplug process. The problem is that if a notifier is waiting on
 an SRCU grace period, that grace period is waiting on a timer, and that
 timer is stranded on the outgoing CPU, then the notifier will never be
 awakened, in other words, deadlock has occurred. This same situation of
-course also prohibits ``srcu_barrier()`` from being invoked from
+course also prohibits srcu_barrier() from being invoked from
 CPU-hotplug notifiers.
 
 SRCU also differs from other RCU flavors in that SRCU's expedited and
@@ -2576,12 +2574,12 @@ have not yet completed. (But please note that this is a property of the
 current implementation, not necessarily of future implementations.) In
 addition, if SRCU has been idle for longer than the interval specified
 by the ``srcutree.exp_holdoff`` kernel boot parameter (25 microseconds
-by default), and if a ``synchronize_srcu()`` invocation ends this idle
+by default), and if a synchronize_srcu() invocation ends this idle
 period, that invocation will be automatically expedited.
 
 As of v4.12, SRCU's callbacks are maintained per-CPU, eliminating a
 locking bottleneck present in prior kernel versions. Although this will
-allow users to put much heavier stress on ``call_srcu()``, it is
+allow users to put much heavier stress on call_srcu(), it is
 important to note that SRCU does not yet take any special steps to deal
 with callback flooding. So if you are posting (say) 10,000 SRCU
 callbacks per second per CPU, you are probably totally OK, but if you
@@ -2592,14 +2590,32 @@ of your CPUs and the size of your memory.
 
 The `SRCU
 API <https://lwn.net/Articles/609973/#RCU%20Per-Flavor%20API%20Table>`__
-includes ``srcu_read_lock()``, ``srcu_read_unlock()``,
-``srcu_dereference()``, ``srcu_dereference_check()``,
-``synchronize_srcu()``, ``synchronize_srcu_expedited()``,
-``call_srcu()``, ``srcu_barrier()``, and ``srcu_read_lock_held()``. It
-also includes ``DEFINE_SRCU()``, ``DEFINE_STATIC_SRCU()``, and
-``init_srcu_struct()`` APIs for defining and initializing
+includes srcu_read_lock(), srcu_read_unlock(),
+srcu_dereference(), srcu_dereference_check(),
+synchronize_srcu(), synchronize_srcu_expedited(),
+call_srcu(), srcu_barrier(), and srcu_read_lock_held(). It
+also includes DEFINE_SRCU(), DEFINE_STATIC_SRCU(), and
+init_srcu_struct() APIs for defining and initializing
 ``srcu_struct`` structures.
 
+More recently, the SRCU API has added polling interfaces:
+
+#. start_poll_synchronize_srcu() returns a cookie identifying
+   the completion of a future SRCU grace period and ensures
+   that this grace period will be started.
+#. poll_state_synchronize_srcu() returns ``true`` iff the
+   specified cookie corresponds to an already-completed
+   SRCU grace period.
+#. get_state_synchronize_srcu() returns a cookie just like
+   start_poll_synchronize_srcu() does, but differs in that
+   it does nothing to ensure that any future SRCU grace period
+   will be started.
+
+These functions are used to avoid unnecessary SRCU grace periods in
+certain types of buffer-cache algorithms having multi-stage age-out
+mechanisms.  The idea is that by the time the block has aged completely
+from the cache, an SRCU grace period will be very likely to have elapsed.
+
 Tasks RCU
 ~~~~~~~~~
 
@@ -2608,11 +2624,11 @@ required to install different types of probes. It would be good to be
 able to free old trampolines, which sounds like a job for some form of
 RCU. However, because it is necessary to be able to install a trace
 anywhere in the code, it is not possible to use read-side markers such
-as ``rcu_read_lock()`` and ``rcu_read_unlock()``. In addition, it does
+as rcu_read_lock() and rcu_read_unlock(). In addition, it does
 not work to have these markers in the trampoline itself, because there
-would need to be instructions following ``rcu_read_unlock()``. Although
-``synchronize_rcu()`` would guarantee that execution reached the
-``rcu_read_unlock()``, it would not be able to guarantee that execution
+would need to be instructions following rcu_read_unlock(). Although
+synchronize_rcu() would guarantee that execution reached the
+rcu_read_unlock(), it would not be able to guarantee that execution
 had completely left the trampoline. Worse yet, in some situations
 the trampoline's protection must extend a few instructions *prior* to
 execution reaching the trampoline.  For example, these few instructions
@@ -2623,16 +2639,16 @@ actually reached the trampoline itself.
 The solution, in the form of `Tasks
 RCU <https://lwn.net/Articles/607117/>`__, is to have implicit read-side
 critical sections that are delimited by voluntary context switches, that
-is, calls to ``schedule()``, ``cond_resched()``, and
-``synchronize_rcu_tasks()``. In addition, transitions to and from
+is, calls to schedule(), cond_resched(), and
+synchronize_rcu_tasks(). In addition, transitions to and from
 userspace execution also delimit tasks-RCU read-side critical sections.
 
 The tasks-RCU API is quite compact, consisting only of
-``call_rcu_tasks()``, ``synchronize_rcu_tasks()``, and
-``rcu_barrier_tasks()``. In ``CONFIG_PREEMPT=n`` kernels, trampolines
-cannot be preempted, so these APIs map to ``call_rcu()``,
-``synchronize_rcu()``, and ``rcu_barrier()``, respectively. In
-``CONFIG_PREEMPT=y`` kernels, trampolines can be preempted, and these
+call_rcu_tasks(), synchronize_rcu_tasks(), and
+rcu_barrier_tasks(). In ``CONFIG_PREEMPTION=n`` kernels, trampolines
+cannot be preempted, so these APIs map to call_rcu(),
+synchronize_rcu(), and rcu_barrier(), respectively. In
+``CONFIG_PREEMPTION=y`` kernels, trampolines can be preempted, and these
 three APIs are therefore implemented by separate functions that check
 for voluntary context switches.
 
@@ -2646,8 +2662,8 @@ grace-period state machine so as to avoid the need for the additional
 latency.
 
 RCU disables CPU hotplug in a few places, perhaps most notably in the
-``rcu_barrier()`` operations. If there is a strong reason to use
-``rcu_barrier()`` in CPU-hotplug notifiers, it will be necessary to
+rcu_barrier() operations. If there is a strong reason to use
+rcu_barrier() in CPU-hotplug notifiers, it will be necessary to
 avoid disabling CPU hotplug. This would introduce some complexity, so
 there had better be a *very* good reason.
 
@@ -2664,7 +2680,7 @@ However, this combining tree does not spread its memory across NUMA
 nodes nor does it align the CPU groups with hardware features such as
 sockets or cores. Such spreading and alignment is currently believed to
 be unnecessary because the hotpath read-side primitives do not access
-the combining tree, nor does ``call_rcu()`` in the common case. If you
+the combining tree, nor does call_rcu() in the common case. If you
 believe that your architecture needs such spreading and alignment, then
 your architecture should also benefit from the
 ``rcutree.rcu_fanout_leaf`` boot parameter, which can be set to the
@@ -2685,7 +2701,7 @@ likely that adjustments will be required to more gracefully handle
 extreme loads. It might also be necessary to be able to relate CPU
 utilization by RCU's kthreads and softirq handlers to the code that
 instigated this CPU utilization. For example, RCU callback overhead
-might be charged back to the originating ``call_rcu()`` instance, though
+might be charged back to the originating call_rcu() instance, though
 probably not in production kernels.
 
 Additional work may be required to provide reasonable forward-progress
index bb7128eb322ef8f42c0d76ea653da146355ebbb6..1030119294d085c6cabdabb0276e7795ad3a44af 100644 (file)
@@ -70,7 +70,7 @@ over a rather long period of time, but improvements are always welcome!
        is less readable and prevents lockdep from detecting locking issues.
 
        Letting RCU-protected pointers "leak" out of an RCU read-side
-       critical section is every bid as bad as letting them leak out
+       critical section is every bit as bad as letting them leak out
        from under a lock.  Unless, of course, you have arranged some
        other means of protection, such as a lock or a reference count
        -before- letting them out of the RCU read-side critical section.
@@ -129,9 +129,7 @@ over a rather long period of time, but improvements are always welcome!
                accesses.  The rcu_dereference() primitive ensures that
                the CPU picks up the pointer before it picks up the data
                that the pointer points to.  This really is necessary
-               on Alpha CPUs.  If you don't believe me, see:
-
-                       http://www.openvms.compaq.com/wizard/wiz_2637.html
+               on Alpha CPUs.
 
                The rcu_dereference() primitive is also an excellent
                documentation aid, letting the person reading the
@@ -214,9 +212,9 @@ over a rather long period of time, but improvements are always welcome!
        the rest of the system.
 
 7.     As of v4.20, a given kernel implements only one RCU flavor,
-       which is RCU-sched for PREEMPT=n and RCU-preempt for PREEMPT=y.
+       which is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y.
        If the updater uses call_rcu() or synchronize_rcu(),
-       then the corresponding readers my use rcu_read_lock() and
+       then the corresponding readers may use rcu_read_lock() and
        rcu_read_unlock(), rcu_read_lock_bh() and rcu_read_unlock_bh(),
        or any pair of primitives that disables and re-enables preemption,
        for example, rcu_read_lock_sched() and rcu_read_unlock_sched().
index f64f4413a47c4583d0de3ea94dc0f305cabbfcb0..3b4a248774961c37f9063195c411a520ce2b9ad7 100644 (file)
@@ -9,7 +9,7 @@ RCU (read-copy update) is a synchronization mechanism that can be thought
 of as a replacement for read-writer locking (among other things), but with
 very low-overhead readers that are immune to deadlock, priority inversion,
 and unbounded latency. RCU read-side critical sections are delimited
-by rcu_read_lock() and rcu_read_unlock(), which, in non-CONFIG_PREEMPT
+by rcu_read_lock() and rcu_read_unlock(), which, in non-CONFIG_PREEMPTION
 kernels, generate no code whatsoever.
 
 This means that RCU writers are unaware of the presence of concurrent
@@ -329,10 +329,10 @@ Answer: This cannot happen. The reason is that on_each_cpu() has its last
        to smp_call_function() and further to smp_call_function_on_cpu(),
        causing this latter to spin until the cross-CPU invocation of
        rcu_barrier_func() has completed. This by itself would prevent
-       a grace period from completing on non-CONFIG_PREEMPT kernels,
+       a grace period from completing on non-CONFIG_PREEMPTION kernels,
        since each CPU must undergo a context switch (or other quiescent
        state) before the grace period can complete. However, this is
-       of no use in CONFIG_PREEMPT kernels.
+       of no use in CONFIG_PREEMPTION kernels.
 
        Therefore, on_each_cpu() disables preemption across its call
        to smp_call_function() and also across the local call to
index c9ab6af4d3be9a00f4e57c956c6c109a989961c7..7148e9be08c34a4148808c8b742225be63a94115 100644 (file)
@@ -25,7 +25,7 @@ warnings:
 
 -      A CPU looping with bottom halves disabled.
 
--      For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
+-      For !CONFIG_PREEMPTION kernels, a CPU looping anywhere in the kernel
        without invoking schedule().  If the looping in the kernel is
        really expected and desirable behavior, you might need to add
        some calls to cond_resched().
@@ -44,7 +44,7 @@ warnings:
        result in the ``rcu_.*kthread starved for`` console-log message,
        which will include additional debugging information.
 
--      A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
+-      A CPU-bound real-time task in a CONFIG_PREEMPTION kernel, which might
        happen to preempt a low-priority task in the middle of an RCU
        read-side critical section.   This is especially damaging if
        that low-priority task is not permitted to run on any other CPU,
@@ -92,7 +92,9 @@ warnings:
        buggy timer hardware through bugs in the interrupt or exception
        path (whether hardware, firmware, or software) through bugs
        in Linux's timer subsystem through bugs in the scheduler, and,
-       yes, even including bugs in RCU itself.
+       yes, even including bugs in RCU itself.  It can also result in
+       the ``rcu_.*timer wakeup didn't happen for`` console-log message,
+       which will include additional debugging information.
 
 -      A bug in the RCU implementation.
 
@@ -292,6 +294,25 @@ kthread is waiting for a short timeout, the "state" precedes value of the
 task_struct ->state field, and the "cpu" indicates that the grace-period
 kthread last ran on CPU 5.
 
+If the relevant grace-period kthread does not wake from FQS wait in a
+reasonable time, then the following additional line is printed::
+
+       kthread timer wakeup didn't happen for 23804 jiffies! g7076 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402
+
+The "23804" indicates that kthread's timer expired more than 23 thousand
+jiffies ago.  The rest of the line has meaning similar to the kthread
+starvation case.
+
+Additionally, the following line is printed::
+
+       Possible timer handling issue on cpu=4 timer-softirq=11142
+
+Here "cpu" indicates that the grace-period kthread last ran on CPU 4,
+where it queued the fqs timer.  The number following the "timer-softirq"
+is the current ``TIMER_SOFTIRQ`` count on cpu 4.  If this value does not
+change on successive RCU CPU stall warnings, there is further reason to
+suspect a timer problem.
+
 
 Multiple Warnings From One Stall
 ================================
index 1a4723f48bd9c527ca2f9f65064d9fdff92c64eb..17e95ab2a201434a6a138beaccd31c8174344889 100644 (file)
@@ -683,7 +683,7 @@ Quick Quiz #1:
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 This section presents a "toy" RCU implementation that is based on
 "classic RCU".  It is also short on performance (but only for updates) and
-on features such as hotplug CPU and the ability to run in CONFIG_PREEMPT
+on features such as hotplug CPU and the ability to run in CONFIG_PREEMPTION
 kernels.  The definitions of rcu_dereference() and rcu_assign_pointer()
 are the same as those shown in the preceding section, so they are omitted.
 ::
@@ -739,7 +739,7 @@ Quick Quiz #2:
 Quick Quiz #3:
                If it is illegal to block in an RCU read-side
                critical section, what the heck do you do in
-               PREEMPT_RT, where normal spinlocks can block???
+               CONFIG_PREEMPT_RT, where normal spinlocks can block???
 
 :ref:`Answers to Quick Quiz <8_whatisRCU>`
 
@@ -1093,7 +1093,7 @@ Quick Quiz #2:
                overhead is **negative**.
 
 Answer:
-               Imagine a single-CPU system with a non-CONFIG_PREEMPT
+               Imagine a single-CPU system with a non-CONFIG_PREEMPTION
                kernel where a routing table is used by process-context
                code, but can be updated by irq-context code (for example,
                by an "ICMP REDIRECT" packet).  The usual way of handling
@@ -1120,10 +1120,10 @@ Answer:
 Quick Quiz #3:
                If it is illegal to block in an RCU read-side
                critical section, what the heck do you do in
-               PREEMPT_RT, where normal spinlocks can block???
+               CONFIG_PREEMPT_RT, where normal spinlocks can block???
 
 Answer:
-               Just as PREEMPT_RT permits preemption of spinlock
+               Just as CONFIG_PREEMPT_RT permits preemption of spinlock
                critical sections, it permits preemption of RCU
                read-side critical sections.  It also permits
                spinlocks blocking while in RCU read-side critical
index 9f8ac776ae4129236cedc135af0d257f1297d94a..b1d6cd58a04c7979ccb14aa0b9fffa67b85ce6c3 100644 (file)
                        value, meaning that RCU_SOFTIRQ is used by default.
                        Specify rcutree.use_softirq=0 to use rcuc kthreads.
 
+                       But note that CONFIG_PREEMPT_RT=y kernels disable
+                       this kernel boot parameter, forcibly setting it
+                       to zero.
+
        rcutree.rcu_fanout_exact= [KNL]
                        Disable autobalancing of the rcu_node combining
                        tree.  This is used by rcutorture, and might
                        Set wakeup interval for idle CPUs that have
                        RCU callbacks (RCU_FAST_NO_HZ=y).
 
-       rcutree.rcu_idle_lazy_gp_delay= [KNL]
-                       Set wakeup interval for idle CPUs that have
-                       only "lazy" RCU callbacks (RCU_FAST_NO_HZ=y).
-                       Lazy RCU callbacks are those which RCU can
-                       prove do nothing more than free memory.
-
        rcutree.rcu_kick_kthreads= [KNL]
                        Cause the grace-period kthread to get an extra
                        wake_up() if it sleeps three times longer than
                        only normal grace-period primitives.  No effect
                        on CONFIG_TINY_RCU kernels.
 
+                       But note that CONFIG_PREEMPT_RT=y kernels enables
+                       this kernel boot parameter, forcibly setting
+                       it to the value one, that is, converting any
+                       post-boot attempt at an expedited RCU grace
+                       period to instead use normal non-expedited
+                       grace-period processing.
+
        rcupdate.rcu_task_ipi_delay= [KNL]
                        Set time in jiffies during which RCU tasks will
                        avoid sending IPIs, starting with the beginning
        refscale.verbose= [KNL]
                        Enable additional printk() statements.
 
+       refscale.verbose_batched= [KNL]
+                       Batch the additional printk() statements.  If zero
+                       (the default) or negative, print everything.  Otherwise,
+                       print every Nth verbose statement, where N is the value
+                       specified.
+
        relax_domain_level=
                        [KNL, SMP] Set scheduler's default relax_domain_level.
                        See Documentation/admin-guide/cgroup-v1/cpusets.rst.
                        are running concurrently, especially on systems
                        with rotating-rust storage.
 
+       torture.verbose_sleep_frequency= [KNL]
+                       Specifies how many verbose printk()s should be
+                       emitted between each sleep.  The default of zero
+                       disables verbose-printk() sleeping.
+
+       torture.verbose_sleep_duration= [KNL]
+                       Duration of each verbose-printk() sleep in jiffies.
+
        tp720=          [HW,PS2]
 
        tpm_suspend_pcr=[HW,TPM]
index 89bdc92e75c339f93a97e87352da0e1f2f193f46..f2af4b4aa4e9ae480a69e24527531e8675083402 100644 (file)
@@ -901,7 +901,7 @@ static inline void hlist_add_before(struct hlist_node *n,
 }
 
 /**
- * hlist_add_behing - add a new entry after the one specified
+ * hlist_add_behind - add a new entry after the one specified
  * @n: new entry to be added
  * @prev: hlist node to add it after, which must be non-NULL
  */
index 5299b90a6c403e3098d5402a60cd9318cde7eb72..af7d050900e73eb0fbb6534ef568c451333ebdc3 100644 (file)
@@ -3169,5 +3169,7 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping,
 
 extern int sysctl_nr_trim_pages;
 
+void mem_dump_obj(void *object);
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_MM_H */
index e0ee52e2756dd9497892c5bbf7f19592780c4189..ebd8dcca4997d2134ceae47ab9d2b8e1764d0453 100644 (file)
@@ -33,6 +33,8 @@
 #define ULONG_CMP_GE(a, b)     (ULONG_MAX / 2 >= (a) - (b))
 #define ULONG_CMP_LT(a, b)     (ULONG_MAX / 2 < (a) - (b))
 #define ulong2long(a)          (*(long *)(&(a)))
+#define USHORT_CMP_GE(a, b)    (USHRT_MAX / 2 >= (unsigned short)((a) - (b)))
+#define USHORT_CMP_LT(a, b)    (USHRT_MAX / 2 < (unsigned short)((a) - (b)))
 
 /* Exported common interfaces */
 void call_rcu(struct rcu_head *head, rcu_callback_t func);
@@ -86,6 +88,12 @@ void rcu_sched_clock_irq(int user);
 void rcu_report_dead(unsigned int cpu);
 void rcutree_migrate_callbacks(int cpu);
 
+#ifdef CONFIG_TASKS_RCU_GENERIC
+void rcu_init_tasks_generic(void);
+#else
+static inline void rcu_init_tasks_generic(void) { }
+#endif
+
 #ifdef CONFIG_RCU_STALL_COMMON
 void rcu_sysrq_start(void);
 void rcu_sysrq_end(void);
@@ -844,19 +852,11 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  */
 #define __is_kvfree_rcu_offset(offset) ((offset) < 4096)
 
-/*
- * Helper macro for kfree_rcu() to prevent argument-expansion eyestrain.
- */
-#define __kvfree_rcu(head, offset) \
-       do { \
-               BUILD_BUG_ON(!__is_kvfree_rcu_offset(offset)); \
-               kvfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \
-       } while (0)
-
 /**
  * kfree_rcu() - kfree an object after a grace period.
- * @ptr:       pointer to kfree
- * @rhf:       the name of the struct rcu_head within the type of @ptr.
+ * @ptr: pointer to kfree for both single- and double-argument invocations.
+ * @rhf: the name of the struct rcu_head within the type of @ptr,
+ *       but only for double-argument invocations.
  *
  * Many rcu callbacks functions just call kfree() on the base structure.
  * These functions are trivial, but their size adds up, and furthermore
@@ -869,7 +869,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  * Because the functions are not allowed in the low-order 4096 bytes of
  * kernel virtual memory, offsets up to 4095 bytes can be accommodated.
  * If the offset is larger than 4095 bytes, a compile-time error will
- * be generated in __kvfree_rcu(). If this error is triggered, you can
+ * be generated in kvfree_rcu_arg_2(). If this error is triggered, you can
  * either fall back to use of call_rcu() or rearrange the structure to
  * position the rcu_head structure into the first 4096 bytes.
  *
@@ -879,13 +879,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  * The BUILD_BUG_ON check must not involve any function calls, hence the
  * checks are done in macros here.
  */
-#define kfree_rcu(ptr, rhf)                                            \
-do {                                                                   \
-       typeof (ptr) ___p = (ptr);                                      \
-                                                                       \
-       if (___p)                                                       \
-               __kvfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
-} while (0)
+#define kfree_rcu kvfree_rcu
 
 /**
  * kvfree_rcu() - kvfree an object after a grace period.
@@ -917,7 +911,17 @@ do {                                                                       \
        kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)
 
 #define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME
-#define kvfree_rcu_arg_2(ptr, rhf) kfree_rcu(ptr, rhf)
+#define kvfree_rcu_arg_2(ptr, rhf)                                     \
+do {                                                                   \
+       typeof (ptr) ___p = (ptr);                                      \
+                                                                       \
+       if (___p) {                                                                     \
+               BUILD_BUG_ON(!__is_kvfree_rcu_offset(offsetof(typeof(*(ptr)), rhf)));   \
+               kvfree_call_rcu(&((___p)->rhf), (rcu_callback_t)(unsigned long)         \
+                       (offsetof(typeof(*(ptr)), rhf)));                               \
+       }                                                                               \
+} while (0)
+
 #define kvfree_rcu_arg_1(ptr)                                  \
 do {                                                           \
        typeof(ptr) ___p = (ptr);                               \
index be4ba5867ac5fdd8d41dd381dc534531506ad41d..7ae60407676703911c32404b8b1225e23a78410d 100644 (file)
@@ -186,6 +186,8 @@ void kfree(const void *);
 void kfree_sensitive(const void *);
 size_t __ksize(const void *);
 size_t ksize(const void *);
+bool kmem_valid_obj(void *object);
+void kmem_dump_obj(void *object);
 
 #ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n, struct page *page,
index e432cc92c73de7d1ae73aa5b69486e8311547d82..a0895bbf71ce01b7ea7a202a99c365dc609428ac 100644 (file)
@@ -60,6 +60,9 @@ void cleanup_srcu_struct(struct srcu_struct *ssp);
 int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
 void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp);
 void synchronize_srcu(struct srcu_struct *ssp);
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp);
+unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp);
+bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie);
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
index 5a5a1941ca156d36270b37095bf7ef9f7c2247f1..0e0cf4d6a72a0ea6bfa22d86b2fdf91d7d314c6e 100644 (file)
@@ -15,7 +15,8 @@
 
 struct srcu_struct {
        short srcu_lock_nesting[2];     /* srcu_read_lock() nesting depth. */
-       short srcu_idx;                 /* Current reader array element. */
+       unsigned short srcu_idx;        /* Current reader array element in bit 0x2. */
+       unsigned short srcu_idx_max;    /* Furthest future srcu_idx request. */
        u8 srcu_gp_running;             /* GP workqueue running? */
        u8 srcu_gp_waiting;             /* GP waiting for readers? */
        struct swait_queue_head srcu_wq;
@@ -59,7 +60,7 @@ static inline int __srcu_read_lock(struct srcu_struct *ssp)
 {
        int idx;
 
-       idx = READ_ONCE(ssp->srcu_idx);
+       idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
        WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1);
        return idx;
 }
@@ -80,7 +81,7 @@ static inline void srcu_torture_stats_print(struct srcu_struct *ssp,
 {
        int idx;
 
-       idx = READ_ONCE(ssp->srcu_idx) & 0x1;
+       idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1;
        pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd)\n",
                 tt, tf, idx,
                 READ_ONCE(ssp->srcu_lock_nesting[!idx]),
index 7f65bd1dd30793ffe535ea697643e4e41b73171e..0910c5803f35a40c0ef88c4649582dfe20fd675b 100644 (file)
 #define TOROUT_STRING(s) \
        pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s)
 #define VERBOSE_TOROUT_STRING(s) \
-       do { if (verbose) pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s); } while (0)
+do {                                                                           \
+       if (verbose) {                                                          \
+               verbose_torout_sleep();                                         \
+               pr_alert("%s" TORTURE_FLAG " %s\n", torture_type, s);           \
+       }                                                                       \
+} while (0)
 #define VERBOSE_TOROUT_ERRSTRING(s) \
-       do { if (verbose) pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s); } while (0)
+do {                                                                           \
+       if (verbose) {                                                          \
+               verbose_torout_sleep();                                         \
+               pr_alert("%s" TORTURE_FLAG "!!! %s\n", torture_type, s);        \
+       }                                                                       \
+} while (0)
+void verbose_torout_sleep(void);
 
 /* Definitions for online/offline exerciser. */
+#ifdef CONFIG_HOTPLUG_CPU
+int torture_num_online_cpus(void);
+#else /* #ifdef CONFIG_HOTPLUG_CPU */
+static inline int torture_num_online_cpus(void) { return 1; }
+#endif /* #else #ifdef CONFIG_HOTPLUG_CPU */
 typedef void torture_ofl_func(void);
 bool torture_offline(int cpu, long *n_onl_attempts, long *n_onl_successes,
                     unsigned long *sum_offl, int *min_onl, int *max_onl);
@@ -61,6 +77,13 @@ static inline void torture_random_init(struct torture_random_state *trsp)
        trsp->trs_count = 0;
 }
 
+/* Definitions for high-resolution-timer sleeps. */
+int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp);
+int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp);
+int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp);
+int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp);
+int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp);
+
 /* Task shuffler, which causes CPUs to occasionally go idle. */
 void torture_shuffle_task_register(struct task_struct *tp);
 int torture_shuffle_init(long shuffint);
index 80c0181c411dff2a2f165d8e26e774841f80f9a6..c18f4751a704ab6985ef63f5b27cceb3422eb6ed 100644 (file)
@@ -246,4 +246,10 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
 int register_vmap_purge_notifier(struct notifier_block *nb);
 int unregister_vmap_purge_notifier(struct notifier_block *nb);
 
+#ifdef CONFIG_MMU
+bool vmalloc_dump_obj(void *object);
+#else
+static inline bool vmalloc_dump_obj(void *object) { return false; }
+#endif
+
 #endif /* _LINUX_VMALLOC_H */
index 6feee7f11eafca4de9fb4dd2101edeb4d1125bef..421640fca3759f551b9d229317c3e3f513585752 100644 (file)
@@ -1518,6 +1518,7 @@ static noinline void __init kernel_init_freeable(void)
 
        init_mm_internals();
 
+       rcu_init_tasks_generic();
        do_pre_smp_initcalls();
        lockup_detector_init();
 
index fd838cea393498e05bbd96052458a5ac9cca813e..0ab94e1f1276a78687efc1454faeb9a5aef28942 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/moduleparam.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <linux/percpu-rwsem.h>
 #include <linux/torture.h>
 #include <linux/reboot.h>
 
index cdc57b4f6d48a966d083ec2cb5269fd1b2f5da84..3128b7cf8e1fd11da74f3aa5b78e9031eaa4e69a 100644 (file)
@@ -95,6 +95,7 @@ config TASKS_RUDE_RCU
 
 config TASKS_TRACE_RCU
        def_bool 0
+       select IRQ_WORK
        help
          This option enables a task-based RCU implementation that uses
          explicit rcu_read_lock_trace() read-side markers, and allows
@@ -188,8 +189,8 @@ config RCU_FAST_NO_HZ
 
 config RCU_BOOST
        bool "Enable RCU priority boosting"
-       depends on RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT
-       default n
+       depends on (RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT) || PREEMPT_RT
+       default y if PREEMPT_RT
        help
          This option boosts the priority of preempted RCU readers that
          block the current preemptible RCU grace period for too long.
index 59ef1ae6dc37c188105049606f2e3302c22fb895..bf0827d4b6593a3b3337125d82acba87cca1ad15 100644 (file)
@@ -378,7 +378,11 @@ do {                                                                       \
        smp_mb__after_unlock_lock();                                    \
 } while (0)
 
-#define raw_spin_unlock_rcu_node(p) raw_spin_unlock(&ACCESS_PRIVATE(p, lock))
+#define raw_spin_unlock_rcu_node(p)                                    \
+do {                                                                   \
+       lockdep_assert_irqs_disabled();                                 \
+       raw_spin_unlock(&ACCESS_PRIVATE(p, lock));                      \
+} while (0)
 
 #define raw_spin_lock_irq_rcu_node(p)                                  \
 do {                                                                   \
@@ -387,7 +391,10 @@ do {                                                                       \
 } while (0)
 
 #define raw_spin_unlock_irq_rcu_node(p)                                        \
-       raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock))
+do {                                                                   \
+       lockdep_assert_irqs_disabled();                                 \
+       raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock));                  \
+} while (0)
 
 #define raw_spin_lock_irqsave_rcu_node(p, flags)                       \
 do {                                                                   \
@@ -396,7 +403,10 @@ do {                                                                       \
 } while (0)
 
 #define raw_spin_unlock_irqrestore_rcu_node(p, flags)                  \
-       raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags)
+do {                                                                   \
+       lockdep_assert_irqs_disabled();                                 \
+       raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags);    \
+} while (0)
 
 #define raw_spin_trylock_rcu_node(p)                                   \
 ({                                                                     \
index b9dd63c166b9b240f4043ab3889f3f4f0b1477d1..99657ffa66887aba18dcead4ecb6209e943c7013 100644 (file)
@@ -85,6 +85,7 @@ torture_param(bool, gp_cond, false, "Use conditional/async GP wait primitives");
 torture_param(bool, gp_exp, false, "Use expedited GP wait primitives");
 torture_param(bool, gp_normal, false,
             "Use normal (non-expedited) GP wait primitives");
+torture_param(bool, gp_poll, false, "Use polling GP wait primitives");
 torture_param(bool, gp_sync, false, "Use synchronous GP wait primitives");
 torture_param(int, irqreader, 1, "Allow RCU readers from irq handlers");
 torture_param(int, leakpointer, 0, "Leak pointer dereferences from readers");
@@ -146,11 +147,22 @@ static struct task_struct *read_exit_task;
 
 #define RCU_TORTURE_PIPE_LEN 10
 
+// Mailbox-like structure to check RCU global memory ordering.
+struct rcu_torture_reader_check {
+       unsigned long rtc_myloops;
+       int rtc_chkrdr;
+       unsigned long rtc_chkloops;
+       int rtc_ready;
+       struct rcu_torture_reader_check *rtc_assigner;
+} ____cacheline_internodealigned_in_smp;
+
+// Update-side data structure used to check RCU readers.
 struct rcu_torture {
        struct rcu_head rtort_rcu;
        int rtort_pipe_count;
        struct list_head rtort_free;
        int rtort_mbtest;
+       struct rcu_torture_reader_check *rtort_chkp;
 };
 
 static LIST_HEAD(rcu_torture_freelist);
@@ -161,10 +173,13 @@ static DEFINE_SPINLOCK(rcu_torture_lock);
 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count);
 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch);
 static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
+static struct rcu_torture_reader_check *rcu_torture_reader_mbchk;
 static atomic_t n_rcu_torture_alloc;
 static atomic_t n_rcu_torture_alloc_fail;
 static atomic_t n_rcu_torture_free;
 static atomic_t n_rcu_torture_mberror;
+static atomic_t n_rcu_torture_mbchk_fail;
+static atomic_t n_rcu_torture_mbchk_tries;
 static atomic_t n_rcu_torture_error;
 static long n_rcu_torture_barrier_error;
 static long n_rcu_torture_boost_ktrerror;
@@ -189,9 +204,11 @@ static int rcu_torture_writer_state;
 #define RTWS_EXP_SYNC          4
 #define RTWS_COND_GET          5
 #define RTWS_COND_SYNC         6
-#define RTWS_SYNC              7
-#define RTWS_STUTTER           8
-#define RTWS_STOPPING          9
+#define RTWS_POLL_GET          7
+#define RTWS_POLL_WAIT         8
+#define RTWS_SYNC              9
+#define RTWS_STUTTER           10
+#define RTWS_STOPPING          11
 static const char * const rcu_torture_writer_state_names[] = {
        "RTWS_FIXED_DELAY",
        "RTWS_DELAY",
@@ -200,6 +217,8 @@ static const char * const rcu_torture_writer_state_names[] = {
        "RTWS_EXP_SYNC",
        "RTWS_COND_GET",
        "RTWS_COND_SYNC",
+       "RTWS_POLL_GET",
+       "RTWS_POLL_WAIT",
        "RTWS_SYNC",
        "RTWS_STUTTER",
        "RTWS_STOPPING",
@@ -317,7 +336,9 @@ struct rcu_torture_ops {
        void (*deferred_free)(struct rcu_torture *p);
        void (*sync)(void);
        void (*exp_sync)(void);
-       unsigned long (*get_state)(void);
+       unsigned long (*get_gp_state)(void);
+       unsigned long (*start_gp_poll)(void);
+       bool (*poll_gp_state)(unsigned long oldstate);
        void (*cond_sync)(unsigned long oldstate);
        call_rcu_func_t call;
        void (*cb_barrier)(void);
@@ -392,7 +413,12 @@ static bool
 rcu_torture_pipe_update_one(struct rcu_torture *rp)
 {
        int i;
+       struct rcu_torture_reader_check *rtrcp = READ_ONCE(rp->rtort_chkp);
 
+       if (rtrcp) {
+               WRITE_ONCE(rp->rtort_chkp, NULL);
+               smp_store_release(&rtrcp->rtc_ready, 1); // Pair with smp_load_acquire().
+       }
        i = READ_ONCE(rp->rtort_pipe_count);
        if (i > RCU_TORTURE_PIPE_LEN)
                i = RCU_TORTURE_PIPE_LEN;
@@ -467,7 +493,7 @@ static struct rcu_torture_ops rcu_ops = {
        .deferred_free  = rcu_torture_deferred_free,
        .sync           = synchronize_rcu,
        .exp_sync       = synchronize_rcu_expedited,
-       .get_state      = get_state_synchronize_rcu,
+       .get_gp_state   = get_state_synchronize_rcu,
        .cond_sync      = cond_synchronize_rcu,
        .call           = call_rcu,
        .cb_barrier     = rcu_barrier,
@@ -576,6 +602,21 @@ static void srcu_torture_synchronize(void)
        synchronize_srcu(srcu_ctlp);
 }
 
+static unsigned long srcu_torture_get_gp_state(void)
+{
+       return get_state_synchronize_srcu(srcu_ctlp);
+}
+
+static unsigned long srcu_torture_start_gp_poll(void)
+{
+       return start_poll_synchronize_srcu(srcu_ctlp);
+}
+
+static bool srcu_torture_poll_gp_state(unsigned long oldstate)
+{
+       return poll_state_synchronize_srcu(srcu_ctlp, oldstate);
+}
+
 static void srcu_torture_call(struct rcu_head *head,
                              rcu_callback_t func)
 {
@@ -607,6 +648,9 @@ static struct rcu_torture_ops srcu_ops = {
        .deferred_free  = srcu_torture_deferred_free,
        .sync           = srcu_torture_synchronize,
        .exp_sync       = srcu_torture_synchronize_expedited,
+       .get_gp_state   = srcu_torture_get_gp_state,
+       .start_gp_poll  = srcu_torture_start_gp_poll,
+       .poll_gp_state  = srcu_torture_poll_gp_state,
        .call           = srcu_torture_call,
        .cb_barrier     = srcu_torture_barrier,
        .stats          = srcu_torture_stats,
@@ -1024,42 +1068,26 @@ rcu_torture_fqs(void *arg)
        return 0;
 }
 
+// Used by writers to randomly choose from the available grace-period
+// primitives.  The only purpose of the initialization is to size the array.
+static int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC, RTWS_COND_GET, RTWS_POLL_GET, RTWS_SYNC };
+static int nsynctypes;
+
 /*
- * RCU torture writer kthread.  Repeatedly substitutes a new structure
- * for that pointed to by rcu_torture_current, freeing the old structure
- * after a series of grace periods (the "pipeline").
+ * Determine which grace-period primitives are available.
  */
-static int
-rcu_torture_writer(void *arg)
+static void rcu_torture_write_types(void)
 {
-       bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
-       int expediting = 0;
-       unsigned long gp_snap;
        bool gp_cond1 = gp_cond, gp_exp1 = gp_exp, gp_normal1 = gp_normal;
-       bool gp_sync1 = gp_sync;
-       int i;
-       int oldnice = task_nice(current);
-       struct rcu_torture *rp;
-       struct rcu_torture *old_rp;
-       static DEFINE_TORTURE_RANDOM(rand);
-       bool stutter_waited;
-       int synctype[] = { RTWS_DEF_FREE, RTWS_EXP_SYNC,
-                          RTWS_COND_GET, RTWS_SYNC };
-       int nsynctypes = 0;
-
-       VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
-       if (!can_expedite)
-               pr_alert("%s" TORTURE_FLAG
-                        " GP expediting controlled from boot/sysfs for %s.\n",
-                        torture_type, cur_ops->name);
+       bool gp_poll1 = gp_poll, gp_sync1 = gp_sync;
 
        /* Initialize synctype[] array.  If none set, take default. */
-       if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_sync1)
-               gp_cond1 = gp_exp1 = gp_normal1 = gp_sync1 = true;
-       if (gp_cond1 && cur_ops->get_state && cur_ops->cond_sync) {
+       if (!gp_cond1 && !gp_exp1 && !gp_normal1 && !gp_poll1 && !gp_sync1)
+               gp_cond1 = gp_exp1 = gp_normal1 = gp_poll1 = gp_sync1 = true;
+       if (gp_cond1 && cur_ops->get_gp_state && cur_ops->cond_sync) {
                synctype[nsynctypes++] = RTWS_COND_GET;
                pr_info("%s: Testing conditional GPs.\n", __func__);
-       } else if (gp_cond && (!cur_ops->get_state || !cur_ops->cond_sync)) {
+       } else if (gp_cond && (!cur_ops->get_gp_state || !cur_ops->cond_sync)) {
                pr_alert("%s: gp_cond without primitives.\n", __func__);
        }
        if (gp_exp1 && cur_ops->exp_sync) {
@@ -1074,12 +1102,46 @@ rcu_torture_writer(void *arg)
        } else if (gp_normal && !cur_ops->deferred_free) {
                pr_alert("%s: gp_normal without primitives.\n", __func__);
        }
+       if (gp_poll1 && cur_ops->start_gp_poll && cur_ops->poll_gp_state) {
+               synctype[nsynctypes++] = RTWS_POLL_GET;
+               pr_info("%s: Testing polling GPs.\n", __func__);
+       } else if (gp_poll && (!cur_ops->start_gp_poll || !cur_ops->poll_gp_state)) {
+               pr_alert("%s: gp_poll without primitives.\n", __func__);
+       }
        if (gp_sync1 && cur_ops->sync) {
                synctype[nsynctypes++] = RTWS_SYNC;
                pr_info("%s: Testing normal GPs.\n", __func__);
        } else if (gp_sync && !cur_ops->sync) {
                pr_alert("%s: gp_sync without primitives.\n", __func__);
        }
+}
+
+/*
+ * RCU torture writer kthread.  Repeatedly substitutes a new structure
+ * for that pointed to by rcu_torture_current, freeing the old structure
+ * after a series of grace periods (the "pipeline").
+ */
+static int
+rcu_torture_writer(void *arg)
+{
+       bool boot_ended;
+       bool can_expedite = !rcu_gp_is_expedited() && !rcu_gp_is_normal();
+       unsigned long cookie;
+       int expediting = 0;
+       unsigned long gp_snap;
+       int i;
+       int idx;
+       int oldnice = task_nice(current);
+       struct rcu_torture *rp;
+       struct rcu_torture *old_rp;
+       static DEFINE_TORTURE_RANDOM(rand);
+       bool stutter_waited;
+
+       VERBOSE_TOROUT_STRING("rcu_torture_writer task started");
+       if (!can_expedite)
+               pr_alert("%s" TORTURE_FLAG
+                        " GP expediting controlled from boot/sysfs for %s.\n",
+                        torture_type, cur_ops->name);
        if (WARN_ONCE(nsynctypes == 0,
                      "rcu_torture_writer: No update-side primitives.\n")) {
                /*
@@ -1093,7 +1155,7 @@ rcu_torture_writer(void *arg)
 
        do {
                rcu_torture_writer_state = RTWS_FIXED_DELAY;
-               schedule_timeout_uninterruptible(1);
+               torture_hrtimeout_us(500, 1000, &rand);
                rp = rcu_torture_alloc();
                if (rp == NULL)
                        continue;
@@ -1113,6 +1175,18 @@ rcu_torture_writer(void *arg)
                        atomic_inc(&rcu_torture_wcount[i]);
                        WRITE_ONCE(old_rp->rtort_pipe_count,
                                   old_rp->rtort_pipe_count + 1);
+                       if (cur_ops->get_gp_state && cur_ops->poll_gp_state) {
+                               idx = cur_ops->readlock();
+                               cookie = cur_ops->get_gp_state();
+                               WARN_ONCE(rcu_torture_writer_state != RTWS_DEF_FREE &&
+                                         cur_ops->poll_gp_state(cookie),
+                                         "%s: Cookie check 1 failed %s(%d) %lu->%lu\n",
+                                         __func__,
+                                         rcu_torture_writer_state_getname(),
+                                         rcu_torture_writer_state,
+                                         cookie, cur_ops->get_gp_state());
+                               cur_ops->readunlock(idx);
+                       }
                        switch (synctype[torture_random(&rand) % nsynctypes]) {
                        case RTWS_DEF_FREE:
                                rcu_torture_writer_state = RTWS_DEF_FREE;
@@ -1125,15 +1199,21 @@ rcu_torture_writer(void *arg)
                                break;
                        case RTWS_COND_GET:
                                rcu_torture_writer_state = RTWS_COND_GET;
-                               gp_snap = cur_ops->get_state();
-                               i = torture_random(&rand) % 16;
-                               if (i != 0)
-                                       schedule_timeout_interruptible(i);
-                               udelay(torture_random(&rand) % 1000);
+                               gp_snap = cur_ops->get_gp_state();
+                               torture_hrtimeout_jiffies(torture_random(&rand) % 16, &rand);
                                rcu_torture_writer_state = RTWS_COND_SYNC;
                                cur_ops->cond_sync(gp_snap);
                                rcu_torture_pipe_update(old_rp);
                                break;
+                       case RTWS_POLL_GET:
+                               rcu_torture_writer_state = RTWS_POLL_GET;
+                               gp_snap = cur_ops->start_gp_poll();
+                               rcu_torture_writer_state = RTWS_POLL_WAIT;
+                               while (!cur_ops->poll_gp_state(gp_snap))
+                                       torture_hrtimeout_jiffies(torture_random(&rand) % 16,
+                                                                 &rand);
+                               rcu_torture_pipe_update(old_rp);
+                               break;
                        case RTWS_SYNC:
                                rcu_torture_writer_state = RTWS_SYNC;
                                cur_ops->sync();
@@ -1143,6 +1223,14 @@ rcu_torture_writer(void *arg)
                                WARN_ON_ONCE(1);
                                break;
                        }
+                       if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
+                               WARN_ONCE(rcu_torture_writer_state != RTWS_DEF_FREE &&
+                                         !cur_ops->poll_gp_state(cookie),
+                                         "%s: Cookie check 2 failed %s(%d) %lu->%lu\n",
+                                         __func__,
+                                         rcu_torture_writer_state_getname(),
+                                         rcu_torture_writer_state,
+                                         cookie, cur_ops->get_gp_state());
                }
                WRITE_ONCE(rcu_torture_current_version,
                           rcu_torture_current_version + 1);
@@ -1161,12 +1249,13 @@ rcu_torture_writer(void *arg)
                                       !rcu_gp_is_normal();
                }
                rcu_torture_writer_state = RTWS_STUTTER;
+               boot_ended = rcu_inkernel_boot_has_ended();
                stutter_waited = stutter_wait("rcu_torture_writer");
                if (stutter_waited &&
                    !READ_ONCE(rcu_fwd_cb_nodelay) &&
                    !cur_ops->slow_gps &&
                    !torture_must_stop() &&
-                   rcu_inkernel_boot_has_ended())
+                   boot_ended)
                        for (i = 0; i < ARRAY_SIZE(rcu_tortures); i++)
                                if (list_empty(&rcu_tortures[i].rtort_free) &&
                                    rcu_access_pointer(rcu_torture_current) !=
@@ -1200,26 +1289,43 @@ rcu_torture_writer(void *arg)
 static int
 rcu_torture_fakewriter(void *arg)
 {
+       unsigned long gp_snap;
        DEFINE_TORTURE_RANDOM(rand);
 
        VERBOSE_TOROUT_STRING("rcu_torture_fakewriter task started");
        set_user_nice(current, MAX_NICE);
 
        do {
-               schedule_timeout_uninterruptible(1 + torture_random(&rand)%10);
-               udelay(torture_random(&rand) & 0x3ff);
+               torture_hrtimeout_jiffies(torture_random(&rand) % 10, &rand);
                if (cur_ops->cb_barrier != NULL &&
                    torture_random(&rand) % (nfakewriters * 8) == 0) {
                        cur_ops->cb_barrier();
-               } else if (gp_normal == gp_exp) {
-                       if (cur_ops->sync && torture_random(&rand) & 0x80)
-                               cur_ops->sync();
-                       else if (cur_ops->exp_sync)
+               } else {
+                       switch (synctype[torture_random(&rand) % nsynctypes]) {
+                       case RTWS_DEF_FREE:
+                               break;
+                       case RTWS_EXP_SYNC:
                                cur_ops->exp_sync();
-               } else if (gp_normal && cur_ops->sync) {
-                       cur_ops->sync();
-               } else if (cur_ops->exp_sync) {
-                       cur_ops->exp_sync();
+                               break;
+                       case RTWS_COND_GET:
+                               gp_snap = cur_ops->get_gp_state();
+                               torture_hrtimeout_jiffies(torture_random(&rand) % 16, &rand);
+                               cur_ops->cond_sync(gp_snap);
+                               break;
+                       case RTWS_POLL_GET:
+                               gp_snap = cur_ops->start_gp_poll();
+                               while (!cur_ops->poll_gp_state(gp_snap)) {
+                                       torture_hrtimeout_jiffies(torture_random(&rand) % 16,
+                                                                 &rand);
+                               }
+                               break;
+                       case RTWS_SYNC:
+                               cur_ops->sync();
+                               break;
+                       default:
+                               WARN_ON_ONCE(1);
+                               break;
+                       }
                }
                stutter_wait("rcu_torture_fakewriter");
        } while (!torture_must_stop());
@@ -1233,6 +1339,62 @@ static void rcu_torture_timer_cb(struct rcu_head *rhp)
        kfree(rhp);
 }
 
+// Set up and carry out testing of RCU's global memory ordering
+static void rcu_torture_reader_do_mbchk(long myid, struct rcu_torture *rtp,
+                                       struct torture_random_state *trsp)
+{
+       unsigned long loops;
+       int noc = torture_num_online_cpus();
+       int rdrchked;
+       int rdrchker;
+       struct rcu_torture_reader_check *rtrcp; // Me.
+       struct rcu_torture_reader_check *rtrcp_assigner; // Assigned us to do checking.
+       struct rcu_torture_reader_check *rtrcp_chked; // Reader being checked.
+       struct rcu_torture_reader_check *rtrcp_chker; // Reader doing checking when not me.
+
+       if (myid < 0)
+               return; // Don't try this from timer handlers.
+
+       // Increment my counter.
+       rtrcp = &rcu_torture_reader_mbchk[myid];
+       WRITE_ONCE(rtrcp->rtc_myloops, rtrcp->rtc_myloops + 1);
+
+       // Attempt to assign someone else some checking work.
+       rdrchked = torture_random(trsp) % nrealreaders;
+       rtrcp_chked = &rcu_torture_reader_mbchk[rdrchked];
+       rdrchker = torture_random(trsp) % nrealreaders;
+       rtrcp_chker = &rcu_torture_reader_mbchk[rdrchker];
+       if (rdrchked != myid && rdrchked != rdrchker && noc >= rdrchked && noc >= rdrchker &&
+           smp_load_acquire(&rtrcp->rtc_chkrdr) < 0 && // Pairs with smp_store_release below.
+           !READ_ONCE(rtp->rtort_chkp) &&
+           !smp_load_acquire(&rtrcp_chker->rtc_assigner)) { // Pairs with smp_store_release below.
+               rtrcp->rtc_chkloops = READ_ONCE(rtrcp_chked->rtc_myloops);
+               WARN_ON_ONCE(rtrcp->rtc_chkrdr >= 0);
+               rtrcp->rtc_chkrdr = rdrchked;
+               WARN_ON_ONCE(rtrcp->rtc_ready); // This gets set after the grace period ends.
+               if (cmpxchg_relaxed(&rtrcp_chker->rtc_assigner, NULL, rtrcp) ||
+                   cmpxchg_relaxed(&rtp->rtort_chkp, NULL, rtrcp))
+                       (void)cmpxchg_relaxed(&rtrcp_chker->rtc_assigner, rtrcp, NULL); // Back out.
+       }
+
+       // If assigned some completed work, do it!
+       rtrcp_assigner = READ_ONCE(rtrcp->rtc_assigner);
+       if (!rtrcp_assigner || !smp_load_acquire(&rtrcp_assigner->rtc_ready))
+               return; // No work or work not yet ready.
+       rdrchked = rtrcp_assigner->rtc_chkrdr;
+       if (WARN_ON_ONCE(rdrchked < 0))
+               return;
+       rtrcp_chked = &rcu_torture_reader_mbchk[rdrchked];
+       loops = READ_ONCE(rtrcp_chked->rtc_myloops);
+       atomic_inc(&n_rcu_torture_mbchk_tries);
+       if (ULONG_CMP_LT(loops, rtrcp_assigner->rtc_chkloops))
+               atomic_inc(&n_rcu_torture_mbchk_fail);
+       rtrcp_assigner->rtc_chkloops = loops + ULONG_MAX / 2;
+       rtrcp_assigner->rtc_ready = 0;
+       smp_store_release(&rtrcp->rtc_assigner, NULL); // Someone else can assign us work.
+       smp_store_release(&rtrcp_assigner->rtc_chkrdr, -1); // Assigner can again assign.
+}
+
 /*
  * Do one extension of an RCU read-side critical section using the
  * current reader state in readstate (set to zero for initial entry
@@ -1368,8 +1530,9 @@ rcutorture_loop_extend(int *readstate, struct torture_random_state *trsp,
  * no data to read.  Can be invoked both from process context and
  * from a timer handler.
  */
-static bool rcu_torture_one_read(struct torture_random_state *trsp)
+static bool rcu_torture_one_read(struct torture_random_state *trsp, long myid)
 {
+       unsigned long cookie;
        int i;
        unsigned long started;
        unsigned long completed;
@@ -1385,6 +1548,8 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp)
        WARN_ON_ONCE(!rcu_is_watching());
        newstate = rcutorture_extend_mask(readstate, trsp);
        rcutorture_one_extend(&readstate, newstate, trsp, rtrsp++);
+       if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
+               cookie = cur_ops->get_gp_state();
        started = cur_ops->get_gp_seq();
        ts = rcu_trace_clock_local();
        p = rcu_dereference_check(rcu_torture_current,
@@ -1400,6 +1565,7 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp)
        }
        if (p->rtort_mbtest == 0)
                atomic_inc(&n_rcu_torture_mberror);
+       rcu_torture_reader_do_mbchk(myid, p, trsp);
        rtrsp = rcutorture_loop_extend(&readstate, trsp, rtrsp);
        preempt_disable();
        pipe_count = READ_ONCE(p->rtort_pipe_count);
@@ -1421,6 +1587,13 @@ static bool rcu_torture_one_read(struct torture_random_state *trsp)
        }
        __this_cpu_inc(rcu_torture_batch[completed]);
        preempt_enable();
+       if (cur_ops->get_gp_state && cur_ops->poll_gp_state)
+               WARN_ONCE(cur_ops->poll_gp_state(cookie),
+                         "%s: Cookie check 3 failed %s(%d) %lu->%lu\n",
+                         __func__,
+                         rcu_torture_writer_state_getname(),
+                         rcu_torture_writer_state,
+                         cookie, cur_ops->get_gp_state());
        rcutorture_one_extend(&readstate, 0, trsp, rtrsp);
        WARN_ON_ONCE(readstate & RCUTORTURE_RDR_MASK);
        // This next splat is expected behavior if leakpointer, especially
@@ -1449,7 +1622,7 @@ static DEFINE_TORTURE_RANDOM_PERCPU(rcu_torture_timer_rand);
 static void rcu_torture_timer(struct timer_list *unused)
 {
        atomic_long_inc(&n_rcu_torture_timers);
-       (void)rcu_torture_one_read(this_cpu_ptr(&rcu_torture_timer_rand));
+       (void)rcu_torture_one_read(this_cpu_ptr(&rcu_torture_timer_rand), -1);
 
        /* Test call_rcu() invocation from interrupt handler. */
        if (cur_ops->call) {
@@ -1485,13 +1658,13 @@ rcu_torture_reader(void *arg)
                        if (!timer_pending(&t))
                                mod_timer(&t, jiffies + 1);
                }
-               if (!rcu_torture_one_read(&rand) && !torture_must_stop())
+               if (!rcu_torture_one_read(&rand, myid) && !torture_must_stop())
                        schedule_timeout_interruptible(HZ);
                if (time_after(jiffies, lastsleep) && !torture_must_stop()) {
-                       schedule_timeout_interruptible(1);
+                       torture_hrtimeout_us(500, 1000, &rand);
                        lastsleep = jiffies + 10;
                }
-               while (num_online_cpus() < mynumonline && !torture_must_stop())
+               while (torture_num_online_cpus() < mynumonline && !torture_must_stop())
                        schedule_timeout_interruptible(HZ / 5);
                stutter_wait("rcu_torture_reader");
        } while (!torture_must_stop());
@@ -1592,8 +1765,9 @@ rcu_torture_stats_print(void)
                atomic_read(&n_rcu_torture_alloc),
                atomic_read(&n_rcu_torture_alloc_fail),
                atomic_read(&n_rcu_torture_free));
-       pr_cont("rtmbe: %d rtbe: %ld rtbke: %ld rtbre: %ld ",
+       pr_cont("rtmbe: %d rtmbkf: %d/%d rtbe: %ld rtbke: %ld rtbre: %ld ",
                atomic_read(&n_rcu_torture_mberror),
+               atomic_read(&n_rcu_torture_mbchk_fail), atomic_read(&n_rcu_torture_mbchk_tries),
                n_rcu_torture_barrier_error,
                n_rcu_torture_boost_ktrerror,
                n_rcu_torture_boost_rterror);
@@ -1612,12 +1786,14 @@ rcu_torture_stats_print(void)
 
        pr_alert("%s%s ", torture_type, TORTURE_FLAG);
        if (atomic_read(&n_rcu_torture_mberror) ||
+           atomic_read(&n_rcu_torture_mbchk_fail) ||
            n_rcu_torture_barrier_error || n_rcu_torture_boost_ktrerror ||
            n_rcu_torture_boost_rterror || n_rcu_torture_boost_failure ||
            i > 1) {
                pr_cont("%s", "!!! ");
                atomic_inc(&n_rcu_torture_error);
                WARN_ON_ONCE(atomic_read(&n_rcu_torture_mberror));
+               WARN_ON_ONCE(atomic_read(&n_rcu_torture_mbchk_fail));
                WARN_ON_ONCE(n_rcu_torture_barrier_error);  // rcu_barrier()
                WARN_ON_ONCE(n_rcu_torture_boost_ktrerror); // no boost kthread
                WARN_ON_ONCE(n_rcu_torture_boost_rterror); // can't set RT prio
@@ -2449,7 +2625,7 @@ static int rcu_torture_read_exit_child(void *trsp_in)
        // Minimize time between reading and exiting.
        while (!kthread_should_stop())
                schedule_timeout_uninterruptible(1);
-       (void)rcu_torture_one_read(trsp);
+       (void)rcu_torture_one_read(trsp, -1);
        return 0;
 }
 
@@ -2571,6 +2747,8 @@ rcu_torture_cleanup(void)
                kfree(reader_tasks);
                reader_tasks = NULL;
        }
+       kfree(rcu_torture_reader_mbchk);
+       rcu_torture_reader_mbchk = NULL;
 
        if (fakewriter_tasks) {
                for (i = 0; i < nfakewriters; i++)
@@ -2668,6 +2846,7 @@ static void rcu_test_debug_objects(void)
 #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
        struct rcu_head rh1;
        struct rcu_head rh2;
+       struct rcu_head *rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);
 
        init_rcu_head_on_stack(&rh1);
        init_rcu_head_on_stack(&rh2);
@@ -2680,6 +2859,10 @@ static void rcu_test_debug_objects(void)
        local_irq_disable(); /* Make it harder to start a new grace period. */
        call_rcu(&rh2, rcu_torture_leak_cb);
        call_rcu(&rh2, rcu_torture_err_cb); /* Duplicate callback. */
+       if (rhp) {
+               call_rcu(rhp, rcu_torture_leak_cb);
+               call_rcu(rhp, rcu_torture_err_cb); /* Another duplicate callback. */
+       }
        local_irq_enable();
        rcu_read_unlock();
        preempt_enable();
@@ -2774,6 +2957,8 @@ rcu_torture_init(void)
        atomic_set(&n_rcu_torture_alloc_fail, 0);
        atomic_set(&n_rcu_torture_free, 0);
        atomic_set(&n_rcu_torture_mberror, 0);
+       atomic_set(&n_rcu_torture_mbchk_fail, 0);
+       atomic_set(&n_rcu_torture_mbchk_tries, 0);
        atomic_set(&n_rcu_torture_error, 0);
        n_rcu_torture_barrier_error = 0;
        n_rcu_torture_boost_ktrerror = 0;
@@ -2793,6 +2978,7 @@ rcu_torture_init(void)
 
        /* Start up the kthreads. */
 
+       rcu_torture_write_types();
        firsterr = torture_create_kthread(rcu_torture_writer, NULL,
                                          writer_task);
        if (firsterr)
@@ -2815,12 +3001,15 @@ rcu_torture_init(void)
        }
        reader_tasks = kcalloc(nrealreaders, sizeof(reader_tasks[0]),
                               GFP_KERNEL);
-       if (reader_tasks == NULL) {
+       rcu_torture_reader_mbchk = kcalloc(nrealreaders, sizeof(*rcu_torture_reader_mbchk),
+                                          GFP_KERNEL);
+       if (!reader_tasks || !rcu_torture_reader_mbchk) {
                VERBOSE_TOROUT_ERRSTRING("out of memory");
                firsterr = -ENOMEM;
                goto unwind;
        }
        for (i = 0; i < nrealreaders; i++) {
+               rcu_torture_reader_mbchk[i].rtc_chkrdr = -1;
                firsterr = torture_create_kthread(rcu_torture_reader, (void *)i,
                                                  reader_tasks[i]);
                if (firsterr)
index 23ff36a66f979eb23420b6c2effeba7b68e42d09..02dd9767b5591bd14dc37e4638382043f52633a0 100644 (file)
 #define VERBOSE_SCALEOUT(s, x...) \
        do { if (verbose) pr_alert("%s" SCALE_FLAG s, scale_type, ## x); } while (0)
 
+static atomic_t verbose_batch_ctr;
+
+#define VERBOSE_SCALEOUT_BATCH(s, x...)                                                        \
+do {                                                                                   \
+       if (verbose &&                                                                  \
+           (verbose_batched <= 0 ||                                                    \
+            !(atomic_inc_return(&verbose_batch_ctr) % verbose_batched))) {             \
+               schedule_timeout_uninterruptible(1);                                    \
+               pr_alert("%s" SCALE_FLAG s, scale_type, ## x);                          \
+       }                                                                               \
+} while (0)
+
 #define VERBOSE_SCALEOUT_ERRSTRING(s, x...) \
        do { if (verbose) pr_alert("%s" SCALE_FLAG "!!! " s, scale_type, ## x); } while (0)
 
@@ -57,6 +69,7 @@ module_param(scale_type, charp, 0444);
 MODULE_PARM_DESC(scale_type, "Type of test (rcu, srcu, refcnt, rwsem, rwlock.");
 
 torture_param(int, verbose, 0, "Enable verbose debugging printk()s");
+torture_param(int, verbose_batched, 0, "Batch verbose debugging printk()s");
 
 // Wait until there are multiple CPUs before starting test.
 torture_param(int, holdoff, IS_BUILTIN(CONFIG_RCU_REF_SCALE_TEST) ? 10 : 0,
@@ -368,14 +381,14 @@ ref_scale_reader(void *arg)
        u64 start;
        s64 duration;
 
-       VERBOSE_SCALEOUT("ref_scale_reader %ld: task started", me);
+       VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: task started", me);
        set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
        set_user_nice(current, MAX_NICE);
        atomic_inc(&n_init);
        if (holdoff)
                schedule_timeout_interruptible(holdoff * HZ);
 repeat:
-       VERBOSE_SCALEOUT("ref_scale_reader %ld: waiting to start next experiment on cpu %d", me, smp_processor_id());
+       VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: waiting to start next experiment on cpu %d", me, smp_processor_id());
 
        // Wait for signal that this reader can start.
        wait_event(rt->wq, (atomic_read(&nreaders_exp) && smp_load_acquire(&rt->start_reader)) ||
@@ -392,7 +405,7 @@ repeat:
                while (atomic_read_acquire(&n_started))
                        cpu_relax();
 
-       VERBOSE_SCALEOUT("ref_scale_reader %ld: experiment %d started", me, exp_idx);
+       VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: experiment %d started", me, exp_idx);
 
 
        // To reduce noise, do an initial cache-warming invocation, check
@@ -421,8 +434,8 @@ repeat:
        if (atomic_dec_and_test(&nreaders_exp))
                wake_up(&main_wq);
 
-       VERBOSE_SCALEOUT("ref_scale_reader %ld: experiment %d ended, (readers remaining=%d)",
-                       me, exp_idx, atomic_read(&nreaders_exp));
+       VERBOSE_SCALEOUT_BATCH("ref_scale_reader %ld: experiment %d ended, (readers remaining=%d)",
+                               me, exp_idx, atomic_read(&nreaders_exp));
 
        if (!torture_must_stop())
                goto repeat;
index 6208c1dae5c955a198470a2010739f44d2c747c4..26344dc6483b0e0306a305f27f2f1a3bb2b35cd8 100644 (file)
@@ -34,6 +34,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp)
        ssp->srcu_gp_running = false;
        ssp->srcu_gp_waiting = false;
        ssp->srcu_idx = 0;
+       ssp->srcu_idx_max = 0;
        INIT_WORK(&ssp->srcu_work, srcu_drive_gp);
        INIT_LIST_HEAD(&ssp->srcu_work.entry);
        return 0;
@@ -84,6 +85,8 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)
        WARN_ON(ssp->srcu_gp_waiting);
        WARN_ON(ssp->srcu_cb_head);
        WARN_ON(&ssp->srcu_cb_head != ssp->srcu_cb_tail);
+       WARN_ON(ssp->srcu_idx != ssp->srcu_idx_max);
+       WARN_ON(ssp->srcu_idx & 0x1);
 }
 EXPORT_SYMBOL_GPL(cleanup_srcu_struct);
 
@@ -114,7 +117,7 @@ void srcu_drive_gp(struct work_struct *wp)
        struct srcu_struct *ssp;
 
        ssp = container_of(wp, struct srcu_struct, srcu_work);
-       if (ssp->srcu_gp_running || !READ_ONCE(ssp->srcu_cb_head))
+       if (ssp->srcu_gp_running || USHORT_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
                return; /* Already running or nothing to do. */
 
        /* Remove recently arrived callbacks and wait for readers. */
@@ -124,11 +127,12 @@ void srcu_drive_gp(struct work_struct *wp)
        ssp->srcu_cb_head = NULL;
        ssp->srcu_cb_tail = &ssp->srcu_cb_head;
        local_irq_enable();
-       idx = ssp->srcu_idx;
-       WRITE_ONCE(ssp->srcu_idx, !ssp->srcu_idx);
+       idx = (ssp->srcu_idx & 0x2) / 2;
+       WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1);
        WRITE_ONCE(ssp->srcu_gp_waiting, true);  /* srcu_read_unlock() wakes! */
        swait_event_exclusive(ssp->srcu_wq, !READ_ONCE(ssp->srcu_lock_nesting[idx]));
        WRITE_ONCE(ssp->srcu_gp_waiting, false); /* srcu_read_unlock() cheap. */
+       WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1);
 
        /* Invoke the callbacks we removed above. */
        while (lh) {
@@ -146,11 +150,27 @@ void srcu_drive_gp(struct work_struct *wp)
         * straighten that out.
         */
        WRITE_ONCE(ssp->srcu_gp_running, false);
-       if (READ_ONCE(ssp->srcu_cb_head))
+       if (USHORT_CMP_LT(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
                schedule_work(&ssp->srcu_work);
 }
 EXPORT_SYMBOL_GPL(srcu_drive_gp);
 
+static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
+{
+       unsigned short cookie;
+
+       cookie = get_state_synchronize_srcu(ssp);
+       if (USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie))
+               return;
+       WRITE_ONCE(ssp->srcu_idx_max, cookie);
+       if (!READ_ONCE(ssp->srcu_gp_running)) {
+               if (likely(srcu_init_done))
+                       schedule_work(&ssp->srcu_work);
+               else if (list_empty(&ssp->srcu_work.entry))
+                       list_add(&ssp->srcu_work.entry, &srcu_boot_list);
+       }
+}
+
 /*
  * Enqueue an SRCU callback on the specified srcu_struct structure,
  * initiating grace-period processing if it is not already running.
@@ -166,12 +186,7 @@ void call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
        *ssp->srcu_cb_tail = rhp;
        ssp->srcu_cb_tail = &rhp->next;
        local_irq_restore(flags);
-       if (!READ_ONCE(ssp->srcu_gp_running)) {
-               if (likely(srcu_init_done))
-                       schedule_work(&ssp->srcu_work);
-               else if (list_empty(&ssp->srcu_work.entry))
-                       list_add(&ssp->srcu_work.entry, &srcu_boot_list);
-       }
+       srcu_gp_start_if_needed(ssp);
 }
 EXPORT_SYMBOL_GPL(call_srcu);
 
@@ -190,6 +205,48 @@ void synchronize_srcu(struct srcu_struct *ssp)
 }
 EXPORT_SYMBOL_GPL(synchronize_srcu);
 
+/*
+ * get_state_synchronize_srcu - Provide an end-of-grace-period cookie
+ */
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
+{
+       unsigned long ret;
+
+       barrier();
+       ret = (READ_ONCE(ssp->srcu_idx) + 3) & ~0x1;
+       barrier();
+       return ret & USHRT_MAX;
+}
+EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
+
+/*
+ * start_poll_synchronize_srcu - Provide cookie and start grace period
+ *
+ * The difference between this and get_state_synchronize_srcu() is that
+ * this function ensures that the poll_state_synchronize_srcu() will
+ * eventually return the value true.
+ */
+unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp)
+{
+       unsigned long ret = get_state_synchronize_srcu(ssp);
+
+       srcu_gp_start_if_needed(ssp);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
+
+/*
+ * poll_state_synchronize_srcu - Has cookie's grace period ended?
+ */
+bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
+{
+       bool ret = USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx), cookie);
+
+       barrier();
+       return ret;
+}
+EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);
+
 /* Lockdep diagnostics.  */
 void __init rcu_scheduler_starting(void)
 {
index 79b7081143a7ba5d7475b4df4de63fd70a0917d9..e26547b34ad33c6b7d075fcd8b0930f036f76804 100644 (file)
@@ -807,6 +807,46 @@ static void srcu_leak_callback(struct rcu_head *rhp)
 {
 }
 
+/*
+ * Start an SRCU grace period, and also queue the callback if non-NULL.
+ */
+static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
+                                            struct rcu_head *rhp, bool do_norm)
+{
+       unsigned long flags;
+       int idx;
+       bool needexp = false;
+       bool needgp = false;
+       unsigned long s;
+       struct srcu_data *sdp;
+
+       check_init_srcu_struct(ssp);
+       idx = srcu_read_lock(ssp);
+       sdp = raw_cpu_ptr(ssp->sda);
+       spin_lock_irqsave_rcu_node(sdp, flags);
+       if (rhp)
+               rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
+       rcu_segcblist_advance(&sdp->srcu_cblist,
+                             rcu_seq_current(&ssp->srcu_gp_seq));
+       s = rcu_seq_snap(&ssp->srcu_gp_seq);
+       (void)rcu_segcblist_accelerate(&sdp->srcu_cblist, s);
+       if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) {
+               sdp->srcu_gp_seq_needed = s;
+               needgp = true;
+       }
+       if (!do_norm && ULONG_CMP_LT(sdp->srcu_gp_seq_needed_exp, s)) {
+               sdp->srcu_gp_seq_needed_exp = s;
+               needexp = true;
+       }
+       spin_unlock_irqrestore_rcu_node(sdp, flags);
+       if (needgp)
+               srcu_funnel_gp_start(ssp, sdp, s, do_norm);
+       else if (needexp)
+               srcu_funnel_exp_start(ssp, sdp->mynode, s);
+       srcu_read_unlock(ssp, idx);
+       return s;
+}
+
 /*
  * Enqueue an SRCU callback on the srcu_data structure associated with
  * the current CPU and the specified srcu_struct structure, initiating
@@ -838,14 +878,6 @@ static void srcu_leak_callback(struct rcu_head *rhp)
 static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
                        rcu_callback_t func, bool do_norm)
 {
-       unsigned long flags;
-       int idx;
-       bool needexp = false;
-       bool needgp = false;
-       unsigned long s;
-       struct srcu_data *sdp;
-
-       check_init_srcu_struct(ssp);
        if (debug_rcu_head_queue(rhp)) {
                /* Probable double call_srcu(), so leak the callback. */
                WRITE_ONCE(rhp->func, srcu_leak_callback);
@@ -853,28 +885,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp,
                return;
        }
        rhp->func = func;
-       idx = srcu_read_lock(ssp);
-       sdp = raw_cpu_ptr(ssp->sda);
-       spin_lock_irqsave_rcu_node(sdp, flags);
-       rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
-       rcu_segcblist_advance(&sdp->srcu_cblist,
-                             rcu_seq_current(&ssp->srcu_gp_seq));
-       s = rcu_seq_snap(&ssp->srcu_gp_seq);
-       (void)rcu_segcblist_accelerate(&sdp->srcu_cblist, s);
-       if (ULONG_CMP_LT(sdp->srcu_gp_seq_needed, s)) {
-               sdp->srcu_gp_seq_needed = s;
-               needgp = true;
-       }
-       if (!do_norm && ULONG_CMP_LT(sdp->srcu_gp_seq_needed_exp, s)) {
-               sdp->srcu_gp_seq_needed_exp = s;
-               needexp = true;
-       }
-       spin_unlock_irqrestore_rcu_node(sdp, flags);
-       if (needgp)
-               srcu_funnel_gp_start(ssp, sdp, s, do_norm);
-       else if (needexp)
-               srcu_funnel_exp_start(ssp, sdp->mynode, s);
-       srcu_read_unlock(ssp, idx);
+       (void)srcu_gp_start_if_needed(ssp, rhp, do_norm);
 }
 
 /**
@@ -1003,6 +1014,77 @@ void synchronize_srcu(struct srcu_struct *ssp)
 }
 EXPORT_SYMBOL_GPL(synchronize_srcu);
 
+/**
+ * get_state_synchronize_srcu - Provide an end-of-grace-period cookie
+ * @ssp: srcu_struct to provide cookie for.
+ *
+ * This function returns a cookie that can be passed to
+ * poll_state_synchronize_srcu(), which will return true if a full grace
+ * period has elapsed in the meantime.  It is the caller's responsibility
+ * to make sure that grace period happens, for example, by invoking
+ * call_srcu() after return from get_state_synchronize_srcu().
+ */
+unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
+{
+       // Any prior manipulation of SRCU-protected data must happen
+       // before the load from ->srcu_gp_seq.
+       smp_mb();
+       return rcu_seq_snap(&ssp->srcu_gp_seq);
+}
+EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
+
+/**
+ * start_poll_synchronize_srcu - Provide cookie and start grace period
+ * @ssp: srcu_struct to provide cookie for.
+ *
+ * This function returns a cookie that can be passed to
+ * poll_state_synchronize_srcu(), which will return true if a full grace
+ * period has elapsed in the meantime.  Unlike get_state_synchronize_srcu(),
+ * this function also ensures that any needed SRCU grace period will be
+ * started.  This convenience does come at a cost in terms of CPU overhead.
+ */
+unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp)
+{
+       return srcu_gp_start_if_needed(ssp, NULL, true);
+}
+EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
+
+/**
+ * poll_state_synchronize_srcu - Has cookie's grace period ended?
+ * @ssp: srcu_struct to provide cookie for.
+ * @cookie: Return value from get_state_synchronize_srcu() or start_poll_synchronize_srcu().
+ *
+ * This function takes the cookie that was returned from either
+ * get_state_synchronize_srcu() or start_poll_synchronize_srcu(), and
+ * returns @true if an SRCU grace period elapsed since the time that the
+ * cookie was created.
+ *
+ * Because cookies are finite in size, wrapping/overflow is possible.
+ * This is more pronounced on 32-bit systems where cookies are 32 bits,
+ * where in theory wrapping could happen in about 14 hours assuming
+ * 25-microsecond expedited SRCU grace periods.  However, a more likely
+ * overflow lower bound is on the order of 24 days in the case of
+ * one-millisecond SRCU grace periods.  Of course, wrapping in a 64-bit
+ * system requires geologic timespans, as in more than seven million years
+ * even for expedited SRCU grace periods.
+ *
+ * Wrapping/overflow is much more of an issue for CONFIG_SMP=n systems
+ * that also have CONFIG_PREEMPTION=n, which selects Tiny SRCU.  This uses
+ * a 16-bit cookie, which rcutorture routinely wraps in a matter of a
+ * few minutes.  If this proves to be a problem, this counter will be
+ * expanded to the same size as for Tree SRCU.
+ */
+bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
+{
+       if (!rcu_seq_done(&ssp->srcu_gp_seq, cookie))
+               return false;
+       // Ensure that the end of the SRCU grace period happens before
+       // any subsequent code that the caller might execute.
+       smp_mb(); // ^^^
+       return true;
+}
+EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);
+
 /*
  * Callback function for srcu_barrier() use.
  */
index 35bdcfd84d42827dc95cdc57e75994ed1fe483d9..af7c19439f4ec95623a9721fe8dcd27a35242158 100644 (file)
@@ -241,7 +241,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
        }
 }
 
-/* Spawn RCU-tasks grace-period kthread, e.g., at core_initcall() time. */
+/* Spawn RCU-tasks grace-period kthread. */
 static void __init rcu_spawn_tasks_kthread_generic(struct rcu_tasks *rtp)
 {
        struct task_struct *t;
@@ -564,7 +564,6 @@ static int __init rcu_spawn_tasks_kthread(void)
        rcu_spawn_tasks_kthread_generic(&rcu_tasks);
        return 0;
 }
-core_initcall(rcu_spawn_tasks_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_classic_gp_kthread(void)
@@ -692,7 +691,6 @@ static int __init rcu_spawn_tasks_rude_kthread(void)
        rcu_spawn_tasks_kthread_generic(&rcu_tasks_rude);
        return 0;
 }
-core_initcall(rcu_spawn_tasks_rude_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_rude_gp_kthread(void)
@@ -968,6 +966,11 @@ static void rcu_tasks_trace_pregp_step(void)
 static void rcu_tasks_trace_pertask(struct task_struct *t,
                                    struct list_head *hop)
 {
+       // During early boot when there is only the one boot CPU, there
+       // is no idle task for the other CPUs. Just return.
+       if (unlikely(t == NULL))
+               return;
+
        WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
        WRITE_ONCE(t->trc_reader_checked, false);
        t->trc_ipi_to_cpu = -1;
@@ -1193,7 +1196,6 @@ static int __init rcu_spawn_tasks_trace_kthread(void)
        rcu_spawn_tasks_kthread_generic(&rcu_tasks_trace);
        return 0;
 }
-core_initcall(rcu_spawn_tasks_trace_kthread);
 
 #if !defined(CONFIG_TINY_RCU)
 void show_rcu_tasks_trace_gp_kthread(void)
@@ -1222,6 +1224,100 @@ void show_rcu_tasks_gp_kthreads(void)
 }
 #endif /* #ifndef CONFIG_TINY_RCU */
 
+#ifdef CONFIG_PROVE_RCU
+struct rcu_tasks_test_desc {
+       struct rcu_head rh;
+       const char *name;
+       bool notrun;
+};
+
+static struct rcu_tasks_test_desc tests[] = {
+       {
+               .name = "call_rcu_tasks()",
+               /* If not defined, the test is skipped. */
+               .notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
+       },
+       {
+               .name = "call_rcu_tasks_rude()",
+               /* If not defined, the test is skipped. */
+               .notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
+       },
+       {
+               .name = "call_rcu_tasks_trace()",
+               /* If not defined, the test is skipped. */
+               .notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
+       }
+};
+
+static void test_rcu_tasks_callback(struct rcu_head *rhp)
+{
+       struct rcu_tasks_test_desc *rttd =
+               container_of(rhp, struct rcu_tasks_test_desc, rh);
+
+       pr_info("Callback from %s invoked.\n", rttd->name);
+
+       rttd->notrun = true;
+}
+
+static void rcu_tasks_initiate_self_tests(void)
+{
+       pr_info("Running RCU-tasks wait API self tests\n");
+#ifdef CONFIG_TASKS_RCU
+       synchronize_rcu_tasks();
+       call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+       synchronize_rcu_tasks_rude();
+       call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+       synchronize_rcu_tasks_trace();
+       call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
+#endif
+}
+
+static int rcu_tasks_verify_self_tests(void)
+{
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(tests); i++) {
+               if (!tests[i].notrun) {         // still hanging.
+                       pr_err("%s has been failed.\n", tests[i].name);
+                       ret = -1;
+               }
+       }
+
+       if (ret)
+               WARN_ON(1);
+
+       return ret;
+}
+late_initcall(rcu_tasks_verify_self_tests);
+#else /* #ifdef CONFIG_PROVE_RCU */
+static void rcu_tasks_initiate_self_tests(void) { }
+#endif /* #else #ifdef CONFIG_PROVE_RCU */
+
+void __init rcu_init_tasks_generic(void)
+{
+#ifdef CONFIG_TASKS_RCU
+       rcu_spawn_tasks_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_RUDE_RCU
+       rcu_spawn_tasks_rude_kthread();
+#endif
+
+#ifdef CONFIG_TASKS_TRACE_RCU
+       rcu_spawn_tasks_trace_kthread();
+#endif
+
+       // Run the self-tests.
+       rcu_tasks_initiate_self_tests();
+}
+
 #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
 static inline void rcu_tasks_bootup_oddness(void) {}
 void show_rcu_tasks_gp_kthreads(void) {}
index e6dee714efe0aff90d95adab2a8f651ccac7c9a5..0f4a6a3c057b0120be8ff35f3f40be6bde7fa3aa 100644 (file)
@@ -103,8 +103,10 @@ static struct rcu_state rcu_state = {
 static bool dump_tree;
 module_param(dump_tree, bool, 0444);
 /* By default, use RCU_SOFTIRQ instead of rcuc kthreads. */
-static bool use_softirq = true;
+static bool use_softirq = !IS_ENABLED(CONFIG_PREEMPT_RT);
+#ifndef CONFIG_PREEMPT_RT
 module_param(use_softirq, bool, 0444);
+#endif
 /* Control rcu_node-tree auto-balancing at boot time. */
 static bool rcu_fanout_exact;
 module_param(rcu_fanout_exact, bool, 0444);
@@ -1772,7 +1774,7 @@ static bool rcu_gp_init(void)
         * go offline later.  Please also refer to "Hotplug CPU" section
         * of RCU's Requirements documentation.
         */
-       rcu_state.gp_state = RCU_GP_ONOFF;
+       WRITE_ONCE(rcu_state.gp_state, RCU_GP_ONOFF);
        rcu_for_each_leaf_node(rnp) {
                smp_mb(); // Pair with barriers used when updating ->ofl_seq to odd values.
                firstseq = READ_ONCE(rnp->ofl_seq);
@@ -1838,7 +1840,7 @@ static bool rcu_gp_init(void)
         * The grace period cannot complete until the initialization
         * process finishes, because this kthread handles both.
         */
-       rcu_state.gp_state = RCU_GP_INIT;
+       WRITE_ONCE(rcu_state.gp_state, RCU_GP_INIT);
        rcu_for_each_node_breadth_first(rnp) {
                rcu_gp_slow(gp_init_delay);
                raw_spin_lock_irqsave_rcu_node(rnp, flags);
@@ -1937,17 +1939,22 @@ static void rcu_gp_fqs_loop(void)
        ret = 0;
        for (;;) {
                if (!ret) {
-                       rcu_state.jiffies_force_qs = jiffies + j;
+                       WRITE_ONCE(rcu_state.jiffies_force_qs, jiffies + j);
+                       /*
+                        * jiffies_force_qs before RCU_GP_WAIT_FQS state
+                        * update; required for stall checks.
+                        */
+                       smp_wmb();
                        WRITE_ONCE(rcu_state.jiffies_kick_kthreads,
                                   jiffies + (j ? 3 * j : 2));
                }
                trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
                                       TPS("fqswait"));
-               rcu_state.gp_state = RCU_GP_WAIT_FQS;
+               WRITE_ONCE(rcu_state.gp_state, RCU_GP_WAIT_FQS);
                ret = swait_event_idle_timeout_exclusive(
                                rcu_state.gp_wq, rcu_gp_fqs_check_wake(&gf), j);
                rcu_gp_torture_wait();
-               rcu_state.gp_state = RCU_GP_DOING_FQS;
+               WRITE_ONCE(rcu_state.gp_state, RCU_GP_DOING_FQS);
                /* Locking provides needed memory barriers. */
                /* If grace period done, leave loop. */
                if (!READ_ONCE(rnp->qsmask) &&
@@ -2061,7 +2068,7 @@ static void rcu_gp_cleanup(void)
        trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq, TPS("end"));
        rcu_seq_end(&rcu_state.gp_seq);
        ASSERT_EXCLUSIVE_WRITER(rcu_state.gp_seq);
-       rcu_state.gp_state = RCU_GP_IDLE;
+       WRITE_ONCE(rcu_state.gp_state, RCU_GP_IDLE);
        /* Check for GP requests since above loop. */
        rdp = this_cpu_ptr(&rcu_data);
        if (!needgp && ULONG_CMP_LT(rnp->gp_seq, rnp->gp_seq_needed)) {
@@ -2100,12 +2107,12 @@ static int __noreturn rcu_gp_kthread(void *unused)
                for (;;) {
                        trace_rcu_grace_period(rcu_state.name, rcu_state.gp_seq,
                                               TPS("reqwait"));
-                       rcu_state.gp_state = RCU_GP_WAIT_GPS;
+                       WRITE_ONCE(rcu_state.gp_state, RCU_GP_WAIT_GPS);
                        swait_event_idle_exclusive(rcu_state.gp_wq,
                                         READ_ONCE(rcu_state.gp_flags) &
                                         RCU_GP_FLAG_INIT);
                        rcu_gp_torture_wait();
-                       rcu_state.gp_state = RCU_GP_DONE_GPS;
+                       WRITE_ONCE(rcu_state.gp_state, RCU_GP_DONE_GPS);
                        /* Locking provides needed memory barrier. */
                        if (rcu_gp_init())
                                break;
@@ -2120,9 +2127,9 @@ static int __noreturn rcu_gp_kthread(void *unused)
                rcu_gp_fqs_loop();
 
                /* Handle grace-period end. */
-               rcu_state.gp_state = RCU_GP_CLEANUP;
+               WRITE_ONCE(rcu_state.gp_state, RCU_GP_CLEANUP);
                rcu_gp_cleanup();
-               rcu_state.gp_state = RCU_GP_CLEANED;
+               WRITE_ONCE(rcu_state.gp_state, RCU_GP_CLEANED);
        }
 }
 
@@ -2577,6 +2584,7 @@ static void rcu_do_batch(struct rcu_data *rdp)
 void rcu_sched_clock_irq(int user)
 {
        trace_rcu_utilization(TPS("Start scheduler-tick"));
+       lockdep_assert_irqs_disabled();
        raw_cpu_inc(rcu_data.ticks_this_gp);
        /* The load-acquire pairs with the store-release setting to true. */
        if (smp_load_acquire(this_cpu_ptr(&rcu_data.rcu_urgent_qs))) {
@@ -2590,6 +2598,7 @@ void rcu_sched_clock_irq(int user)
        rcu_flavor_sched_clock_irq(user);
        if (rcu_pending(user))
                invoke_rcu_core();
+       lockdep_assert_irqs_disabled();
 
        trace_rcu_utilization(TPS("End scheduler-tick"));
 }
@@ -2952,6 +2961,7 @@ static void check_cb_ovld(struct rcu_data *rdp)
 static void
 __call_rcu(struct rcu_head *head, rcu_callback_t func)
 {
+       static atomic_t doublefrees;
        unsigned long flags;
        struct rcu_data *rdp;
        bool was_alldone;
@@ -2965,8 +2975,10 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func)
                 * Use rcu:rcu_callback trace event to find the previous
                 * time callback was passed to __call_rcu().
                 */
-               WARN_ONCE(1, "__call_rcu(): Double-freed CB %p->%pS()!!!\n",
-                         head, head->func);
+               if (atomic_inc_return(&doublefrees) < 4) {
+                       pr_err("%s(): Double-freed CB %p->%pS()!!!  ", __func__, head, head->func);
+                       mem_dump_obj(head);
+               }
                WRITE_ONCE(head->func, rcu_leak_callback);
                return;
        }
@@ -3511,6 +3523,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
                goto unlock_return;
        }
 
+       kasan_record_aux_stack(ptr);
        success = kvfree_call_rcu_add_ptr_to_bulk(krcp, ptr);
        if (!success) {
                run_page_cache_worker(krcp);
@@ -3760,6 +3773,8 @@ static int rcu_pending(int user)
        struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
        struct rcu_node *rnp = rdp->mynode;
 
+       lockdep_assert_irqs_disabled();
+
        /* Check for CPU stalls, if enabled. */
        check_cpu_stall(rdp);
 
index 8760b6ead770a9dd03dc1043052da2a2135cdf74..6c6ff06d4ae653586e8114ed1444e99877aaf705 100644 (file)
@@ -545,7 +545,7 @@ static void synchronize_rcu_expedited_wait(void)
                        data_race(rnp_root->expmask),
                        ".T"[!!data_race(rnp_root->exp_tasks)]);
                if (ndetected) {
-                       pr_err("blocking rcu_node structures:");
+                       pr_err("blocking rcu_node structures (internal RCU debug):");
                        rcu_for_each_node_breadth_first(rnp) {
                                if (rnp == rnp_root)
                                        continue; /* printed unconditionally */
index 6f56f9e51e67c60180e3e70fb57459e82a6095be..231a0c6cf03c179580cd1c9a44097c369d20307d 100644 (file)
@@ -682,6 +682,7 @@ static void rcu_flavor_sched_clock_irq(int user)
 {
        struct task_struct *t = current;
 
+       lockdep_assert_irqs_disabled();
        if (user || rcu_is_cpu_rrupt_from_idle()) {
                rcu_note_voluntary_context_switch(current);
        }
index 70d48c52fabc9947397c8a06eacde26c15c56722..475b26171b20fff053842f265fc5b1dc2d7fcd17 100644 (file)
@@ -266,6 +266,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
        struct task_struct *t;
        struct task_struct *ts[8];
 
+       lockdep_assert_irqs_disabled();
        if (!rcu_preempt_blocked_readers_cgp(rnp))
                return 0;
        pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
@@ -290,6 +291,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
                                ".q"[rscr.rs.b.need_qs],
                                ".e"[rscr.rs.b.exp_hint],
                                ".l"[rscr.on_blkd_list]);
+               lockdep_assert_irqs_disabled();
                put_task_struct(t);
                ndetected++;
        }
@@ -333,9 +335,12 @@ static void rcu_dump_cpu_stacks(void)
        rcu_for_each_leaf_node(rnp) {
                raw_spin_lock_irqsave_rcu_node(rnp, flags);
                for_each_leaf_node_possible_cpu(rnp, cpu)
-                       if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu))
-                               if (!trigger_single_cpu_backtrace(cpu))
+                       if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
+                               if (cpu_is_offline(cpu))
+                                       pr_err("Offline CPU %d blocking current GP.\n", cpu);
+                               else if (!trigger_single_cpu_backtrace(cpu))
                                        dump_cpu_task(cpu);
+                       }
                raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
        }
 }
@@ -449,25 +454,66 @@ static void print_cpu_stall_info(int cpu)
 /* Complain about starvation of grace-period kthread.  */
 static void rcu_check_gp_kthread_starvation(void)
 {
+       int cpu;
        struct task_struct *gpk = rcu_state.gp_kthread;
        unsigned long j;
 
        if (rcu_is_gp_kthread_starving(&j)) {
+               cpu = gpk ? task_cpu(gpk) : -1;
                pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#lx ->cpu=%d\n",
                       rcu_state.name, j,
                       (long)rcu_seq_current(&rcu_state.gp_seq),
                       data_race(rcu_state.gp_flags),
                       gp_state_getname(rcu_state.gp_state), rcu_state.gp_state,
-                      gpk ? gpk->state : ~0, gpk ? task_cpu(gpk) : -1);
+                      gpk ? gpk->state : ~0, cpu);
                if (gpk) {
                        pr_err("\tUnless %s kthread gets sufficient CPU time, OOM is now expected behavior.\n", rcu_state.name);
                        pr_err("RCU grace-period kthread stack dump:\n");
                        sched_show_task(gpk);
+                       if (cpu >= 0) {
+                               if (cpu_is_offline(cpu)) {
+                                       pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
+                               } else  {
+                                       pr_err("Stack dump where RCU GP kthread last ran:\n");
+                                       if (!trigger_single_cpu_backtrace(cpu))
+                                               dump_cpu_task(cpu);
+                               }
+                       }
                        wake_up_process(gpk);
                }
        }
 }
 
+/* Complain about missing wakeups from expired fqs wait timer */
+static void rcu_check_gp_kthread_expired_fqs_timer(void)
+{
+       struct task_struct *gpk = rcu_state.gp_kthread;
+       short gp_state;
+       unsigned long jiffies_fqs;
+       int cpu;
+
+       /*
+        * Order reads of .gp_state and .jiffies_force_qs.
+        * Matching smp_wmb() is present in rcu_gp_fqs_loop().
+        */
+       gp_state = smp_load_acquire(&rcu_state.gp_state);
+       jiffies_fqs = READ_ONCE(rcu_state.jiffies_force_qs);
+
+       if (gp_state == RCU_GP_WAIT_FQS &&
+           time_after(jiffies, jiffies_fqs + RCU_STALL_MIGHT_MIN) &&
+           gpk && !READ_ONCE(gpk->on_rq)) {
+               cpu = task_cpu(gpk);
+               pr_err("%s kthread timer wakeup didn't happen for %ld jiffies! g%ld f%#x %s(%d) ->state=%#lx\n",
+                      rcu_state.name, (jiffies - jiffies_fqs),
+                      (long)rcu_seq_current(&rcu_state.gp_seq),
+                      data_race(rcu_state.gp_flags),
+                      gp_state_getname(RCU_GP_WAIT_FQS), RCU_GP_WAIT_FQS,
+                      gpk->state);
+               pr_err("\tPossible timer handling issue on cpu=%d timer-softirq=%u\n",
+                      cpu, kstat_softirqs_cpu(TIMER_SOFTIRQ, cpu));
+       }
+}
+
 static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
 {
        int cpu;
@@ -478,6 +524,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
        struct rcu_node *rnp;
        long totqlen = 0;
 
+       lockdep_assert_irqs_disabled();
+
        /* Kick and suppress, if so configured. */
        rcu_stall_kick_kthreads();
        if (rcu_stall_is_suppressed())
@@ -499,6 +547,7 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
                                }
                }
                ndetected += rcu_print_task_stall(rnp, flags); // Releases rnp->lock.
+               lockdep_assert_irqs_disabled();
        }
 
        for_each_possible_cpu(cpu)
@@ -529,6 +578,7 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
                WRITE_ONCE(rcu_state.jiffies_stall,
                           jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
 
+       rcu_check_gp_kthread_expired_fqs_timer();
        rcu_check_gp_kthread_starvation();
 
        panic_on_rcu_stall();
@@ -544,6 +594,8 @@ static void print_cpu_stall(unsigned long gps)
        struct rcu_node *rnp = rcu_get_root();
        long totqlen = 0;
 
+       lockdep_assert_irqs_disabled();
+
        /* Kick and suppress, if so configured. */
        rcu_stall_kick_kthreads();
        if (rcu_stall_is_suppressed())
@@ -564,6 +616,7 @@ static void print_cpu_stall(unsigned long gps)
                jiffies - gps,
                (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
 
+       rcu_check_gp_kthread_expired_fqs_timer();
        rcu_check_gp_kthread_starvation();
 
        rcu_dump_cpu_stacks();
@@ -598,6 +651,7 @@ static void check_cpu_stall(struct rcu_data *rdp)
        unsigned long js;
        struct rcu_node *rnp;
 
+       lockdep_assert_irqs_disabled();
        if ((rcu_stall_is_suppressed() && !READ_ONCE(rcu_kick_kthreads)) ||
            !rcu_gp_in_progress())
                return;
index 39334d2d2b37991f1801a9ee8bf179db21d7fb0e..b95ae86c40a7d022742648d120c958b902a9557e 100644 (file)
 #ifndef CONFIG_TINY_RCU
 module_param(rcu_expedited, int, 0);
 module_param(rcu_normal, int, 0);
-static int rcu_normal_after_boot;
+static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT);
+#ifndef CONFIG_PREEMPT_RT
 module_param(rcu_normal_after_boot, int, 0);
+#endif
 #endif /* #ifndef CONFIG_TINY_RCU */
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
index d55a9f8cda3d48dd654fcbb5e0ff11cc031ac298..2377cbb324742e47692179279876ebf8ee36d7cd 100644 (file)
@@ -398,6 +398,7 @@ static void scftorture_invoke_one(struct scf_statistics *scfp, struct torture_ra
 static int scftorture_invoker(void *arg)
 {
        int cpu;
+       int curcpu;
        DEFINE_TORTURE_RANDOM(rand);
        struct scf_statistics *scfp = (struct scf_statistics *)arg;
        bool was_offline = false;
@@ -412,7 +413,10 @@ static int scftorture_invoker(void *arg)
        VERBOSE_SCFTORTOUT("scftorture_invoker %d: Waiting for all SCF torturers from cpu %d", scfp->cpu, smp_processor_id());
 
        // Make sure that the CPU is affinitized appropriately during testing.
-       WARN_ON_ONCE(smp_processor_id() != scfp->cpu);
+       curcpu = smp_processor_id();
+       WARN_ONCE(curcpu != scfp->cpu % nr_cpu_ids,
+                 "%s: Wanted CPU %d, running on %d, nr_cpu_ids = %d\n",
+                 __func__, scfp->cpu, curcpu, nr_cpu_ids);
 
        if (!atomic_dec_return(&n_started))
                while (atomic_read_acquire(&n_started)) {
index 15d2562118d1727aa197bd5f9cc6314cfebace6c..a75c608839c4d6d52bd80157b85bb98234670091 100644 (file)
@@ -3464,7 +3464,7 @@ out:
 
 /**
  * try_invoke_on_locked_down_task - Invoke a function on task in fixed state
- * @p: Process for which the function is to be invoked.
+ * @p: Process for which the function is to be invoked, can be @current.
  * @func: Function to invoke.
  * @arg: Argument to function.
  *
@@ -3482,12 +3482,11 @@ out:
  */
 bool try_invoke_on_locked_down_task(struct task_struct *p, bool (*func)(struct task_struct *t, void *arg), void *arg)
 {
-       bool ret = false;
        struct rq_flags rf;
+       bool ret = false;
        struct rq *rq;
 
-       lockdep_assert_irqs_enabled();
-       raw_spin_lock_irq(&p->pi_lock);
+       raw_spin_lock_irqsave(&p->pi_lock, rf.flags);
        if (p->on_rq) {
                rq = __task_rq_lock(p, &rf);
                if (task_rq(p) == rq)
@@ -3504,7 +3503,7 @@ bool try_invoke_on_locked_down_task(struct task_struct *p, bool (*func)(struct t
                                ret = func(p, arg);
                }
        }
-       raw_spin_unlock_irq(&p->pi_lock);
+       raw_spin_unlock_irqrestore(&p->pi_lock, rf.flags);
        return ret;
 }
 
index 8562ac18d2eb531a6ade87793d086e377a622b75..01e336f1e5b20db21ffb63879fc12b1462d1e720 100644 (file)
@@ -48,6 +48,12 @@ module_param(disable_onoff_at_boot, bool, 0444);
 static bool ftrace_dump_at_shutdown;
 module_param(ftrace_dump_at_shutdown, bool, 0444);
 
+static int verbose_sleep_frequency;
+module_param(verbose_sleep_frequency, int, 0444);
+
+static int verbose_sleep_duration = 1;
+module_param(verbose_sleep_duration, int, 0444);
+
 static char *torture_type;
 static int verbose;
 
@@ -58,6 +64,95 @@ static int verbose;
 static int fullstop = FULLSTOP_RMMOD;
 static DEFINE_MUTEX(fullstop_mutex);
 
+static atomic_t verbose_sleep_counter;
+
+/*
+ * Sleep if needed from VERBOSE_TOROUT*().
+ */
+void verbose_torout_sleep(void)
+{
+       if (verbose_sleep_frequency > 0 &&
+           verbose_sleep_duration > 0 &&
+           !(atomic_inc_return(&verbose_sleep_counter) % verbose_sleep_frequency))
+               schedule_timeout_uninterruptible(verbose_sleep_duration);
+}
+EXPORT_SYMBOL_GPL(verbose_torout_sleep);
+
+/*
+ * Schedule a high-resolution-timer sleep in nanoseconds, with a 32-bit
+ * nanosecond random fuzz.  This function and its friends desynchronize
+ * testing from the timer wheel.
+ */
+int torture_hrtimeout_ns(ktime_t baset_ns, u32 fuzzt_ns, struct torture_random_state *trsp)
+{
+       ktime_t hto = baset_ns;
+
+       if (trsp)
+               hto += (torture_random(trsp) >> 3) % fuzzt_ns;
+       set_current_state(TASK_UNINTERRUPTIBLE);
+       return schedule_hrtimeout(&hto, HRTIMER_MODE_REL);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_ns);
+
+/*
+ * Schedule a high-resolution-timer sleep in microseconds, with a 32-bit
+ * nanosecond (not microsecond!) random fuzz.
+ */
+int torture_hrtimeout_us(u32 baset_us, u32 fuzzt_ns, struct torture_random_state *trsp)
+{
+       ktime_t baset_ns = baset_us * NSEC_PER_USEC;
+
+       return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_us);
+
+/*
+ * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
+ * microsecond (not millisecond!) random fuzz.
+ */
+int torture_hrtimeout_ms(u32 baset_ms, u32 fuzzt_us, struct torture_random_state *trsp)
+{
+       ktime_t baset_ns = baset_ms * NSEC_PER_MSEC;
+       u32 fuzzt_ns;
+
+       if ((u32)~0U / NSEC_PER_USEC < fuzzt_us)
+               fuzzt_ns = (u32)~0U;
+       else
+               fuzzt_ns = fuzzt_us * NSEC_PER_USEC;
+       return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_ms);
+
+/*
+ * Schedule a high-resolution-timer sleep in jiffies, with an
+ * implied one-jiffy random fuzz.  This is intended to replace calls to
+ * schedule_timeout_interruptible() and friends.
+ */
+int torture_hrtimeout_jiffies(u32 baset_j, struct torture_random_state *trsp)
+{
+       ktime_t baset_ns = jiffies_to_nsecs(baset_j);
+
+       return torture_hrtimeout_ns(baset_ns, jiffies_to_nsecs(1), trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_jiffies);
+
+/*
+ * Schedule a high-resolution-timer sleep in milliseconds, with a 32-bit
+ * millisecond (not second!) random fuzz.
+ */
+int torture_hrtimeout_s(u32 baset_s, u32 fuzzt_ms, struct torture_random_state *trsp)
+{
+       ktime_t baset_ns = baset_s * NSEC_PER_SEC;
+       u32 fuzzt_ns;
+
+       if ((u32)~0U / NSEC_PER_MSEC < fuzzt_ms)
+               fuzzt_ns = (u32)~0U;
+       else
+               fuzzt_ns = fuzzt_ms * NSEC_PER_MSEC;
+       return torture_hrtimeout_ns(baset_ns, fuzzt_ns, trsp);
+}
+EXPORT_SYMBOL_GPL(torture_hrtimeout_s);
+
 #ifdef CONFIG_HOTPLUG_CPU
 
 /*
@@ -80,6 +175,19 @@ static unsigned long sum_online;
 static int min_online = -1;
 static int max_online;
 
+static int torture_online_cpus = NR_CPUS;
+
+/*
+ * Some torture testing leverages confusion as to the number of online
+ * CPUs.  This function returns the torture-testing view of this number,
+ * which allows torture tests to load-balance appropriately.
+ */
+int torture_num_online_cpus(void)
+{
+       return READ_ONCE(torture_online_cpus);
+}
+EXPORT_SYMBOL_GPL(torture_num_online_cpus);
+
 /*
  * Attempt to take a CPU offline.  Return false if the CPU is already
  * offline or if it is not subject to CPU-hotplug operations.  The
@@ -134,6 +242,8 @@ bool torture_offline(int cpu, long *n_offl_attempts, long *n_offl_successes,
                        *min_offl = delta;
                if (*max_offl < delta)
                        *max_offl = delta;
+               WRITE_ONCE(torture_online_cpus, torture_online_cpus - 1);
+               WARN_ON_ONCE(torture_online_cpus <= 0);
        }
 
        return true;
@@ -190,12 +300,33 @@ bool torture_online(int cpu, long *n_onl_attempts, long *n_onl_successes,
                        *min_onl = delta;
                if (*max_onl < delta)
                        *max_onl = delta;
+               WRITE_ONCE(torture_online_cpus, torture_online_cpus + 1);
        }
 
        return true;
 }
 EXPORT_SYMBOL_GPL(torture_online);
 
+/*
+ * Get everything online at the beginning and ends of tests.
+ */
+static void torture_online_all(char *phase)
+{
+       int cpu;
+       int ret;
+
+       for_each_possible_cpu(cpu) {
+               if (cpu_online(cpu))
+                       continue;
+               ret = add_cpu(cpu);
+               if (ret && verbose) {
+                       pr_alert("%s" TORTURE_FLAG
+                                "%s: %s online %d: errno %d\n",
+                                __func__, phase, torture_type, cpu, ret);
+               }
+       }
+}
+
 /*
  * Execute random CPU-hotplug operations at the interval specified
  * by the onoff_interval.
@@ -206,25 +337,12 @@ torture_onoff(void *arg)
        int cpu;
        int maxcpu = -1;
        DEFINE_TORTURE_RANDOM(rand);
-       int ret;
 
        VERBOSE_TOROUT_STRING("torture_onoff task started");
        for_each_online_cpu(cpu)
                maxcpu = cpu;
        WARN_ON(maxcpu < 0);
-       if (!IS_MODULE(CONFIG_TORTURE_TEST)) {
-               for_each_possible_cpu(cpu) {
-                       if (cpu_online(cpu))
-                               continue;
-                       ret = add_cpu(cpu);
-                       if (ret && verbose) {
-                               pr_alert("%s" TORTURE_FLAG
-                                        "%s: Initial online %d: errno %d\n",
-                                        __func__, torture_type, cpu, ret);
-                       }
-               }
-       }
-
+       torture_online_all("Initial");
        if (maxcpu == 0) {
                VERBOSE_TOROUT_STRING("Only one CPU, so CPU-hotplug testing is disabled");
                goto stop;
@@ -252,6 +370,7 @@ torture_onoff(void *arg)
 
 stop:
        torture_kthread_stopping("torture_onoff");
+       torture_online_all("Final");
        return 0;
 }
 
@@ -602,7 +721,6 @@ static int stutter_gap;
  */
 bool stutter_wait(const char *title)
 {
-       ktime_t delay;
        unsigned int i = 0;
        bool ret = false;
        int spt;
@@ -618,11 +736,8 @@ bool stutter_wait(const char *title)
                        schedule_timeout_interruptible(1);
                } else if (spt == 2) {
                        while (READ_ONCE(stutter_pause_test)) {
-                               if (!(i++ & 0xffff)) {
-                                       set_current_state(TASK_INTERRUPTIBLE);
-                                       delay = 10 * NSEC_PER_USEC;
-                                       schedule_hrtimeout(&delay, HRTIMER_MODE_REL);
-                               }
+                               if (!(i++ & 0xffff))
+                                       torture_hrtimeout_us(10, 0, NULL);
                                cond_resched();
                        }
                } else {
@@ -640,7 +755,6 @@ EXPORT_SYMBOL_GPL(stutter_wait);
  */
 static int torture_stutter(void *arg)
 {
-       ktime_t delay;
        DEFINE_TORTURE_RANDOM(rand);
        int wtime;
 
@@ -651,20 +765,15 @@ static int torture_stutter(void *arg)
                        if (stutter > 2) {
                                WRITE_ONCE(stutter_pause_test, 1);
                                wtime = stutter - 3;
-                               delay = ktime_divns(NSEC_PER_SEC * wtime, HZ);
-                               delay += (torture_random(&rand) >> 3) % NSEC_PER_MSEC;
-                               set_current_state(TASK_INTERRUPTIBLE);
-                               schedule_hrtimeout(&delay, HRTIMER_MODE_REL);
+                               torture_hrtimeout_jiffies(wtime, &rand);
                                wtime = 2;
                        }
                        WRITE_ONCE(stutter_pause_test, 2);
-                       delay = ktime_divns(NSEC_PER_SEC * wtime, HZ);
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_hrtimeout(&delay, HRTIMER_MODE_REL);
+                       torture_hrtimeout_jiffies(wtime, NULL);
                }
                WRITE_ONCE(stutter_pause_test, 0);
                if (!torture_must_stop())
-                       schedule_timeout_interruptible(stutter_gap);
+                       torture_hrtimeout_jiffies(stutter_gap, NULL);
                torture_shutdown_absorb("torture_stutter");
        } while (!torture_must_stop());
        torture_kthread_stopping("torture_stutter");
index e59eda07305e61481beef67dd2122d31f3718d3c..a1071cdefb5aa4e629493ae1f32c7a15422a695b 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/sched.h>
 #include <linux/wait.h>
 #include <linux/slab.h>
+#include <linux/mm.h>
 #include <linux/percpu-refcount.h>
 
 /*
@@ -168,6 +169,7 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head *rcu)
                        struct percpu_ref_data, rcu);
        struct percpu_ref *ref = data->ref;
        unsigned long __percpu *percpu_count = percpu_count_ptr(ref);
+       static atomic_t underflows;
        unsigned long count = 0;
        int cpu;
 
@@ -191,9 +193,13 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head *rcu)
         */
        atomic_long_add((long)count - PERCPU_COUNT_BIAS, &data->count);
 
-       WARN_ONCE(atomic_long_read(&data->count) <= 0,
-                 "percpu ref (%ps) <= 0 (%ld) after switching to atomic",
-                 data->release, atomic_long_read(&data->count));
+       if (WARN_ONCE(atomic_long_read(&data->count) <= 0,
+                     "percpu ref (%ps) <= 0 (%ld) after switching to atomic",
+                     data->release, atomic_long_read(&data->count)) &&
+           atomic_inc_return(&underflows) < 4) {
+               pr_err("%s(): percpu_ref underflow", __func__);
+               mem_dump_obj(data);
+       }
 
        /* @ref is viewed as dead on all CPUs, send out switch confirmation */
        percpu_ref_call_confirm_rcu(rcu);
index d7c8da9319c782f5dd4f20179e65c696526dc854..dcc55e78f3534a97682b173ea3ed2506d1bafbfb 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3635,6 +3635,26 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t flags,
 EXPORT_SYMBOL(__kmalloc_node_track_caller);
 #endif /* CONFIG_NUMA */
 
+void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
+{
+       struct kmem_cache *cachep;
+       unsigned int objnr;
+       void *objp;
+
+       kpp->kp_ptr = object;
+       kpp->kp_page = page;
+       cachep = page->slab_cache;
+       kpp->kp_slab_cache = cachep;
+       objp = object - obj_offset(cachep);
+       kpp->kp_data_offset = obj_offset(cachep);
+       page = virt_to_head_page(objp);
+       objnr = obj_to_index(cachep, page, objp);
+       objp = index_to_obj(cachep, page, objnr);
+       kpp->kp_objp = objp;
+       if (DEBUG && cachep->flags & SLAB_STORE_USER)
+               kpp->kp_ret = *dbg_userword(cachep, objp);
+}
+
 /**
  * __do_kmalloc - allocate memory
  * @size: how many bytes of memory are required.
index 1a756a359fa8b7ea4291910c3a5988607569ae8c..ecad9b57bc441dad3719677ba63bdb5e560a64e0 100644 (file)
--- a/mm/slab.h
+++ b/mm/slab.h
@@ -615,4 +615,16 @@ static inline bool slab_want_init_on_free(struct kmem_cache *c)
        return false;
 }
 
+#define KS_ADDRS_COUNT 16
+struct kmem_obj_info {
+       void *kp_ptr;
+       struct page *kp_page;
+       void *kp_objp;
+       unsigned long kp_data_offset;
+       struct kmem_cache *kp_slab_cache;
+       void *kp_ret;
+       void *kp_stack[KS_ADDRS_COUNT];
+};
+void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);
+
 #endif /* MM_SLAB_H */
index e981c80d216c276907487d7765297871e6e0a7e3..adbace4256efb9adb53678d9062631c53132582a 100644 (file)
@@ -537,6 +537,81 @@ bool slab_is_available(void)
        return slab_state >= UP;
 }
 
+/**
+ * kmem_valid_obj - does the pointer reference a valid slab object?
+ * @object: pointer to query.
+ *
+ * Return: %true if the pointer is to a not-yet-freed object from
+ * kmalloc() or kmem_cache_alloc(), either %true or %false if the pointer
+ * is to an already-freed object, and %false otherwise.
+ */
+bool kmem_valid_obj(void *object)
+{
+       struct page *page;
+
+       /* Some arches consider ZERO_SIZE_PTR to be a valid address. */
+       if (object < (void *)PAGE_SIZE || !virt_addr_valid(object))
+               return false;
+       page = virt_to_head_page(object);
+       return PageSlab(page);
+}
+
+/**
+ * kmem_dump_obj - Print available slab provenance information
+ * @object: slab object for which to find provenance information.
+ *
+ * This function uses pr_cont(), so that the caller is expected to have
+ * printed out whatever preamble is appropriate.  The provenance information
+ * depends on the type of object and on how much debugging is enabled.
+ * For a slab-cache object, the fact that it is a slab object is printed,
+ * and, if available, the slab name, return address, and stack trace from
+ * the allocation of that object.
+ *
+ * This function will splat if passed a pointer to a non-slab object.
+ * If you are not sure what type of object you have, you should instead
+ * use mem_dump_obj().
+ */
+void kmem_dump_obj(void *object)
+{
+       char *cp = IS_ENABLED(CONFIG_MMU) ? "" : "/vmalloc";
+       int i;
+       struct page *page;
+       unsigned long ptroffset;
+       struct kmem_obj_info kp = { };
+
+       if (WARN_ON_ONCE(!virt_addr_valid(object)))
+               return;
+       page = virt_to_head_page(object);
+       if (WARN_ON_ONCE(!PageSlab(page))) {
+               pr_cont(" non-slab memory.\n");
+               return;
+       }
+       kmem_obj_info(&kp, object, page);
+       if (kp.kp_slab_cache)
+               pr_cont(" slab%s %s", cp, kp.kp_slab_cache->name);
+       else
+               pr_cont(" slab%s", cp);
+       if (kp.kp_objp)
+               pr_cont(" start %px", kp.kp_objp);
+       if (kp.kp_data_offset)
+               pr_cont(" data offset %lu", kp.kp_data_offset);
+       if (kp.kp_objp) {
+               ptroffset = ((char *)object - (char *)kp.kp_objp) - kp.kp_data_offset;
+               pr_cont(" pointer offset %lu", ptroffset);
+       }
+       if (kp.kp_slab_cache && kp.kp_slab_cache->usersize)
+               pr_cont(" size %u", kp.kp_slab_cache->usersize);
+       if (kp.kp_ret)
+               pr_cont(" allocated at %pS\n", kp.kp_ret);
+       else
+               pr_cont("\n");
+       for (i = 0; i < ARRAY_SIZE(kp.kp_stack); i++) {
+               if (!kp.kp_stack[i])
+                       break;
+               pr_info("    %pS\n", kp.kp_stack[i]);
+       }
+}
+
 #ifndef CONFIG_SLOB
 /* Create a cache during boot when no slab services are available yet */
 void __init create_boot_cache(struct kmem_cache *s, const char *name,
index 8d4bfa46247f47e4d8e870f0d11c9e4d99bb88ad..ef87ada8705d8d1fa5e264d74744a87c3743bb07 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -461,6 +461,12 @@ out:
        spin_unlock_irqrestore(&slob_lock, flags);
 }
 
+void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
+{
+       kpp->kp_ptr = object;
+       kpp->kp_page = page;
+}
+
 /*
  * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
  */
index 0c8b43a5b3b0339820c891cb9cde893387e03b13..3c1a84316fd7dcf467c5b1b32bc145ded994b3f1 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3919,6 +3919,46 @@ int __kmem_cache_shutdown(struct kmem_cache *s)
        return 0;
 }
 
+void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
+{
+       void *base;
+       int __maybe_unused i;
+       unsigned int objnr;
+       void *objp;
+       void *objp0;
+       struct kmem_cache *s = page->slab_cache;
+       struct track __maybe_unused *trackp;
+
+       kpp->kp_ptr = object;
+       kpp->kp_page = page;
+       kpp->kp_slab_cache = s;
+       base = page_address(page);
+       objp0 = kasan_reset_tag(object);
+#ifdef CONFIG_SLUB_DEBUG
+       objp = restore_red_left(s, objp0);
+#else
+       objp = objp0;
+#endif
+       objnr = obj_to_index(s, page, objp);
+       kpp->kp_data_offset = (unsigned long)((char *)objp0 - (char *)objp);
+       objp = base + s->size * objnr;
+       kpp->kp_objp = objp;
+       if (WARN_ON_ONCE(objp < base || objp >= base + page->objects * s->size || (objp - base) % s->size) ||
+           !(s->flags & SLAB_STORE_USER))
+               return;
+#ifdef CONFIG_SLUB_DEBUG
+       trackp = get_track(s, objp, TRACK_ALLOC);
+       kpp->kp_ret = (void *)trackp->addr;
+#ifdef CONFIG_STACKTRACE
+       for (i = 0; i < KS_ADDRS_COUNT && i < TRACK_ADDRS_COUNT; i++) {
+               kpp->kp_stack[i] = (void *)trackp->addrs[i];
+               if (!kpp->kp_stack[i])
+                       break;
+       }
+#endif
+#endif
+}
+
 /********************************************************************
  *             Kmalloc subsystem
  *******************************************************************/
index 8c9b7d1e7c499828c429b93853af28e7299edcc1..54870226cea64aa36e253b1c1f196e9c8ec58c2a 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -982,3 +982,34 @@ int __weak memcmp_pages(struct page *page1, struct page *page2)
        kunmap_atomic(addr1);
        return ret;
 }
+
+/**
+ * mem_dump_obj - Print available provenance information
+ * @object: object for which to find provenance information.
+ *
+ * This function uses pr_cont(), so that the caller is expected to have
+ * printed out whatever preamble is appropriate.  The provenance information
+ * depends on the type of object and on how much debugging is enabled.
+ * For example, for a slab-cache object, the slab name is printed, and,
+ * if available, the return address and stack trace from the allocation
+ * of that object.
+ */
+void mem_dump_obj(void *object)
+{
+       if (kmem_valid_obj(object)) {
+               kmem_dump_obj(object);
+               return;
+       }
+       if (vmalloc_dump_obj(object))
+               return;
+       if (!virt_addr_valid(object)) {
+               if (object == NULL)
+                       pr_cont(" NULL pointer.\n");
+               else if (object == ZERO_SIZE_PTR)
+                       pr_cont(" zero-size pointer.\n");
+               else
+                       pr_cont(" non-paged memory.\n");
+               return;
+       }
+       pr_cont(" non-slab/vmalloc memory.\n");
+}
index 4d88fe5a277ac2d0e520f37f4dc7ec0a779fc9fe..e3229ff627ea06523a2771de7308ced4f25ca78c 100644 (file)
@@ -3448,6 +3448,19 @@ void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
 }
 #endif /* CONFIG_SMP */
 
+bool vmalloc_dump_obj(void *object)
+{
+       struct vm_struct *vm;
+       void *objp = (void *)PAGE_ALIGN((unsigned long)object);
+
+       vm = find_vm_area(objp);
+       if (!vm)
+               return false;
+       pr_cont(" %u-page vmalloc region starting at %#lx allocated at %pS\n",
+               vm->nr_pages, (unsigned long)vm->addr, vm->caller);
+       return true;
+}
+
 #ifdef CONFIG_PROC_FS
 static void *s_start(struct seq_file *m, loff_t *pos)
        __acquires(&vmap_purge_lock)
diff --git a/tools/testing/selftests/rcutorture/bin/config2csv.sh b/tools/testing/selftests/rcutorture/bin/config2csv.sh
new file mode 100755 (executable)
index 0000000..d5a1663
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Create a spreadsheet from torture-test Kconfig options and kernel boot
+# parameters.  Run this in the directory containing the scenario files.
+#
+# Usage: config2csv path.csv [ "scenario1 scenario2 ..." ]
+#
+# By default, this script will take the list of scenarios from the CFLIST
+# file in that directory, otherwise it will consider only the scenarios
+# specified on the command line.  It will examine each scenario's file
+# and also its .boot file, if present, and create a column in the .csv
+# output file.  Note that "CFLIST" is a synonym for all the scenarios in the
+# CFLIST file, which allows easy comparison of those scenarios with selected
+# scenarios such as BUSTED that are normally omitted from CFLIST files.
+
+csvout=${1}
+if test -z "$csvout"
+then
+       echo "Need .csv output file as first argument."
+       exit 1
+fi
+shift
+defaultconfigs="`tr '\012' ' ' < CFLIST`"
+if test "$#" -eq 0
+then
+       scenariosarg=$defaultconfigs
+else
+       scenariosarg=$*
+fi
+scenarios="`echo $scenariosarg | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
+
+T=/tmp/config2latex.sh.$$
+trap 'rm -rf $T' 0
+mkdir $T
+
+cat << '---EOF---' >> $T/p.awk
+END    {
+---EOF---
+for i in $scenarios
+do
+       echo '  s["'$i'"] = 1;' >> $T/p.awk
+       grep -v '^#' < $i | grep -v '^ *$' > $T/p
+       if test -r $i.boot
+       then
+               tr -s ' ' '\012' < $i.boot | grep -v '^#' >> $T/p
+       fi
+       sed -e 's/^[^=]*$/&=?/' < $T/p |
+       sed -e 's/^\([^=]*\)=\(.*\)$/\tp["\1:'"$i"'"] = "\2";\n\tc["\1"] = 1;/' >> $T/p.awk
+done
+cat << '---EOF---' >> $T/p.awk
+       ns = asorti(s, ss);
+       nc = asorti(c, cs);
+       for (j = 1; j <= ns; j++)
+               printf ",\"%s\"", ss[j];
+       printf "\n";
+       for (i = 1; i <= nc; i++) {
+               printf "\"%s\"", cs[i];
+               for (j = 1; j <= ns; j++) {
+                       printf ",\"%s\"", p[cs[i] ":" ss[j]];
+               }
+               printf "\n";
+       }
+}
+---EOF---
+awk -f $T/p.awk < /dev/null > $T/p.csv
+cp $T/p.csv $csvout
index 80ae7f08b363e4bfd2fa323b0ba05e4c21c5b127..e6a132df6172175c342070317ca327178d578bfa 100755 (executable)
@@ -14,4 +14,5 @@ egrep 'Badness|WARNING:|Warn|BUG|===========|Call Trace:|Oops:|detected stalls o
 grep -v 'ODEBUG: ' |
 grep -v 'This means that this is a DEBUG kernel and it is' |
 grep -v 'Warning: unable to open an initial console' |
+grep -v 'Warning: Failed to add ttynull console. No stdin, stdout, and stderr.*the init process!' |
 grep -v 'NOHZ tick-stop error: Non-RCU local softirq work is pending, handler'
index 82663495fb383149db32c0e45e25db32f4af35f4..c35ba24f994c36b82b94e7536d8715fc677b599c 100644 (file)
@@ -108,6 +108,39 @@ configfrag_hotplug_cpu () {
        grep -q '^CONFIG_HOTPLUG_CPU=y$' "$1"
 }
 
+# get_starttime
+#
+# Returns a cookie identifying the current time.
+get_starttime () {
+       awk 'BEGIN { print systime() }' < /dev/null
+}
+
+# get_starttime_duration starttime
+#
+# Given the return value from get_starttime, compute a human-readable
+# string denoting the time since get_starttime.
+get_starttime_duration () {
+       awk -v starttime=$1 '
+       BEGIN {
+               ts = systime() - starttime; 
+               tm = int(ts / 60);
+               th = int(ts / 3600);
+               td = int(ts / 86400);
+               d = td;
+               h = th - td * 24;
+               m = tm - th * 60;
+               s = ts - tm * 60;
+               if (d >= 1)
+                       printf "%dd %d:%02d:%02d\n", d, h, m, s
+               else if (h >= 1)
+                       printf "%d:%02d:%02d\n", h, m, s
+               else if (m >= 1)
+                       printf "%d:%02d.0\n", m, s
+               else
+                       print s " seconds"
+       }' < /dev/null
+}
+
 # identify_boot_image qemu-cmd
 #
 # Returns the relative path to the kernel build image.  This will be
@@ -170,6 +203,7 @@ identify_qemu () {
 # and the TORTURE_QEMU_INTERACTIVE environment variable.
 identify_qemu_append () {
        echo debug_boot_weak_hash
+       echo panic=-1
        local console=ttyS0
        case "$1" in
        qemu-system-x86_64|qemu-system-i386)
@@ -232,7 +266,7 @@ identify_qemu_args () {
 # Returns the number of virtual CPUs available to the aggregate of the
 # guest OSes.
 identify_qemu_vcpus () {
-       lscpu | grep '^CPU(s):' | sed -e 's/CPU(s)://' -e 's/[  ]*//g'
+       getconf _NPROCESSORS_ONLN
 }
 
 # print_bug
index 6f50722f251f8955412e9e8e92464fa2f8192f31..0670841122d8a0fc9feb74e1534b2fd03dc21cef 100755 (executable)
@@ -39,12 +39,14 @@ done
 if test -n "$files"
 then
        $editor $files
+       editorret=1
 else
        echo No build errors.
 fi
 if grep -q -e "--buildonly" < ${rundir}/log
 then
        echo Build-only run, no console logs to check.
+       exit $editorret
 fi
 
 # Find console logs with errors
@@ -62,5 +64,10 @@ then
        exit 1
 else
        echo No errors in console logs.
-       exit 0
+       if test -n "$editorret"
+       then
+               exit $editorret
+       else
+               exit 0
+       fi
 fi
index 840a4679a0d78ba4e8175dec5e9ff47cfe445cb2..47cf4db10896cacdfcf2265e01a327082e57476c 100755 (executable)
@@ -87,15 +87,16 @@ do
        fi
 done
 EDITOR=echo kvm-find-errors.sh "${@: -1}" > $T 2>&1
-ret=$?
 builderrors="`tr ' ' '\012' < $T | grep -c '/Make.out.diags'`"
 if test "$builderrors" -gt 0
 then
        echo $builderrors runs with build errors.
+       ret=1
 fi
 runerrors="`tr ' ' '\012' < $T | grep -c '/console.log.diags'`"
 if test "$runerrors" -gt 0
 then
        echo $runerrors runs with runtime errors.
+       ret=2
 fi
 exit $ret
index 3cd03d01857cff221638956219e11e2c4c209a82..536d103ef1667f16a296c58d4c719d57873a69a8 100755 (executable)
@@ -125,7 +125,6 @@ seconds=$4
 qemu_args=$5
 boot_args=$6
 
-kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
 if test -z "$TORTURE_BUILDONLY"
 then
        echo ' ---' `date`: Starting kernel
@@ -158,6 +157,8 @@ then
        boot_args="$boot_args $TORTURE_BOOT_GDB_ARG"
 fi
 echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd
+echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd
+echo "# seconds=$seconds" >> $resdir/qemu-cmd
 
 if test -n "$TORTURE_BUILDONLY"
 then
@@ -174,6 +175,7 @@ echo 'echo $! > $resdir/qemu_pid' >> $T/qemu-cmd
 echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
 
 # Attempt to run qemu
+kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
 ( . $T/qemu-cmd; wait `cat  $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) &
 commandcompleted=0
 if test -z "$TORTURE_KCONFIG_GDB_ARG"
@@ -209,7 +211,7 @@ do
                if test -n "$TORTURE_KCONFIG_GDB_ARG"
                then
                        :
-               elif test $kruntime -ge $seconds || test -f "$TORTURE_STOPFILE"
+               elif test $kruntime -ge $seconds || test -f "$resdir/../STOP.1"
                then
                        break;
                fi
@@ -252,16 +254,16 @@ then
 fi
 if test $commandcompleted -eq 0 -a -n "$qemu_pid"
 then
-       if ! test -f "$TORTURE_STOPFILE"
+       if ! test -f "$resdir/../STOP.1"
        then
                echo Grace period for qemu job at pid $qemu_pid
        fi
        oldline="`tail $resdir/console.log`"
        while :
        do
-               if test -f "$TORTURE_STOPFILE"
+               if test -f "$resdir/../STOP.1"
                then
-                       echo "PID $qemu_pid killed due to run STOP request" >> $resdir/Warnings 2>&1
+                       echo "PID $qemu_pid killed due to run STOP.1 request" >> $resdir/Warnings 2>&1
                        kill -KILL $qemu_pid
                        break
                fi
index 45d07b7b69f5954fae076e82403fb112b95136ec..8d3c99b35e06032da71711b0f2b7d3d141da61a2 100755 (executable)
@@ -47,6 +47,9 @@ cpus=0
 ds=`date +%Y.%m.%d-%H.%M.%S`
 jitter="-1"
 
+startdate="`date`"
+starttime="`get_starttime`"
+
 usage () {
        echo "Usage: $scriptname optional arguments:"
        echo "       --allcpus"
@@ -57,7 +60,7 @@ usage () {
        echo "       --cpus N"
        echo "       --datestamp string"
        echo "       --defconfig string"
-       echo "       --dryrun sched|script"
+       echo "       --dryrun batches|sched|script"
        echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
        echo "       --gdb"
        echo "       --help"
@@ -85,7 +88,7 @@ do
                ;;
        --bootargs|--bootarg)
                checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
-               TORTURE_BOOTARGS="$2"
+               TORTURE_BOOTARGS="$TORTURE_BOOTARGS $2"
                shift
                ;;
        --bootimage)
@@ -97,8 +100,8 @@ do
                TORTURE_BUILDONLY=1
                ;;
        --configs|--config)
-               checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
-               configs="$2"
+               checkarg --configs "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
+               configs="$configs $2"
                shift
                ;;
        --cpus)
@@ -113,7 +116,7 @@ do
                shift
                ;;
        --datestamp)
-               checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
+               checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._-/]*$' '^--'
                ds=$2
                shift
                ;;
@@ -123,7 +126,7 @@ do
                shift
                ;;
        --dryrun)
-               checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
+               checkarg --dryrun "batches|sched|script" $# "$2" 'batches\|sched\|script' '^--'
                dryrun=$2
                shift
                ;;
@@ -162,18 +165,18 @@ do
                ;;
        --kconfig|--kconfigs)
                checkarg --kconfig "(Kconfig options)" $# "$2" '^CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\( CONFIG_[A-Z0-9_]\+=\([ynm]\|[0-9]\+\)\)*$' '^error$'
-               TORTURE_KCONFIG_ARG="$2"
+               TORTURE_KCONFIG_ARG="`echo "$TORTURE_KCONFIG_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
                shift
                ;;
        --kasan)
                TORTURE_KCONFIG_KASAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KASAN=y"; export TORTURE_KCONFIG_KASAN_ARG
                ;;
        --kcsan)
-               TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_VERBOSE=y CONFIG_KCSAN_INTERRUPT_WATCHER=y"; export TORTURE_KCONFIG_KCSAN_ARG
+               TORTURE_KCONFIG_KCSAN_ARG="CONFIG_DEBUG_INFO=y CONFIG_KCSAN=y CONFIG_KCSAN_ASSUME_PLAIN_WRITES_ATOMIC=n CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY=n CONFIG_KCSAN_REPORT_ONCE_IN_MS=100000 CONFIG_KCSAN_INTERRUPT_WATCHER=y CONFIG_KCSAN_VERBOSE=y CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y"; export TORTURE_KCONFIG_KCSAN_ARG
                ;;
        --kmake-arg|--kmake-args)
                checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
-               TORTURE_KMAKE_ARG="$2"
+               TORTURE_KMAKE_ARG="`echo "$TORTURE_KMAKE_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
                shift
                ;;
        --mac)
@@ -191,7 +194,7 @@ do
                ;;
        --qemu-args|--qemu-arg)
                checkarg --qemu-args "(qemu arguments)" $# "$2" '^-' '^error'
-               TORTURE_QEMU_ARG="$2"
+               TORTURE_QEMU_ARG="`echo "$TORTURE_QEMU_ARG $2" | sed -e 's/^ *//' -e 's/ *$//'`"
                shift
                ;;
        --qemu-cmd)
@@ -232,7 +235,7 @@ do
        shift
 done
 
-if test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
+if test -n "$dryrun" || test -z "$TORTURE_INITRD" || tools/testing/selftests/rcutorture/bin/mkinitrd.sh
 then
        :
 else
@@ -283,19 +286,34 @@ then
                exit 1
        fi
 fi
-for CF1 in $configs_derep
+echo 'BEGIN {' > $T/cfgcpu.awk
+for CF1 in `echo $configs_derep | tr -s ' ' '\012' | sort -u`
 do
        if test -f "$CONFIGFRAG/$CF1"
        then
-               cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
+               if echo "$TORTURE_KCONFIG_ARG" | grep -q '\<CONFIG_NR_CPUS='
+               then
+                       echo "$TORTURE_KCONFIG_ARG" | tr -s ' ' | tr ' ' '\012' > $T/KCONFIG_ARG
+                       cpu_count=`configNR_CPUS.sh $T/KCONFIG_ARG`
+               else
+                       cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
+               fi
                cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
                cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
-               echo $CF1 $cpu_count >> $T/cfgcpu
+               echo 'scenariocpu["'"$CF1"'"] = '"$cpu_count"';' >> $T/cfgcpu.awk
        else
                echo "The --configs file $CF1 does not exist, terminating."
                exit 1
        fi
 done
+cat << '___EOF___' >> $T/cfgcpu.awk
+}
+{
+       for (i = 1; i <= NF; i++)
+               print $i, scenariocpu[$i];
+}
+___EOF___
+echo $configs_derep | awk -f $T/cfgcpu.awk > $T/cfgcpu
 sort -k2nr $T/cfgcpu -T="$T" > $T/cfgcpu.sort
 
 # Use a greedy bin-packing algorithm, sorting the list accordingly.
@@ -315,11 +333,10 @@ END {
        batch = 0;
        nc = -1;
 
-       # Each pass through the following loop creates on test batch
-       # that can be executed concurrently given ncpus.  Note that a
-       # given test that requires more than the available CPUs will run in
-       # their own batch.  Such tests just have to make do with what
-       # is available.
+       # Each pass through the following loop creates on test batch that
+       # can be executed concurrently given ncpus.  Note that a given test
+       # that requires more than the available CPUs will run in its own
+       # batch.  Such tests just have to make do with what is available.
        while (nc != ncpus) {
                batch++;
                nc = ncpus;
@@ -375,9 +392,9 @@ if ! test -e $resdir
 then
        mkdir -p "$resdir" || :
 fi
-mkdir $resdir/$ds
+mkdir -p $resdir/$ds
 TORTURE_RESDIR="$resdir/$ds"; export TORTURE_RESDIR
-TORTURE_STOPFILE="$resdir/$ds/STOP"; export TORTURE_STOPFILE
+TORTURE_STOPFILE="$resdir/$ds/STOP.1"; export TORTURE_STOPFILE
 echo Results directory: $resdir/$ds
 echo $scriptname $args
 touch $resdir/$ds/log
@@ -517,14 +534,19 @@ END {
                dump(first, i, batchnum);
 }' >> $T/script
 
+cat << '___EOF___' >> $T/script
+echo | tee -a $TORTURE_RESDIR/log
+echo | tee -a $TORTURE_RESDIR/log
+echo " --- `date` Test summary:" | tee -a $TORTURE_RESDIR/log
+___EOF___
 cat << ___EOF___ >> $T/script
-echo
-echo
-echo " --- `date` Test summary:"
-echo Results directory: $resdir/$ds
-kcsan-collapse.sh $resdir/$ds
-kvm-recheck.sh $resdir/$ds
+echo Results directory: $resdir/$ds | tee -a $resdir/$ds/log
+kcsan-collapse.sh $resdir/$ds | tee -a $resdir/$ds/log
+kvm-recheck.sh $resdir/$ds > $T/kvm-recheck.sh.out 2>&1
 ___EOF___
+echo 'ret=$?' >> $T/script
+echo "cat $T/kvm-recheck.sh.out | tee -a $resdir/$ds/log" >> $T/script
+echo 'exit $ret' >> $T/script
 
 if test "$dryrun" = script
 then
@@ -533,13 +555,34 @@ then
 elif test "$dryrun" = sched
 then
        # Extract the test run schedule from the script.
-       egrep 'Start batch|Starting build\.' $T/script |
-               grep -v ">>" |
+       egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
                sed -e 's/:.*$//' -e 's/^echo //'
+       nbuilds="`grep 'Starting build\.' $T/script |
+                 grep -v ">>" | sed -e 's/:.*$//' -e 's/^echo //' |
+                 awk '{ print $1 }' | grep -v '\.' | wc -l`"
+       echo Total number of builds: $nbuilds
+       nbatches="`grep 'Start batch' $T/script | grep -v ">>" | wc -l`"
+       echo Total number of batches: $nbatches
        exit 0
+elif test "$dryrun" = batches
+then
+       # Extract the tests and their batches from the script.
+       egrep 'Start batch|Starting build\.' $T/script | grep -v ">>" |
+               sed -e 's/:.*$//' -e 's/^echo //' -e 's/-ovf//' |
+               awk '
+               /^----Start/ {
+                       batchno = $3;
+                       next;
+               }
+               {
+                       print batchno, $1, $2
+               }'
 else
        # Not a dryrun, so run the script.
-       sh $T/script
+       bash $T/script
+       ret=$?
+       echo " --- Done at `date` (`get_starttime_duration $starttime`) exitcode $ret" | tee -a $resdir/$ds/log
+       exit $ret
 fi
 
 # Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier
index 09155c15ea651549d8958a0fa52db9ff67f6f758..9313e5065ae923bb1612ed4be7e14e89bff163ef 100755 (executable)
@@ -21,7 +21,7 @@ mkdir $T
 
 . functions.sh
 
-if grep -q CC < $F || test -n "$TORTURE_TRUST_MAKE"
+if grep -q CC < $F || test -n "$TORTURE_TRUST_MAKE" || grep -qe --trust-make < `dirname $F`/../log
 then
        :
 else
index 263b1be5000802d015bc1753593fe3c0d2695c95..9f624bd53c27739ec631b14fd98cf56d1a251d46 100755 (executable)
@@ -128,7 +128,7 @@ then
        then
                summary="$summary  Badness: $n_badness"
        fi
-       n_warn=`grep -v 'Warning: unable to open an initial console' $file | egrep -c 'WARNING:|Warn'`
+       n_warn=`grep -v 'Warning: unable to open an initial console' $file | grep -v 'Warning: Failed to add ttynull console. No stdin, stdout, and stderr for the init process' | egrep -c 'WARNING:|Warn'`
        if test "$n_warn" -ne 0
        then
                summary="$summary  Warnings: $n_warn"
diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh b/tools/testing/selftests/rcutorture/bin/torture.sh
new file mode 100755 (executable)
index 0000000..ad7525b
--- /dev/null
@@ -0,0 +1,442 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Run a series of torture tests, intended for overnight or
+# longer timeframes, and also for large systems.
+#
+# Usage: torture.sh [ options ]
+#
+# Copyright (C) 2020 Facebook, Inc.
+#
+# Authors: Paul E. McKenney <paulmck@kernel.org>
+
+scriptname=$0
+args="$*"
+
+KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
+PATH=${KVM}/bin:$PATH; export PATH
+. functions.sh
+
+TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
+MAKE_ALLOTED_CPUS=$((TORTURE_ALLOTED_CPUS*2))
+HALF_ALLOTED_CPUS=$((TORTURE_ALLOTED_CPUS/2))
+if test "$HALF_ALLOTED_CPUS" -lt 1
+then
+       HALF_ALLOTED_CPUS=1
+fi
+VERBOSE_BATCH_CPUS=$((TORTURE_ALLOTED_CPUS/16))
+if test "$VERBOSE_BATCH_CPUS" -lt 2
+then
+       VERBOSE_BATCH_CPUS=0
+fi
+
+# Configurations/scenarios.
+configs_rcutorture=
+configs_locktorture=
+configs_scftorture=
+kcsan_kmake_args=
+
+# Default compression, duration, and apportionment.
+compress_kasan_vmlinux="`identify_qemu_vcpus`"
+duration_base=10
+duration_rcutorture_frac=7
+duration_locktorture_frac=1
+duration_scftorture_frac=2
+
+# "yes" or "no" parameters
+do_allmodconfig=yes
+do_rcutorture=yes
+do_locktorture=yes
+do_scftorture=yes
+do_rcuscale=yes
+do_refscale=yes
+do_kvfree=yes
+do_kasan=yes
+do_kcsan=no
+
+# doyesno - Helper function for yes/no arguments
+function doyesno () {
+       if test "$1" = "$2"
+       then
+               echo yes
+       else
+               echo no
+       fi
+}
+
+usage () {
+       echo "Usage: $scriptname optional arguments:"
+       echo "       --compress-kasan-vmlinux concurrency"
+       echo "       --configs-rcutorture \"config-file list w/ repeat factor (3*TINY01)\""
+       echo "       --configs-locktorture \"config-file list w/ repeat factor (10*LOCK01)\""
+       echo "       --configs-scftorture \"config-file list w/ repeat factor (2*CFLIST)\""
+       echo "       --doall"
+       echo "       --doallmodconfig / --do-no-allmodconfig"
+       echo "       --do-kasan / --do-no-kasan"
+       echo "       --do-kcsan / --do-no-kcsan"
+       echo "       --do-kvfree / --do-no-kvfree"
+       echo "       --do-locktorture / --do-no-locktorture"
+       echo "       --do-none"
+       echo "       --do-rcuscale / --do-no-rcuscale"
+       echo "       --do-rcutorture / --do-no-rcutorture"
+       echo "       --do-refscale / --do-no-refscale"
+       echo "       --do-scftorture / --do-no-scftorture"
+       echo "       --duration [ <minutes> | <hours>h | <days>d ]"
+       echo "       --kcsan-kmake-arg kernel-make-arguments"
+       exit 1
+}
+
+while test $# -gt 0
+do
+       case "$1" in
+       --compress-kasan-vmlinux)
+               checkarg --compress-kasan-vmlinux "(concurrency level)" $# "$2" '^[0-9][0-9]*$' '^error'
+               compress_kasan_vmlinux=$2
+               shift
+               ;;
+       --config-rcutorture|--configs-rcutorture)
+               checkarg --configs-rcutorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
+               configs_rcutorture="$configs_rcutorture $2"
+               shift
+               ;;
+       --config-locktorture|--configs-locktorture)
+               checkarg --configs-locktorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
+               configs_locktorture="$configs_locktorture $2"
+               shift
+               ;;
+       --config-scftorture|--configs-scftorture)
+               checkarg --configs-scftorture "(list of config files)" "$#" "$2" '^[^/]\+$' '^--'
+               configs_scftorture="$configs_scftorture $2"
+               shift
+               ;;
+       --doall)
+               do_allmodconfig=yes
+               do_rcutorture=yes
+               do_locktorture=yes
+               do_scftorture=yes
+               do_rcuscale=yes
+               do_refscale=yes
+               do_kvfree=yes
+               do_kasan=yes
+               do_kcsan=yes
+               ;;
+       --do-allmodconfig|--do-no-allmodconfig)
+               do_allmodconfig=`doyesno "$1" --do-allmodconfig`
+               ;;
+       --do-kasan|--do-no-kasan)
+               do_kasan=`doyesno "$1" --do-kasan`
+               ;;
+       --do-kcsan|--do-no-kcsan)
+               do_kcsan=`doyesno "$1" --do-kcsan`
+               ;;
+       --do-kvfree|--do-no-kvfree)
+               do_kvfree=`doyesno "$1" --do-kvfree`
+               ;;
+       --do-locktorture|--do-no-locktorture)
+               do_locktorture=`doyesno "$1" --do-locktorture`
+               ;;
+       --do-none)
+               do_allmodconfig=no
+               do_rcutorture=no
+               do_locktorture=no
+               do_scftorture=no
+               do_rcuscale=no
+               do_refscale=no
+               do_kvfree=no
+               do_kasan=no
+               do_kcsan=no
+               ;;
+       --do-rcuscale|--do-no-rcuscale)
+               do_rcuscale=`doyesno "$1" --do-rcuscale`
+               ;;
+       --do-rcutorture|--do-no-rcutorture)
+               do_rcutorture=`doyesno "$1" --do-rcutorture`
+               ;;
+       --do-refscale|--do-no-refscale)
+               do_refscale=`doyesno "$1" --do-refscale`
+               ;;
+       --do-scftorture|--do-no-scftorture)
+               do_scftorture=`doyesno "$1" --do-scftorture`
+               ;;
+       --duration)
+               checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(m\|h\|d\|\)$' '^error'
+               mult=1
+               if echo "$2" | grep -q 'm$'
+               then
+                       mult=1
+               elif echo "$2" | grep -q 'h$'
+               then
+                       mult=60
+               elif echo "$2" | grep -q 'd$'
+               then
+                       mult=1440
+               fi
+               ts=`echo $2 | sed -e 's/[smhd]$//'`
+               duration_base=$(($ts*mult))
+               shift
+               ;;
+       --kcsan-kmake-arg|--kcsan-kmake-args)
+               checkarg --kcsan-kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
+               kcsan_kmake_args="`echo "$kcsan_kmake_args $2" | sed -e 's/^ *//' -e 's/ *$//'`"
+               shift
+               ;;
+       *)
+               echo Unknown argument $1
+               usage
+               ;;
+       esac
+       shift
+done
+
+ds="`date +%Y.%m.%d-%H.%M.%S`-torture"
+startdate="`date`"
+starttime="`get_starttime`"
+
+T=/tmp/torture.sh.$$
+trap 'rm -rf $T' 0 2
+mkdir $T
+
+echo " --- " $scriptname $args | tee -a $T/log
+echo " --- Results directory: " $ds | tee -a $T/log
+
+# Calculate rcutorture defaults and apportion time
+if test -z "$configs_rcutorture"
+then
+       configs_rcutorture=CFLIST
+fi
+duration_rcutorture=$((duration_base*duration_rcutorture_frac/10))
+if test "$duration_rcutorture" -eq 0
+then
+       echo " --- Zero time for rcutorture, disabling" | tee -a $T/log
+       do_rcutorture=no
+fi
+
+# Calculate locktorture defaults and apportion time
+if test -z "$configs_locktorture"
+then
+       configs_locktorture=CFLIST
+fi
+duration_locktorture=$((duration_base*duration_locktorture_frac/10))
+if test "$duration_locktorture" -eq 0
+then
+       echo " --- Zero time for locktorture, disabling" | tee -a $T/log
+       do_locktorture=no
+fi
+
+# Calculate scftorture defaults and apportion time
+if test -z "$configs_scftorture"
+then
+       configs_scftorture=CFLIST
+fi
+duration_scftorture=$((duration_base*duration_scftorture_frac/10))
+if test "$duration_scftorture" -eq 0
+then
+       echo " --- Zero time for scftorture, disabling" | tee -a $T/log
+       do_scftorture=no
+fi
+
+touch $T/failures
+touch $T/successes
+
+# torture_one - Does a single kvm.sh run.
+#
+# Usage:
+#      torture_bootargs="[ kernel boot arguments ]"
+#      torture_one flavor [ kvm.sh arguments ]
+#
+# Note that "flavor" is an arbitrary string.  Supply --torture if needed.
+# Note that quoting is problematic.  So on the command line, pass multiple
+# values with multiple kvm.sh argument instances.
+function torture_one {
+       local cur_bootargs=
+       local boottag=
+
+       echo " --- $curflavor:" Start `date` | tee -a $T/log
+       if test -n "$torture_bootargs"
+       then
+               boottag="--bootargs"
+               cur_bootargs="$torture_bootargs"
+       fi
+       "$@" $boottag "$cur_bootargs" --datestamp "$ds/results-$curflavor" > $T/$curflavor.out 2>&1
+       retcode=$?
+       resdir="`grep '^Results directory: ' $T/$curflavor.out | tail -1 | sed -e 's/^Results directory: //'`"
+       if test -z "$resdir"
+       then
+               cat $T/$curflavor.out | tee -a $T/log
+               echo retcode=$retcode | tee -a $T/log
+       fi
+       if test "$retcode" == 0
+       then
+               echo "$curflavor($retcode)" $resdir >> $T/successes
+       else
+               echo "$curflavor($retcode)" $resdir >> $T/failures
+       fi
+}
+
+# torture_set - Does a set of tortures with and without KASAN and KCSAN.
+#
+# Usage:
+#      torture_bootargs="[ kernel boot arguments ]"
+#      torture_set flavor [ kvm.sh arguments ]
+#
+# Note that "flavor" is an arbitrary string.  Supply --torture if needed.
+# Note that quoting is problematic.  So on the command line, pass multiple
+# values with multiple kvm.sh argument instances.
+function torture_set {
+       local cur_kcsan_kmake_args=
+       local kcsan_kmake_tag=
+       local flavor=$1
+       shift
+       curflavor=$flavor
+       torture_one "$@"
+       if test "$do_kasan" = "yes"
+       then
+               curflavor=${flavor}-kasan
+               torture_one "$@" --kasan
+       fi
+       if test "$do_kcsan" = "yes"
+       then
+               curflavor=${flavor}-kcsan
+               if test -n "$kcsan_kmake_args"
+               then
+                       kcsan_kmake_tag="--kmake-args"
+                       cur_kcsan_kmake_args="$kcsan_kmake_args"
+               fi
+               torture_one $* --kconfig "CONFIG_DEBUG_LOCK_ALLOC=y CONFIG_PROVE_LOCKING=y" $kcsan_kmake_tag $cur_kcsan_kmake_args --kcsan
+       fi
+}
+
+# make allmodconfig
+if test "$do_allmodconfig" = "yes"
+then
+       echo " --- allmodconfig:" Start `date` | tee -a $T/log
+       amcdir="tools/testing/selftests/rcutorture/res/$ds/allmodconfig"
+       mkdir -p "$amcdir"
+       echo " --- make clean" > "$amcdir/Make.out" 2>&1
+       make -j$MAKE_ALLOTED_CPUS clean >> "$amcdir/Make.out" 2>&1
+       echo " --- make allmodconfig" >> "$amcdir/Make.out" 2>&1
+       make -j$MAKE_ALLOTED_CPUS allmodconfig >> "$amcdir/Make.out" 2>&1
+       echo " --- make " >> "$amcdir/Make.out" 2>&1
+       make -j$MAKE_ALLOTED_CPUS >> "$amcdir/Make.out" 2>&1
+       retcode="$?"
+       echo $retcode > "$amcdir/Make.exitcode"
+       if test "$retcode" == 0
+       then
+               echo "allmodconfig($retcode)" $amcdir >> $T/successes
+       else
+               echo "allmodconfig($retcode)" $amcdir >> $T/failures
+       fi
+fi
+
+# --torture rcu
+if test "$do_rcutorture" = "yes"
+then
+       torture_bootargs="rcupdate.rcu_cpu_stall_suppress_at_boot=1 torture.disable_onoff_at_boot rcupdate.rcu_task_stall_timeout=30000"
+       torture_set "rcutorture" tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration "$duration_rcutorture" --configs "$configs_rcutorture" --trust-make
+fi
+
+if test "$do_locktorture" = "yes"
+then
+       torture_bootargs="torture.disable_onoff_at_boot"
+       torture_set "locktorture" tools/testing/selftests/rcutorture/bin/kvm.sh --torture lock --allcpus --duration "$duration_locktorture" --configs "$configs_locktorture" --trust-make
+fi
+
+if test "$do_scftorture" = "yes"
+then
+       torture_bootargs="scftorture.nthreads=$HALF_ALLOTED_CPUS torture.disable_onoff_at_boot"
+       torture_set "scftorture" tools/testing/selftests/rcutorture/bin/kvm.sh --torture scf --allcpus --duration "$duration_scftorture" --configs "$configs_scftorture" --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --trust-make
+fi
+
+if test "$do_refscale" = yes
+then
+       primlist="`grep '\.name[        ]*=' kernel/rcu/refscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`"
+else
+       primlist=
+fi
+for prim in $primlist
+do
+       torture_bootargs="refscale.scale_type="$prim" refscale.nreaders=$HALF_ALLOTED_CPUS refscale.loops=10000 refscale.holdoff=20 torture.disable_onoff_at_boot"
+       torture_set "refscale-$prim" tools/testing/selftests/rcutorture/bin/kvm.sh --torture refscale --allcpus --duration 5 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --bootargs "verbose_batched=$VERBOSE_BATCH_CPUS torture.verbose_sleep_frequency=8 torture.verbose_sleep_duration=$VERBOSE_BATCH_CPUS" --trust-make
+done
+
+if test "$do_rcuscale" = yes
+then
+       primlist="`grep '\.name[        ]*=' kernel/rcu/rcuscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`"
+else
+       primlist=
+fi
+for prim in $primlist
+do
+       torture_bootargs="rcuscale.scale_type="$prim" rcuscale.nwriters=$HALF_ALLOTED_CPUS rcuscale.holdoff=20 torture.disable_onoff_at_boot"
+       torture_set "rcuscale-$prim" tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus --duration 5 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --trust-make
+done
+
+if test "$do_kvfree" = "yes"
+then
+       torture_bootargs="rcuscale.kfree_rcu_test=1 rcuscale.kfree_nthreads=16 rcuscale.holdoff=20 rcuscale.kfree_loops=10000 torture.disable_onoff_at_boot"
+       torture_set "rcuscale-kvfree" tools/testing/selftests/rcutorture/bin/kvm.sh --torture rcuscale --allcpus --duration 10 --kconfig "CONFIG_NR_CPUS=$HALF_ALLOTED_CPUS" --trust-make
+fi
+
+echo " --- " $scriptname $args
+echo " --- " Done `date` | tee -a $T/log
+ret=0
+nsuccesses=0
+echo SUCCESSES: | tee -a $T/log
+if test -s "$T/successes"
+then
+       cat "$T/successes" | tee -a $T/log
+       nsuccesses="`wc -l "$T/successes" | awk '{ print $1 }'`"
+fi
+nfailures=0
+echo FAILURES: | tee -a $T/log
+if test -s "$T/failures"
+then
+       cat "$T/failures" | tee -a $T/log
+       nfailures="`wc -l "$T/failures" | awk '{ print $1 }'`"
+       ret=2
+fi
+echo Started at $startdate, ended at `date`, duration `get_starttime_duration $starttime`. | tee -a $T/log
+echo Summary: Successes: $nsuccesses Failures: $nfailures. | tee -a $T/log
+tdir="`cat $T/successes $T/failures | head -1 | awk '{ print $NF }' | sed -e 's,/[^/]\+/*$,,'`"
+if test -n "$tdir" && test $compress_kasan_vmlinux -gt 0
+then
+       # KASAN vmlinux files can approach 1GB in size, so compress them.
+       echo Looking for KASAN files to compress: `date` > "$tdir/log-xz" 2>&1
+       find "$tdir" -type d -name '*-kasan' -print > $T/xz-todo
+       ncompresses=0
+       batchno=1
+       if test -s $T/xz-todo
+       then
+               echo Size before compressing: `du -sh $tdir | awk '{ print $1 }'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
+               for i in `cat $T/xz-todo`
+               do
+                       echo Compressing vmlinux files in ${i}: `date` >> "$tdir/log-xz" 2>&1
+                       for j in $i/*/vmlinux
+                       do
+                               xz "$j" >> "$tdir/log-xz" 2>&1 &
+                               ncompresses=$((ncompresses+1))
+                               if test $ncompresses -ge $compress_kasan_vmlinux
+                               then
+                                       echo Waiting for batch $batchno of $ncompresses compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
+                                       wait
+                                       ncompresses=0
+                                       batchno=$((batchno+1))
+                               fi
+                       done
+               done
+               if test $ncompresses -gt 0
+               then
+                       echo Waiting for final batch $batchno of $ncompresses compressions `date` | tee -a "$tdir/log-xz" | tee -a $T/log
+               fi
+               wait
+               echo Size after compressing: `du -sh $tdir | awk '{ print $1 }'` `date` 2>&1 | tee -a "$tdir/log-xz" | tee -a $T/log
+               echo Total duration `get_starttime_duration $starttime`. | tee -a $T/log
+       else
+               echo No compression needed: `date` >> "$tdir/log-xz" 2>&1
+       fi
+fi
+if test -n "$tdir"
+then
+       cp $T/log "$tdir"
+fi
+exit $ret
index 9363708c9075c4a34ca934b78f0887724e9a2fd3..932a0799eb0843918c2a73338752297349884f01 100644 (file)
@@ -1 +1,2 @@
 rcutorture.torture_type=tasks-rude
+rcutree.use_softirq=0
index cd2a188eeb6d986034e40d91359341944a1d2716..22cdeced98ea86f62be2c30bf20a5c29c1ccad1c 100644 (file)
@@ -1 +1,2 @@
 rcutorture.torture_type=tasks
+rcutree.use_softirq=0