diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2014-08-25 23:25:06 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2014-09-18 19:22:27 -0400 |
commit | dd56af42bd829c6e770ed69812bd65a04eaeb1e4 (patch) | |
tree | 6d510ac693c3dfb05dcc383cb60acd3e1e8cab6c /kernel/rcu/tree.c | |
parent | ec4518aad8329364af373f4bf7f4eff25a01a339 (diff) |
rcu: Eliminate deadlock between CPU hotplug and expedited grace periods
Currently, the expedited grace-period primitives do get_online_cpus().
This greatly simplifies their implementation, but means that calls
to them holding locks that are acquired by CPU-hotplug notifiers (to
say nothing of calls to these primitives from CPU-hotplug notifiers)
can deadlock. But this is starting to become inconvenient, as can be
seen here: https://lkml.org/lkml/2014/8/5/754. The problem in this
case is that some developers need to acquire a mutex from a CPU-hotplug
notifier, but also need to hold it across a synchronize_rcu_expedited().
As noted above, this currently results in deadlock.
This commit avoids the deadlock and retains the simplicity by creating
a try_get_online_cpus(), which returns false if the get_online_cpus()
reference count could not immediately be incremented. If a call to
try_get_online_cpus() returns true, the expedited primitives operate as
before. If a call returns false, the expedited primitives fall back to
normal grace-period operations. This falling back of course results in
increased grace-period latency, but only during times when CPU hotplug
operations are actually in flight. The effect should therefore be
negligible during normal operation.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Tested-by: Lan Tianyu <tianyu.lan@intel.com>
Diffstat (limited to 'kernel/rcu/tree.c')
-rw-r--r-- | kernel/rcu/tree.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index d7a3b13bc94c..133e47223095 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c | |||
@@ -2940,11 +2940,6 @@ static int synchronize_sched_expedited_cpu_stop(void *data) | |||
2940 | * restructure your code to batch your updates, and then use a single | 2940 | * restructure your code to batch your updates, and then use a single |
2941 | * synchronize_sched() instead. | 2941 | * synchronize_sched() instead. |
2942 | * | 2942 | * |
2943 | * Note that it is illegal to call this function while holding any lock | ||
2944 | * that is acquired by a CPU-hotplug notifier. And yes, it is also illegal | ||
2945 | * to call this function from a CPU-hotplug notifier. Failing to observe | ||
2946 | * these restriction will result in deadlock. | ||
2947 | * | ||
2948 | * This implementation can be thought of as an application of ticket | 2943 | * This implementation can be thought of as an application of ticket |
2949 | * locking to RCU, with sync_sched_expedited_started and | 2944 | * locking to RCU, with sync_sched_expedited_started and |
2950 | * sync_sched_expedited_done taking on the roles of the halves | 2945 | * sync_sched_expedited_done taking on the roles of the halves |
@@ -2994,7 +2989,12 @@ void synchronize_sched_expedited(void) | |||
2994 | */ | 2989 | */ |
2995 | snap = atomic_long_inc_return(&rsp->expedited_start); | 2990 | snap = atomic_long_inc_return(&rsp->expedited_start); |
2996 | firstsnap = snap; | 2991 | firstsnap = snap; |
2997 | get_online_cpus(); | 2992 | if (!try_get_online_cpus()) { |
2993 | /* CPU hotplug operation in flight, fall back to normal GP. */ | ||
2994 | wait_rcu_gp(call_rcu_sched); | ||
2995 | atomic_long_inc(&rsp->expedited_normal); | ||
2996 | return; | ||
2997 | } | ||
2998 | WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id())); | 2998 | WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id())); |
2999 | 2999 | ||
3000 | /* | 3000 | /* |
@@ -3041,7 +3041,12 @@ void synchronize_sched_expedited(void) | |||
3041 | * and they started after our first try, so their grace | 3041 | * and they started after our first try, so their grace |
3042 | * period works for us. | 3042 | * period works for us. |
3043 | */ | 3043 | */ |
3044 | get_online_cpus(); | 3044 | if (!try_get_online_cpus()) { |
3045 | /* CPU hotplug operation in flight, use normal GP. */ | ||
3046 | wait_rcu_gp(call_rcu_sched); | ||
3047 | atomic_long_inc(&rsp->expedited_normal); | ||
3048 | return; | ||
3049 | } | ||
3045 | snap = atomic_long_read(&rsp->expedited_start); | 3050 | snap = atomic_long_read(&rsp->expedited_start); |
3046 | smp_mb(); /* ensure read is before try_stop_cpus(). */ | 3051 | smp_mb(); /* ensure read is before try_stop_cpus(). */ |
3047 | } | 3052 | } |