[PATCH v3 2/3] test-ww_mutex: Report errors from stress workers

Håkon Bugge <[email protected]>
Newsgroups gmane.linux.kernel
Message-ID <[email protected]>
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 <[email protected]>
Acked-by: John Stultz <[email protected]>

---

v1 -> v2:
      * Added John's a-b
---
 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 8311ff38ab683..5ed91f2cf30d9 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.