2016-04-15 23:35:29 +00:00
|
|
|
/*
|
|
|
|
* RCU expedited grace periods
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you can access it online at
|
|
|
|
* http://www.gnu.org/licenses/gpl-2.0.html.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corporation, 2016
|
|
|
|
*
|
|
|
|
* Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2016-12-18 21:31:02 +00:00
|
|
|
/*
|
|
|
|
* Record the start of an expedited grace period.
|
|
|
|
*/
|
2016-04-15 23:35:29 +00:00
|
|
|
static void rcu_exp_gp_seq_start(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
rcu_seq_start(&rsp->expedited_sequence);
|
|
|
|
}
|
2016-12-18 21:31:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Record the end of an expedited grace period.
|
|
|
|
*/
|
2016-04-15 23:35:29 +00:00
|
|
|
static void rcu_exp_gp_seq_end(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
rcu_seq_end(&rsp->expedited_sequence);
|
|
|
|
smp_mb(); /* Ensure that consecutive grace periods serialize. */
|
|
|
|
}
|
2016-12-18 21:31:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a snapshot of the expedited-grace-period counter.
|
|
|
|
*/
|
2016-04-15 23:35:29 +00:00
|
|
|
static unsigned long rcu_exp_gp_seq_snap(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
unsigned long s;
|
|
|
|
|
|
|
|
smp_mb(); /* Caller's modifications seen first by other CPUs. */
|
|
|
|
s = rcu_seq_snap(&rsp->expedited_sequence);
|
|
|
|
trace_rcu_exp_grace_period(rsp->name, s, TPS("snap"));
|
|
|
|
return s;
|
|
|
|
}
|
2016-12-18 21:31:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a counter snapshot from rcu_exp_gp_seq_snap(), return true
|
|
|
|
* if a full expedited grace period has elapsed since that snapshot
|
|
|
|
* was taken.
|
|
|
|
*/
|
2016-04-15 23:35:29 +00:00
|
|
|
static bool rcu_exp_gp_seq_done(struct rcu_state *rsp, unsigned long s)
|
|
|
|
{
|
|
|
|
return rcu_seq_done(&rsp->expedited_sequence, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the ->expmaskinit values in the rcu_node tree to reflect any
|
|
|
|
* recent CPU-online activity. Note that these masks are not cleared
|
|
|
|
* when CPUs go offline, so they reflect the union of all CPUs that have
|
|
|
|
* ever been online. This means that this function normally takes its
|
|
|
|
* no-work-to-do fastpath.
|
|
|
|
*/
|
|
|
|
static void sync_exp_reset_tree_hotplug(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
bool done;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long mask;
|
|
|
|
unsigned long oldmask;
|
|
|
|
int ncpus = READ_ONCE(rsp->ncpus);
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
struct rcu_node *rnp_up;
|
|
|
|
|
|
|
|
/* If no new CPUs onlined since last time, nothing to do. */
|
|
|
|
if (likely(ncpus == rsp->ncpus_snap))
|
|
|
|
return;
|
|
|
|
rsp->ncpus_snap = ncpus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each pass through the following loop propagates newly onlined
|
|
|
|
* CPUs for the current rcu_node structure up the rcu_node tree.
|
|
|
|
*/
|
|
|
|
rcu_for_each_leaf_node(rsp, rnp) {
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
|
|
|
if (rnp->expmaskinit == rnp->expmaskinitnext) {
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
continue; /* No new CPUs, nothing to do. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update this node's mask, track old value for propagation. */
|
|
|
|
oldmask = rnp->expmaskinit;
|
|
|
|
rnp->expmaskinit = rnp->expmaskinitnext;
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
|
|
|
|
/* If was already nonzero, nothing to propagate. */
|
|
|
|
if (oldmask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Propagate the new CPU up the tree. */
|
|
|
|
mask = rnp->grpmask;
|
|
|
|
rnp_up = rnp->parent;
|
|
|
|
done = false;
|
|
|
|
while (rnp_up) {
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp_up, flags);
|
|
|
|
if (rnp_up->expmaskinit)
|
|
|
|
done = true;
|
|
|
|
rnp_up->expmaskinit |= mask;
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp_up, flags);
|
|
|
|
if (done)
|
|
|
|
break;
|
|
|
|
mask = rnp_up->grpmask;
|
|
|
|
rnp_up = rnp_up->parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the ->expmask values in the rcu_node tree in preparation for
|
|
|
|
* a new expedited grace period.
|
|
|
|
*/
|
|
|
|
static void __maybe_unused sync_exp_reset_tree(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
|
|
|
|
sync_exp_reset_tree_hotplug(rsp);
|
|
|
|
rcu_for_each_node_breadth_first(rsp, rnp) {
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
|
|
|
WARN_ON_ONCE(rnp->expmask);
|
|
|
|
rnp->expmask = rnp->expmaskinit;
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return non-zero if there is no RCU expedited grace period in progress
|
|
|
|
* for the specified rcu_node structure, in other words, if all CPUs and
|
|
|
|
* tasks covered by the specified rcu_node structure have done their bit
|
|
|
|
* for the current expedited grace period. Works only for preemptible
|
|
|
|
* RCU -- other RCU implementation use other means.
|
|
|
|
*
|
|
|
|
* Caller must hold the rcu_state's exp_mutex.
|
|
|
|
*/
|
|
|
|
static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
|
|
|
|
{
|
|
|
|
return rnp->exp_tasks == NULL &&
|
|
|
|
READ_ONCE(rnp->expmask) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report the exit from RCU read-side critical section for the last task
|
|
|
|
* that queued itself during or before the current expedited preemptible-RCU
|
|
|
|
* grace period. This event is reported either to the rcu_node structure on
|
|
|
|
* which the task was queued or to one of that rcu_node structure's ancestors,
|
|
|
|
* recursively up the tree. (Calm down, calm down, we do the recursion
|
|
|
|
* iteratively!)
|
|
|
|
*
|
|
|
|
* Caller must hold the rcu_state's exp_mutex and the specified rcu_node
|
|
|
|
* structure's ->lock.
|
|
|
|
*/
|
|
|
|
static void __rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
|
|
|
|
bool wake, unsigned long flags)
|
|
|
|
__releases(rnp->lock)
|
|
|
|
{
|
|
|
|
unsigned long mask;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!sync_rcu_preempt_exp_done(rnp)) {
|
|
|
|
if (!rnp->expmask)
|
|
|
|
rcu_initiate_boost(rnp, flags);
|
|
|
|
else
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rnp->parent == NULL) {
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
if (wake) {
|
|
|
|
smp_mb(); /* EGP done before wake_up(). */
|
|
|
|
swake_up(&rsp->expedited_wq);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mask = rnp->grpmask;
|
|
|
|
raw_spin_unlock_rcu_node(rnp); /* irqs remain disabled */
|
|
|
|
rnp = rnp->parent;
|
|
|
|
raw_spin_lock_rcu_node(rnp); /* irqs already disabled */
|
|
|
|
WARN_ON_ONCE(!(rnp->expmask & mask));
|
|
|
|
rnp->expmask &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report expedited quiescent state for specified node. This is a
|
|
|
|
* lock-acquisition wrapper function for __rcu_report_exp_rnp().
|
|
|
|
*
|
|
|
|
* Caller must hold the rcu_state's exp_mutex.
|
|
|
|
*/
|
|
|
|
static void __maybe_unused rcu_report_exp_rnp(struct rcu_state *rsp,
|
|
|
|
struct rcu_node *rnp, bool wake)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
|
|
|
__rcu_report_exp_rnp(rsp, rnp, wake, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report expedited quiescent state for multiple CPUs, all covered by the
|
|
|
|
* specified leaf rcu_node structure. Caller must hold the rcu_state's
|
|
|
|
* exp_mutex.
|
|
|
|
*/
|
|
|
|
static void rcu_report_exp_cpu_mult(struct rcu_state *rsp, struct rcu_node *rnp,
|
|
|
|
unsigned long mask, bool wake)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
|
|
|
if (!(rnp->expmask & mask)) {
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rnp->expmask &= ~mask;
|
|
|
|
__rcu_report_exp_rnp(rsp, rnp, wake, flags); /* Releases rnp->lock. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report expedited quiescent state for specified rcu_data (CPU).
|
|
|
|
*/
|
|
|
|
static void rcu_report_exp_rdp(struct rcu_state *rsp, struct rcu_data *rdp,
|
|
|
|
bool wake)
|
|
|
|
{
|
|
|
|
rcu_report_exp_cpu_mult(rsp, rdp->mynode, rdp->grpmask, wake);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Common code for synchronize_{rcu,sched}_expedited() work-done checking. */
|
|
|
|
static bool sync_exp_work_done(struct rcu_state *rsp, atomic_long_t *stat,
|
|
|
|
unsigned long s)
|
|
|
|
{
|
|
|
|
if (rcu_exp_gp_seq_done(rsp, s)) {
|
|
|
|
trace_rcu_exp_grace_period(rsp->name, s, TPS("done"));
|
|
|
|
/* Ensure test happens before caller kfree(). */
|
|
|
|
smp_mb__before_atomic(); /* ^^^ */
|
|
|
|
atomic_long_inc(stat);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Funnel-lock acquisition for expedited grace periods. Returns true
|
|
|
|
* if some other task completed an expedited grace period that this task
|
|
|
|
* can piggy-back on, and with no mutex held. Otherwise, returns false
|
|
|
|
* with the mutex held, indicating that the caller must actually do the
|
|
|
|
* expedited grace period.
|
|
|
|
*/
|
|
|
|
static bool exp_funnel_lock(struct rcu_state *rsp, unsigned long s)
|
|
|
|
{
|
|
|
|
struct rcu_data *rdp = per_cpu_ptr(rsp->rda, raw_smp_processor_id());
|
|
|
|
struct rcu_node *rnp = rdp->mynode;
|
|
|
|
struct rcu_node *rnp_root = rcu_get_root(rsp);
|
|
|
|
|
|
|
|
/* Low-contention fastpath. */
|
|
|
|
if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s) &&
|
|
|
|
(rnp == rnp_root ||
|
|
|
|
ULONG_CMP_LT(READ_ONCE(rnp_root->exp_seq_rq), s)) &&
|
|
|
|
mutex_trylock(&rsp->exp_mutex))
|
|
|
|
goto fastpath;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each pass through the following loop works its way up
|
|
|
|
* the rcu_node tree, returning if others have done the work or
|
|
|
|
* otherwise falls through to acquire rsp->exp_mutex. The mapping
|
|
|
|
* from CPU to rcu_node structure can be inexact, as it is just
|
|
|
|
* promoting locality and is not strictly needed for correctness.
|
|
|
|
*/
|
|
|
|
for (; rnp != NULL; rnp = rnp->parent) {
|
|
|
|
if (sync_exp_work_done(rsp, &rdp->exp_workdone1, s))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Work not done, either wait here or go up. */
|
|
|
|
spin_lock(&rnp->exp_lock);
|
|
|
|
if (ULONG_CMP_GE(rnp->exp_seq_rq, s)) {
|
|
|
|
|
|
|
|
/* Someone else doing GP, so wait for them. */
|
|
|
|
spin_unlock(&rnp->exp_lock);
|
|
|
|
trace_rcu_exp_funnel_lock(rsp->name, rnp->level,
|
|
|
|
rnp->grplo, rnp->grphi,
|
|
|
|
TPS("wait"));
|
|
|
|
wait_event(rnp->exp_wq[(s >> 1) & 0x3],
|
|
|
|
sync_exp_work_done(rsp,
|
|
|
|
&rdp->exp_workdone2, s));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
rnp->exp_seq_rq = s; /* Followers can wait on us. */
|
|
|
|
spin_unlock(&rnp->exp_lock);
|
|
|
|
trace_rcu_exp_funnel_lock(rsp->name, rnp->level, rnp->grplo,
|
|
|
|
rnp->grphi, TPS("nxtlvl"));
|
|
|
|
}
|
|
|
|
mutex_lock(&rsp->exp_mutex);
|
|
|
|
fastpath:
|
|
|
|
if (sync_exp_work_done(rsp, &rdp->exp_workdone3, s)) {
|
|
|
|
mutex_unlock(&rsp->exp_mutex);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
rcu_exp_gp_seq_start(rsp);
|
|
|
|
trace_rcu_exp_grace_period(rsp->name, s, TPS("start"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoked on each online non-idle CPU for expedited quiescent state. */
|
|
|
|
static void sync_sched_exp_handler(void *data)
|
|
|
|
{
|
|
|
|
struct rcu_data *rdp;
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
struct rcu_state *rsp = data;
|
|
|
|
|
|
|
|
rdp = this_cpu_ptr(rsp->rda);
|
|
|
|
rnp = rdp->mynode;
|
|
|
|
if (!(READ_ONCE(rnp->expmask) & rdp->grpmask) ||
|
|
|
|
__this_cpu_read(rcu_sched_data.cpu_no_qs.b.exp))
|
|
|
|
return;
|
|
|
|
if (rcu_is_cpu_rrupt_from_idle()) {
|
|
|
|
rcu_report_exp_rdp(&rcu_sched_state,
|
|
|
|
this_cpu_ptr(&rcu_sched_data), true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
__this_cpu_write(rcu_sched_data.cpu_no_qs.b.exp, true);
|
|
|
|
resched_cpu(smp_processor_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send IPI for expedited cleanup if needed at end of CPU-hotplug operation. */
|
|
|
|
static void sync_sched_exp_online_cleanup(int cpu)
|
|
|
|
{
|
|
|
|
struct rcu_data *rdp;
|
|
|
|
int ret;
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
struct rcu_state *rsp = &rcu_sched_state;
|
|
|
|
|
|
|
|
rdp = per_cpu_ptr(rsp->rda, cpu);
|
|
|
|
rnp = rdp->mynode;
|
|
|
|
if (!(READ_ONCE(rnp->expmask) & rdp->grpmask))
|
|
|
|
return;
|
|
|
|
ret = smp_call_function_single(cpu, sync_sched_exp_handler, rsp, 0);
|
|
|
|
WARN_ON_ONCE(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Select the nodes that the upcoming expedited grace period needs
|
|
|
|
* to wait for.
|
|
|
|
*/
|
|
|
|
static void sync_rcu_exp_select_cpus(struct rcu_state *rsp,
|
|
|
|
smp_call_func_t func)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned long mask_ofl_test;
|
|
|
|
unsigned long mask_ofl_ipi;
|
|
|
|
int ret;
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
|
|
|
|
sync_exp_reset_tree(rsp);
|
|
|
|
rcu_for_each_leaf_node(rsp, rnp) {
|
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
|
|
|
|
|
|
|
/* Each pass checks a CPU for identity, offline, and idle. */
|
|
|
|
mask_ofl_test = 0;
|
rcu: Correctly handle sparse possible cpus
In many cases in the RCU tree code, we iterate over the set of cpus for
a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
per-cpu data for each cpu in this range. However, if the set of possible
cpus is sparse, some cpus described in this range are not possible, and
thus no per-cpu region will have been allocated (or initialised) for
them by the generic percpu code.
Erroneous accesses to a per-cpu area for these !possible cpus may fault
or may hit other data depending on the addressed generated when the
erroneous per cpu offset is applied. In practice, both cases have been
observed on arm64 hardware (the former being silent, but detectable with
additional patches).
To avoid issues resulting from this, we must iterate over the set of
*possible* cpus for a given leaf node. This patch add a new helper,
for_each_leaf_node_possible_cpu, to enable this. As iteration is often
intertwined with rcu_node local bitmask manipulation, a new
leaf_node_cpu_bit helper is added to make this simpler and more
consistent. The RCU tree code is made to use both of these where
appropriate.
Without this patch, running reboot at a shell can result in an oops
like:
[ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
[ 3369.083881] pgd = ffffffc3ecdda000
[ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
[ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
[ 3369.101781] Modules linked in:
[ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G W 4.6.0+ #3
[ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
[ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
[ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
[ 3369.146860] sp : ffffffc3eb9435a0
[ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
[ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
[ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
[ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
[ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
[ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
[ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
[ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
[ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
[ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
[ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
[ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
[ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
[ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
[ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
...
[ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
[ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
[ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
[ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
[ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
[ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
[ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
[ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
[ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
[ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
[ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
[ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
[ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
[ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
[ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
[ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
[ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
[ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
[ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Dennis Chen <dennis.chen@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
2016-06-03 14:20:04 +00:00
|
|
|
for_each_leaf_node_possible_cpu(rnp, cpu) {
|
2016-04-15 23:35:29 +00:00
|
|
|
struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
|
|
|
|
|
2016-10-11 13:09:59 +00:00
|
|
|
rdp->exp_dynticks_snap =
|
2016-11-02 21:12:05 +00:00
|
|
|
rcu_dynticks_snap(rdp->dynticks);
|
2016-04-15 23:35:29 +00:00
|
|
|
if (raw_smp_processor_id() == cpu ||
|
2016-11-03 00:25:06 +00:00
|
|
|
rcu_dynticks_in_eqs(rdp->exp_dynticks_snap) ||
|
2016-06-30 00:04:19 +00:00
|
|
|
!(rnp->qsmaskinitnext & rdp->grpmask))
|
2016-04-15 23:35:29 +00:00
|
|
|
mask_ofl_test |= rdp->grpmask;
|
|
|
|
}
|
|
|
|
mask_ofl_ipi = rnp->expmask & ~mask_ofl_test;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need to wait for any blocked tasks as well. Note that
|
|
|
|
* additional blocking tasks will also block the expedited
|
|
|
|
* GP until such time as the ->expmask bits are cleared.
|
|
|
|
*/
|
|
|
|
if (rcu_preempt_has_tasks(rnp))
|
|
|
|
rnp->exp_tasks = rnp->blkd_tasks.next;
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
|
|
|
|
/* IPI the remaining CPUs for expedited quiescent state. */
|
rcu: Correctly handle sparse possible cpus
In many cases in the RCU tree code, we iterate over the set of cpus for
a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
per-cpu data for each cpu in this range. However, if the set of possible
cpus is sparse, some cpus described in this range are not possible, and
thus no per-cpu region will have been allocated (or initialised) for
them by the generic percpu code.
Erroneous accesses to a per-cpu area for these !possible cpus may fault
or may hit other data depending on the addressed generated when the
erroneous per cpu offset is applied. In practice, both cases have been
observed on arm64 hardware (the former being silent, but detectable with
additional patches).
To avoid issues resulting from this, we must iterate over the set of
*possible* cpus for a given leaf node. This patch add a new helper,
for_each_leaf_node_possible_cpu, to enable this. As iteration is often
intertwined with rcu_node local bitmask manipulation, a new
leaf_node_cpu_bit helper is added to make this simpler and more
consistent. The RCU tree code is made to use both of these where
appropriate.
Without this patch, running reboot at a shell can result in an oops
like:
[ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
[ 3369.083881] pgd = ffffffc3ecdda000
[ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
[ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
[ 3369.101781] Modules linked in:
[ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G W 4.6.0+ #3
[ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
[ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
[ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
[ 3369.146860] sp : ffffffc3eb9435a0
[ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
[ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
[ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
[ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
[ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
[ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
[ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
[ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
[ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
[ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
[ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
[ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
[ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
[ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
[ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
...
[ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
[ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
[ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
[ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
[ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
[ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
[ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
[ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
[ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
[ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
[ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
[ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
[ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
[ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
[ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
[ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
[ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
[ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
[ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Dennis Chen <dennis.chen@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
2016-06-03 14:20:04 +00:00
|
|
|
for_each_leaf_node_possible_cpu(rnp, cpu) {
|
|
|
|
unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
|
2016-10-11 13:09:59 +00:00
|
|
|
struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
|
|
|
|
|
2016-04-15 23:35:29 +00:00
|
|
|
if (!(mask_ofl_ipi & mask))
|
|
|
|
continue;
|
|
|
|
retry_ipi:
|
2016-11-03 00:25:06 +00:00
|
|
|
if (rcu_dynticks_in_eqs_since(rdp->dynticks,
|
|
|
|
rdp->exp_dynticks_snap)) {
|
2016-10-11 13:09:59 +00:00
|
|
|
mask_ofl_test |= mask;
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-15 23:35:29 +00:00
|
|
|
ret = smp_call_function_single(cpu, func, rsp, 0);
|
|
|
|
if (!ret) {
|
|
|
|
mask_ofl_ipi &= ~mask;
|
|
|
|
continue;
|
|
|
|
}
|
2016-06-30 19:16:11 +00:00
|
|
|
/* Failed, raced with CPU hotplug operation. */
|
2016-04-15 23:35:29 +00:00
|
|
|
raw_spin_lock_irqsave_rcu_node(rnp, flags);
|
2016-06-30 19:16:11 +00:00
|
|
|
if ((rnp->qsmaskinitnext & mask) &&
|
2016-04-15 23:35:29 +00:00
|
|
|
(rnp->expmask & mask)) {
|
2016-06-30 19:16:11 +00:00
|
|
|
/* Online, so delay for a bit and try again. */
|
2016-04-15 23:35:29 +00:00
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
schedule_timeout_uninterruptible(1);
|
2016-06-30 19:16:11 +00:00
|
|
|
goto retry_ipi;
|
2016-04-15 23:35:29 +00:00
|
|
|
}
|
2016-06-30 19:16:11 +00:00
|
|
|
/* CPU really is offline, so we can ignore it. */
|
2016-04-15 23:35:29 +00:00
|
|
|
if (!(rnp->expmask & mask))
|
|
|
|
mask_ofl_ipi &= ~mask;
|
|
|
|
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
|
|
|
|
}
|
|
|
|
/* Report quiescent states for those that went offline. */
|
|
|
|
mask_ofl_test |= mask_ofl_ipi;
|
|
|
|
if (mask_ofl_test)
|
|
|
|
rcu_report_exp_cpu_mult(rsp, rnp, mask_ofl_test, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void synchronize_sched_expedited_wait(struct rcu_state *rsp)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
unsigned long jiffies_stall;
|
|
|
|
unsigned long jiffies_start;
|
|
|
|
unsigned long mask;
|
|
|
|
int ndetected;
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
struct rcu_node *rnp_root = rcu_get_root(rsp);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
jiffies_stall = rcu_jiffies_till_stall_check();
|
|
|
|
jiffies_start = jiffies;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ret = swait_event_timeout(
|
|
|
|
rsp->expedited_wq,
|
|
|
|
sync_rcu_preempt_exp_done(rnp_root),
|
|
|
|
jiffies_stall);
|
|
|
|
if (ret > 0 || sync_rcu_preempt_exp_done(rnp_root))
|
|
|
|
return;
|
2016-06-29 21:34:59 +00:00
|
|
|
WARN_ON(ret < 0); /* workqueues should not be signaled. */
|
2016-06-29 21:49:29 +00:00
|
|
|
if (rcu_cpu_stall_suppress)
|
|
|
|
continue;
|
|
|
|
panic_on_rcu_stall();
|
2016-04-15 23:35:29 +00:00
|
|
|
pr_err("INFO: %s detected expedited stalls on CPUs/tasks: {",
|
|
|
|
rsp->name);
|
|
|
|
ndetected = 0;
|
|
|
|
rcu_for_each_leaf_node(rsp, rnp) {
|
|
|
|
ndetected += rcu_print_task_exp_stall(rnp);
|
rcu: Correctly handle sparse possible cpus
In many cases in the RCU tree code, we iterate over the set of cpus for
a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
per-cpu data for each cpu in this range. However, if the set of possible
cpus is sparse, some cpus described in this range are not possible, and
thus no per-cpu region will have been allocated (or initialised) for
them by the generic percpu code.
Erroneous accesses to a per-cpu area for these !possible cpus may fault
or may hit other data depending on the addressed generated when the
erroneous per cpu offset is applied. In practice, both cases have been
observed on arm64 hardware (the former being silent, but detectable with
additional patches).
To avoid issues resulting from this, we must iterate over the set of
*possible* cpus for a given leaf node. This patch add a new helper,
for_each_leaf_node_possible_cpu, to enable this. As iteration is often
intertwined with rcu_node local bitmask manipulation, a new
leaf_node_cpu_bit helper is added to make this simpler and more
consistent. The RCU tree code is made to use both of these where
appropriate.
Without this patch, running reboot at a shell can result in an oops
like:
[ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
[ 3369.083881] pgd = ffffffc3ecdda000
[ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
[ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
[ 3369.101781] Modules linked in:
[ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G W 4.6.0+ #3
[ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
[ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
[ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
[ 3369.146860] sp : ffffffc3eb9435a0
[ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
[ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
[ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
[ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
[ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
[ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
[ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
[ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
[ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
[ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
[ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
[ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
[ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
[ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
[ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
...
[ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
[ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
[ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
[ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
[ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
[ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
[ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
[ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
[ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
[ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
[ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
[ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
[ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
[ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
[ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
[ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
[ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
[ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
[ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Dennis Chen <dennis.chen@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
2016-06-03 14:20:04 +00:00
|
|
|
for_each_leaf_node_possible_cpu(rnp, cpu) {
|
2016-04-15 23:35:29 +00:00
|
|
|
struct rcu_data *rdp;
|
|
|
|
|
rcu: Correctly handle sparse possible cpus
In many cases in the RCU tree code, we iterate over the set of cpus for
a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
per-cpu data for each cpu in this range. However, if the set of possible
cpus is sparse, some cpus described in this range are not possible, and
thus no per-cpu region will have been allocated (or initialised) for
them by the generic percpu code.
Erroneous accesses to a per-cpu area for these !possible cpus may fault
or may hit other data depending on the addressed generated when the
erroneous per cpu offset is applied. In practice, both cases have been
observed on arm64 hardware (the former being silent, but detectable with
additional patches).
To avoid issues resulting from this, we must iterate over the set of
*possible* cpus for a given leaf node. This patch add a new helper,
for_each_leaf_node_possible_cpu, to enable this. As iteration is often
intertwined with rcu_node local bitmask manipulation, a new
leaf_node_cpu_bit helper is added to make this simpler and more
consistent. The RCU tree code is made to use both of these where
appropriate.
Without this patch, running reboot at a shell can result in an oops
like:
[ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
[ 3369.083881] pgd = ffffffc3ecdda000
[ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
[ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
[ 3369.101781] Modules linked in:
[ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G W 4.6.0+ #3
[ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
[ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
[ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
[ 3369.146860] sp : ffffffc3eb9435a0
[ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
[ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
[ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
[ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
[ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
[ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
[ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
[ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
[ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
[ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
[ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
[ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
[ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
[ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
[ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
...
[ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
[ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
[ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
[ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
[ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
[ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
[ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
[ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
[ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
[ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
[ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
[ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
[ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
[ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
[ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
[ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
[ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
[ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
[ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Dennis Chen <dennis.chen@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
2016-06-03 14:20:04 +00:00
|
|
|
mask = leaf_node_cpu_bit(rnp, cpu);
|
2016-04-15 23:35:29 +00:00
|
|
|
if (!(rnp->expmask & mask))
|
|
|
|
continue;
|
|
|
|
ndetected++;
|
|
|
|
rdp = per_cpu_ptr(rsp->rda, cpu);
|
|
|
|
pr_cont(" %d-%c%c%c", cpu,
|
|
|
|
"O."[!!cpu_online(cpu)],
|
|
|
|
"o."[!!(rdp->grpmask & rnp->expmaskinit)],
|
|
|
|
"N."[!!(rdp->grpmask & rnp->expmaskinitnext)]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n",
|
|
|
|
jiffies - jiffies_start, rsp->expedited_sequence,
|
|
|
|
rnp_root->expmask, ".T"[!!rnp_root->exp_tasks]);
|
|
|
|
if (ndetected) {
|
|
|
|
pr_err("blocking rcu_node structures:");
|
|
|
|
rcu_for_each_node_breadth_first(rsp, rnp) {
|
|
|
|
if (rnp == rnp_root)
|
|
|
|
continue; /* printed unconditionally */
|
|
|
|
if (sync_rcu_preempt_exp_done(rnp))
|
|
|
|
continue;
|
|
|
|
pr_cont(" l=%u:%d-%d:%#lx/%c",
|
|
|
|
rnp->level, rnp->grplo, rnp->grphi,
|
|
|
|
rnp->expmask,
|
|
|
|
".T"[!!rnp->exp_tasks]);
|
|
|
|
}
|
|
|
|
pr_cont("\n");
|
|
|
|
}
|
|
|
|
rcu_for_each_leaf_node(rsp, rnp) {
|
rcu: Correctly handle sparse possible cpus
In many cases in the RCU tree code, we iterate over the set of cpus for
a leaf node described by rcu_node::grplo and rcu_node::grphi, checking
per-cpu data for each cpu in this range. However, if the set of possible
cpus is sparse, some cpus described in this range are not possible, and
thus no per-cpu region will have been allocated (or initialised) for
them by the generic percpu code.
Erroneous accesses to a per-cpu area for these !possible cpus may fault
or may hit other data depending on the addressed generated when the
erroneous per cpu offset is applied. In practice, both cases have been
observed on arm64 hardware (the former being silent, but detectable with
additional patches).
To avoid issues resulting from this, we must iterate over the set of
*possible* cpus for a given leaf node. This patch add a new helper,
for_each_leaf_node_possible_cpu, to enable this. As iteration is often
intertwined with rcu_node local bitmask manipulation, a new
leaf_node_cpu_bit helper is added to make this simpler and more
consistent. The RCU tree code is made to use both of these where
appropriate.
Without this patch, running reboot at a shell can result in an oops
like:
[ 3369.075979] Unable to handle kernel paging request at virtual address ffffff8008b21b4c
[ 3369.083881] pgd = ffffffc3ecdda000
[ 3369.087270] [ffffff8008b21b4c] *pgd=00000083eca48003, *pud=00000083eca48003, *pmd=0000000000000000
[ 3369.096222] Internal error: Oops: 96000007 [#1] PREEMPT SMP
[ 3369.101781] Modules linked in:
[ 3369.104825] CPU: 2 PID: 1817 Comm: NetworkManager Tainted: G W 4.6.0+ #3
[ 3369.121239] task: ffffffc0fa13e000 ti: ffffffc3eb940000 task.ti: ffffffc3eb940000
[ 3369.128708] PC is at sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.134094] LR is at sync_rcu_exp_select_cpus+0x104/0x510
[ 3369.139479] pc : [<ffffff80081109a8>] lr : [<ffffff8008110924>] pstate: 200001c5
[ 3369.146860] sp : ffffffc3eb9435a0
[ 3369.150162] x29: ffffffc3eb9435a0 x28: ffffff8008be4f88
[ 3369.155465] x27: ffffff8008b66c80 x26: ffffffc3eceb2600
[ 3369.160767] x25: 0000000000000001 x24: ffffff8008be4f88
[ 3369.166070] x23: ffffff8008b51c3c x22: ffffff8008b66c80
[ 3369.171371] x21: 0000000000000001 x20: ffffff8008b21b40
[ 3369.176673] x19: ffffff8008b66c80 x18: 0000000000000000
[ 3369.181975] x17: 0000007fa951a010 x16: ffffff80086a30f0
[ 3369.187278] x15: 0000007fa9505590 x14: 0000000000000000
[ 3369.192580] x13: ffffff8008b51000 x12: ffffffc3eb940000
[ 3369.197882] x11: 0000000000000006 x10: ffffff8008b51b78
[ 3369.203184] x9 : 0000000000000001 x8 : ffffff8008be4000
[ 3369.208486] x7 : ffffff8008b21b40 x6 : 0000000000001003
[ 3369.213788] x5 : 0000000000000000 x4 : ffffff8008b27280
[ 3369.219090] x3 : ffffff8008b21b4c x2 : 0000000000000001
[ 3369.224406] x1 : 0000000000000001 x0 : 0000000000000140
...
[ 3369.972257] [<ffffff80081109a8>] sync_rcu_exp_select_cpus+0x188/0x510
[ 3369.978685] [<ffffff80081128b4>] synchronize_rcu_expedited+0x64/0xa8
[ 3369.985026] [<ffffff80086b987c>] synchronize_net+0x24/0x30
[ 3369.990499] [<ffffff80086ddb54>] dev_deactivate_many+0x28c/0x298
[ 3369.996493] [<ffffff80086b6bb8>] __dev_close_many+0x60/0xd0
[ 3370.002052] [<ffffff80086b6d48>] __dev_close+0x28/0x40
[ 3370.007178] [<ffffff80086bf62c>] __dev_change_flags+0x8c/0x158
[ 3370.012999] [<ffffff80086bf718>] dev_change_flags+0x20/0x60
[ 3370.018558] [<ffffff80086cf7f0>] do_setlink+0x288/0x918
[ 3370.023771] [<ffffff80086d0798>] rtnl_newlink+0x398/0x6a8
[ 3370.029158] [<ffffff80086cee84>] rtnetlink_rcv_msg+0xe4/0x220
[ 3370.034891] [<ffffff80086e274c>] netlink_rcv_skb+0xc4/0xf8
[ 3370.040364] [<ffffff80086ced8c>] rtnetlink_rcv+0x2c/0x40
[ 3370.045663] [<ffffff80086e1fe8>] netlink_unicast+0x160/0x238
[ 3370.051309] [<ffffff80086e24b8>] netlink_sendmsg+0x2f0/0x358
[ 3370.056956] [<ffffff80086a0070>] sock_sendmsg+0x18/0x30
[ 3370.062168] [<ffffff80086a21cc>] ___sys_sendmsg+0x26c/0x280
[ 3370.067728] [<ffffff80086a30ac>] __sys_sendmsg+0x44/0x88
[ 3370.073027] [<ffffff80086a3100>] SyS_sendmsg+0x10/0x20
[ 3370.078153] [<ffffff8008085e70>] el0_svc_naked+0x24/0x28
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reported-by: Dennis Chen <dennis.chen@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
2016-06-03 14:20:04 +00:00
|
|
|
for_each_leaf_node_possible_cpu(rnp, cpu) {
|
|
|
|
mask = leaf_node_cpu_bit(rnp, cpu);
|
2016-04-15 23:35:29 +00:00
|
|
|
if (!(rnp->expmask & mask))
|
|
|
|
continue;
|
|
|
|
dump_cpu_task(cpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jiffies_stall = 3 * rcu_jiffies_till_stall_check() + 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the current expedited grace period to complete, and then
|
|
|
|
* wake up everyone who piggybacked on the just-completed expedited
|
|
|
|
* grace period. Also update all the ->exp_seq_rq counters as needed
|
|
|
|
* in order to avoid counter-wrap problems.
|
|
|
|
*/
|
|
|
|
static void rcu_exp_wait_wake(struct rcu_state *rsp, unsigned long s)
|
|
|
|
{
|
|
|
|
struct rcu_node *rnp;
|
|
|
|
|
|
|
|
synchronize_sched_expedited_wait(rsp);
|
|
|
|
rcu_exp_gp_seq_end(rsp);
|
|
|
|
trace_rcu_exp_grace_period(rsp->name, s, TPS("end"));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch over to wakeup mode, allowing the next GP, but -only- the
|
|
|
|
* next GP, to proceed.
|
|
|
|
*/
|
|
|
|
mutex_lock(&rsp->exp_wake_mutex);
|
|
|
|
|
|
|
|
rcu_for_each_node_breadth_first(rsp, rnp) {
|
|
|
|
if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s)) {
|
|
|
|
spin_lock(&rnp->exp_lock);
|
|
|
|
/* Recheck, avoid hang in case someone just arrived. */
|
|
|
|
if (ULONG_CMP_LT(rnp->exp_seq_rq, s))
|
|
|
|
rnp->exp_seq_rq = s;
|
|
|
|
spin_unlock(&rnp->exp_lock);
|
|
|
|
}
|
|
|
|
wake_up_all(&rnp->exp_wq[(rsp->expedited_sequence >> 1) & 0x3]);
|
|
|
|
}
|
|
|
|
trace_rcu_exp_grace_period(rsp->name, s, TPS("endwake"));
|
|
|
|
mutex_unlock(&rsp->exp_wake_mutex);
|
|
|
|
}
|
|
|
|
|
2016-06-29 20:46:25 +00:00
|
|
|
/* Let the workqueue handler know what it is supposed to do. */
|
|
|
|
struct rcu_exp_work {
|
|
|
|
smp_call_func_t rew_func;
|
|
|
|
struct rcu_state *rew_rsp;
|
|
|
|
unsigned long rew_s;
|
|
|
|
struct work_struct rew_work;
|
|
|
|
};
|
|
|
|
|
rcu: Narrow early boot window of illegal synchronous grace periods
The current preemptible RCU implementation goes through three phases
during bootup. In the first phase, there is only one CPU that is running
with preemption disabled, so that a no-op is a synchronous grace period.
In the second mid-boot phase, the scheduler is running, but RCU has
not yet gotten its kthreads spawned (and, for expedited grace periods,
workqueues are not yet running. During this time, any attempt to do
a synchronous grace period will hang the system (or complain bitterly,
depending). In the third and final phase, RCU is fully operational and
everything works normally.
This has been OK for some time, but there has recently been some
synchronous grace periods showing up during the second mid-boot phase.
This code worked "by accident" for awhile, but started failing as soon
as expedited RCU grace periods switched over to workqueues in commit
8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue").
Note that the code was buggy even before this commit, as it was subject
to failure on real-time systems that forced all expedited grace periods
to run as normal grace periods (for example, using the rcu_normal ksysfs
parameter). The callchain from the failure case is as follows:
early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited
The kernel showing this callchain was built with CONFIG_PREEMPT_RCU=y,
which caused the code to try using workqueues before they were
initialized, which did not go well.
This commit therefore reworks RCU to permit synchronous grace periods
to proceed during this mid-boot phase. This commit is therefore a
fix to a regression introduced in v4.9, and is therefore being put
forward post-merge-window in v4.10.
This commit sets a flag from the existing rcu_scheduler_starting()
function which causes all synchronous grace periods to take the expedited
path. The expedited path now checks this flag, using the requesting task
to drive the expedited grace period forward during the mid-boot phase.
Finally, this flag is updated by a core_initcall() function named
rcu_exp_runtime_mode(), which causes the runtime codepaths to be used.
Note that this arrangement assumes that tasks are not sent POSIX signals
(or anything similar) from the time that the first task is spawned
through core_initcall() time.
Fixes: 8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue")
Reported-by: "Zheng, Lv" <lv.zheng@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Stan Kain <stan.kain@gmail.com>
Tested-by: Ivan <waffolz@hotmail.com>
Tested-by: Emanuel Castelo <emanuel.castelo@gmail.com>
Tested-by: Bruno Pesavento <bpesavento@infinito.it>
Tested-by: Borislav Petkov <bp@suse.de>
Tested-by: Frederic Bezies <fredbezies@gmail.com>
Cc: <stable@vger.kernel.org> # 4.9.0-
2017-01-10 10:28:26 +00:00
|
|
|
/*
|
|
|
|
* Common code to drive an expedited grace period forward, used by
|
|
|
|
* workqueues and mid-boot-time tasks.
|
|
|
|
*/
|
|
|
|
static void rcu_exp_sel_wait_wake(struct rcu_state *rsp,
|
|
|
|
smp_call_func_t func, unsigned long s)
|
|
|
|
{
|
|
|
|
/* Initialize the rcu_node tree in preparation for the wait. */
|
|
|
|
sync_rcu_exp_select_cpus(rsp, func);
|
|
|
|
|
|
|
|
/* Wait and clean up, including waking everyone. */
|
|
|
|
rcu_exp_wait_wake(rsp, s);
|
|
|
|
}
|
|
|
|
|
2016-06-29 20:46:25 +00:00
|
|
|
/*
|
|
|
|
* Work-queue handler to drive an expedited grace period forward.
|
|
|
|
*/
|
|
|
|
static void wait_rcu_exp_gp(struct work_struct *wp)
|
|
|
|
{
|
|
|
|
struct rcu_exp_work *rewp;
|
|
|
|
|
|
|
|
rewp = container_of(wp, struct rcu_exp_work, rew_work);
|
rcu: Narrow early boot window of illegal synchronous grace periods
The current preemptible RCU implementation goes through three phases
during bootup. In the first phase, there is only one CPU that is running
with preemption disabled, so that a no-op is a synchronous grace period.
In the second mid-boot phase, the scheduler is running, but RCU has
not yet gotten its kthreads spawned (and, for expedited grace periods,
workqueues are not yet running. During this time, any attempt to do
a synchronous grace period will hang the system (or complain bitterly,
depending). In the third and final phase, RCU is fully operational and
everything works normally.
This has been OK for some time, but there has recently been some
synchronous grace periods showing up during the second mid-boot phase.
This code worked "by accident" for awhile, but started failing as soon
as expedited RCU grace periods switched over to workqueues in commit
8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue").
Note that the code was buggy even before this commit, as it was subject
to failure on real-time systems that forced all expedited grace periods
to run as normal grace periods (for example, using the rcu_normal ksysfs
parameter). The callchain from the failure case is as follows:
early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited
The kernel showing this callchain was built with CONFIG_PREEMPT_RCU=y,
which caused the code to try using workqueues before they were
initialized, which did not go well.
This commit therefore reworks RCU to permit synchronous grace periods
to proceed during this mid-boot phase. This commit is therefore a
fix to a regression introduced in v4.9, and is therefore being put
forward post-merge-window in v4.10.
This commit sets a flag from the existing rcu_scheduler_starting()
function which causes all synchronous grace periods to take the expedited
path. The expedited path now checks this flag, using the requesting task
to drive the expedited grace period forward during the mid-boot phase.
Finally, this flag is updated by a core_initcall() function named
rcu_exp_runtime_mode(), which causes the runtime codepaths to be used.
Note that this arrangement assumes that tasks are not sent POSIX signals
(or anything similar) from the time that the first task is spawned
through core_initcall() time.
Fixes: 8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue")
Reported-by: "Zheng, Lv" <lv.zheng@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Stan Kain <stan.kain@gmail.com>
Tested-by: Ivan <waffolz@hotmail.com>
Tested-by: Emanuel Castelo <emanuel.castelo@gmail.com>
Tested-by: Bruno Pesavento <bpesavento@infinito.it>
Tested-by: Borislav Petkov <bp@suse.de>
Tested-by: Frederic Bezies <fredbezies@gmail.com>
Cc: <stable@vger.kernel.org> # 4.9.0-
2017-01-10 10:28:26 +00:00
|
|
|
rcu_exp_sel_wait_wake(rewp->rew_rsp, rewp->rew_func, rewp->rew_s);
|
2016-06-29 20:46:25 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 18:30:32 +00:00
|
|
|
/*
|
|
|
|
* Given an rcu_state pointer and a smp_call_function() handler, kick
|
|
|
|
* off the specified flavor of expedited grace period.
|
|
|
|
*/
|
|
|
|
static void _synchronize_rcu_expedited(struct rcu_state *rsp,
|
|
|
|
smp_call_func_t func)
|
|
|
|
{
|
2016-06-29 20:46:25 +00:00
|
|
|
struct rcu_data *rdp;
|
|
|
|
struct rcu_exp_work rew;
|
|
|
|
struct rcu_node *rnp;
|
2016-06-24 18:30:32 +00:00
|
|
|
unsigned long s;
|
|
|
|
|
|
|
|
/* If expedited grace periods are prohibited, fall back to normal. */
|
|
|
|
if (rcu_gp_is_normal()) {
|
|
|
|
wait_rcu_gp(rsp->call);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Take a snapshot of the sequence number. */
|
|
|
|
s = rcu_exp_gp_seq_snap(rsp);
|
|
|
|
if (exp_funnel_lock(rsp, s))
|
|
|
|
return; /* Someone else did our work for us. */
|
|
|
|
|
rcu: Narrow early boot window of illegal synchronous grace periods
The current preemptible RCU implementation goes through three phases
during bootup. In the first phase, there is only one CPU that is running
with preemption disabled, so that a no-op is a synchronous grace period.
In the second mid-boot phase, the scheduler is running, but RCU has
not yet gotten its kthreads spawned (and, for expedited grace periods,
workqueues are not yet running. During this time, any attempt to do
a synchronous grace period will hang the system (or complain bitterly,
depending). In the third and final phase, RCU is fully operational and
everything works normally.
This has been OK for some time, but there has recently been some
synchronous grace periods showing up during the second mid-boot phase.
This code worked "by accident" for awhile, but started failing as soon
as expedited RCU grace periods switched over to workqueues in commit
8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue").
Note that the code was buggy even before this commit, as it was subject
to failure on real-time systems that forced all expedited grace periods
to run as normal grace periods (for example, using the rcu_normal ksysfs
parameter). The callchain from the failure case is as follows:
early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited
The kernel showing this callchain was built with CONFIG_PREEMPT_RCU=y,
which caused the code to try using workqueues before they were
initialized, which did not go well.
This commit therefore reworks RCU to permit synchronous grace periods
to proceed during this mid-boot phase. This commit is therefore a
fix to a regression introduced in v4.9, and is therefore being put
forward post-merge-window in v4.10.
This commit sets a flag from the existing rcu_scheduler_starting()
function which causes all synchronous grace periods to take the expedited
path. The expedited path now checks this flag, using the requesting task
to drive the expedited grace period forward during the mid-boot phase.
Finally, this flag is updated by a core_initcall() function named
rcu_exp_runtime_mode(), which causes the runtime codepaths to be used.
Note that this arrangement assumes that tasks are not sent POSIX signals
(or anything similar) from the time that the first task is spawned
through core_initcall() time.
Fixes: 8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue")
Reported-by: "Zheng, Lv" <lv.zheng@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Stan Kain <stan.kain@gmail.com>
Tested-by: Ivan <waffolz@hotmail.com>
Tested-by: Emanuel Castelo <emanuel.castelo@gmail.com>
Tested-by: Bruno Pesavento <bpesavento@infinito.it>
Tested-by: Borislav Petkov <bp@suse.de>
Tested-by: Frederic Bezies <fredbezies@gmail.com>
Cc: <stable@vger.kernel.org> # 4.9.0-
2017-01-10 10:28:26 +00:00
|
|
|
/* Ensure that load happens before action based on it. */
|
|
|
|
if (unlikely(rcu_scheduler_active == RCU_SCHEDULER_INIT)) {
|
|
|
|
/* Direct call during scheduler init and early_initcalls(). */
|
|
|
|
rcu_exp_sel_wait_wake(rsp, func, s);
|
|
|
|
} else {
|
|
|
|
/* Marshall arguments & schedule the expedited grace period. */
|
|
|
|
rew.rew_func = func;
|
|
|
|
rew.rew_rsp = rsp;
|
|
|
|
rew.rew_s = s;
|
|
|
|
INIT_WORK_ONSTACK(&rew.rew_work, wait_rcu_exp_gp);
|
|
|
|
schedule_work(&rew.rew_work);
|
|
|
|
}
|
2016-06-29 20:46:25 +00:00
|
|
|
|
|
|
|
/* Wait for expedited grace period to complete. */
|
|
|
|
rdp = per_cpu_ptr(rsp->rda, raw_smp_processor_id());
|
|
|
|
rnp = rcu_get_root(rsp);
|
|
|
|
wait_event(rnp->exp_wq[(s >> 1) & 0x3],
|
|
|
|
sync_exp_work_done(rsp,
|
|
|
|
&rdp->exp_workdone0, s));
|
|
|
|
|
|
|
|
/* Let the next expedited grace period start. */
|
|
|
|
mutex_unlock(&rsp->exp_mutex);
|
2016-06-24 18:30:32 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 23:35:29 +00:00
|
|
|
/**
|
|
|
|
* synchronize_sched_expedited - Brute-force RCU-sched grace period
|
|
|
|
*
|
|
|
|
* Wait for an RCU-sched grace period to elapse, but use a "big hammer"
|
|
|
|
* approach to force the grace period to end quickly. This consumes
|
|
|
|
* significant time on all CPUs and is unfriendly to real-time workloads,
|
|
|
|
* so is thus not recommended for any sort of common-case code. In fact,
|
|
|
|
* if you are using synchronize_sched_expedited() in a loop, please
|
|
|
|
* restructure your code to batch your updates, and then use a single
|
|
|
|
* synchronize_sched() instead.
|
|
|
|
*
|
|
|
|
* This implementation can be thought of as an application of sequence
|
|
|
|
* locking to expedited grace periods, but using the sequence counter to
|
|
|
|
* determine when someone else has already done the work instead of for
|
|
|
|
* retrying readers.
|
|
|
|
*/
|
|
|
|
void synchronize_sched_expedited(void)
|
|
|
|
{
|
|
|
|
struct rcu_state *rsp = &rcu_sched_state;
|
|
|
|
|
2017-01-09 23:25:55 +00:00
|
|
|
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_sched_expedited() in RCU read-side critical section");
|
|
|
|
|
2016-04-15 23:35:29 +00:00
|
|
|
/* If only one CPU, this is automatically a grace period. */
|
|
|
|
if (rcu_blocking_is_gp())
|
|
|
|
return;
|
|
|
|
|
2016-06-24 18:30:32 +00:00
|
|
|
_synchronize_rcu_expedited(rsp, sync_sched_exp_handler);
|
2016-04-15 23:35:29 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
|
2016-04-15 23:44:07 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_PREEMPT_RCU
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remote handler for smp_call_function_single(). If there is an
|
|
|
|
* RCU read-side critical section in effect, request that the
|
|
|
|
* next rcu_read_unlock() record the quiescent state up the
|
|
|
|
* ->expmask fields in the rcu_node tree. Otherwise, immediately
|
|
|
|
* report the quiescent state.
|
|
|
|
*/
|
|
|
|
static void sync_rcu_exp_handler(void *info)
|
|
|
|
{
|
|
|
|
struct rcu_data *rdp;
|
|
|
|
struct rcu_state *rsp = info;
|
|
|
|
struct task_struct *t = current;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Within an RCU read-side critical section, request that the next
|
|
|
|
* rcu_read_unlock() report. Unless this RCU read-side critical
|
|
|
|
* section has already blocked, in which case it is already set
|
|
|
|
* up for the expedited grace period to wait on it.
|
|
|
|
*/
|
|
|
|
if (t->rcu_read_lock_nesting > 0 &&
|
|
|
|
!t->rcu_read_unlock_special.b.blocked) {
|
|
|
|
t->rcu_read_unlock_special.b.exp_need_qs = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We are either exiting an RCU read-side critical section (negative
|
|
|
|
* values of t->rcu_read_lock_nesting) or are not in one at all
|
|
|
|
* (zero value of t->rcu_read_lock_nesting). Or we are in an RCU
|
|
|
|
* read-side critical section that blocked before this expedited
|
|
|
|
* grace period started. Either way, we can immediately report
|
|
|
|
* the quiescent state.
|
|
|
|
*/
|
|
|
|
rdp = this_cpu_ptr(rsp->rda);
|
|
|
|
rcu_report_exp_rdp(rsp, rdp, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* synchronize_rcu_expedited - Brute-force RCU grace period
|
|
|
|
*
|
|
|
|
* Wait for an RCU-preempt grace period, but expedite it. The basic
|
|
|
|
* idea is to IPI all non-idle non-nohz online CPUs. The IPI handler
|
|
|
|
* checks whether the CPU is in an RCU-preempt critical section, and
|
|
|
|
* if so, it sets a flag that causes the outermost rcu_read_unlock()
|
|
|
|
* to report the quiescent state. On the other hand, if the CPU is
|
|
|
|
* not in an RCU read-side critical section, the IPI handler reports
|
|
|
|
* the quiescent state immediately.
|
|
|
|
*
|
|
|
|
* Although this is a greate improvement over previous expedited
|
|
|
|
* implementations, it is still unfriendly to real-time workloads, so is
|
|
|
|
* thus not recommended for any sort of common-case code. In fact, if
|
|
|
|
* you are using synchronize_rcu_expedited() in a loop, please restructure
|
|
|
|
* your code to batch your updates, and then Use a single synchronize_rcu()
|
|
|
|
* instead.
|
|
|
|
*/
|
|
|
|
void synchronize_rcu_expedited(void)
|
|
|
|
{
|
|
|
|
struct rcu_state *rsp = rcu_state_p;
|
|
|
|
|
2017-01-09 23:25:55 +00:00
|
|
|
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_expedited() in RCU read-side critical section");
|
|
|
|
|
rcu: Narrow early boot window of illegal synchronous grace periods
The current preemptible RCU implementation goes through three phases
during bootup. In the first phase, there is only one CPU that is running
with preemption disabled, so that a no-op is a synchronous grace period.
In the second mid-boot phase, the scheduler is running, but RCU has
not yet gotten its kthreads spawned (and, for expedited grace periods,
workqueues are not yet running. During this time, any attempt to do
a synchronous grace period will hang the system (or complain bitterly,
depending). In the third and final phase, RCU is fully operational and
everything works normally.
This has been OK for some time, but there has recently been some
synchronous grace periods showing up during the second mid-boot phase.
This code worked "by accident" for awhile, but started failing as soon
as expedited RCU grace periods switched over to workqueues in commit
8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue").
Note that the code was buggy even before this commit, as it was subject
to failure on real-time systems that forced all expedited grace periods
to run as normal grace periods (for example, using the rcu_normal ksysfs
parameter). The callchain from the failure case is as follows:
early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited
The kernel showing this callchain was built with CONFIG_PREEMPT_RCU=y,
which caused the code to try using workqueues before they were
initialized, which did not go well.
This commit therefore reworks RCU to permit synchronous grace periods
to proceed during this mid-boot phase. This commit is therefore a
fix to a regression introduced in v4.9, and is therefore being put
forward post-merge-window in v4.10.
This commit sets a flag from the existing rcu_scheduler_starting()
function which causes all synchronous grace periods to take the expedited
path. The expedited path now checks this flag, using the requesting task
to drive the expedited grace period forward during the mid-boot phase.
Finally, this flag is updated by a core_initcall() function named
rcu_exp_runtime_mode(), which causes the runtime codepaths to be used.
Note that this arrangement assumes that tasks are not sent POSIX signals
(or anything similar) from the time that the first task is spawned
through core_initcall() time.
Fixes: 8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue")
Reported-by: "Zheng, Lv" <lv.zheng@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Stan Kain <stan.kain@gmail.com>
Tested-by: Ivan <waffolz@hotmail.com>
Tested-by: Emanuel Castelo <emanuel.castelo@gmail.com>
Tested-by: Bruno Pesavento <bpesavento@infinito.it>
Tested-by: Borislav Petkov <bp@suse.de>
Tested-by: Frederic Bezies <fredbezies@gmail.com>
Cc: <stable@vger.kernel.org> # 4.9.0-
2017-01-10 10:28:26 +00:00
|
|
|
if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
|
|
|
|
return;
|
2016-06-24 18:30:32 +00:00
|
|
|
_synchronize_rcu_expedited(rsp, sync_rcu_exp_handler);
|
2016-04-15 23:44:07 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
|
|
|
|
|
|
|
|
#else /* #ifdef CONFIG_PREEMPT_RCU */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for an rcu-preempt grace period, but make it happen quickly.
|
|
|
|
* But because preemptible RCU does not exist, map to rcu-sched.
|
|
|
|
*/
|
|
|
|
void synchronize_rcu_expedited(void)
|
|
|
|
{
|
|
|
|
synchronize_sched_expedited();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
|
|
|
|
|
|
|
|
#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
|
rcu: Narrow early boot window of illegal synchronous grace periods
The current preemptible RCU implementation goes through three phases
during bootup. In the first phase, there is only one CPU that is running
with preemption disabled, so that a no-op is a synchronous grace period.
In the second mid-boot phase, the scheduler is running, but RCU has
not yet gotten its kthreads spawned (and, for expedited grace periods,
workqueues are not yet running. During this time, any attempt to do
a synchronous grace period will hang the system (or complain bitterly,
depending). In the third and final phase, RCU is fully operational and
everything works normally.
This has been OK for some time, but there has recently been some
synchronous grace periods showing up during the second mid-boot phase.
This code worked "by accident" for awhile, but started failing as soon
as expedited RCU grace periods switched over to workqueues in commit
8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue").
Note that the code was buggy even before this commit, as it was subject
to failure on real-time systems that forced all expedited grace periods
to run as normal grace periods (for example, using the rcu_normal ksysfs
parameter). The callchain from the failure case is as follows:
early_amd_iommu_init()
|-> acpi_put_table(ivrs_base);
|-> acpi_tb_put_table(table_desc);
|-> acpi_tb_invalidate_table(table_desc);
|-> acpi_tb_release_table(...)
|-> acpi_os_unmap_memory
|-> acpi_os_unmap_iomem
|-> acpi_os_map_cleanup
|-> synchronize_rcu_expedited
The kernel showing this callchain was built with CONFIG_PREEMPT_RCU=y,
which caused the code to try using workqueues before they were
initialized, which did not go well.
This commit therefore reworks RCU to permit synchronous grace periods
to proceed during this mid-boot phase. This commit is therefore a
fix to a regression introduced in v4.9, and is therefore being put
forward post-merge-window in v4.10.
This commit sets a flag from the existing rcu_scheduler_starting()
function which causes all synchronous grace periods to take the expedited
path. The expedited path now checks this flag, using the requesting task
to drive the expedited grace period forward during the mid-boot phase.
Finally, this flag is updated by a core_initcall() function named
rcu_exp_runtime_mode(), which causes the runtime codepaths to be used.
Note that this arrangement assumes that tasks are not sent POSIX signals
(or anything similar) from the time that the first task is spawned
through core_initcall() time.
Fixes: 8b355e3bc140 ("rcu: Drive expedited grace periods from workqueue")
Reported-by: "Zheng, Lv" <lv.zheng@intel.com>
Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Tested-by: Stan Kain <stan.kain@gmail.com>
Tested-by: Ivan <waffolz@hotmail.com>
Tested-by: Emanuel Castelo <emanuel.castelo@gmail.com>
Tested-by: Bruno Pesavento <bpesavento@infinito.it>
Tested-by: Borislav Petkov <bp@suse.de>
Tested-by: Frederic Bezies <fredbezies@gmail.com>
Cc: <stable@vger.kernel.org> # 4.9.0-
2017-01-10 10:28:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch to run-time mode once Tree RCU has fully initialized.
|
|
|
|
*/
|
|
|
|
static int __init rcu_exp_runtime_mode(void)
|
|
|
|
{
|
|
|
|
rcu_test_sync_prims();
|
|
|
|
rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
|
|
|
|
rcu_test_sync_prims();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
core_initcall(rcu_exp_runtime_mode);
|