From nobody Fri Jun 12 12:49:00 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 512D22F90C5 for ; Fri, 15 May 2026 06:02:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778824969; cv=none; b=MtKwpoDkBwRtaVThYaAgcm8R5E2oRMqoIwJxtX5lyx9h8r89NPVoCmjSBIh0YmOz5WN4w6E4O8HYhSVd+MIyPV2v/X8kOZLIWVbdyJCTWhaxLc4cg2jW5J3CbvJKYT5ppUXL4PDaW1bK7muNVosu1DiqZzAR1+PVM0Tir2RosN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778824969; c=relaxed/simple; bh=wR7jKA0t4CicrNC69Yqv2+I4dYOHHNscXFwVsJu3sCs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=NMwrNBxdwPmX+oDY1WjIihYr3EQxyLzydcktiXclSfLl15wTdhaTFZxQAUVGrn6YmzZdx3YBr8YERbUZGsxBV32n3D9x5P5TPgV8JmkAK9dyVoxwisTF8zU9d4yKsFGn/i5vPk8KIl5sdlQfbbtua60rD+cUs+Fs3+3C8uMPdl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=HIoD/zqW; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HIoD/zqW" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-837dfccd950so4477501b3a.0 for ; Thu, 14 May 2026 23:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1778824967; x=1779429767; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=hBdfbCTSyRrEf51qC6bvgO49tgTiXounMMZECu9Vp8k=; b=HIoD/zqWLfBDlONwYIPKqLxY+V/dz/RAdxdZiMBXdIju6RdQEyfIS0S6JXA5rrqQeX wz3iYjewEnWgcTLRr0BKQjdN90fEUo6qDHEm+LJsUHczDs/nR51QSLa5AApAeo2Fxmpt 2rOyjX8+uXkxFaCMBmMHDZIWllm/qTSmGLymQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778824967; x=1779429767; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hBdfbCTSyRrEf51qC6bvgO49tgTiXounMMZECu9Vp8k=; b=K99Pm2YoUyt3W/cLJJHYSloMweXrl/cO8IIJsQoaCijfIpXbtlYZgarBGIcGl7E2UB 5kW9V+MT3VF83FT7StQ/OkTKz1LW/Bpp1vysrBQTh56im/CQ4LjNFagCiGgzam560Mn3 hs8lUvt4BUIGPe8apSOsHn7p5B3zPt4/JJKQO3ttVDMYVTqm63eDp7EwnY8y1oXVdSAC MrQMxEYWTECoEp93IFfzZq69+rnS2PvWGJGAY1xpllB5WX8mdutZcepI/Hw6HcUeKjyM zG/eU0O1n20bO6BaRxdxRIfJUmdn98F4GKfR2kZlxjk2lCR/DJiSc2tR97vFz2p8PTUH gn9w== X-Forwarded-Encrypted: i=1; AFNElJ/zXcMCmn9/ckcSfgVI4pAyL4FfJkwU1Nk3+wlDsozlpWix6iYWLWxg4IPseeYsl4uqyxt8nhzt6qv5Flc=@vger.kernel.org X-Gm-Message-State: AOJu0Ywrg9iXrdOR+bBh/r5R2byT0pCdhsECSpgfppnr+HWOOiwpkTM2 6aYv7nWaKDvEFruWTfOapZlxcdwKInKJHyaZxGapgVd5isObCUjq062SLpiIVhucrGtx/pKJi6U h080= X-Gm-Gg: Acq92OE1hm5fm1QecMp6KYW9/EKAo7XaWUi9La5vGtoIa04nTa9f6ilskZHhhCurVIE 58ZFr04Mt31UOqfAew/izTpKLnx6SFNfBOr66vQ+EoHv08XQHDfYvYs8uo/iwuB4dlQMP2//Vof yPBqdTiwYj8W4zol634E+PXNQkJtKuSWaFOF3NtZpmJdlmfcYPE3gb7lm4wvHD5QM5QoMTI5lDs nCbmOGOunmQs1896i8aixMyGGLtRSxqUmSDYotuMV8GCTFcDgrvpXblJR5xTf/MOwnR8Dj8/4YI +sXhEgvWSoPwxrEY9Cf1O1oLtVuQlVuBL2WF+i877AlEyywOivPmp8yl8wBHBqe2WywmhD7qYwf BShxfNwLOkJhe+jhAP+dD4YibeKBX0tCwCROWa3wi1lf5gsEf6kHrBAipTTXelvAczQUSNTdI2U 2UYHwipYGqS6tbPhZRN8JSGg80JMLidhTomd4x27S95X9JF9325DatxT5Ztd7zRMu3bFb6f/XFS YOBC31hjlTivF8HryRd0OGN X-Received: by 2002:a05:6a00:178e:b0:82c:e9cc:f61d with SMTP id d2e1a72fcca58-83f33ba0aa1mr2853552b3a.9.1778824967552; Thu, 14 May 2026 23:02:47 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2a00:79e0:2031:6:68cc:d8b9:b76e:e07e]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19c77822sm4985125b3a.41.2026.05.14.23.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 23:02:46 -0700 (PDT) From: Sergey Senozhatsky To: Heikki Krogerus Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH] usb: typec: ucsi: split connector lock classes Date: Fri, 15 May 2026 15:00:30 +0900 Message-ID: <20260515060042.136083-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Lockdep detects a possible recursive locking scenario during ucsi init: [ 5.418616] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ 5.418634] WARNING: possible recursive locking detected [ 5.418706] -------------------------------------------- [ 5.418725] kworker/4:1/82 is trying to acquire lock: [ 5.418759] ffff888119a34648 (&con->lock){+.+.}-{3:3}, at: ucsi_init_wor= k+0x1a78/0x2eb0 [typec_ucsi] [ 5.418801] but task is already holding lock: [ 5.418835] ffff888119a34080 (&con->lock){+.+.}-{3:3}, at: ucsi_init_wor= k+0x1a78/0x2eb0 [typec_ucsi] [ 5.418884] other info that might help us debug this: [ 5.418904] Possible unsafe locking scenario: [ 5.418937] CPU0 [ 5.418956] ---- [ 5.418991] lock(&con->lock); [ 5.419013] lock(&con->lock); [ 5.419033] *** DEADLOCK *** [ 5.419387] Call Trace: [ 5.419406] [ 5.419425] dump_stack_lvl+0x61/0xa0 [ 5.419448] print_deadlock_bug+0x4a6/0x650 [ 5.419483] __lock_acquire+0x62b6/0x7f50 [ 5.419507] lock_acquire+0x11b/0x390 [ 5.419654] __mutex_lock+0xbc/0xcd0 [ 5.419741] ucsi_init_work+0x1a78/0x2eb0 [ 5.419785] ? worker_thread+0xf53/0x2bc0 [ 5.419819] worker_thread+0xff4/0x2bc0 [ 5.419842] kthread+0x2a7/0x330 [ 5.419863] ? __pfx_worker_thread+0x10/0x10 [ 5.419896] ? __pfx_kthread+0x10/0x10 [ 5.419916] ret_from_fork+0x38/0x70 [ 5.419936] ? __pfx_kthread+0x10/0x10 [ 5.419969] ret_from_fork_asm+0x1b/0x30 [ 5.419991] [ 5.420009] ---[ end trace 0000000000000000 ]--- The problem is that all connector locks belong to the same lockdep lock class, so the following loop: for (i =3D 0; i < ucsi->cap.num_connectors; i++) ucsi_register_port(connector[i]) mutex_lock(&connector[i]->lock) looks like a recursive acquire of the same mutex. Put each connector lock into a dedicated lock class so that lockdep doesn't see it as a possible recursion. Signed-off-by: Sergey Senozhatsky Reviewed-by: Heikki Krogerus --- drivers/usb/typec/ucsi/ucsi.c | 8 ++++++++ drivers/usb/typec/ucsi/ucsi.h | 1 + 2 files changed, 9 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 5b7ad9e99cb9..43da7512dea0 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1642,6 +1642,7 @@ static int ucsi_register_port(struct ucsi *ucsi, stru= ct ucsi_connector *con) INIT_WORK(&con->work, ucsi_handle_connector_change); init_completion(&con->complete); mutex_init(&con->lock); + lockdep_set_class(&con->lock, &con->lock_key); INIT_LIST_HEAD(&con->partner_tasks); con->ucsi =3D ucsi; =20 @@ -1887,6 +1888,9 @@ static int ucsi_init(struct ucsi *ucsi) goto err_reset; } =20 + for (i =3D 0; i < ucsi->cap.num_connectors; i++) + lockdep_register_key(&connector[i].lock_key); + /* Register all connectors */ for (i =3D 0; i < ucsi->cap.num_connectors; i++) { connector[i].num =3D i + 1; @@ -1916,6 +1920,9 @@ static int ucsi_init(struct ucsi *ucsi) return 0; =20 err_unregister: + for (i =3D 0; i < ucsi->cap.num_connectors; i++) + lockdep_unregister_key(&connector[i].lock_key); + for (con =3D connector; con->port; con++) { if (con->wq) destroy_workqueue(con->wq); @@ -2166,6 +2173,7 @@ void ucsi_unregister(struct ucsi *ucsi) usb_power_delivery_unregister(ucsi->connector[i].pd); ucsi->connector[i].pd =3D NULL; typec_unregister_port(ucsi->connector[i].port); + lockdep_unregister_key(&ucsi->connector[i].lock_key); } =20 kfree(ucsi->connector); diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index cff9ddc2ae21..51f6c3c0d365 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -517,6 +517,7 @@ struct ucsi_connector { =20 struct ucsi *ucsi; struct mutex lock; /* port lock */ + struct lock_class_key lock_key; struct work_struct work; struct completion complete; struct workqueue_struct *wq; --=20 2.54.0.563.g4f69b47b94-goog