From: Boqun Feng <boqun.feng@gmail.com>
To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org, kvm@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Waiman Long <longman@redhat.com>,
Boqun Feng <boqun.feng@gmail.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
David Woodhouse <dwmw2@infradead.org>,
Paolo Bonzini <pbonzini@redhat.com>,
seanjc@google.com, Joel Fernandes <joel@joelfernandes.org>,
Matthew Wilcox <willy@infradead.org>,
Michal Luczaj <mhal@rbox.co>
Subject: [PATCH 3/3] WIP: locking/lockdep: selftests: Add selftests for SRCU
Date: Thu, 12 Jan 2023 22:59:55 -0800 [thread overview]
Message-ID: <20230113065955.815667-4-boqun.feng@gmail.com> (raw)
In-Reply-To: <20230113065955.815667-1-boqun.feng@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
lib/locking-selftest.c | 71 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 8d24279fad05..5fc206a2f9f1 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -60,6 +60,7 @@ __setup("debug_locks_verbose=", setup_debug_locks_verbose);
#define LOCKTYPE_RTMUTEX 0x20
#define LOCKTYPE_LL 0x40
#define LOCKTYPE_SPECIAL 0x80
+#define LOCKTYPE_SRCU 0x100
static struct ww_acquire_ctx t, t2;
static struct ww_mutex o, o2, o3;
@@ -100,6 +101,13 @@ static DEFINE_RT_MUTEX(rtmutex_D);
#endif
+#ifdef CONFIG_SRCU
+static struct lock_class_key srcu_A_key;
+static struct lock_class_key srcu_B_key;
+static struct srcu_struct srcu_A;
+static struct srcu_struct srcu_B;
+#endif
+
/*
* Locks that we initialize dynamically as well so that
* e.g. X1 and X2 becomes two instances of the same class,
@@ -1418,6 +1426,12 @@ static void reset_locks(void)
memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key));
memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key));
local_irq_enable();
+
+#ifdef CONFIG_SRCU
+ __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key);
+ __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key);
+#endif
+
}
#undef I
@@ -2360,6 +2374,58 @@ static void ww_tests(void)
pr_cont("\n");
}
+static void srcu_ABBA(void)
+{
+ int ia, ib;
+
+ ia = srcu_read_lock(&srcu_A);
+ synchronize_srcu(&srcu_B);
+ srcu_read_unlock(&srcu_A, ia);
+
+ ib = srcu_read_lock(&srcu_B);
+ synchronize_srcu(&srcu_A);
+ srcu_read_unlock(&srcu_B, ib); // should fail
+}
+
+static void srcu_mutex_ABBA(void)
+{
+ int ia;
+
+ mutex_lock(&mutex_A);
+ synchronize_srcu(&srcu_A);
+ mutex_unlock(&mutex_A);
+
+ ia = srcu_read_lock(&srcu_A);
+ mutex_lock(&mutex_A);
+ mutex_unlock(&mutex_A);
+ srcu_read_unlock(&srcu_A, ia); // should fail
+}
+
+static void srcu_irqsafe(void)
+{
+ int ia;
+
+ HARDIRQ_ENTER();
+ ia = srcu_read_lock(&srcu_A);
+ srcu_read_unlock(&srcu_A, ia);
+ HARDIRQ_EXIT();
+
+ synchronize_srcu(&srcu_A); // should NOT fail
+}
+
+static void srcu_tests(void)
+{
+ printk(" --------------------------------------------------------------------------\n");
+ printk(" | SRCU tests |\n");
+ printk(" ---------------\n");
+ print_testname("ABBA read-sync/read-sync");
+ dotest(srcu_ABBA, FAILURE, LOCKTYPE_SRCU);
+ print_testname("ABBA mutex-sync/read-mutex");
+ dotest(srcu_mutex_ABBA, FAILURE, LOCKTYPE_SRCU);
+ print_testname("Irqsafe synchronize_srcu");
+ dotest(srcu_irqsafe, SUCCESS, LOCKTYPE_SRCU);
+ pr_cont("\n");
+}
/*
* <in hardirq handler>
@@ -2881,6 +2947,10 @@ void locking_selftest(void)
printk(" --------------------------------------------------------------------------\n");
init_shared_classes();
+#ifdef CONFIG_SRCU
+ __init_srcu_struct(&srcu_A, "srcuA", &srcu_A_key);
+ __init_srcu_struct(&srcu_B, "srcuB", &srcu_B_key);
+#endif
lockdep_set_selftest_task(current);
DO_TESTCASE_6R("A-A deadlock", AA);
@@ -2965,6 +3035,7 @@ void locking_selftest(void)
DO_TESTCASE_6x2x2RW("irq read-recursion #3", irq_read_recursion3);
ww_tests();
+ srcu_tests();
force_read_lock_recursive = 0;
/*
--
2.38.1
next prev parent reply other threads:[~2023-01-13 7:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 6:59 [PATCH 0/3] Detect SRCU related deadlocks Boqun Feng
2023-01-13 6:59 ` [PATCH 1/3] locking/lockdep: Introduce lock_sync() Boqun Feng
2023-01-16 21:56 ` Waiman Long
2023-01-13 6:59 ` [PATCH 2/3] rcu: Equip sleepable RCU with lockdep dependency graph checks Boqun Feng
2023-01-13 11:29 ` Paul E. McKenney
2023-01-13 18:05 ` Boqun Feng
2023-01-13 19:11 ` Paul E. McKenney
2023-01-16 17:36 ` Paolo Bonzini
2023-01-16 17:54 ` Boqun Feng
2023-01-16 18:56 ` Paul E. McKenney
2023-01-16 22:01 ` Waiman Long
2023-01-13 6:59 ` Boqun Feng [this message]
2023-01-13 12:46 ` [PATCH 0/3] KVM: Make use of SRCU deadlock detection support David Woodhouse
2023-01-13 12:46 ` [PATCH 1/3] KVM: Show lockdep the kvm->mutex vs. kvm->srcu ordering rule David Woodhouse
2023-01-13 12:46 ` [PATCH 2/3] KVM: selftests: Use enum for test numbers in xen_shinfo_test David Woodhouse
2023-01-13 17:13 ` David Woodhouse
2023-01-13 12:46 ` [PATCH 3/3] KVM: selftests: Add EVTCHNOP_send slow path test to xen_shinfo_test David Woodhouse
2023-02-04 2:32 ` Sean Christopherson
2023-02-04 2:34 ` [PATCH 0/3] KVM: Make use of SRCU deadlock detection support Sean Christopherson
2023-01-13 23:57 ` [PATCH 4/3] locking/lockdep: Improve the deadlock scenario print for sync and read lock Boqun Feng
2023-01-16 22:21 ` Waiman Long
2023-01-16 22:35 ` Boqun Feng
2023-01-17 1:36 ` Waiman Long
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=20230113065955.815667-4-boqun.feng@gmail.com \
--to=boqun.feng@gmail.com \
--cc=dwmw2@infradead.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhal@rbox.co \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.com \
--cc=will@kernel.org \
--cc=willy@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox