rcu.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rcu/nocb: Extend checks for offloaded rdp by migrate_disable
@ 2021-07-27 16:38 Sebastian Andrzej Siewior
  2021-07-27 17:23 ` Paul E. McKenney
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-07-27 16:38 UTC (permalink / raw)
  To: rcu
  Cc: Paul E. McKenney, Josh Triplett, Steven Rostedt,
	Mathieu Desnoyers, Lai Jiangshan, Joel Fernandes,
	Thomas Gleixner, Frederic Weisbecker

Commit 3820b513a2e33 ("rcu/nocb: Detect unsafe checks for offloaded
rdp") added checks for safe rdp usage in the nocb case.

On PREEMPT_RT this checks triggers in the
 rcu_cpu_kthread() -> rcu_core() -> rcu_check_quiescent_state() ->
  rcu_rdp_is_offloaded()

call chain. On !PREEMPT_RT this warnings is suppressed because rcu_core()
is invoked with disabled BH which also disables preemption and
"preemptible()" is part of the checks which are considered safe.
On PREEMPT_RT disabling BH does not disable preemption and since there
is no other criteria the warning triggers.

According to the mentioned commit the goal is to check if the rcu data
pointer is "stable … and prevent from its value to be changed under us".
My understanding is that this may happen if the task is preemptible and
therefore free to be migrated to another CPU which would then lead to
another value of `rcu_data'.
One thing that has been overseen is that a task within a migrate-disable
region (as on PREEMPT_RT with disabled BH) is fully preemptible but may
not be migrated to another CPU which should be enough to guarantee that
rdp remains stable.

Check also disabled migration of the task if the RCU data pointer is
from current CPU. Put the whole check within an SMP ifdef block since
without SMP there are not CPU migrations to worry about (also
task_struct::migration_disabled is missing).

Cc: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
I don't fully understand why the CPU-hotplug lock matters here but this
is beside the point ;)

 kernel/rcu/tree_plugin.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index 0ff5e4fb933e7..d8a623ba7d243 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -57,16 +57,18 @@ static bool rcu_rdp_is_offloaded(struct rcu_data *rdp)
 	 * timers have their own means of synchronization against the
 	 * offloaded state updaters.
 	 */
+#ifdef CONFIG_SMP
 	RCU_LOCKDEP_WARN(
 		!(lockdep_is_held(&rcu_state.barrier_mutex) ||
 		  (IS_ENABLED(CONFIG_HOTPLUG_CPU) && lockdep_is_cpus_held()) ||
 		  rcu_lockdep_is_held_nocb(rdp) ||
 		  (rdp == this_cpu_ptr(&rcu_data) &&
-		   !(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible())) ||
+		   (!(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible()) ||
+		    current->migration_disabled)) ||
 		  rcu_current_is_nocb_kthread(rdp)),
 		"Unsafe read of RCU_NOCB offloaded state"
 	);
-
+#endif
 	return rcu_segcblist_is_offloaded(&rdp->cblist);
 }
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-07-28 11:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 16:38 [PATCH] rcu/nocb: Extend checks for offloaded rdp by migrate_disable Sebastian Andrzej Siewior
2021-07-27 17:23 ` Paul E. McKenney
2021-07-27 19:26   ` Sebastian Andrzej Siewior
2021-07-27 23:26     ` Frederic Weisbecker
2021-07-27 19:33   ` Thomas Gleixner
2021-07-27 23:32     ` Frederic Weisbecker
2021-07-28  8:34       ` Thomas Gleixner
2021-07-28 11:50         ` Frederic Weisbecker
2021-07-27 23:20   ` Frederic Weisbecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).