From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.45 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796113689; b=FYZ0AR/5jVPVxrAB+OyrqoKB9T1yC0djCb4T3L9G/vlGmQDM65yvArWySBRz188sxyP3 4SH02Qm7o2DH6yBqItgTaC+HoWRaITAs4QOVsDK8SkuN30oJBl8qRGvIPgStI2RsYZy1w i5IAp1rYCipsoZn//hftR1fyMYyZV6U+xD1SHxoXi3UcfchQ1IIiOuAXYzN3IP7we1aex +3u4U2L9mj6vBINRx+tZSjKDW4kJUT4KHl4SRGIAcREiyGaHbVskkxeGmcyU0VjcNByzd xFM0n0S4XhrGFzobJ70LCzRCWwo1P6a8Kl4AFyyBkoKypWwdfie4vjJVUYdqT7zgiRQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796113689; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=XHwjIEKTpH6hlBdt0fprydxukzRVxVB7U4h5GhKQokA=; b=k5I9r4N2retHNTeV+u8PAT1PiQPMTXkv59fQdigdCbGx+zkjMueFKP7aMpZhM6ILTRLu z6tE8HwRZ+csyN7uPoukcu21HUuBpxes4O3/tjjVMWdc5tMQHWrUjzKzWHZaPcWh7SSOq r9Qfiqky+BSD88rPr+dCh2dEEBZeXMuSGQZZtg4YQmRc2JKTtCSBr0G+plEVES9FMRMsZ oupitPd4P6g6GNfQ9zmAb0a6+T+ltiapjCe89qP/3eMIKSUhWWzznOjM618PqAWHDKQ/d J0phuutXQIxfZ1X8jv/rUfSyY8vXC6X8l1h6G9pfFnwylGhevHuPsKpDu+95R9Z+Fcg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ZnP6JOlZ; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.45 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010045.outbound.protection.outlook.com [52.101.85.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 465A9606A31A; Tue, 1 Dec 2026 08:28:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 465A9606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=ZnP6JOlZ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hHG8r1JoHUtmKtxk+hCN6LTD0Sa6QvKqM762MSzFBzrE3LTO0/7v2AlIHOqV7ioJ+ZPG8wFi+nza1bS0jMkAI9mzna4/QXutS3amWh3EiFH3rGpMgdExyjXH47opqxJELd6+ogLy6y1Zd+vxzd0CZnApVMRmQF6krdmFxbHntIH1OLXDVbT4vQXsGVIIKWouX0Wn3DxIHO78l9Nq/HDTcz/9b5y06Lt6wXm9fG/hhIr9AX0BPImaDZJHTszeEO3a/vR2dMVuZqMXsl/mHAFPKL5kAp9dBaJnFL4X/1ASTiqzUyceYED9Rx8dpKwfhhuoGGbxDYng7w45NeQnloWB/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XHwjIEKTpH6hlBdt0fprydxukzRVxVB7U4h5GhKQokA=; b=jnotjrqSbIxShXjP7/EwCXRh82WkYWY4AI3+Rk2LAnmselnnICiLLaXSj8kciJpv7WQ4W5QvQeJO3w9Xa5wJij9Z+ZmyPlxAB9T/uCPFYsLKkiGrMpdFclEh8mk42qif1LOkTqms+CYsPi8bRoiZoQuJMcybC+Wd/gBYuI6PzwwozdCNunl6ky6UI14bJun42h0RZhCyTQgRg3eMQRz3PsuqgON0KfYPTOKzqStdygb/LJekmYV05T/6ZKLVOFfapytgHleYjzPoH1YNE/gjwpp8+WqNgTl7806a3HS0JoHWfpejXcpsbNx+mf79rdDPfyCwuDXqRS1uSmQds34OVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XHwjIEKTpH6hlBdt0fprydxukzRVxVB7U4h5GhKQokA=; b=ZnP6JOlZ+VC7xRMxTJMaRGfo0DxDjBUiU1Mm6UYbTzYzv1An6Q5pXCzbGTBy8Z/58aVv5mSf1ZijT1PQmc6rHzIE0Fnd/vyIyi/JgSZYULMRgTojCQqtJMQq3azF9Y9QIMFHJa5MFZtAv0JjXzb3K9NTQ99yDpOb4Gm35IQK/5M= Received: from BLAPR03CA0132.namprd03.prod.outlook.com (2603:10b6:208:32e::17) by SA1PR12MB9547.namprd12.prod.outlook.com (2603:10b6:806:45a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 08:28:05 +0000 Received: from IA0PEPF0000003C.namprd03.prod.outlook.com (2603:10b6:208:32e:cafe::16) by BLAPR03CA0132.outlook.office365.com (2603:10b6:208:32e::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.13 via Frontend Transport; Tue, 1 Dec 2026 08:28:05 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by IA0PEPF0000003C.mail.protection.outlook.com (10.167.249.73) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 08:28:05 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 02:28:02 -0600 Received: from amd-System-Product-Name.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Tue, 1 Dec 2026 02:27:59 -0600 From: Vijendar Mukunda To: CC: , , , , , , , , , , "Vijendar Mukunda" Subject: [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() Date: Tue, 1 Dec 2026 13:56:26 +0530 Message-ID: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA0PEPF0000003C:EE_|SA1PR12MB9547:EE_ X-MS-Office365-Filtering-Correlation-Id: 504830db-1018-49a7-e7c1-08df4f8505d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700016|23010399003|11063799006|6133799003|261009221227099003|261009223027099003|18002099003|261026140227099003|10067099003|56012099006|261028144727099003|261026121527099003|261022075727099003|261022105027099003|261021123027099003|261102123227099003|261021121427099003; X-Microsoft-Antispam-Message-Info: PuXHarhvQrghUiLTeG5F1Ta2CyB1BypHN8eckl/rjDXH4vlKDU5WJyTCMTm8htl2R4tPhybI6PSDmbCGcVO6jJsy7uPzi+ROLxjFN4h9oNvXk4Ilaup8tLOi6jKFWmFMv4ukmszcQOSelYW3ToenahdHKul1zmdEEjKcLmZDyNk4MNveOOgXhRQxtryllr8p7zh8AOqfG0QUICxSusG9LSysf2DIZhau39e0un/izD3wDCxF3YOoYBiAgZnzvgi0cKK/l0qlf+JDeJdaqoVAM07EPoNC6J2hVJb4EFhFTH7gOrcKnPrQW8byi4tI3VxjUEMxDXjD4zCz3X3jGbvWrq2hRjajhGBF30lP/vs38AJAyyDTo1LehiaFyZs3mcjHvQoO78ba+kgZRnsTsiaNAsQjOyOvBfWxuAnxczLNG5RMoL3gsIzw2EizUe8BQPMrYNpuIgGdtQvGfAlNd3UcLccOLueAwUaVMwWf+oLnDxXGf9CPIc/QXR+xYzWGuVJECFifhipSRTsLpHoybyPCOebz3BUYP4gXqlveyPf0Kf+a+c2zdVJegh1INtiEcxhY8F0E7JL2FrvL1aDXGZ0LBJsCvZO5Sn6LFIJwN+cr2WElw0dak9/gfLdDaOCU88BU/KNhJhlyUqIlh71EHXt0Gniy1VFNpJkDUm0Ltl9wZJvqjdbTfV/qx5HE34p6lKAbMC7jqhU9DzaaALo0+uTWfQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(1800799024)(36860700016)(23010399003)(11063799006)(6133799003)(261009221227099003)(261009223027099003)(18002099003)(261026140227099003)(10067099003)(56012099006)(261028144727099003)(261026121527099003)(261022075727099003)(261022105027099003)(261021123027099003)(261102123227099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WqCo8noEyxVpCi8H7M/g0XGLVGJxehzOfH3kFgYrNwyLjI2rg3yFGiV0PM7V8xRp9CLvdzKeLpZlreZ84h/fgSta8PmYZu6qCUu94UWUPaixtvFpPMyEDPoPhjWTyS9zsfS/Fcbd29n2EHG6YUrI+Dk/Dbs9MwNT5z7v36Mb1DgXfpMZQGV2xHB4GT26ouLMKtwvb/szQ8+3m9st+i1HpxmP1UZ+qyjTYyD/WhHdyvz5MNPob4BCDapFxeVhNdVWQuAB6S/+P4TAAc6tJmja/J+kXDpD5rtf+290bO29B37ATTopCpXpW+BIVYFXImj0/LpTpSDEil15VAGdDWx+0L6iraCqQ7AB5gwhfQ2Hu+O22OJwtvERi2++r5nEN9oEXFqKdkvw+4ZYgVl5y6PkUESacKW0J5sMmJuafHQ8qLXZKtzvTjcY2SRmX7BLFPwH X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 08:28:05.6565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 504830db-1018-49a7-e7c1-08df4f8505d5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: IA0PEPF0000003C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB9547 sdw_handle_slave_alerts() calls pm_runtime_get_sync(&slave->dev) which, when slave->dev is not in RPM_ACTIVE, calls rpm_resume() on the slave. rpm_resume() propagates synchronously up the parent chain: slave->dev -> bus->dev -> manager->dev. If manager->dev is in RPM_SUSPENDING at that point, rpm_resume() blocks on dev->power.wait_queue waiting for the suspend to complete. This creates a deadlock: the manager's runtime_suspend callback is blocked in cancel_work_sync() waiting for the alert work to finish, while the alert work is blocked in pm_runtime_get_sync() waiting for the manager's runtime_suspend to complete. Fix this by first checking the manager device state using pm_runtime_get_if_active() on slave->bus->dev->parent (the physical manager device). This is an atomic check: if it returns 1 the usage counter is incremented in the same operation and the manager cannot transition to RPM_SUSPENDING while the reference is held. - If the manager reference cannot be taken (ret == 0, manager not RPM_ACTIVE): request an async resume via pm_request_resume(mgr_dev) and return early. This avoids I/O on potentially inaccessible hardware and breaks the cancel_work_sync() deadlock. After the manager resumes, the peripheral re-asserts the alert via the first PING frame. - If the manager reference is taken (ret > 0, manager is RPM_ACTIVE): proceed with pm_runtime_resume_and_get(&slave->dev) to resume the slave. Holding the manager reference prevents the manager from entering RPM_SUSPENDING while the slave resumes, closing the deadlock window for all slave PM states. - If ret < 0 (-EINVAL, PM disabled on manager): fall through without a manager reference. PM being disabled means no suspend/resume callbacks run, so no deadlock risk. This is consistent with the original -EACCES exemption for the slave. pm_runtime_resume_and_get() is used for the slave (instead of pm_runtime_get_sync()) because it does not increment the usage counter on error, simplifying the error-path accounting. Introduce have_pm_ref and have_mgr_ref booleans to guard the pm_runtime_put calls at io_err: so they are only reached when a reference was actually taken. The manager reference is released at the new mgr_put: label after io_err:. Fixes: aa79293517b3 ("soundwire: bus: fix io error when processing alert event") Signed-off-by: Vijendar Mukunda --- drivers/soundwire/bus.c | 60 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 15c66effbf4f..5dc3598eb85f 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -1667,15 +1667,60 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) u8 buf, buf2[2]; bool parity_check; bool parity_quirk; + bool have_pm_ref = false; + bool have_mgr_ref = false; + struct device *mgr_dev = slave->bus->dev->parent; sdw_modify_slave_status(slave, SDW_SLAVE_ALERT); - ret = pm_runtime_get_sync(&slave->dev); + ret = pm_runtime_get_if_active(mgr_dev); + if (ret == 0) { + /* + * Manager is not RPM_ACTIVE (RPM_SUSPENDED, RPM_SUSPENDING, or + * RPM_RESUMING). Return early to avoid I/O on potentially + * inaccessible hardware and to prevent a deadlock: if the manager + * is in RPM_SUSPENDING, its runtime_suspend callback may be blocked + * in cancel_work_sync() waiting for this work, while this work + * would block in pm_runtime_resume_and_get() waiting for the + * manager to complete its suspend. + * + * Request an async resume so the deferred alert is re-serviced: + * - RPM_SUSPENDING: pm_request_resume() sets deferred_resume so + * the manager resumes immediately after its suspend completes; + * on resume the peripheral re-asserts the alert via the first + * PING frame and the interrupt fires again. + * - RPM_RESUMING: pm_request_resume() is a no-op (device already + * resuming); after the manager reaches RPM_ACTIVE, the peripheral + * re-asserts the alert via the first PING frame. + * - RPM_SUSPENDED: pm_request_resume() triggers an async resume; + * after resume the peripheral re-asserts via PING. + * + * When the SoundWire link fully powers off (e.g. D3 or equivalent), + * the peripheral loses power and its alert state does not survive; + * pm_request_resume() is unnecessary but harmless. + */ + pm_request_resume(mgr_dev); + dev_dbg(&slave->dev, "Alert deferred: manager not active\n"); + return 0; + } + if (ret > 0) + have_mgr_ref = true; + /* + * ret < 0 (-EINVAL): PM is disabled (CONFIG_PM=n or disable_depth > 0). + * Proceed without a manager reference. + */ + + ret = pm_runtime_resume_and_get(&slave->dev); if (ret < 0 && ret != -EACCES) { dev_err(&slave->dev, "Failed to resume device: %d\n", ret); - pm_runtime_put_noidle(&slave->dev); - return ret; + goto mgr_put; } + if (ret >= 0) + have_pm_ref = true; + /* + * ret == -EACCES: PM is disabled on slave; proceed without a + * slave reference, consistent with the original -EACCES exemption. + */ /* Read Intstat 1, Intstat 2 and Intstat 3 registers */ ret = sdw_read_no_pm(slave, SDW_SCP_INT1); @@ -1861,8 +1906,13 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) dev_warn(&slave->dev, "Reached MAX_RETRY on alert read\n"); io_err: - pm_runtime_mark_last_busy(&slave->dev); - pm_runtime_put_autosuspend(&slave->dev); + if (have_pm_ref) { + pm_runtime_mark_last_busy(&slave->dev); + pm_runtime_put_autosuspend(&slave->dev); + } +mgr_put: + if (have_mgr_ref) + pm_runtime_put(mgr_dev); return ret; } -- 2.53.0