Skip to content

Commit 8cc01d4

Browse files
committed
Merge tag 'rcu.2023.02.10a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull RCU updates from Paul McKenney: - Documentation updates - Miscellaneous fixes, perhaps most notably: - Throttling callback invocation based on the number of callbacks that are now ready to invoke instead of on the total number of callbacks - Several patches that suppress false-positive boot-time diagnostics, for example, due to lockdep not yet being initialized - Make expedited RCU CPU stall warnings dump stacks of any tasks that are blocking the stalled grace period. (Normal RCU CPU stall warnings have done this for many years) - Lazy-callback fixes to avoid delays during boot, suspend, and resume. (Note that lazy callbacks must be explicitly enabled, so this should not (yet) affect production use cases) - Make kfree_rcu() and friends take advantage of polled grace periods, thus reducing memory footprint by almost two orders of magnitude, admittedly on a microbenchmark This also begins the transition from kfree_rcu(p) to kfree_rcu_mightsleep(p). This transition was motivated by bugs where kfree_rcu(p), which can block, was typed instead of the intended kfree_rcu(p, rh) - SRCU updates, perhaps most notably fixing a bug that causes SRCU to fail when booted on a system with a non-zero boot CPU. This surprising situation actually happens for kdump kernels on the powerpc architecture This also adds an srcu_down_read() and srcu_up_read(), which act like srcu_read_lock() and srcu_read_unlock(), but allow an SRCU read-side critical section to be handed off from one task to another - Clean up the now-useless SRCU Kconfig option There are a few more commits that are not yet acked or pulled into maintainer trees, and these will be in a pull request for a later merge window - RCU-tasks updates, perhaps most notably these fixes: - A strange interaction between PID-namespace unshare and the RCU-tasks grace period that results in a low-probability but very real hang - A race between an RCU tasks rude grace period on a single-CPU system and CPU-hotplug addition of the second CPU that can result in a too-short grace period - A race between shrinking RCU tasks down to a single callback list and queuing a new callback to some other CPU, but where that queuing is delayed for more than an RCU grace period. This can result in that callback being stranded on the non-boot CPU - Torture-test updates and fixes - Torture-test scripting updates and fixes - Provide additional RCU CPU stall-warning information in kernels built with CONFIG_RCU_CPU_STALL_CPUTIME=y, and restore the full five-minute timeout limit for expedited RCU CPU stall warnings * tag 'rcu.2023.02.10a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: (80 commits) rcu/kvfree: Add kvfree_rcu_mightsleep() and kfree_rcu_mightsleep() kernel/notifier: Remove CONFIG_SRCU init: Remove "select SRCU" fs/quota: Remove "select SRCU" fs/notify: Remove "select SRCU" fs/btrfs: Remove "select SRCU" fs: Remove CONFIG_SRCU drivers/pci/controller: Remove "select SRCU" drivers/net: Remove "select SRCU" drivers/md: Remove "select SRCU" drivers/hwtracing/stm: Remove "select SRCU" drivers/dax: Remove "select SRCU" drivers/base: Remove CONFIG_SRCU rcu: Disable laziness if lazy-tracking says so rcu: Track laziness during boot and suspend rcu: Remove redundant call to rcu_boost_kthread_setaffinity() rcu: Allow up to five minutes expedited RCU CPU stall-warning timeouts rcu: Align the output of RCU CPU stall warning messages rcu: Add RCU stall diagnosis information sched: Add helper nr_context_switches_cpu() ...
2 parents 8ca8d89 + bba8d3d commit 8cc01d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1734
-839
lines changed

Documentation/RCU/NMI-RCU.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Although RCU is usually used to protect read-mostly data structures,
88
it is possible to use RCU to provide dynamic non-maskable interrupt
99
handlers, as well as dynamic irq handlers. This document describes
1010
how to do this, drawing loosely from Zwane Mwaikambo's NMI-timer
11-
work in "arch/x86/kernel/traps.c".
11+
work in an old version of "arch/x86/kernel/traps.c".
1212

1313
The relevant pieces of code are listed below, each followed by a
1414
brief explanation::
@@ -116,7 +116,7 @@ Answer to Quick Quiz:
116116

117117
This same sad story can happen on other CPUs when using
118118
a compiler with aggressive pointer-value speculation
119-
optimizations.
119+
optimizations. (But please don't!)
120120

121121
More important, the rcu_dereference_sched() makes it
122122
clear to someone reading the code that the pointer is

Documentation/RCU/UP.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ by having call_rcu() directly invoke its arguments only if it was called
3838
from process context. However, this can fail in a similar manner.
3939

4040
Suppose that an RCU-based algorithm again scans a linked list containing
41-
elements A, B, and C in process contexts, but that it invokes a function
41+
elements A, B, and C in process context, but that it invokes a function
4242
on each element as it is scanned. Suppose further that this function
4343
deletes element B from the list, then passes it to call_rcu() for deferred
4444
freeing. This may be a bit unconventional, but it is perfectly legal
@@ -59,7 +59,8 @@ Example 3: Death by Deadlock
5959
Suppose that call_rcu() is invoked while holding a lock, and that the
6060
callback function must acquire this same lock. In this case, if
6161
call_rcu() were to directly invoke the callback, the result would
62-
be self-deadlock.
62+
be self-deadlock *even if* this invocation occurred from a later
63+
call_rcu() invocation a full grace period later.
6364

6465
In some cases, it would possible to restructure to code so that
6566
the call_rcu() is delayed until after the lock is released. However,
@@ -85,6 +86,14 @@ Quick Quiz #2:
8586

8687
:ref:`Answers to Quick Quiz <answer_quick_quiz_up>`
8788

89+
It is important to note that userspace RCU implementations *do*
90+
permit call_rcu() to directly invoke callbacks, but only if a full
91+
grace period has elapsed since those callbacks were queued. This is
92+
the case because some userspace environments are extremely constrained.
93+
Nevertheless, people writing userspace RCU implementations are strongly
94+
encouraged to avoid invoking callbacks from call_rcu(), thus obtaining
95+
the deadlock-avoidance benefits called out above.
96+
8897
Summary
8998
-------
9099

Documentation/RCU/lockdep.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ checking of rcu_dereference() primitives:
6969
value of the pointer itself, for example, against NULL.
7070

7171
The rcu_dereference_check() check expression can be any boolean
72-
expression, but would normally include a lockdep expression. However,
73-
any boolean expression can be used. For a moderately ornate example,
74-
consider the following::
72+
expression, but would normally include a lockdep expression. For a
73+
moderately ornate example, consider the following::
7574

7675
file = rcu_dereference_check(fdt->fd[fd],
7776
lockdep_is_held(&files->file_lock) ||
@@ -97,10 +96,10 @@ code, it could instead be written as follows::
9796
atomic_read(&files->count) == 1);
9897

9998
This would verify cases #2 and #3 above, and furthermore lockdep would
100-
complain if this was used in an RCU read-side critical section unless one
101-
of these two cases held. Because rcu_dereference_protected() omits all
102-
barriers and compiler constraints, it generates better code than do the
103-
other flavors of rcu_dereference(). On the other hand, it is illegal
99+
complain even if this was used in an RCU read-side critical section unless
100+
one of these two cases held. Because rcu_dereference_protected() omits
101+
all barriers and compiler constraints, it generates better code than do
102+
the other flavors of rcu_dereference(). On the other hand, it is illegal
104103
to use rcu_dereference_protected() if either the RCU-protected pointer
105104
or the RCU-protected data that it points to can change concurrently.
106105

Documentation/RCU/rcu.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@ Frequently Asked Questions
7777
search for the string "Patent" in Documentation/RCU/RTFP.txt to find them.
7878
Of these, one was allowed to lapse by the assignee, and the
7979
others have been contributed to the Linux kernel under GPL.
80+
Many (but not all) have long since expired.
8081
There are now also LGPL implementations of user-level RCU
8182
available (https://liburcu.org/).
8283

8384
- I hear that RCU needs work in order to support realtime kernels?
8485

85-
Realtime-friendly RCU can be enabled via the CONFIG_PREEMPT_RCU
86+
Realtime-friendly RCU are enabled via the CONFIG_PREEMPTION
8687
kernel configuration parameter.
8788

8889
- Where can I find more information on RCU?
8990

9091
See the Documentation/RCU/RTFP.txt file.
91-
Or point your browser at (http://www.rdrop.com/users/paulmck/RCU/).
92+
Or point your browser at (https://docs.google.com/document/d/1X0lThx8OK0ZgLMqVoXiR4ZrGURHrXK6NyLRbeXe3Xac/edit)
93+
or (https://docs.google.com/document/d/1GCdQC8SDbb54W1shjEXqGZ0Rq8a6kIeYutdSIajfpLA/edit?usp=sharing).

Documentation/RCU/rcu_dereference.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Follow these rules to keep your RCU code working properly:
1919
can reload the value, and won't your code have fun with two
2020
different values for a single pointer! Without rcu_dereference(),
2121
DEC Alpha can load a pointer, dereference that pointer, and
22-
return data preceding initialization that preceded the store of
23-
the pointer.
22+
return data preceding initialization that preceded the store
23+
of the pointer. (As noted later, in recent kernels READ_ONCE()
24+
also prevents DEC Alpha from playing these tricks.)
2425

2526
In addition, the volatile cast in rcu_dereference() prevents the
2627
compiler from deducing the resulting pointer value. Please see
@@ -34,7 +35,7 @@ Follow these rules to keep your RCU code working properly:
3435
takes on the role of the lockless_dereference() primitive that
3536
was removed in v4.15.
3637

37-
- You are only permitted to use rcu_dereference on pointer values.
38+
- You are only permitted to use rcu_dereference() on pointer values.
3839
The compiler simply knows too much about integral values to
3940
trust it to carry dependencies through integer operations.
4041
There are a very few exceptions, namely that you can temporarily
@@ -240,6 +241,7 @@ precautions. To see this, consider the following code fragment::
240241
struct foo *q;
241242
int r1, r2;
242243

244+
rcu_read_lock();
243245
p = rcu_dereference(gp2);
244246
if (p == NULL)
245247
return;
@@ -248,7 +250,10 @@ precautions. To see this, consider the following code fragment::
248250
if (p == q) {
249251
/* The compiler decides that q->c is same as p->c. */
250252
r2 = p->c; /* Could get 44 on weakly order system. */
253+
} else {
254+
r2 = p->c - r1; /* Unconditional access to p->c. */
251255
}
256+
rcu_read_unlock();
252257
do_something_with(r1, r2);
253258
}
254259

@@ -297,6 +302,7 @@ Then one approach is to use locking, for example, as follows::
297302
struct foo *q;
298303
int r1, r2;
299304

305+
rcu_read_lock();
300306
p = rcu_dereference(gp2);
301307
if (p == NULL)
302308
return;
@@ -306,7 +312,12 @@ Then one approach is to use locking, for example, as follows::
306312
if (p == q) {
307313
/* The compiler decides that q->c is same as p->c. */
308314
r2 = p->c; /* Locking guarantees r2 == 144. */
315+
} else {
316+
spin_lock(&q->lock);
317+
r2 = q->c - r1;
318+
spin_unlock(&q->lock);
309319
}
320+
rcu_read_unlock();
310321
spin_unlock(&p->lock);
311322
do_something_with(r1, r2);
312323
}
@@ -364,7 +375,7 @@ the exact value of "p" even in the not-equals case. This allows the
364375
compiler to make the return values independent of the load from "gp",
365376
in turn destroying the ordering between this load and the loads of the
366377
return values. This can result in "p->b" returning pre-initialization
367-
garbage values.
378+
garbage values on weakly ordered systems.
368379

369380
In short, rcu_dereference() is *not* optional when you are going to
370381
dereference the resulting pointer.
@@ -430,7 +441,7 @@ member of the rcu_dereference() to use in various situations:
430441
SPARSE CHECKING OF RCU-PROTECTED POINTERS
431442
-----------------------------------------
432443

433-
The sparse static-analysis tool checks for direct access to RCU-protected
444+
The sparse static-analysis tool checks for non-RCU access to RCU-protected
434445
pointers, which can result in "interesting" bugs due to compiler
435446
optimizations involving invented loads and perhaps also load tearing.
436447
For example, suppose someone mistakenly does something like this::

0 commit comments

Comments
 (0)