Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98502345CC9 for ; Thu, 6 Aug 2026 13:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786022819; cv=none; b=qDHqyAUVA1c6Z2LYXLPsKimmItJSrfsYMjq1Y3kYXQFtotY97xhxSrqqPamMH88e2yc6tzsr4BM5c82vy4E3f4wDrrHXV/Xc+CkDyEqZv5sLfLpSuUaINY/bFsbnAoykrarcIKo49taiJ61J2RaDUrmMB0Z6qCCPKtrIFbcJSC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786022819; c=relaxed/simple; bh=kchTI7XWSEK6kI3cuCB2HpQ5ck5V2tKnTatHqXARWjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jTE94sTzd9YqulOUbsRyv0JgvorROsNt9m2prD2iVPj4VksyzAVwtlep5t61O/AwHnCOVY3tCJxKc3sN/W4ibg453Uwf+E5GnY7I31iPmDp4ZJqP/UbtHl5zj6ZgvHRhXwhJElUAWTKhO6XnaGSociql7gRU92dHandJvSRdLSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=XljfUYHA; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XljfUYHA" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 676CEPqb2559121; Thu, 6 Aug 2026 13:26:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2025-04-25; bh=P6cVHs3UknO6rg5OXBf6YquXPjgwRf6XCQu9eDem6kw=; b= XljfUYHAQHtSHR53AVX7pDTgZgLyDNsucUQMzNXlcKS6377ToO6jnZ8Tyj43amLf 80mbmIReLvgfYDYokPEMphni+TWQoQ1So7XikWhACjOvQYIicag1RRFuFhGDrmdL 3zSGB01NN7vhcilOb1S8nb8fz+u42MlVzGY7GWl3X/228sFHnTac2Rmh0CGlb1Ft fkAWvz3KYcMI6+SdCUwtdmUsoYh/i4g//mIEvDk8ciI4FkA+3jjqWKcaX4vKYexh 9d9Hsd3qpcq441BzYmhQ2/V1w0QfNXvRP174fFgducjFRABGbGZWwxosdPZAaj+2 b/srn/0/UEioOP72jxiHTw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4fs9btdhpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Aug 2026 13:26:35 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.7/8.18.1.7) with ESMTP id 676DFRvI033462; Thu, 6 Aug 2026 13:26:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4fs78ehpkn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 06 Aug 2026 13:26:35 +0000 (GMT) Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.1.12) with ESMTP id 676DQVrn002301; Thu, 6 Aug 2026 13:26:34 GMT Received: from lab61.no.oracle.com (lab61.no.oracle.com [10.172.144.82]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4fs78ehpg4-2; Thu, 06 Aug 2026 13:26:34 +0000 (GMT) From: =?UTF-8?q?H=C3=A5kon=20Bugge?= To: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Chris Wilson Cc: =?UTF-8?q?H=C3=A5kon=20Bugge?= , Ingo Molnar Subject: [PATCH 2/2] test-ww_mutex: Fix deadlock in test_cycle_work Date: Thu, 6 Aug 2026 15:26:26 +0200 Message-ID: <20260806132629.3334938-2-haakon.bugge@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260806132629.3334938-1-haakon.bugge@oracle.com> References: <20260806132629.3334938-1-haakon.bugge@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-05_06,2026-08-05_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2606160000 definitions=main-2608060104 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODA2MDEwNSBTYWx0ZWRfX4E9YFSezuAhd a5FLIaR86ZA3ZlvwN+skR9WNRdISPvzQdk3O3zoPIenF3YsLZnEFWlgCm0oN/b+JXmY0pLTdeCP psE6qvOOFn6iZG08xn4UI27q7ErBks22WZwpGzDdwlTLlInjMpbPTS7rislaFPGTaIEJG1O4F7p 0aEW0+katQPVA+3lYm98lR+wcBPy71VqK5FJ9KbgXa6GxwuLu1rBoTp+wIJKkOrzbO5i5HyHGwS L8H1syG2LmnpMeCbTwaaG57lyZKTWbmYlDpEIrpjiyuD3S0wZavnhkqgVqGqM32YPDY2rw/R2Lu b/gnl3mNRsIexEWGCpsnQpBM3oh5AMWkyC1HC4fU6AS+Ra92lgcRDHSdQlpe2X7ZnsTFwKyatsL Sh6+iQk0jSUZ/OjB7ctlRd/YgGzBM7PjwaeEBz7V32l9hx7wL5HG3evuhh4IMDCFD3AIYyk6pXe S0EzX1l11RRZIpPFMhg== X-Proofpoint-ORIG-GUID: 2ZuDuLodB4PQn8SywCAeJOfsbkuqtl8N X-Proofpoint-Spam-Info: AW1haW4tMjYwODA2MDEwNSBTYWx0ZWRfX+FOFda1FctKO TzGY/88qednkUR6f2/cMPIXau50mxZazG+Cty4VGHktO+8ATAkoEN0ft8wSsmZIICh5vMHZzhQq 6YHSL6kNqVgqu1vcYQJFaCS3vm9NSu+wCPiby9sIZx2GnIBEKXAR X-Authority-Analysis: v=2.4 cv=ZOTnX37b c=1 sm=1 tr=0 ts=6a748b8c b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=M51BFTxLslgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=jiCTI4zE5U7BLdzWsZGv:22 a=7Gl3-_t3PgB9XO-mQDs3:22 a=yPCof4ZbAAAA:8 a=WAdc_XZaImYrliwInUAA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=WmVTiCyuxqgg3mnwYu6p:22 X-Proofpoint-GUID: 2ZuDuLodB4PQn8SywCAeJOfsbkuqtl8N When running with N online CPUs, where N is fairly large, let's say 512, a deadlock may happen in test_cycle_work() when running with N + 1 kernel threads. The reason is that the min_active is too small in order to let N + 1 worker threads run concurrently. The following is my analyzes. The test sets up a circular dependency with ww_mutexes and completions: work[1] completes signal[0] work[2] completes signal[1] ... work[511] completes signal[510] work[512] would complete signal[511] work[0] completes signal[512] Therefore: work[0..510] -> blocked in ww_mutex_lock(b_mutex) work[511] -> blocked in wait_for_completion(signal[511]) work[512] -> inactive; test_cycle_work() has not started Because the last worker thread has not started, worker 511 hangs forever in wait_for_completion(). This bug produces the following splats (slightly edited for better brevity). This for the worker threads hung in ww_mutex_lock(): INFO: task kworker/u2066:1:13658 blocked for more than 123 seconds. Workqueue: test-ww_mutex test_cycle_work [test_ww_mutex] Call Trace: __schedule+0x28e/0x670 schedule+0x27/0xa0 schedule_preempt_disabled+0x15/0x30 __ww_mutex_lock.constprop.0+0x841/0xe00 test_cycle_work+0x9d/0x150 [test_ww_mutex] process_one_work+0x196/0x370 worker_thread+0x1af/0x320 kthread+0xe3/0x120 ret_from_fork+0x19e/0x260 ret_from_fork_asm+0x1a/0x30 And this for the single worker thread 511, hung in wait_for_completion(): Workqueue: test-ww_mutex test_cycle_work [test_ww_mutex] Call Trace: __schedule+0x28e/0x670 schedule+0x27/0xa0 schedule_timeout+0xac/0xf0 __wait_for_common+0x97/0x1b0 test_cycle_work+0x80/0x160 [test_ww_mutex] process_one_work+0x196/0x370 worker_thread+0x1af/0x320 kthread+0xe3/0x120 ret_from_fork+0x19e/0x260 ret_from_fork_asm+0x1a/0x30 We fix this by adjusting the wq's min_active parameter. When num_online_cpus() has been sampled in run_tests(), we adjust the {min,max}_active values of the wq, to make sure both are set to ncpus + 1 in order to avoid the above deadlock. Note that this fix is invariant to num_online_cpus() changing after it has been sampled, because the RC here is the number of runnable worker threads vs. threads created, not per se the number of online CPUs. Also, in order to avoid exceeding WQ_MAX_ACTIVE, we create cycle_ncpus and clamp it. We do not want to change ncpus for the other tests, not affected by this bug. Fixes: d1b42b800e5d ("locking/ww_mutex: Add kselftests for resolving ww_mutex cyclic deadlocks") Signed-off-by: HÃ¥kon Bugge --- kernel/locking/test-ww_mutex.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c index 47e016a4f4fea..04bc58c9b934b 100644 --- a/kernel/locking/test-ww_mutex.c +++ b/kernel/locking/test-ww_mutex.c @@ -676,6 +676,7 @@ static int stress(struct ww_class *class, int nlocks, int nthreads, unsigned int static int run_tests(struct ww_class *class) { int ncpus = num_online_cpus(); + int cycle_ncpus = min_t(int, ncpus, WQ_MAX_ACTIVE - 1); int ret, i; ret = test_mutex(class); @@ -696,7 +697,17 @@ static int run_tests(struct ww_class *class) return ret; } - ret = test_cycle(class, ncpus); + /* + * test_cycle_work() has a linear dependency which requires + * all kernel threads to be run-able. With N CPUs and N + 1 + * worker threads, deadlock may happen. Hence, adjust + * min_active. Set both max and min, in case max is too + * small. Cap N so that N + 1 doesn't exceed WQ_MAX_ACTIVE. + */ + workqueue_set_max_active(wq, cycle_ncpus + 1); + workqueue_set_min_active(wq, cycle_ncpus + 1); + + ret = test_cycle(class, cycle_ncpus); if (ret) return ret; -- 2.43.5