Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

doc: Update checklist.txt

This commit updates checklist.txt to reflect RCU additions and changes
over the past few years.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

+141 -99
+141 -99
Documentation/RCU/checklist.rst
··· 32 32 for lockless updates. This does result in the mildly 33 33 counter-intuitive situation where rcu_read_lock() and 34 34 rcu_read_unlock() are used to protect updates, however, this 35 - approach provides the same potential simplifications that garbage 36 - collectors do. 35 + approach can provide the same simplifications to certain types 36 + of lockless algorithms that garbage collectors do. 37 37 38 38 1. Does the update code have proper mutual exclusion? 39 39 ··· 49 49 them -- even x86 allows later loads to be reordered to precede 50 50 earlier stores), and be prepared to explain why this added 51 51 complexity is worthwhile. If you choose #c, be prepared to 52 - explain how this single task does not become a major bottleneck on 53 - big multiprocessor machines (for example, if the task is updating 54 - information relating to itself that other tasks can read, there 55 - by definition can be no bottleneck). Note that the definition 56 - of "large" has changed significantly: Eight CPUs was "large" 57 - in the year 2000, but a hundred CPUs was unremarkable in 2017. 52 + explain how this single task does not become a major bottleneck 53 + on large systems (for example, if the task is updating information 54 + relating to itself that other tasks can read, there by definition 55 + can be no bottleneck). Note that the definition of "large" has 56 + changed significantly: Eight CPUs was "large" in the year 2000, 57 + but a hundred CPUs was unremarkable in 2017. 58 58 59 59 2. Do the RCU read-side critical sections make proper use of 60 60 rcu_read_lock() and friends? These primitives are needed ··· 97 97 98 98 b. Proceed as in (a) above, but also maintain per-element 99 99 locks (that are acquired by both readers and writers) 100 - that guard per-element state. Of course, fields that 101 - the readers refrain from accessing can be guarded by 102 - some other lock acquired only by updaters, if desired. 100 + that guard per-element state. Fields that the readers 101 + refrain from accessing can be guarded by some other lock 102 + acquired only by updaters, if desired. 103 103 104 - This works quite well, also. 104 + This also works quite well. 105 105 106 106 c. Make updates appear atomic to readers. For example, 107 107 pointer updates to properly aligned fields will 108 108 appear atomic, as will individual atomic primitives. 109 109 Sequences of operations performed under a lock will *not* 110 110 appear to be atomic to RCU readers, nor will sequences 111 - of multiple atomic primitives. 111 + of multiple atomic primitives. One alternative is to 112 + move multiple individual fields to a separate structure, 113 + thus solving the multiple-field problem by imposing an 114 + additional level of indirection. 112 115 113 116 This can work, but is starting to get a bit tricky. 114 117 115 - d. Carefully order the updates and the reads so that 116 - readers see valid data at all phases of the update. 117 - This is often more difficult than it sounds, especially 118 - given modern CPUs' tendency to reorder memory references. 119 - One must usually liberally sprinkle memory barriers 120 - (smp_wmb(), smp_rmb(), smp_mb()) through the code, 121 - making it difficult to understand and to test. 118 + d. Carefully order the updates and the reads so that readers 119 + see valid data at all phases of the update. This is often 120 + more difficult than it sounds, especially given modern 121 + CPUs' tendency to reorder memory references. One must 122 + usually liberally sprinkle memory-ordering operations 123 + through the code, making it difficult to understand and 124 + to test. Where it works, it is better to use things 125 + like smp_store_release() and smp_load_acquire(), but in 126 + some cases the smp_mb() full memory barrier is required. 122 127 123 - It is usually better to group the changing data into 124 - a separate structure, so that the change may be made 125 - to appear atomic by updating a pointer to reference 126 - a new structure containing updated values. 128 + As noted earlier, it is usually better to group the 129 + changing data into a separate structure, so that the 130 + change may be made to appear atomic by updating a pointer 131 + to reference a new structure containing updated values. 127 132 128 133 4. Weakly ordered CPUs pose special challenges. Almost all CPUs 129 134 are weakly ordered -- even x86 CPUs allow later loads to be ··· 193 188 when publicizing a pointer to a structure that can 194 189 be traversed by an RCU read-side critical section. 195 190 196 - 5. If call_rcu() or call_srcu() is used, the callback function will 197 - be called from softirq context. In particular, it cannot block. 198 - If you need the callback to block, run that code in a workqueue 199 - handler scheduled from the callback. The queue_rcu_work() 200 - function does this for you in the case of call_rcu(). 191 + 5. If any of call_rcu(), call_srcu(), call_rcu_tasks(), 192 + call_rcu_tasks_rude(), or call_rcu_tasks_trace() is used, 193 + the callback function may be invoked from softirq context, 194 + and in any case with bottom halves disabled. In particular, 195 + this callback function cannot block. If you need the callback 196 + to block, run that code in a workqueue handler scheduled from 197 + the callback. The queue_rcu_work() function does this for you 198 + in the case of call_rcu(). 201 199 202 200 6. Since synchronize_rcu() can block, it cannot be called 203 201 from any sort of irq context. The same rule applies 204 - for synchronize_srcu(), synchronize_rcu_expedited(), and 205 - synchronize_srcu_expedited(). 202 + for synchronize_srcu(), synchronize_rcu_expedited(), 203 + synchronize_srcu_expedited(), synchronize_rcu_tasks(), 204 + synchronize_rcu_tasks_rude(), and synchronize_rcu_tasks_trace(). 206 205 207 206 The expedited forms of these primitives have the same semantics 208 - as the non-expedited forms, but expediting is both expensive and 209 - (with the exception of synchronize_srcu_expedited()) unfriendly 210 - to real-time workloads. Use of the expedited primitives should 211 - be restricted to rare configuration-change operations that would 212 - not normally be undertaken while a real-time workload is running. 213 - However, real-time workloads can use rcupdate.rcu_normal kernel 214 - boot parameter to completely disable expedited grace periods, 215 - though this might have performance implications. 207 + as the non-expedited forms, but expediting is more CPU intensive. 208 + Use of the expedited primitives should be restricted to rare 209 + configuration-change operations that would not normally be 210 + undertaken while a real-time workload is running. Note that 211 + IPI-sensitive real-time workloads can use the rcupdate.rcu_normal 212 + kernel boot parameter to completely disable expedited grace 213 + periods, though this might have performance implications. 216 214 217 215 In particular, if you find yourself invoking one of the expedited 218 216 primitives repeatedly in a loop, please do everyone a favor: ··· 223 215 a single non-expedited primitive to cover the entire batch. 224 216 This will very likely be faster than the loop containing the 225 217 expedited primitive, and will be much much easier on the rest 226 - of the system, especially to real-time workloads running on 227 - the rest of the system. 218 + of the system, especially to real-time workloads running on the 219 + rest of the system. Alternatively, instead use asynchronous 220 + primitives such as call_rcu(). 228 221 229 222 7. As of v4.20, a given kernel implements only one RCU flavor, which 230 223 is RCU-sched for PREEMPTION=n and RCU-preempt for PREEMPTION=y. ··· 248 239 the corresponding readers must use rcu_read_lock_trace() and 249 240 rcu_read_unlock_trace(). If an updater uses call_rcu_tasks_rude() 250 241 or synchronize_rcu_tasks_rude(), then the corresponding readers 251 - must use anything that disables interrupts. 242 + must use anything that disables preemption, for example, 243 + preempt_disable() and preempt_enable(). 252 244 253 245 Mixing things up will result in confusion and broken kernels, and 254 246 has even resulted in an exploitable security issue. Therefore, ··· 263 253 that this usage is safe is that readers can use anything that 264 254 disables BH when updaters use call_rcu() or synchronize_rcu(). 265 255 266 - 8. Although synchronize_rcu() is slower than is call_rcu(), it 267 - usually results in simpler code. So, unless update performance is 268 - critically important, the updaters cannot block, or the latency of 269 - synchronize_rcu() is visible from userspace, synchronize_rcu() 270 - should be used in preference to call_rcu(). Furthermore, 271 - kfree_rcu() usually results in even simpler code than does 272 - synchronize_rcu() without synchronize_rcu()'s multi-millisecond 273 - latency. So please take advantage of kfree_rcu()'s "fire and 274 - forget" memory-freeing capabilities where it applies. 256 + 8. Although synchronize_rcu() is slower than is call_rcu(), 257 + it usually results in simpler code. So, unless update 258 + performance is critically important, the updaters cannot block, 259 + or the latency of synchronize_rcu() is visible from userspace, 260 + synchronize_rcu() should be used in preference to call_rcu(). 261 + Furthermore, kfree_rcu() and kvfree_rcu() usually result 262 + in even simpler code than does synchronize_rcu() without 263 + synchronize_rcu()'s multi-millisecond latency. So please take 264 + advantage of kfree_rcu()'s and kvfree_rcu()'s "fire and forget" 265 + memory-freeing capabilities where it applies. 275 266 276 267 An especially important property of the synchronize_rcu() 277 268 primitive is that it automatically self-limits: if grace periods ··· 282 271 cases where grace periods are delayed, as failing to do so can 283 272 result in excessive realtime latencies or even OOM conditions. 284 273 285 - Ways of gaining this self-limiting property when using call_rcu() 286 - include: 274 + Ways of gaining this self-limiting property when using call_rcu(), 275 + kfree_rcu(), or kvfree_rcu() include: 287 276 288 277 a. Keeping a count of the number of data-structure elements 289 278 used by the RCU-protected data structure, including ··· 315 304 here is that superuser already has lots of ways to crash 316 305 the machine. 317 306 318 - d. Periodically invoke synchronize_rcu(), permitting a limited 319 - number of updates per grace period. Better yet, periodically 320 - invoke rcu_barrier() to wait for all outstanding callbacks. 307 + d. Periodically invoke rcu_barrier(), permitting a limited 308 + number of updates per grace period. 321 309 322 - The same cautions apply to call_srcu() and kfree_rcu(). 310 + The same cautions apply to call_srcu(), call_rcu_tasks(), 311 + call_rcu_tasks_rude(), and call_rcu_tasks_trace(). This is 312 + why there is an srcu_barrier(), rcu_barrier_tasks(), 313 + rcu_barrier_tasks_rude(), and rcu_barrier_tasks_rude(), 314 + respectively. 323 315 324 - Note that although these primitives do take action to avoid memory 325 - exhaustion when any given CPU has too many callbacks, a determined 326 - user could still exhaust memory. This is especially the case 327 - if a system with a large number of CPUs has been configured to 328 - offload all of its RCU callbacks onto a single CPU, or if the 329 - system has relatively little free memory. 316 + Note that although these primitives do take action to avoid 317 + memory exhaustion when any given CPU has too many callbacks, 318 + a determined user or administrator can still exhaust memory. 319 + This is especially the case if a system with a large number of 320 + CPUs has been configured to offload all of its RCU callbacks onto 321 + a single CPU, or if the system has relatively little free memory. 330 322 331 323 9. All RCU list-traversal primitives, which include 332 324 rcu_dereference(), list_for_each_entry_rcu(), and ··· 358 344 and you don't hold the appropriate update-side lock, you *must* 359 345 use the "_rcu()" variants of the list macros. Failing to do so 360 346 will break Alpha, cause aggressive compilers to generate bad code, 361 - and confuse people trying to read your code. 347 + and confuse people trying to understand your code. 362 348 363 349 11. Any lock acquired by an RCU callback must be acquired elsewhere 364 - with softirq disabled, e.g., via spin_lock_irqsave(), 365 - spin_lock_bh(), etc. Failing to disable softirq on a given 366 - acquisition of that lock will result in deadlock as soon as 367 - the RCU softirq handler happens to run your RCU callback while 368 - interrupting that acquisition's critical section. 350 + with softirq disabled, e.g., via spin_lock_bh(). Failing to 351 + disable softirq on a given acquisition of that lock will result 352 + in deadlock as soon as the RCU softirq handler happens to run 353 + your RCU callback while interrupting that acquisition's critical 354 + section. 369 355 370 356 12. RCU callbacks can be and are executed in parallel. In many cases, 371 357 the callback code simply wrappers around kfree(), so that this ··· 386 372 for some real-time workloads, this is the whole point of using 387 373 the rcu_nocbs= kernel boot parameter. 388 374 389 - 13. Unlike other forms of RCU, it *is* permissible to block in an 375 + In addition, do not assume that callbacks queued in a given order 376 + will be invoked in that order, even if they all are queued on the 377 + same CPU. Furthermore, do not assume that same-CPU callbacks will 378 + be invoked serially. For example, in recent kernels, CPUs can be 379 + switched between offloaded and de-offloaded callback invocation, 380 + and while a given CPU is undergoing such a switch, its callbacks 381 + might be concurrently invoked by that CPU's softirq handler and 382 + that CPU's rcuo kthread. At such times, that CPU's callbacks 383 + might be executed both concurrently and out of order. 384 + 385 + 13. Unlike most flavors of RCU, it *is* permissible to block in an 390 386 SRCU read-side critical section (demarked by srcu_read_lock() 391 387 and srcu_read_unlock()), hence the "SRCU": "sleepable RCU". 392 388 Please note that if you don't need to sleep in read-side critical ··· 436 412 never sends IPIs to other CPUs, so it is easier on 437 413 real-time workloads than is synchronize_rcu_expedited(). 438 414 415 + It is also permissible to sleep in RCU Tasks Trace read-side 416 + critical, which are delimited by rcu_read_lock_trace() and 417 + rcu_read_unlock_trace(). However, this is a specialized flavor 418 + of RCU, and you should not use it without first checking with 419 + its current users. In most cases, you should instead use SRCU. 420 + 439 421 Note that rcu_assign_pointer() relates to SRCU just as it does to 440 422 other forms of RCU, but instead of rcu_dereference() you should 441 423 use srcu_dereference() in order to avoid lockdep splats. ··· 472 442 find problems as follows: 473 443 474 444 CONFIG_PROVE_LOCKING: 475 - check that accesses to RCU-protected data 476 - structures are carried out under the proper RCU 477 - read-side critical section, while holding the right 478 - combination of locks, or whatever other conditions 479 - are appropriate. 445 + check that accesses to RCU-protected data structures 446 + are carried out under the proper RCU read-side critical 447 + section, while holding the right combination of locks, 448 + or whatever other conditions are appropriate. 480 449 481 450 CONFIG_DEBUG_OBJECTS_RCU_HEAD: 482 - check that you don't pass the 483 - same object to call_rcu() (or friends) before an RCU 484 - grace period has elapsed since the last time that you 485 - passed that same object to call_rcu() (or friends). 451 + check that you don't pass the same object to call_rcu() 452 + (or friends) before an RCU grace period has elapsed 453 + since the last time that you passed that same object to 454 + call_rcu() (or friends). 486 455 487 456 __rcu sparse checks: 488 - tag the pointer to the RCU-protected data 489 - structure with __rcu, and sparse will warn you if you 490 - access that pointer without the services of one of the 491 - variants of rcu_dereference(). 457 + tag the pointer to the RCU-protected data structure 458 + with __rcu, and sparse will warn you if you access that 459 + pointer without the services of one of the variants 460 + of rcu_dereference(). 492 461 493 462 These debugging aids can help you find problems that are 494 463 otherwise extremely difficult to spot. 495 464 496 - 17. If you register a callback using call_rcu() or call_srcu(), and 497 - pass in a function defined within a loadable module, then it in 498 - necessary to wait for all pending callbacks to be invoked after 499 - the last invocation and before unloading that module. Note that 500 - it is absolutely *not* sufficient to wait for a grace period! 501 - The current (say) synchronize_rcu() implementation is *not* 502 - guaranteed to wait for callbacks registered on other CPUs. 503 - Or even on the current CPU if that CPU recently went offline 504 - and came back online. 465 + 17. If you pass a callback function defined within a module to one of 466 + call_rcu(), call_srcu(), call_rcu_tasks(), call_rcu_tasks_rude(), 467 + or call_rcu_tasks_trace(), then it is necessary to wait for all 468 + pending callbacks to be invoked before unloading that module. 469 + Note that it is absolutely *not* sufficient to wait for a grace 470 + period! For example, synchronize_rcu() implementation is *not* 471 + guaranteed to wait for callbacks registered on other CPUs via 472 + call_rcu(). Or even on the current CPU if that CPU recently 473 + went offline and came back online. 505 474 506 475 You instead need to use one of the barrier functions: 507 476 508 477 - call_rcu() -> rcu_barrier() 509 478 - call_srcu() -> srcu_barrier() 479 + - call_rcu_tasks() -> rcu_barrier_tasks() 480 + - call_rcu_tasks_rude() -> rcu_barrier_tasks_rude() 481 + - call_rcu_tasks_trace() -> rcu_barrier_tasks_trace() 510 482 511 483 However, these barrier functions are absolutely *not* guaranteed 512 - to wait for a grace period. In fact, if there are no call_rcu() 513 - callbacks waiting anywhere in the system, rcu_barrier() is within 514 - its rights to return immediately. 484 + to wait for a grace period. For example, if there are no 485 + call_rcu() callbacks queued anywhere in the system, rcu_barrier() 486 + can and will return immediately. 515 487 516 - So if you need to wait for both an RCU grace period and for 517 - all pre-existing call_rcu() callbacks, you will need to execute 518 - both rcu_barrier() and synchronize_rcu(), if necessary, using 519 - something like workqueues to execute them concurrently. 488 + So if you need to wait for both a grace period and for all 489 + pre-existing callbacks, you will need to invoke both functions, 490 + with the pair depending on the flavor of RCU: 491 + 492 + - Either synchronize_rcu() or synchronize_rcu_expedited(), 493 + together with rcu_barrier() 494 + - Either synchronize_srcu() or synchronize_srcu_expedited(), 495 + together with and srcu_barrier() 496 + - synchronize_rcu_tasks() and rcu_barrier_tasks() 497 + - synchronize_tasks_rude() and rcu_barrier_tasks_rude() 498 + - synchronize_tasks_trace() and rcu_barrier_tasks_trace() 499 + 500 + If necessary, you can use something like workqueues to execute 501 + the requisite pair of functions concurrently. 520 502 521 503 See rcubarrier.rst for more information.