All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>,
	rcu@vger.kernel.org, David Woodhouse <dwmw2@infradead.org>
Subject: [RFC] Catch dwmw2's deadlock
Date: Fri, 30 Dec 2022 11:38:21 +0000	[thread overview]
Message-ID: <Y67NrWVLaL7B/EuO@casper.infradead.org> (raw)


<dwmw2> why doesn't lockdep catch us calling synchronize_srcu() with
   a lock held, and elsewhere obtaining that lock within an srcu critical
   region ("read lock") ?

Because synchronize_srcu() doesn't acquire the lock, merely checks that
it isn't held.

Would this work?  Not even compile tested.

You can put my SoB on this if it works.

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index ca4b5dcec675..e9c2ab8369c0 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1267,11 +1267,11 @@ static void __synchronize_srcu(struct srcu_struct *ssp, bool do_norm)
 {
 	struct rcu_synchronize rcu;
 
-	RCU_LOCKDEP_WARN(lockdep_is_held(ssp) ||
-			 lock_is_held(&rcu_bh_lock_map) ||
+	rcu_lock_acquire(&ssp->dep_map);
+	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_srcu() in same-type SRCU (or in RCU) read-side critical section");
+			 "Illegal synchronize_srcu() in RCU read-side critical section");
 
 	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
 		return;
@@ -1282,6 +1282,7 @@ static void __synchronize_srcu(struct srcu_struct *ssp, bool do_norm)
 	__call_srcu(ssp, &rcu.head, wakeme_after_rcu, do_norm);
 	wait_for_completion(&rcu.completion);
 	destroy_rcu_head_on_stack(&rcu.head);
+	rcu_lock_release(&ssp->dep_map);
 
 	/*
 	 * Make sure that later code is ordered after the SRCU grace

             reply	other threads:[~2022-12-30 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-30 11:38 Matthew Wilcox [this message]
2022-12-30 12:28 ` [RFC] Catch dwmw2's deadlock David Woodhouse
2022-12-30 13:18   ` Joel Fernandes
2022-12-31  1:26     ` Michal Luczaj
2022-12-30 20:30 ` Paul E. McKenney
2022-12-30 21:58   ` Matthew Wilcox
2022-12-30 23:24     ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y67NrWVLaL7B/EuO@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=dwmw2@infradead.org \
    --cc=josh@joshtriplett.org \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.