From nobody Fri Dec 19 16:19:55 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 E039656B81 for ; Fri, 5 Dec 2025 01:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898523; cv=none; b=JwOJ9qTvbXkUK/IwZAM6tnAoWpEwFeLnMJZRf/kLnX1VwVpyazA05RzK+GiiE+DEhBc0/lhIYBmyuut+dVZBR9JHGqicjG+DPeHBPeU5QbOLLz6/44sg0PkDIUh46ObdWhAnz1pMm0uXBkIxtHfb1o2bO9zucC45n3DdVxDfVlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898523; c=relaxed/simple; bh=4vUZUEJKKYiEs/AbgDbBhiHQVkEo4MbIIMT9FhwAwak=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OVCRQPllC3pH3M1WNsZFpcSAwFDpUqueojqcz5y5Tna8Nub5ynqaogV3YuuM556ZhGdnu2UytsvjAq+3VX4bn0KZYU21eyZUrM95NvpO5JHyvotECNRy25+qHkTROYoCYK8rSHUEmYSQeK+l5FdnhXzOBIKqwOnOly5ef9bpYY4= 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=17jXJC/X; arc=none smtp.client-ip=209.85.216.73 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="17jXJC/X" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34188ba5990so3717093a91.0 for ; Thu, 04 Dec 2025 17:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764898521; x=1765503321; 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=ru6jbXmqiIelLijSMeB+CXh2C27hKMlSMEQfMG1dxvc=; b=17jXJC/XsfYylEz2pYyl1TQ8r9a8h58AdWFvxp0nSHi7VaN396TSz6aGfv+5Uhc3oI U0VMmJy7TUpsmE5M2s+QjN0tKhZfGocLzt8eJcmRR++J2Ssz0vFC2sVrzzmcbi7k20QR qWKr5xtElEIQLIdCiPApwcN5L2IkzCJKgeHzctnT/5poLEE58En8aDa7CyJuadl/eEk+ ubZwjS7MaLt+5TLseabwXxo8RkWK+KfuhG8ZmhtAP4if6oBHe0yjrHnVQx0RcOmhFYFd oyj6lY+C8ngmt6iZVak7tmZe+DflAz1TOHMnrzR4gjdONQ4gvAqnbyAz/luDOsDDgkmj dlcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764898521; x=1765503321; 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=ru6jbXmqiIelLijSMeB+CXh2C27hKMlSMEQfMG1dxvc=; b=XjbOYrUhlunrayvmI44bIZmKgjsVN0pF5Poyyz6aMQV8M1gEKxawJc39VncCQ+Clg5 Iyvgr0GB536G7sfiCJluGoW8HqLWLVXnIZMVwppyUf6SrGN2X6NdrsTgwVMUWvURwW7n Ni0+4Jds+p5wAigdXaua3aaA945gRv++Vj4txw+tDxGUKSIJNxOi9RXqJoxC/rLO+A+p B8w1lNxBFalgU1EPnCcg+7IlxQ5QJekxC+IIR0D79hTZMlRg2e1rJUPkNrwOdK6iWnt/ Jx1wFGR0eNmHOAZhKLAVX+XgPSCyGNm8yvusZdQkz9EJplA2GU3X8Vv2WQ0JctIP2CiF QPCA== X-Gm-Message-State: AOJu0YySA54HjB/L7OCXSrCx1JxKhlWfemnUlOh5opce0orRRpqoski3 edQTDxp2qPKV8JpHlqB/cWhrDCi149hcuvAz7rLaVws2mY4y/v8hUVelVqzDr5ZKXj4uptqCIKu 9gaAMPaH6vwwrwYtacSlJ8tlODX2hkaIlK6gs4omaHRYBYHyQOAXH6tbyKBoIdbUFmD6yelK1Os ANnLZ6ATCcrWt4YcIrY0G7sfGu8ISSrSJAHC3wIbqZMvl+DY6+ X-Google-Smtp-Source: AGHT+IE/5n0K1G+unD7ZUeyBEomGJmqWby7uKG0WSlaIXbnWOh1YjbrnSBj+lVSeGNT5vrEc+BQUZcqxMNMI X-Received: from pjbsi10.prod.google.com ([2002:a17:90b:528a:b0:341:4c7:aacc]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b51:b0:340:c070:82d7 with SMTP id 98e67ed59e1d1-34947f23117mr5407082a91.35.1764898521079; Thu, 04 Dec 2025 17:35:21 -0800 (PST) Date: Fri, 5 Dec 2025 01:35:09 +0000 In-Reply-To: <20251205013515.759030-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: <20251205013515.759030-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251205013515.759030-2-jstultz@google.com> Subject: [RESEND x5][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.223.gf5cc29aaa4-goog From nobody Fri Dec 19 16:19:55 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 729392459D7 for ; Fri, 5 Dec 2025 01:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898525; cv=none; b=AFIJ87ZjN6xW6x4lt9kI/SwTstzCCe5k0XJSSYVYcigL62+e/BxKP0dUG9gKj8qkW+otfO1vi3GWmQNewtgzxtzyfHEqhvWEDUAfmAa+LfNAFB9bZhxfSZDjsa28nKCFK0yVuy3UqmWS1HlKKH/ObLXrywYNA7cf2DW9lJ6/SRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898525; c=relaxed/simple; bh=HlWp//qYPazXx4/ZKXRtyFzwkj8oGixdqikfuGikMnw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TYgFrC6mFBNLjUrI+naG4TdJECMdOzdu6MDs3jmgsXG8cEABp+g0Dfj6BKA5HMUbjmHfTWiqSz5Q7e0Soy3dVWanNyoZJa+kRmsF/ewWxdqc/R0PCxv2E0bBfLU384MjoNnWr1UUu/LW7HltZC2Wr+o/H/M87cg/Zc1ycO/vEI4= 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=HtmnsMFC; arc=none smtp.client-ip=209.85.216.74 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="HtmnsMFC" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-345b4f2a8e8so2744914a91.1 for ; Thu, 04 Dec 2025 17:35:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764898523; x=1765503323; 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=gNibO24KeJuu0lE1mYqVLUauFcQWMqqglwaPHaV7Lj8=; b=HtmnsMFCdqSW22Ez5/parsSDQEKP9KXS9vzt81K9dbpUcRw7SYQyIUnRUV9tCaQczH bTr0ErypNUsiCb0ZNS0Ca4HIu6G9spGDB+EFQNp0yXsAmuUduj9U0Ol+LxNziPv1a++S w4JeHH5M3AdRNehltTixKMGm3k38vxUgKAY5jNE8KRAek07DbQeX2XK+F0qIKSfGFAQq eA9GCKy+niC1fX4rUPCDACyH/+hPDOHL+tVWBSSz3WYtx2FNVnEt/vDh6OFCXlpqyguR 2o/0M1lbFsODJJfmPFNSNyFC6zmOe4ryryXbw/2dtaSI0IagxWMT4eKVRWx5ZWRbsqZP c6hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764898523; x=1765503323; 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=gNibO24KeJuu0lE1mYqVLUauFcQWMqqglwaPHaV7Lj8=; b=w5GFYd27jzirCSV1Pejffd2InDIBMQSeEBmHJG8ckIX7jJXzKDu099gLyw4Hx2IMG/ g9A38LztAsnWPqO07VYVCNTL1S6lAdKlreS3JmVwJSgroRJmhCXV5TrcBoyaR+msFMtw s2lIulxMBFKze8B1phfgAj00Ac0iIdmjQMM7KWz82dlcBPf8IfitzyArGCM11EXkMSQn TOUKrTyegBX2NjLJqV+C78UdoLH0eOn2FN9ue1paHjOH1MpCOFk7HiV2PjlM2gcuzoaB Z+NwB+HCr3WLu92CXBF4T6cbeREXvVaevhi+iY0XxjJ2QwD0CP4Njc1Bzu2kwSHnevaj FcIA== X-Gm-Message-State: AOJu0Yy35xBivDPapJ5d4LtKUMvBH0JNVBO1PanrWqW5yjD85sBngSDm 01apiUpQ5Mhxp+hTY/pYJXTopcBljtCqg3nH4ZOczx8PwnSeQTg/AGM78pzQ3izIeX3taEfQFCu kb62RFmoZ85T5/uLI3HVSWR+50ClfPBaBP7THXMsRG+6TQ2u7asAg9vPpJet4HGrfnfd+YJQfpF v/MSzwze8ZNB2l7blt3KrOyKFQpqBu8nGPY8ZP0jkD7XJe8lqb X-Google-Smtp-Source: AGHT+IEBTLcJWgNhV+3ahJMm/XW2lJhTreF8zRr8ofoQcOHpX9SL2VohiLGsTkEfSxRIJMaOigfUVsDBlH0e X-Received: from pjzh9.prod.google.com ([2002:a17:90a:ea89:b0:340:bb52:b060]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d0f:b0:340:bde5:c9e3 with SMTP id 98e67ed59e1d1-349126c863fmr8472580a91.23.1764898522529; Thu, 04 Dec 2025 17:35:22 -0800 (PST) Date: Fri, 5 Dec 2025 01:35:10 +0000 In-Reply-To: <20251205013515.759030-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: <20251205013515.759030-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251205013515.759030-3-jstultz@google.com> Subject: [RESEND x5][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.223.gf5cc29aaa4-goog From nobody Fri Dec 19 16:19:55 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 F0F421E3DE8 for ; Fri, 5 Dec 2025 01:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898526; cv=none; b=tll23x9btCVscmiq806hvCdf1uNlNHKW1Gx8C7lSuFStH1B9wGZZpvxFWUifBSIlYzyo82g85gL92Dvity2kBV3zGedPtMQoytbghEqYjV8HgQdbK5g9iDFH3rBzPpOvkkh3wdfZ+ypS8b50Zgx8nYc+tPOwk7WTill6PiJILGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764898526; c=relaxed/simple; bh=fceokh9ZDj3iTBx5iWtCTbWWN8dcyN/kyS4Uh7Ge2SM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cOwZX0hZ+LPAvqr2HUh9m+S+jSDxNWDvNJNClWxtdIjV2zMI2P/tltBREeolP/SZyGiE2wJ3DLwibsmJipxkAvMc0Phg+4W2x51Q5DbMAXrrRJAk/5Bzobk5VPxllC77+pxwbWEiXIeCLsUHsa/JhaIopJ4JBS6mPaPT/cQzNIo= 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=2M5smhb0; arc=none smtp.client-ip=209.85.216.73 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="2M5smhb0" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-340bc4ef67fso1733738a91.3 for ; Thu, 04 Dec 2025 17:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764898524; x=1765503324; 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=rm/x06f7hG+OOm8I2O8TRX4qj73dKa/XNTRoxwtX7cY=; b=2M5smhb0tUir4gUy+na0GdCB2V52M/OZT9VxI96gLfhO4aZ4O6IFnQF5F1YC7A/Z6g INTc7Q5TjNL/x8IW5gnxWikDznygxATmGh2O/ALTuKmULjK20vkDZ4NlBtepQuUxR8pp rT6hS/9ka9qjrXaoRxUTKodHVe5i3clfNUVHRCkK98Tepkc0zGaulGaVWb7rij66llHi oBSfkFSv67ohhcim9agHPs/4/BV7/UXeNjzsDumdTyuWPQdApk6S22H/e0H+9QjiPMzW +IAIf/GaHUv+UP8PijE9sP40WKO1wvI5e1zFBjrtq638roOUAhUfNnvxUYGg7I9haLO0 12gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764898524; x=1765503324; 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=rm/x06f7hG+OOm8I2O8TRX4qj73dKa/XNTRoxwtX7cY=; b=Wf8jDeaxCuHImoJvj7H5MDUemHTl6GruxwMG3OjGGG4cLhKZJSVX2NFn2eA9xUawin zUPSOpZzTOvqxtIQrLmxLnVLaMxN7uVM0LgfQXGv1/dCoVQalM0PAWhte9TAH6MTOURC jma07OHM6fSdFgIIYc0/WEwfPIAMFEbdbus6vL/R7Fs/Wr6tLzwnMP1mV0n+TphbVXcZ 7nodA5qYLd92q8FK0dKdw5zzTQ0nDPFPDd9FcDQn3nYK+n+0uA2RQ5mJ+A2Urq4MNLiA x+jAGp3vI1q1lRFiovOHEykfYDDLF/iuDQoWicIHhGsKDmnP2WYECgxglYcH48Ty6gwV xj4g== X-Gm-Message-State: AOJu0Yx4s+Kpo080Iu7ZjKNnicSsUTGHEDx5vAdq5o+/XVrcZ27bTLu9 V3DgdCkT0Y9L8x2Me/Wo+1ViW9VGGtXHiuut4ETFWVmWgApkNVYRnd5ny0hxSI6seZoXh15aAr3 Ivk/54NlHbyxEXFQGYTHfpiseYgMf80c0ZFCGljh8D10w7WnkvJMByuXZWrfUpYNZhI0YBhGPWM VJuO/pw103WPkrNOB7X5k9023jsNaYH/ikbE2JYN5zs6VOvyco X-Google-Smtp-Source: AGHT+IEYUhdXd+yr0MRwOv7fosCzQ5DqubqfzfP5XgbfTyrzJ19jumGbMrQ3La0zM1isi3xSF2CcqlJFdwTs X-Received: from pjq8.prod.google.com ([2002:a17:90b:5608:b0:340:9a17:4b10]) (user=jstultz job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:17c5:b0:340:f7d6:dc70 with SMTP id 98e67ed59e1d1-34947da717emr3949914a91.13.1764898523929; Thu, 04 Dec 2025 17:35:23 -0800 (PST) Date: Fri, 5 Dec 2025 01:35:11 +0000 In-Reply-To: <20251205013515.759030-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: <20251205013515.759030-1-jstultz@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251205013515.759030-4-jstultz@google.com> Subject: [RESEND x5][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.223.gf5cc29aaa4-goog