mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Håkon Bugge" <haakon.bugge@oracle.com>
To: linux-kernel@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
	Chris Wilson <chris@chris-wilson.co.uk>
Cc: "Håkon Bugge" <haakon.bugge@oracle.com>,
	"Ingo Molnar" <mingo@kernel.org>
Subject: [PATCH 2/4] test-ww_mutex: Report errors from stress workers
Date: Wed, 17 Jun 2026 14:13:31 +0200	[thread overview]
Message-ID: <20260617121335.2036954-3-haakon.bugge@oracle.com> (raw)
In-Reply-To: <20260617121335.2036954-1-haakon.bugge@oracle.com>

If any of stress_one_work(), stress_reorder_work(), or
stress_inorder_work() fails, the error is not conveyed back to the
test harness function stress().

We may then see in the log:

   stress (stress_inorder_work) failed with -35
   Beginning ww (die) mutex selftests
   All ww mutex selftests passed

Besides being a contradiction by terms, the failure to return error
from said worker functions leads to false-positive results.

We fix that by adding a *result* variable to *struct stress*, update
it in said worker functions, and finally, in stress(), scan the
*stress_array* and report the first error if any.

Fixes: 2a0c11282881 ("locking/ww_mutex: Add kselftests for ww_mutex stress")
Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
---
 kernel/locking/test-ww_mutex.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 6f56a29ed6d77..5a4c92801bdfb 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -392,6 +392,7 @@ struct stress {
 	struct ww_class *class;
 	unsigned long timeout;
 	int nlocks;
+	int result;
 };
 
 struct rnd_state rng;
@@ -440,6 +441,9 @@ static void stress_inorder_work(struct work_struct *work)
 	struct ww_mutex *locks = stress->locks;
 	struct ww_acquire_ctx ctx;
 	int *order;
+	int err;
+
+	stress->result = -ENOMEM;
 
 	order = get_random_order(nlocks);
 	if (!order)
@@ -447,7 +451,7 @@ static void stress_inorder_work(struct work_struct *work)
 
 	do {
 		int contended = -1;
-		int n, err;
+		int n;
 
 		ww_acquire_init(&ctx, stress->class);
 retry:
@@ -485,6 +489,7 @@ static void stress_inorder_work(struct work_struct *work)
 	} while (!time_after(jiffies, stress->timeout));
 
 	kfree(order);
+	stress->result = err;
 }
 
 struct reorder_lock {
@@ -501,6 +506,8 @@ static void stress_reorder_work(struct work_struct *work)
 	int *order;
 	int n, err;
 
+	stress->result = -ENOMEM;
+
 	order = get_random_order(stress->nlocks);
 	if (!order)
 		return;
@@ -545,6 +552,8 @@ static void stress_reorder_work(struct work_struct *work)
 		ww_acquire_fini(&ctx);
 	} while (!time_after(jiffies, stress->timeout));
 
+	stress->result = err;
+
 out:
 	list_for_each_entry_safe(ll, ln, &locks, link)
 		kfree(ll);
@@ -569,6 +578,8 @@ static void stress_one_work(struct work_struct *work)
 			break;
 		}
 	} while (!time_after(jiffies, stress->timeout));
+
+	stress->result = err;
 }
 
 #define STRESS_INORDER BIT(0)
@@ -581,6 +592,7 @@ static int stress(struct ww_class *class, int nlocks, int nthreads, unsigned int
 	struct ww_mutex *locks;
 	struct stress *stress_array;
 	int n, count;
+	int res = 0;
 
 	locks = kmalloc_objs(*locks, nlocks);
 	if (!locks)
@@ -635,10 +647,15 @@ static int stress(struct ww_class *class, int nlocks, int nthreads, unsigned int
 
 	for (n = 0; n < nlocks; n++)
 		ww_mutex_destroy(&locks[n]);
+
+	/* Report the first error */
+	for (n = 0; !res && n < count; n++)
+		res = stress_array[n].result;
+
 	kfree(stress_array);
 	kfree(locks);
 
-	return 0;
+	return res;
 }
 
 static int run_tests(struct ww_class *class)
-- 
2.43.5


  parent reply	other threads:[~2026-06-17 12:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 12:13 [PATCH 0/4] test-ww_mutex: Miscellaneous fixes Håkon Bugge
2026-06-17 12:13 ` [PATCH 1/4] test-ww_mutex: Fix module cleanup Håkon Bugge
2026-06-18 17:49   ` John Stultz
2026-06-17 12:13 ` Håkon Bugge [this message]
2026-06-18 17:52   ` [PATCH 2/4] test-ww_mutex: Report errors from stress workers John Stultz
2026-07-09  0:03     ` John Stultz
2026-07-09 16:51       ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 3/4] test-ww_mutex: Handle transient -EDEADLK in test_cycle_work Håkon Bugge
2026-06-18 19:04   ` John Stultz
2026-06-22 13:21     ` Haakon Bugge
2026-07-08 19:55       ` John Stultz
2026-07-09 17:05         ` Haakon Bugge
2026-06-17 12:13 ` [PATCH 4/4] test-ww_mutex: Retry lock acquisition after timeout if deadlocked Håkon Bugge
2026-06-18 18:55   ` John Stultz
2026-06-22 13:47     ` Haakon Bugge
2026-07-06  9:01       ` Haakon Bugge
2026-07-06  9:02         ` Haakon Bugge
2026-07-08 20:01       ` John Stultz
2026-07-09 16:56         ` Haakon Bugge

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=20260617121335.2036954-3-haakon.bugge@oracle.com \
    --to=haakon.bugge@oracle.com \
    --cc=boqun@kernel.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®