From nobody Tue Dec 2 02:52:37 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 688E5F9E8 for ; Tue, 18 Nov 2025 00:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427535; cv=none; b=tC7jH/YFlbLnLnZ2nwn95f96E59tELbMUT0P4QsIk/zXKD9TyxIPJzvMPkkQTtybqRK8N5Q1Ndn2CPpKCUXHjxLhhiSUhktO+n2t5m22xP4xfe3QhBfNOKoxPjOidF1ptNFNqyhRIhm6Rfr3tniJ8WQIpmOWGurfHxPaWqkOubg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427535; c=relaxed/simple; bh=grBIWFxq7tPrHDRBtUOfTySRs4vuSbt8U3pp/DHhJl8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DdHAYjwZ7DAkAbZkHe+WFpt5xRqdwDfApZnnYbXE7G8ZLtEQUuXedQEKEBBLb4xD4SO4Sq5EtKZmgbX9oe/vg7lLaKcCWDMwfjrP/XxK8YcwuRKMEgACByy3d+8k0wK8OHEmtO1J74oF0oO+WEnADOlbyKtUbSnDNWyXnM7ahyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4s2iivqw; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4s2iivqw" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7b6b194cf71so6527860b3a.3 for ; Mon, 17 Nov 2025 16:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763427533; x=1764032333; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JWR+mlOtpP2fHMxa4iG6YmAgdQreLK5E62Wzk+S8KXk=; b=4s2iivqwtCNj3rIUgFyFDngtGahtwDEKYbPzh3lEPMoYgGE2ZUw1KzcWjQTOhgJlO5 /5musa8kuJskOyAu7DO7199t3EtkGz6gQ4juo4J/MxqGJxANp2Eb1H152Yw8RsJ9ujmv J3wo6fKYANEcIvagLCEcx5okmCI1S1mew1f+9mBZ/THYPGLUwFdp8KhUcusn3Lfl8J9p tTUXyS40W6xm5lO9JTW4rMmq7prEwH4Yimi4fsSmAxyN5fkY1vhnKMxmqTslO/QY0zTJ e7UxvRNNPLBh+XHqqFuuuX+ewXkGbSxqbYXRbA3C66N9oLOytxcOetHgfvnrsjCYmdGy RSLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763427533; x=1764032333; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JWR+mlOtpP2fHMxa4iG6YmAgdQreLK5E62Wzk+S8KXk=; b=pdfix2K8fysragxm3FVbQaKFlSfCjkqvLheOJTgIwT2LxNuFwjbN/ZseHF95TNftc5 yc1dT02q9Wh+RyT4Xa/R/ybIPbtXX/ABN2dBJduS8nGJpSOb92/jh9oU8agXm6iE1pdv 2kGMbeIoOKJ0oVEnQYHU8A/Ui6oRRRdufP/QKxrM40QilOjk5vPb9sWmT4wBu/ybN7pK WsTXz/ppZ26Zcpu98iZpkpAuKygWlRq+qE8US3mHOKfJweu4RhoZt9Txs8/uop4k2sfV 7lJqpuS5JHYlksABK+T+n5Bbrkx+pvCbEJE92Uge9rIVbtd9fnuk++i9bjMcIyZ+ftVU yx1w== X-Gm-Message-State: AOJu0Yw83LmDZqQAJL9W+mdUuTj+kXNKPTsXIeGhgRwbjTyHul9JLkM+ wql5VDJRV9dXxzBlmXXVzfAK07VHE59GslcKa0jSoNElpeaaP2e6V135KAttohBz3ufSvVIl1SG 34I16vf6rIt33tVsTI+3rsYaow345LDO2cvBmW5TheNRR5adg4lCNJfxyt2f+qCocy5zp1cOTd4 +l1ORtN9FkWA9NUjdBxWmIFN3TU59/4hdoJo9muNJP7VgQEuqL X-Google-Smtp-Source: AGHT+IEivd6umlDIZuK6Jpf92mU1wKeGTNooZ8rUr6Tq5RIlnKz+80popTEylUk5E0kzGw7kQM3qlTIATY++ X-Received: from pfks7.prod.google.com ([2002:a05:6a00:1947:b0:781:1659:e630]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d07:b0:33f:4e3d:aff0 with SMTP id adf61e73a8af0-35ba0577ed1mr17361969637.21.1763427532520; Mon, 17 Nov 2025 16:58:52 -0800 (PST) Date: Tue, 18 Nov 2025 00:58:34 +0000 In-Reply-To: <20251118005843.3902476-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251118005843.3902476-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251118005843.3902476-2-jstultz@google.com> Subject: [RESEND x4][PATCH 1/3] test-ww_mutex: Extend ww_mutex tests to test both classes of ww_mutexes From: John Stultz To: LKML Cc: John Stultz , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , Joel Fernandes , Dietmar Eggemann , Suleiman Souhlal , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently the test-ww_mutex tool only utilizes the wait-die class of ww_mutexes, and thus isn't very helpful in exercising the wait-wound class of ww_mutexes. So extend the test to exercise both classes of ww_mutexes for all of the subtests. Signed-off-by: John Stultz --- Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E . McKenney" Cc: Joel Fernandes Cc: Dietmar Eggemann Cc: Suleiman Souhlal Cc: kernel-team@android.com --- kernel/locking/test-ww_mutex.c | 114 +++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index bcb1b9fea5880..d27aaaa860a36 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -13,7 +13,8 @@ #include #include =20 -static DEFINE_WD_CLASS(ww_class); +static DEFINE_WD_CLASS(wd_class); +static DEFINE_WW_CLASS(ww_class); struct workqueue_struct *wq; =20 #ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH @@ -54,16 +55,16 @@ static void test_mutex_work(struct work_struct *work) ww_mutex_unlock(&mtx->mutex); } =20 -static int __test_mutex(unsigned int flags) +static int __test_mutex(struct ww_class *class, unsigned int flags) { #define TIMEOUT (HZ / 16) struct test_mutex mtx; struct ww_acquire_ctx ctx; int ret; =20 - ww_mutex_init(&mtx.mutex, &ww_class); + ww_mutex_init(&mtx.mutex, class); if (flags & TEST_MTX_CTX) - ww_acquire_init(&ctx, &ww_class); + ww_acquire_init(&ctx, class); =20 INIT_WORK_ONSTACK(&mtx.work, test_mutex_work); init_completion(&mtx.ready); @@ -106,13 +107,13 @@ static int __test_mutex(unsigned int flags) #undef TIMEOUT } =20 -static int test_mutex(void) +static int test_mutex(struct ww_class *class) { int ret; int i; =20 for (i =3D 0; i < __TEST_MTX_LAST; i++) { - ret =3D __test_mutex(i); + ret =3D __test_mutex(class, i); if (ret) return ret; } @@ -120,15 +121,15 @@ static int test_mutex(void) return 0; } =20 -static int test_aa(bool trylock) +static int test_aa(struct ww_class *class, bool trylock) { struct ww_mutex mutex; struct ww_acquire_ctx ctx; int ret; const char *from =3D trylock ? "trylock" : "lock"; =20 - ww_mutex_init(&mutex, &ww_class); - ww_acquire_init(&ctx, &ww_class); + ww_mutex_init(&mutex, class); + ww_acquire_init(&ctx, class); =20 if (!trylock) { ret =3D ww_mutex_lock(&mutex, &ctx); @@ -177,6 +178,7 @@ static int test_aa(bool trylock) =20 struct test_abba { struct work_struct work; + struct ww_class *class; struct ww_mutex a_mutex; struct ww_mutex b_mutex; struct completion a_ready; @@ -191,7 +193,7 @@ static void test_abba_work(struct work_struct *work) struct ww_acquire_ctx ctx; int err; =20 - ww_acquire_init_noinject(&ctx, &ww_class); + ww_acquire_init_noinject(&ctx, abba->class); if (!abba->trylock) ww_mutex_lock(&abba->b_mutex, &ctx); else @@ -217,23 +219,24 @@ static void test_abba_work(struct work_struct *work) abba->result =3D err; } =20 -static int test_abba(bool trylock, bool resolve) +static int test_abba(struct ww_class *class, bool trylock, bool resolve) { struct test_abba abba; struct ww_acquire_ctx ctx; int err, ret; =20 - ww_mutex_init(&abba.a_mutex, &ww_class); - ww_mutex_init(&abba.b_mutex, &ww_class); + ww_mutex_init(&abba.a_mutex, class); + ww_mutex_init(&abba.b_mutex, class); INIT_WORK_ONSTACK(&abba.work, test_abba_work); init_completion(&abba.a_ready); init_completion(&abba.b_ready); + abba.class =3D class; abba.trylock =3D trylock; abba.resolve =3D resolve; =20 schedule_work(&abba.work); =20 - ww_acquire_init_noinject(&ctx, &ww_class); + ww_acquire_init_noinject(&ctx, class); if (!trylock) ww_mutex_lock(&abba.a_mutex, &ctx); else @@ -278,6 +281,7 @@ static int test_abba(bool trylock, bool resolve) =20 struct test_cycle { struct work_struct work; + struct ww_class *class; struct ww_mutex a_mutex; struct ww_mutex *b_mutex; struct completion *a_signal; @@ -291,7 +295,7 @@ static void test_cycle_work(struct work_struct *work) struct ww_acquire_ctx ctx; int err, erra =3D 0; =20 - ww_acquire_init_noinject(&ctx, &ww_class); + ww_acquire_init_noinject(&ctx, cycle->class); ww_mutex_lock(&cycle->a_mutex, &ctx); =20 complete(cycle->a_signal); @@ -314,7 +318,7 @@ static void test_cycle_work(struct work_struct *work) cycle->result =3D err ?: erra; } =20 -static int __test_cycle(unsigned int nthreads) +static int __test_cycle(struct ww_class *class, unsigned int nthreads) { struct test_cycle *cycles; unsigned int n, last =3D nthreads - 1; @@ -327,7 +331,8 @@ static int __test_cycle(unsigned int nthreads) for (n =3D 0; n < nthreads; n++) { struct test_cycle *cycle =3D &cycles[n]; =20 - ww_mutex_init(&cycle->a_mutex, &ww_class); + cycle->class =3D class; + ww_mutex_init(&cycle->a_mutex, class); if (n =3D=3D last) cycle->b_mutex =3D &cycles[0].a_mutex; else @@ -367,13 +372,13 @@ static int __test_cycle(unsigned int nthreads) return ret; } =20 -static int test_cycle(unsigned int ncpus) +static int test_cycle(struct ww_class *class, unsigned int ncpus) { unsigned int n; int ret; =20 for (n =3D 2; n <=3D ncpus + 1; n++) { - ret =3D __test_cycle(n); + ret =3D __test_cycle(class, n); if (ret) return ret; } @@ -384,6 +389,7 @@ static int test_cycle(unsigned int ncpus) struct stress { struct work_struct work; struct ww_mutex *locks; + struct ww_class *class; unsigned long timeout; int nlocks; }; @@ -443,7 +449,7 @@ static void stress_inorder_work(struct work_struct *wor= k) int contended =3D -1; int n, err; =20 - ww_acquire_init(&ctx, &ww_class); + ww_acquire_init(&ctx, stress->class); retry: err =3D 0; for (n =3D 0; n < nlocks; n++) { @@ -511,7 +517,7 @@ static void stress_reorder_work(struct work_struct *wor= k) order =3D NULL; =20 do { - ww_acquire_init(&ctx, &ww_class); + ww_acquire_init(&ctx, stress->class); =20 list_for_each_entry(ll, &locks, link) { err =3D ww_mutex_lock(ll->lock, &ctx); @@ -570,7 +576,7 @@ static void stress_one_work(struct work_struct *work) #define STRESS_ONE BIT(2) #define STRESS_ALL (STRESS_INORDER | STRESS_REORDER | STRESS_ONE) =20 -static int stress(int nlocks, int nthreads, unsigned int flags) +static int stress(struct ww_class *class, int nlocks, int nthreads, unsign= ed int flags) { struct ww_mutex *locks; struct stress *stress_array; @@ -588,7 +594,7 @@ static int stress(int nlocks, int nthreads, unsigned in= t flags) } =20 for (n =3D 0; n < nlocks; n++) - ww_mutex_init(&locks[n], &ww_class); + ww_mutex_init(&locks[n], class); =20 count =3D 0; for (n =3D 0; nthreads; n++) { @@ -617,6 +623,7 @@ static int stress(int nlocks, int nthreads, unsigned in= t flags) stress =3D &stress_array[count++]; =20 INIT_WORK(&stress->work, fn); + stress->class =3D class; stress->locks =3D locks; stress->nlocks =3D nlocks; stress->timeout =3D jiffies + 2*HZ; @@ -635,57 +642,82 @@ static int stress(int nlocks, int nthreads, unsigned = int flags) return 0; } =20 -static int __init test_ww_mutex_init(void) +static int __init run_tests(struct ww_class *class) { int ncpus =3D num_online_cpus(); int ret, i; =20 - printk(KERN_INFO "Beginning ww mutex selftests\n"); - - prandom_seed_state(&rng, get_random_u64()); - - wq =3D alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0); - if (!wq) - return -ENOMEM; - - ret =3D test_mutex(); + ret =3D test_mutex(class); if (ret) return ret; =20 - ret =3D test_aa(false); + ret =3D test_aa(class, false); if (ret) return ret; =20 - ret =3D test_aa(true); + ret =3D test_aa(class, true); if (ret) return ret; =20 for (i =3D 0; i < 4; i++) { - ret =3D test_abba(i & 1, i & 2); + ret =3D test_abba(class, i & 1, i & 2); if (ret) return ret; } =20 - ret =3D test_cycle(ncpus); + ret =3D test_cycle(class, ncpus); if (ret) return ret; =20 - ret =3D stress(16, 2*ncpus, STRESS_INORDER); + ret =3D stress(class, 16, 2 * ncpus, STRESS_INORDER); if (ret) return ret; =20 - ret =3D stress(16, 2*ncpus, STRESS_REORDER); + ret =3D stress(class, 16, 2 * ncpus, STRESS_REORDER); if (ret) return ret; =20 - ret =3D stress(2046, hweight32(STRESS_ALL)*ncpus, STRESS_ALL); + ret =3D stress(class, 2046, hweight32(STRESS_ALL) * ncpus, STRESS_ALL); if (ret) return ret; =20 - printk(KERN_INFO "All ww mutex selftests passed\n"); return 0; } =20 +static int __init run_test_classes(void) +{ + int ret; + + pr_info("Beginning ww (wound) mutex selftests\n"); + + ret =3D run_tests(&ww_class); + if (ret) + return ret; + + pr_info("Beginning ww (die) mutex selftests\n"); + ret =3D run_tests(&wd_class); + if (ret) + return ret; + + pr_info("All ww mutex selftests passed\n"); + return 0; +} + +static int __init test_ww_mutex_init(void) +{ + int ret; + + prandom_seed_state(&rng, get_random_u64()); + + wq =3D alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0); + if (!wq) + return -ENOMEM; + + ret =3D run_test_classes(); + + return ret; +} + static void __exit test_ww_mutex_exit(void) { destroy_workqueue(wq); --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Tue Dec 2 02:52:37 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 006BD2F49EF for ; Tue, 18 Nov 2025 00:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427536; cv=none; b=pvd1g0/0EeTnw8/CXW3d0nkAX4X5dBUb3HTqeQwim0OFkY/AhDPcHb6X0sW2grTzBhrBX9SaUb16wNl6U1885AB0RZNlExUsI5fzgutARaIvqkSPeeRJ1LXeJatEW6V+e4EGZfMSHnf0HcdUK376ICJo1afJi8z7rJ/z79NaWOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427536; c=relaxed/simple; bh=9uCjmsVJlgRuTrmPs2raK8kdcDL3jRjX+PF7SRJLhRk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=avx8vDUMH1TEJZCilQiIYu0stcMSBz+zfDlG8QFL89FBpK/a6Uc+RLqU/ton0SpJkfHC1RpnK3a9TY9JEBnzSvP5mgtfISiX981RVCCaMsv7MDcZDWDZRbvA+pCtRjMR0Kv8Catz+S5ggdmxfv7qURe0QYHdTI1j4hQYUXiJro8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=z4jlpqd8; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="z4jlpqd8" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7bb2303fe94so4047996b3a.3 for ; Mon, 17 Nov 2025 16:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763427534; x=1764032334; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NBxRf2wtLdLE8Skv8eCm0JMvzZuD+zdUaznpa5o+LWs=; b=z4jlpqd8Oj+tzRJ3urtlxwy3Bu43eikZ/4djQy40d1q5R5AMQ2ldlawvDXFz8Ho6Tu DpUw2qj4XScT8WGLnjmaLMSguSSfF3bn0A+z31CsBqq3KS5gsWpsevwIdtktmQp2IR9o ORJ01ZevSxXlkbIOzENdY8kYTgeL2D+FCdDOeV56+Jm19t1G35iqBw9LRoBjLorQqJg1 ebKq9msn4jGrVUDIk2tq6mYKe+BeDOGQFIsTuRkn1qhreGx4ZnI07+Kc+rZFPlk10SCo W4uZLGsERp9xZvLY0TAFTXSQs23uny3nRKqci1a+YXpZwayYpX5SsJsBWEqezXCOU31C 6sVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763427534; x=1764032334; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NBxRf2wtLdLE8Skv8eCm0JMvzZuD+zdUaznpa5o+LWs=; b=oFLJBqPTa26FHaQUVQubm3OUNS334fQd5VBr8HpkWlXMuc82xeH5F+ukT801cBdr28 4HShp6D+gmXjnGZadrkZzbfo+5S2CYUdNDUyS6P3z/DzqJPFEvgEyIL82qkb93y4FcCk nsL6G+K+f5AXxVuwlyx4xW3M4zHmR/NGCh713ceX/80I7aiob0no+nASX7yLuuqezWyy 7wITLl2Iely46yNV+LHfSVOVc2Mk46HqeSMOcz18+89Vr4AB78RPHSU0sewZwP+eJBgc OmVoapt9g4L99J46OTk16ML2tzXGXBLmaQConjobzQ36rMFArdcY1ckidpQi5fV/R/L4 c+jg== X-Gm-Message-State: AOJu0YyFFD0zZ6j+4ycXqOAnwIpW7nWcgOI1YsKW0dJFJtyb9utAqOu7 CV0qH23B6kD/JWyhknyWeT2PrILRJ/4cgWzA3VdXhX0MWXci4rx2lFcPGe2pKrgA8z4ezVZv6aK Xtrj9caREnh5tUA9780NOosn93a3yJVzi2BGMdv3UelDQyhgX7Ox0a2BMQkVs0by0AIl40JURVg ueERgllzHx5xdHx4qwTUNI3C8bTxfF2Xv4NCBrBbLMrEzLCGSk X-Google-Smtp-Source: AGHT+IFD1ljpXbD0VDwxFZxKfyx+2BVmpwkAJoneSyAaJWscjC6ElEBwuwkP6u1Np2g/Xq2Ljd4/GJ9QuDam X-Received: from pfjj8.prod.google.com ([2002:a05:6a00:2348:b0:7b8:282e:c971]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2d1e:b0:7b8:c7f7:645e with SMTP id d2e1a72fcca58-7ba3c07eeebmr19923121b3a.17.1763427533761; Mon, 17 Nov 2025 16:58:53 -0800 (PST) Date: Tue, 18 Nov 2025 00:58:35 +0000 In-Reply-To: <20251118005843.3902476-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251118005843.3902476-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251118005843.3902476-3-jstultz@google.com> Subject: [RESEND x4][PATCH 2/3] test-ww_mutex: Move work to its own UNBOUND workqueue From: John Stultz To: LKML Cc: John Stultz , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , Joel Fernandes , Dietmar Eggemann , Suleiman Souhlal , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The test-ww_mutex test already allocates its own workqueue so be sure to use it for the mtx.work and abba.work rather then the default system workqueue. This resolves numerous messages of the sort: "workqueue: test_abba_work hogged CPU... consider switching to WQ_UNBOUND" "workqueue: test_mutex_work hogged CPU... consider switching to WQ_UNBOUND" Signed-off-by: John Stultz --- Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E . McKenney" Cc: Joel Fernandes Cc: Dietmar Eggemann Cc: Suleiman Souhlal Cc: kernel-team@android.com --- kernel/locking/test-ww_mutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index d27aaaa860a36..30512b3e95c99 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -72,7 +72,7 @@ static int __test_mutex(struct ww_class *class, unsigned = int flags) init_completion(&mtx.done); mtx.flags =3D flags; =20 - schedule_work(&mtx.work); + queue_work(wq, &mtx.work); =20 wait_for_completion(&mtx.ready); ww_mutex_lock(&mtx.mutex, (flags & TEST_MTX_CTX) ? &ctx : NULL); @@ -234,7 +234,7 @@ static int test_abba(struct ww_class *class, bool trylo= ck, bool resolve) abba.trylock =3D trylock; abba.resolve =3D resolve; =20 - schedule_work(&abba.work); + queue_work(wq, &abba.work); =20 ww_acquire_init_noinject(&ctx, class); if (!trylock) --=20 2.52.0.rc1.455.g30608eb744-goog From nobody Tue Dec 2 02:52:37 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F6092F9C2D for ; Tue, 18 Nov 2025 00:58:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427537; cv=none; b=HtqApV1/3LGtIAG3tEdAAwtSu3O1WAe5UIjeIoWpOFHaB17R6enDa34dDJpOXTptj7JCj+4GEf3Hwh87awNW4EbBJdswqFTsfmlL1fdZNG427WCQ2REr6TFtmFQ7ISf7/COOcrU15abd10nFs1tJ3cKeVLt3duI9/NoKRB3TUDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763427537; c=relaxed/simple; bh=/hxurh43P8vC9I1/T0ywT6hUFcH+xTHlJs6hwJZYagk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eC2npMl58RNoSHinJjBsEOLMnoL/+lvraTZSl2DZhwxUZc4WbcBMpNZS2LVOaNzJ0A4rxiWd8hLeJUZPn3uqYm0qcA1iEzVxxnZr4GFAoEpjm6anzrXCxePFYHlgkTqjryBgT+8g/CCjnZIGJrmbNZGGGnYLbjIFHGrYd2pYu0o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hWglYFwc; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jstultz.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hWglYFwc" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7b9321b9312so12672997b3a.1 for ; Mon, 17 Nov 2025 16:58:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763427535; x=1764032335; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+DEcSd5dptwQKYQuUosq48/ZpRDI7umpzBhDTI2aNWs=; b=hWglYFwcnQQh5cLxvAMy4AzMs6uk42G23k+v+zP7eNuRR+I0L5loJHBkiUQrI0Yuzn jwpU/YmGxmN6zp606M/+vEHTs+nurgWYpivzFjIXfdLcH9oXnbxd3SRNt5dhYAGcFadR HUJNEFelD6hNExW3Vn987JIJhlR+CwIHKOlvXh7uLC3XpCLeTPQY/2Ahv/j62pmcgGSq Te7RegRZgF2HT4DW9tRss5HW74iBBE5tVqifL5FPd24yYOoV9KeVlxdYGFIgQK5fccCT tDWuS9vU7gmyi1DfCyUZlP1JG6fcmUwiHU61bVnJfcU6zkWhlytlb258gLaZSrxFSkg/ eTyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763427535; x=1764032335; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+DEcSd5dptwQKYQuUosq48/ZpRDI7umpzBhDTI2aNWs=; b=pOzmksrXXe+Jeem/dzKd85OTcnR4G84NX5XEwvT4TsqqRy7279LCri2uyVGYJN1t+I ryVaa2oBcbc2SRfAhoeVFhDnrWpuRboa6/I6axWY+/u8lu1rdxDkH+5y6Z1K+YXHb32+ hKIGrjex74YetueUmOE2twc+UHIa9wr2LwMUFytNtAvvk7ijIBgSI3lbReF2OaJ8pILH czLpoil0FWejTIo1xEl1D4gvPnB/LHcZCJOqUS6X9Yjy1e2896cH7rHx9TnftLzDG0nE sJtIDpQUmUbaFbFmcAReU0lFkldGUolsF4fJPJxqQIQ0rKEWFxLuvslv/qUEz5TxTmQV bBjQ== X-Gm-Message-State: AOJu0YzHuBoyLAsHpQq86ytI4mbUf4SiGiiYQRld7EPx1beE//CByGvS 0h/kt40cTsGFHeyNeFA0YQKBjzBYD/ReMjerXIH/0wpk/RkWoumZNgqdOXwK9irGnG0iGromiKj 70Usd6qs4kOT0w43oJsmzBjrSQZ9l8GPJVzteMTftVJld42G9oOr+J4LcWIo8CzPPVoxb+6yP+j UfolxMVOTAL3M8DvMeuNKw+1/Nove0sNCgzVpCXOWTZsY2AbaW X-Google-Smtp-Source: AGHT+IE9jQ0+hNyYBlYGQ307mwaNIfu2L9/QeZ7PQnmTmzXlJmyHYblp4YqDtKQ5GFys5argiW7PnC5UaJrj X-Received: from pgbfm25.prod.google.com ([2002:a05:6a02:4999:b0:bac:a20:5ee2]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:5493:b0:34e:8c68:35f with SMTP id adf61e73a8af0-35b9fa7e14cmr16963347637.12.1763427535129; Mon, 17 Nov 2025 16:58:55 -0800 (PST) Date: Tue, 18 Nov 2025 00:58:36 +0000 In-Reply-To: <20251118005843.3902476-1-jstultz@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251118005843.3902476-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251118005843.3902476-4-jstultz@google.com> Subject: [RESEND x4][PATCH 3/3] test-ww_mutex: Allow test to be run (and re-run) from userland From: John Stultz To: LKML Cc: John Stultz , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , "Paul E . McKenney" , Joel Fernandes , Dietmar Eggemann , Suleiman Souhlal , kernel-team@android.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In cases where the ww_mutex test was occasionally tripping on hard to find issues, leaving qemu in a reboot loop was my best way to reproduce problems. These reboots however wasted time when I just wanted to run the test-ww_mutex logic. So tweak the test-ww_mutex test so that it can be re-triggered via a sysfs file, so the test can be run repeatedly without doing module loads or restarting. This has been particularly valuable to stressing and finding issues with the proxy-exec series. To use, run as root: echo 1 > /sys/kernel/test_ww_mutex/run_tests Signed-off-by: John Stultz --- Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Will Deacon Cc: Waiman Long Cc: Boqun Feng Cc: "Paul E . McKenney" Cc: Joel Fernandes Cc: Dietmar Eggemann Cc: Suleiman Souhlal Cc: kernel-team@android.com --- kernel/locking/test-ww_mutex.c | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index 30512b3e95c99..79b5e45f8d4c2 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -642,7 +642,7 @@ static int stress(struct ww_class *class, int nlocks, i= nt nthreads, unsigned int return 0; } =20 -static int __init run_tests(struct ww_class *class) +static int run_tests(struct ww_class *class) { int ncpus =3D num_online_cpus(); int ret, i; @@ -684,7 +684,7 @@ static int __init run_tests(struct ww_class *class) return 0; } =20 -static int __init run_test_classes(void) +static int run_test_classes(void) { int ret; =20 @@ -703,6 +703,36 @@ static int __init run_test_classes(void) return 0; } =20 +static DEFINE_MUTEX(run_lock); + +static ssize_t run_tests_store(struct kobject *kobj, struct kobj_attribute= *attr, + const char *buf, size_t count) +{ + if (!mutex_trylock(&run_lock)) { + pr_err("Test already running\n"); + return count; + } + + run_test_classes(); + mutex_unlock(&run_lock); + + return count; +} + +static struct kobj_attribute run_tests_attribute =3D + __ATTR(run_tests, 0664, NULL, run_tests_store); + +static struct attribute *attrs[] =3D { + &run_tests_attribute.attr, + NULL, /* need to NULL terminate the list of attributes */ +}; + +static struct attribute_group attr_group =3D { + .attrs =3D attrs, +}; + +static struct kobject *test_ww_mutex_kobj; + static int __init test_ww_mutex_init(void) { int ret; @@ -713,13 +743,30 @@ static int __init test_ww_mutex_init(void) if (!wq) return -ENOMEM; =20 + test_ww_mutex_kobj =3D kobject_create_and_add("test_ww_mutex", kernel_kob= j); + if (!test_ww_mutex_kobj) { + destroy_workqueue(wq); + return -ENOMEM; + } + + /* Create the files associated with this kobject */ + ret =3D sysfs_create_group(test_ww_mutex_kobj, &attr_group); + if (ret) { + kobject_put(test_ww_mutex_kobj); + destroy_workqueue(wq); + return ret; + } + + mutex_lock(&run_lock); ret =3D run_test_classes(); + mutex_unlock(&run_lock); =20 return ret; } =20 static void __exit test_ww_mutex_exit(void) { + kobject_put(test_ww_mutex_kobj); destroy_workqueue(wq); } =20 --=20 2.52.0.rc1.455.g30608eb744-goog