mirror of
https://github.com/torvalds/linux.git
synced 2025-04-09 14:45:27 +00:00

This pull request contains the following branches: docs.2025.02.04a: - Add broken-timing possibility to stallwarn.rst. - Improve discussion of this_cpu_ptr(), add raw_cpu_ptr(). - Document self-propagating callbacks. - Point call_srcu() to call_rcu() for detailed memory ordering. - Add CONFIG_RCU_LAZY delays to call_rcu() kernel-doc header. - Clarify RCU_LAZY and RCU_LAZY_DEFAULT_OFF help text. - Remove references to old grace-period-wait primitives. srcu.2025.02.05a: - Introduce srcu_read_{un,}lock_fast(), which is similar to srcu_read_{un,}lock_lite(): avoid smp_mb()s in lock and unlock at the cost of calling synchronize_rcu() in synchronize_srcu(). Moreover, by returning the percpu offset of the counter at srcu_read_lock_fast() time, srcu_read_unlock_fast() can save extra pointer dereferencing, which makes it faster than srcu_read_{un,}lock_lite(). srcu_read_{un,}lock_fast() are intended to replace rcu_read_{un,}lock_trace() if possible. torture.2025.02.05a: - Add get_torture_init_jiffies() to return the start time of the test. - Add a test_boost_holdoff module parameter to allow delaying boosting tests when building rcutorture as built-in. - Add grace period sequence number logging at the beginning and end of failure/close-call results. - Switch to hexadecimal for the expedited grace period sequence number in the rcu_exp_grace_period trace point. - Make cur_ops->format_gp_seqs take buffer length. - Move RCU_TORTURE_TEST_{CHK_RDR_STATE,LOG_CPU} to bool. - Complain when invalid SRCU reader_flavor is specified. - Add FORCE_NEED_SRCU_NMI_SAFE Kconfig for testing, which forces SRCU uses atomics even when percpu ops are NMI safe, and use the Kconfig for SRCU lockdep testing. misc.2025.03.04a: - Split rcu_report_exp_cpu_mult() mask parameter and use for tracing. - Remove READ_ONCE() for rdp->gpwrap access in __note_gp_changes(). - Fix get_state_synchronize_rcu_full() GP-start detection. - Move RCU Tasks self-tests to core_initcall(). - Print segment lengths in show_rcu_nocb_gp_state(). - Make RCU watch ct_kernel_exit_state() warning. - Flush console log from kernel_power_off(). - rcutorture: Allow a negative value for nfakewriters. - rcu: Update TREE05.boot to test normal synchronize_rcu(). - rcu: Use _full() API to debug synchronize_rcu(). lazypreempt.2025.03.04a: Make RCU handle PREEMPT_LAZY better: - Fix header guard for rcu_all_qs(). - rcu: Rename PREEMPT_AUTO to PREEMPT_LAZY. - Update __cond_resched comment about RCU quiescent states. - Handle unstable rdp in rcu_read_unlock_strict(). - Handle quiescent states for PREEMPT_RCU=n, PREEMPT_COUNT=y. - osnoise: Provide quiescent states. - Adjust rcutorture with possible PREEMPT_RCU=n && PREEMPT_COUNT=y combination. - Limit PREEMPT_RCU configurations. - Make rcutorture senario TREE07 and senario TREE10 use PREEMPT_LAZY=y. -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAmfeBLQACgkQSXnow7UH +rh11Qf/Rt6IZJ/YT/V9Sd+8hMx4O0BMh779pr9cD6mbAG+FDk2Yeva1m8vIdFOb qId6oc8K/ef2JfFjSn0oHMzQP2D3XUyiJWPNbBDHv/D8Os8GZgjzu8dkxVkSbdbY OxtvIflbcqFN1JDJfGKZnTEW0/YxGqfnS9b6R7iyyA7SOGQ/WubGOE5qNCqPufc9 zJiP+qTUFYQzCIiPlEJul39o9KboPogbt3QAAQjWmi3utd77ehJnm/15FvAjyau4 uhC2cnGfMY535rQaiaQeBQ/IHIowKripCq0JQFvcUNdyArZM3HOI2x79+2II6ft7 mjHskNODOIJHfW2o1RzQ0yRYAywFIg== =J+mH -----END PGP SIGNATURE----- Merge tag 'rcu-next-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux Pull RCU updates from Boqun Feng: "Documentation: - Add broken-timing possibility to stallwarn.rst - Improve discussion of this_cpu_ptr(), add raw_cpu_ptr() - Document self-propagating callbacks - Point call_srcu() to call_rcu() for detailed memory ordering - Add CONFIG_RCU_LAZY delays to call_rcu() kernel-doc header - Clarify RCU_LAZY and RCU_LAZY_DEFAULT_OFF help text - Remove references to old grace-period-wait primitives srcu: - Introduce srcu_read_{un,}lock_fast(), which is similar to srcu_read_{un,}lock_lite(): avoid smp_mb()s in lock and unlock at the cost of calling synchronize_rcu() in synchronize_srcu() Moreover, by returning the percpu offset of the counter at srcu_read_lock_fast() time, srcu_read_unlock_fast() can avoid extra pointer dereferencing, which makes it faster than srcu_read_{un,}lock_lite() srcu_read_{un,}lock_fast() are intended to replace rcu_read_{un,}lock_trace() if possible RCU torture: - Add get_torture_init_jiffies() to return the start time of the test - Add a test_boost_holdoff module parameter to allow delaying boosting tests when building rcutorture as built-in - Add grace period sequence number logging at the beginning and end of failure/close-call results - Switch to hexadecimal for the expedited grace period sequence number in the rcu_exp_grace_period trace point - Make cur_ops->format_gp_seqs take buffer length - Move RCU_TORTURE_TEST_{CHK_RDR_STATE,LOG_CPU} to bool - Complain when invalid SRCU reader_flavor is specified - Add FORCE_NEED_SRCU_NMI_SAFE Kconfig for testing, which forces SRCU uses atomics even when percpu ops are NMI safe, and use the Kconfig for SRCU lockdep testing Misc: - Split rcu_report_exp_cpu_mult() mask parameter and use for tracing - Remove READ_ONCE() for rdp->gpwrap access in __note_gp_changes() - Fix get_state_synchronize_rcu_full() GP-start detection - Move RCU Tasks self-tests to core_initcall() - Print segment lengths in show_rcu_nocb_gp_state() - Make RCU watch ct_kernel_exit_state() warning - Flush console log from kernel_power_off() - rcutorture: Allow a negative value for nfakewriters - rcu: Update TREE05.boot to test normal synchronize_rcu() - rcu: Use _full() API to debug synchronize_rcu() Make RCU handle PREEMPT_LAZY better: - Fix header guard for rcu_all_qs() - rcu: Rename PREEMPT_AUTO to PREEMPT_LAZY - Update __cond_resched comment about RCU quiescent states - Handle unstable rdp in rcu_read_unlock_strict() - Handle quiescent states for PREEMPT_RCU=n, PREEMPT_COUNT=y - osnoise: Provide quiescent states - Adjust rcutorture with possible PREEMPT_RCU=n && PREEMPT_COUNT=y combination - Limit PREEMPT_RCU configurations - Make rcutorture senario TREE07 and senario TREE10 use PREEMPT_LAZY=y" * tag 'rcu-next-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/rcu/linux: (59 commits) rcutorture: Make scenario TREE07 build CONFIG_PREEMPT_LAZY=y rcutorture: Make scenario TREE10 build CONFIG_PREEMPT_LAZY=y rcu: limit PREEMPT_RCU configurations rcutorture: Update ->extendables check for lazy preemption rcutorture: Update rcutorture_one_extend_check() for lazy preemption osnoise: provide quiescent states rcu: Use _full() API to debug synchronize_rcu() rcu: Update TREE05.boot to test normal synchronize_rcu() rcutorture: Allow a negative value for nfakewriters Flush console log from kernel_power_off() context_tracking: Make RCU watch ct_kernel_exit_state() warning rcu/nocb: Print segment lengths in show_rcu_nocb_gp_state() rcu-tasks: Move RCU Tasks self-tests to core_initcall() rcu: Fix get_state_synchronize_rcu_full() GP-start detection torture: Make SRCU lockdep testing use srcu_read_lock_nmisafe() srcu: Add FORCE_NEED_SRCU_NMI_SAFE Kconfig for testing rcutorture: Complain when invalid SRCU reader_flavor is specified rcutorture: Move RCU_TORTURE_TEST_{CHK_RDR_STATE,LOG_CPU} to bool rcutorture: Make cur_ops->format_gp_seqs take buffer length rcutorture: Add ftrace-compatible timestamp to GP# failure/close-call output ...
255 lines
6.7 KiB
C
255 lines
6.7 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition.
|
|
*
|
|
* Copyright IBM Corporation, 2008
|
|
*
|
|
* Author: Paul E. McKenney <paulmck@linux.ibm.com>
|
|
*
|
|
* For detailed explanation of Read-Copy Update mechanism see -
|
|
* Documentation/RCU
|
|
*/
|
|
#include <linux/completion.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/rcupdate_wait.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/export.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/types.h>
|
|
#include <linux/init.h>
|
|
#include <linux/time.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/prefetch.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/mm.h>
|
|
|
|
#include "rcu.h"
|
|
|
|
/* Global control variables for rcupdate callback mechanism. */
|
|
struct rcu_ctrlblk {
|
|
struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */
|
|
struct rcu_head **donetail; /* ->next pointer of last "done" CB. */
|
|
struct rcu_head **curtail; /* ->next pointer of last CB. */
|
|
unsigned long gp_seq; /* Grace-period counter. */
|
|
};
|
|
|
|
/* Definition for rcupdate control block. */
|
|
static struct rcu_ctrlblk rcu_ctrlblk = {
|
|
.donetail = &rcu_ctrlblk.rcucblist,
|
|
.curtail = &rcu_ctrlblk.rcucblist,
|
|
.gp_seq = 0 - 300UL,
|
|
};
|
|
|
|
void rcu_barrier(void)
|
|
{
|
|
wait_rcu_gp(call_rcu_hurry);
|
|
}
|
|
EXPORT_SYMBOL(rcu_barrier);
|
|
|
|
/* Record an rcu quiescent state. */
|
|
void rcu_qs(void)
|
|
{
|
|
unsigned long flags;
|
|
|
|
local_irq_save(flags);
|
|
if (rcu_ctrlblk.donetail != rcu_ctrlblk.curtail) {
|
|
rcu_ctrlblk.donetail = rcu_ctrlblk.curtail;
|
|
raise_softirq_irqoff(RCU_SOFTIRQ);
|
|
}
|
|
WRITE_ONCE(rcu_ctrlblk.gp_seq, rcu_ctrlblk.gp_seq + 2);
|
|
local_irq_restore(flags);
|
|
}
|
|
|
|
/*
|
|
* Check to see if the scheduling-clock interrupt came from an extended
|
|
* quiescent state, and, if so, tell RCU about it. This function must
|
|
* be called from hardirq context. It is normally called from the
|
|
* scheduling-clock interrupt.
|
|
*/
|
|
void rcu_sched_clock_irq(int user)
|
|
{
|
|
if (user) {
|
|
rcu_qs();
|
|
} else if (rcu_ctrlblk.donetail != rcu_ctrlblk.curtail) {
|
|
set_tsk_need_resched(current);
|
|
set_preempt_need_resched();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Reclaim the specified callback, either by invoking it for non-kfree cases or
|
|
* freeing it directly (for kfree). Return true if kfreeing, false otherwise.
|
|
*/
|
|
static inline bool rcu_reclaim_tiny(struct rcu_head *head)
|
|
{
|
|
rcu_callback_t f;
|
|
|
|
rcu_lock_acquire(&rcu_callback_map);
|
|
|
|
trace_rcu_invoke_callback("", head);
|
|
f = head->func;
|
|
debug_rcu_head_callback(head);
|
|
WRITE_ONCE(head->func, (rcu_callback_t)0L);
|
|
f(head);
|
|
rcu_lock_release(&rcu_callback_map);
|
|
return false;
|
|
}
|
|
|
|
/* Invoke the RCU callbacks whose grace period has elapsed. */
|
|
static __latent_entropy void rcu_process_callbacks(void)
|
|
{
|
|
struct rcu_head *next, *list;
|
|
unsigned long flags;
|
|
|
|
/* Move the ready-to-invoke callbacks to a local list. */
|
|
local_irq_save(flags);
|
|
if (rcu_ctrlblk.donetail == &rcu_ctrlblk.rcucblist) {
|
|
/* No callbacks ready, so just leave. */
|
|
local_irq_restore(flags);
|
|
return;
|
|
}
|
|
list = rcu_ctrlblk.rcucblist;
|
|
rcu_ctrlblk.rcucblist = *rcu_ctrlblk.donetail;
|
|
*rcu_ctrlblk.donetail = NULL;
|
|
if (rcu_ctrlblk.curtail == rcu_ctrlblk.donetail)
|
|
rcu_ctrlblk.curtail = &rcu_ctrlblk.rcucblist;
|
|
rcu_ctrlblk.donetail = &rcu_ctrlblk.rcucblist;
|
|
local_irq_restore(flags);
|
|
|
|
/* Invoke the callbacks on the local list. */
|
|
while (list) {
|
|
next = list->next;
|
|
prefetch(next);
|
|
debug_rcu_head_unqueue(list);
|
|
rcu_reclaim_tiny(list);
|
|
list = next;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Wait for a grace period to elapse. But it is illegal to invoke
|
|
* synchronize_rcu() from within an RCU read-side critical section.
|
|
* Therefore, any legal call to synchronize_rcu() is a quiescent state,
|
|
* and so on a UP system, synchronize_rcu() need do nothing, other than
|
|
* let the polled APIs know that another grace period elapsed.
|
|
*
|
|
* (But Lai Jiangshan points out the benefits of doing might_sleep()
|
|
* to reduce latency.)
|
|
*
|
|
* Cool, huh? (Due to Josh Triplett.)
|
|
*/
|
|
void synchronize_rcu(void)
|
|
{
|
|
RCU_LOCKDEP_WARN(lock_is_held(&rcu_bh_lock_map) ||
|
|
lock_is_held(&rcu_lock_map) ||
|
|
lock_is_held(&rcu_sched_lock_map),
|
|
"Illegal synchronize_rcu() in RCU read-side critical section");
|
|
preempt_disable();
|
|
WRITE_ONCE(rcu_ctrlblk.gp_seq, rcu_ctrlblk.gp_seq + 2);
|
|
preempt_enable();
|
|
}
|
|
EXPORT_SYMBOL_GPL(synchronize_rcu);
|
|
|
|
/*
|
|
* Post an RCU callback to be invoked after the end of an RCU grace
|
|
* period. But since we have but one CPU, that would be after any
|
|
* quiescent state.
|
|
*/
|
|
void call_rcu(struct rcu_head *head, rcu_callback_t func)
|
|
{
|
|
static atomic_t doublefrees;
|
|
unsigned long flags;
|
|
|
|
if (debug_rcu_head_queue(head)) {
|
|
if (atomic_inc_return(&doublefrees) < 4) {
|
|
pr_err("%s(): Double-freed CB %p->%pS()!!! ", __func__, head, head->func);
|
|
mem_dump_obj(head);
|
|
}
|
|
return;
|
|
}
|
|
|
|
head->func = func;
|
|
head->next = NULL;
|
|
|
|
local_irq_save(flags);
|
|
*rcu_ctrlblk.curtail = head;
|
|
rcu_ctrlblk.curtail = &head->next;
|
|
local_irq_restore(flags);
|
|
|
|
if (unlikely(is_idle_task(current))) {
|
|
/* force scheduling for rcu_qs() */
|
|
resched_cpu(0);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(call_rcu);
|
|
|
|
/*
|
|
* Store a grace-period-counter "cookie". For more information,
|
|
* see the Tree RCU header comment.
|
|
*/
|
|
void get_completed_synchronize_rcu_full(struct rcu_gp_oldstate *rgosp)
|
|
{
|
|
rgosp->rgos_norm = RCU_GET_STATE_COMPLETED;
|
|
}
|
|
EXPORT_SYMBOL_GPL(get_completed_synchronize_rcu_full);
|
|
|
|
/*
|
|
* Return a grace-period-counter "cookie". For more information,
|
|
* see the Tree RCU header comment.
|
|
*/
|
|
unsigned long get_state_synchronize_rcu(void)
|
|
{
|
|
return READ_ONCE(rcu_ctrlblk.gp_seq);
|
|
}
|
|
EXPORT_SYMBOL_GPL(get_state_synchronize_rcu);
|
|
|
|
/*
|
|
* Return a grace-period-counter "cookie" and ensure that a future grace
|
|
* period completes. For more information, see the Tree RCU header comment.
|
|
*/
|
|
unsigned long start_poll_synchronize_rcu(void)
|
|
{
|
|
unsigned long gp_seq = get_state_synchronize_rcu();
|
|
|
|
if (unlikely(is_idle_task(current))) {
|
|
/* force scheduling for rcu_qs() */
|
|
resched_cpu(0);
|
|
}
|
|
return gp_seq;
|
|
}
|
|
EXPORT_SYMBOL_GPL(start_poll_synchronize_rcu);
|
|
|
|
/*
|
|
* Return true if the grace period corresponding to oldstate has completed
|
|
* and false otherwise. For more information, see the Tree RCU header
|
|
* comment.
|
|
*/
|
|
bool poll_state_synchronize_rcu(unsigned long oldstate)
|
|
{
|
|
return oldstate == RCU_GET_STATE_COMPLETED || READ_ONCE(rcu_ctrlblk.gp_seq) != oldstate;
|
|
}
|
|
EXPORT_SYMBOL_GPL(poll_state_synchronize_rcu);
|
|
|
|
#if IS_ENABLED(CONFIG_RCU_TORTURE_TEST)
|
|
unsigned long long rcutorture_gather_gp_seqs(void)
|
|
{
|
|
return READ_ONCE(rcu_ctrlblk.gp_seq) & 0xffffULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(rcutorture_gather_gp_seqs);
|
|
|
|
void rcutorture_format_gp_seqs(unsigned long long seqs, char *cp, size_t len)
|
|
{
|
|
snprintf(cp, len, "g%04llx", seqs & 0xffffULL);
|
|
}
|
|
EXPORT_SYMBOL_GPL(rcutorture_format_gp_seqs);
|
|
#endif
|
|
|
|
void __init rcu_init(void)
|
|
{
|
|
open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
|
|
rcu_early_boot_tests();
|
|
tasks_cblist_init_generic();
|
|
}
|