[v2,2/4] locktorture: Add nested locking to mutex torture tests

Message ID 20230203200138.3872873-2-jstultz@google.com
State New
Headers
Series [v2,1/4] locktorture: Add nested_[un]lock() hooks and nlocks parameter |

Commit Message

John Stultz Feb. 3, 2023, 8:01 p.m. UTC
  This patch adds randomized nested locking to the mutex torture
tests, as well as new LOCK08 config files for testing mutexes
with nested locking

This was inspired by locktorture extensions originally implemented
by Connor O'Brien, for stress testing the proxy-execution series:
  https://lore.kernel.org/lkml/20221003214501.2050087-12-connoro@google.com/

Comments or feedback would be greatly appreciated!

Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: John Stultz <jstultz@google.com>
---
v2:
* Add LOCK08 config file suggested by Paul McKenney
---
 kernel/locking/locktorture.c                  | 35 +++++++++++++++++++
 .../selftests/rcutorture/configs/lock/CFLIST  |  1 +
 .../selftests/rcutorture/configs/lock/LOCK08  |  6 ++++
 .../rcutorture/configs/lock/LOCK08.boot       |  1 +
 4 files changed, 43 insertions(+)
 create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK08
 create mode 100644 tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot
  

Comments

Davidlohr Bueso Feb. 5, 2023, 7:07 p.m. UTC | #1
On Fri, 03 Feb 2023, John Stultz wrote:

>This patch adds randomized nested locking to the mutex torture
>tests, as well as new LOCK08 config files for testing mutexes
>with nested locking
>
>This was inspired by locktorture extensions originally implemented
>by Connor O'Brien, for stress testing the proxy-execution series:
>  https://lore.kernel.org/lkml/20221003214501.2050087-12-connoro@google.com/
>
>Comments or feedback would be greatly appreciated!
>
>Cc: Davidlohr Bueso <dave@stgolabs.net>
>Cc: "Paul E. McKenney" <paulmck@kernel.org>
>Cc: Josh Triplett <josh@joshtriplett.org>
>Cc: Joel Fernandes <joel@joelfernandes.org>
>Cc: Juri Lelli <juri.lelli@redhat.com>
>Cc: Valentin Schneider <vschneid@redhat.com>
>Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
>Signed-off-by: John Stultz <jstultz@google.com>

Just realized I sent two review tags for rtmutex, one was supposed
to be this patch.

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
  
Paul E. McKenney Feb. 6, 2023, 5:20 p.m. UTC | #2
On Sun, Feb 05, 2023 at 11:07:53AM -0800, Davidlohr Bueso wrote:
> On Fri, 03 Feb 2023, John Stultz wrote:
> 
> > This patch adds randomized nested locking to the mutex torture
> > tests, as well as new LOCK08 config files for testing mutexes
> > with nested locking
> > 
> > This was inspired by locktorture extensions originally implemented
> > by Connor O'Brien, for stress testing the proxy-execution series:
> >  https://lore.kernel.org/lkml/20221003214501.2050087-12-connoro@google.com/
> > 
> > Comments or feedback would be greatly appreciated!
> > 
> > Cc: Davidlohr Bueso <dave@stgolabs.net>
> > Cc: "Paul E. McKenney" <paulmck@kernel.org>
> > Cc: Josh Triplett <josh@joshtriplett.org>
> > Cc: Joel Fernandes <joel@joelfernandes.org>
> > Cc: Juri Lelli <juri.lelli@redhat.com>
> > Cc: Valentin Schneider <vschneid@redhat.com>
> > Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> > Signed-off-by: John Stultz <jstultz@google.com>
> 
> Just realized I sent two review tags for rtmutex, one was supposed
> to be this patch.
> 
> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

Thank you!

I will apply this to these commits on my next rebase:

f5a632cbbbea ("locktorture: Add nested locking to mutex torture tests")
83743c9839f5 ("locktorture: Add nested locking to rtmutex torture tests")

John, if you send a new version of these, please add Davidlohr's review
tags.

							Thanx, Paul
  
John Stultz Feb. 6, 2023, 7:24 p.m. UTC | #3
On Mon, Feb 6, 2023 at 9:20 AM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> On Sun, Feb 05, 2023 at 11:07:53AM -0800, Davidlohr Bueso wrote:
> > On Fri, 03 Feb 2023, John Stultz wrote:
> >
> > > This patch adds randomized nested locking to the mutex torture
> > > tests, as well as new LOCK08 config files for testing mutexes
> > > with nested locking
> > >
> > > This was inspired by locktorture extensions originally implemented
> > > by Connor O'Brien, for stress testing the proxy-execution series:
> > >  https://lore.kernel.org/lkml/20221003214501.2050087-12-connoro@google.com/
> > >
> > > Comments or feedback would be greatly appreciated!
> > >
> > > Cc: Davidlohr Bueso <dave@stgolabs.net>
> > > Cc: "Paul E. McKenney" <paulmck@kernel.org>
> > > Cc: Josh Triplett <josh@joshtriplett.org>
> > > Cc: Joel Fernandes <joel@joelfernandes.org>
> > > Cc: Juri Lelli <juri.lelli@redhat.com>
> > > Cc: Valentin Schneider <vschneid@redhat.com>
> > > Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> > > Signed-off-by: John Stultz <jstultz@google.com>
> >
> > Just realized I sent two review tags for rtmutex, one was supposed
> > to be this patch.
> >
> > Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
>
> Thank you!
>
> I will apply this to these commits on my next rebase:
>
> f5a632cbbbea ("locktorture: Add nested locking to mutex torture tests")
> 83743c9839f5 ("locktorture: Add nested locking to rtmutex torture tests")
>
> John, if you send a new version of these, please add Davidlohr's review
> tags.

Yeah. I'll respin to address most of the feedback.

thanks
-john
  

Patch

diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c
index f4fbd3194654..27d92ce36836 100644
--- a/kernel/locking/locktorture.c
+++ b/kernel/locking/locktorture.c
@@ -332,6 +332,28 @@  static struct lock_torture_ops rw_lock_irq_ops = {
 };
 
 static DEFINE_MUTEX(torture_mutex);
+static struct mutex torture_nested_mutexes[MAX_LOCKS];
+static struct lock_class_key nested_mutex_keys[MAX_LOCKS];
+
+static void torture_mutex_init(void)
+{
+	int i;
+
+	for (i = 0; i < MAX_LOCKS; i++)
+		__mutex_init(&torture_nested_mutexes[i], __func__,
+			     &nested_mutex_keys[i]);
+}
+
+static int torture_mutex_nested_lock(int tid __maybe_unused,
+				     u32 lockset)
+{
+	int i;
+
+	for (i = 0; i < nlocks; i++)
+		if (lockset & (1 << i))
+			mutex_lock(&torture_nested_mutexes[i]);
+	return 0;
+}
 
 static int torture_mutex_lock(int tid __maybe_unused)
 __acquires(torture_mutex)
@@ -360,11 +382,24 @@  __releases(torture_mutex)
 	mutex_unlock(&torture_mutex);
 }
 
+static void torture_mutex_nested_unlock(int tid __maybe_unused,
+					u32 lockset)
+{
+	int i;
+
+	for (i = nlocks - 1; i >= 0; i--)
+		if (lockset & (1 << i))
+			mutex_unlock(&torture_nested_mutexes[i]);
+}
+
 static struct lock_torture_ops mutex_lock_ops = {
+	.init		= torture_mutex_init,
+	.nested_lock	= torture_mutex_nested_lock,
 	.writelock	= torture_mutex_lock,
 	.write_delay	= torture_mutex_delay,
 	.task_boost     = torture_boost_dummy,
 	.writeunlock	= torture_mutex_unlock,
+	.nested_unlock	= torture_mutex_nested_unlock,
 	.readlock       = NULL,
 	.read_delay     = NULL,
 	.readunlock     = NULL,
diff --git a/tools/testing/selftests/rcutorture/configs/lock/CFLIST b/tools/testing/selftests/rcutorture/configs/lock/CFLIST
index 41bae5824339..a48bba0d35a6 100644
--- a/tools/testing/selftests/rcutorture/configs/lock/CFLIST
+++ b/tools/testing/selftests/rcutorture/configs/lock/CFLIST
@@ -5,3 +5,4 @@  LOCK04
 LOCK05
 LOCK06
 LOCK07
+LOCK08
diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK08 b/tools/testing/selftests/rcutorture/configs/lock/LOCK08
new file mode 100644
index 000000000000..1d1da1477fc3
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK08
@@ -0,0 +1,6 @@ 
+CONFIG_SMP=y
+CONFIG_NR_CPUS=4
+CONFIG_HOTPLUG_CPU=y
+CONFIG_PREEMPT_NONE=n
+CONFIG_PREEMPT_VOLUNTARY=n
+CONFIG_PREEMPT=y
diff --git a/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot b/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot
new file mode 100644
index 000000000000..e59a369b470e
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/configs/lock/LOCK08.boot
@@ -0,0 +1 @@ 
+locktorture.torture_type=mutex_lock locktorture.nlocks=8