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.57.71 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796297706; b=ntmWgSNK1qsV2BPRU5dpzhJE1w/OTFg0ajzMly8TjFnCEbITRQvGyEWrtQo9AF6C9SlR jskCYHfNjKEfNYUqip004dkoAZCJ71QKj7sk3fTFMi4EEHk5v/QnAQ4Cl/VCd3nV8Nk6d vgRzuGFK+Ir/Y2gOtuLX9ioEqeMNw27cL5JqOJCZ2R5f5jlljBOFcEmikbZk6gDqdtj4P aoDXbVpwtC+MgDeAG87VxcdJNJTcM4UqoGCvxmHZpr7QzNIR+LJvuYlZB2EZyIRGC5M5I f4kOXNOXdbl7WjxzmsV9dwTdO7YooJLlcA6VMl2zOg2z5lb2gsvWMH1ISRO+Qm26O3g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297706; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: 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-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=ooCWuDLHsyfU1LTEjnejd24/jCfKg/wUKltGEV5vzM8=; b=Fb6PfVhzW+zBAWlDqNN79aGooDFw91bSVQy1u81yoO2ChnqcoziKdZeyvqJXeklbFpzi ZqJdB/HytViEsad6q+/nFUEuufMXGo2wbbYyRG83xq5CHVk9P6nCN01rWS21qzOTZ/vO6 MYewZdeMOhP8hwx8qzVrw7b9mQIUO0KkuVhMhMaTVDzr65SWGQilU4nr+E6UHEQ9JKJt8 7bZxr5vh/fvrnG/CSGxAOYViR7Ra1iloWvD8i5sHOrOerlGVk/gM0w5KOLAF4YnDYDd6r k+3W/6cESlZxVd0mxHxKZZvFzqUogoMjqHu8CUmboGIm+EEGA2xNvoryjKUO2wKN8cg== 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=c1XdKgQG; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.57.71 Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011071.outbound.protection.outlook.com [52.101.57.71]) (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 B01F2606A32F; Thu, 3 Dec 2026 11:35:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B01F2606A32F 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=c1XdKgQG ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u/P5GqHGBwWHHMR3KQfWa4BkMu+cXHRrOkSJh4ZUwoCx1WtGWT8GEHMcvdAuGQmmaTMLE95OlTTm5Jp4JYVvfkgr/XLCKSR6tMkB5ZrAo4dQnTcRAO3fUNfiIM0cZdioQSOXLacImkWUgnqubDtebKls1x8FbOn1KeSrbAHsyU/x4RYZW8bi2P9PAEREPmxOg3ta/o1eqr03Wj6/h8ZFQ0iVPiqZtSu2/0Awj4jlMg6IdMBCWyBxt4g7A1Aqvhni6CWGCk4JWrapMg2m1u69Zac4fA7GstB4rMK5NI6+/92uTCnK8MiF24uGRvGUVI3R/wEAeiDogUrNA+Bhe0pxUQ== 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=ooCWuDLHsyfU1LTEjnejd24/jCfKg/wUKltGEV5vzM8=; b=ly/2Cv+qH9pa1qK82h0sJnMDNXSzZZ/m+2qNnbnSSIrEfs7/+oSQ+fGk3uiXVeygnTACalJ2DrEedQCTu9dqg6wbQbkNjvb9+PqHb37HzCoYjysdgu+2bUpp35CtZm0sBRiAjE9dW09NzXLFQYW1Y22UzlXEFclCtRefXliLKRHzNd/HRo1hnJ+8bYZaS1dKv5WSCUPxZ11hrjb6OzX2tVB8nE6m4bw2+HJz+dPlba61tzVVMrpF1nUZp7SeHr7JJzIN8AkJENmNn6i0QrvoQmL8FZfgwVIKVMIVsJQFfG3Jd36SSDc+IeGdiF/x1HfwLZWsMkR/O+hLA4WARc7jWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=ooCWuDLHsyfU1LTEjnejd24/jCfKg/wUKltGEV5vzM8=; b=c1XdKgQG1lWDNeSs5FVNvTGylxVO0iI7+i9LkILV/deJzUS7E2qeVBDnY0Heswe1dEg9Z4I/H2/z98Y9OiIeoE0RIDDQlyAN+tqopMVyZLE85nPBIdSVj56LNbdRZFtWlqV3SzwDImw1Q+Gnw8fdCOpXJdmCZl6CSGFBpHm9Bas= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CY5PR12MB6252.namprd12.prod.outlook.com (2603:10b6:930:20::17) by IA1PR12MB8264.namprd12.prod.outlook.com (2603:10b6:208:3f5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Thu, 3 Dec 2026 11:35:00 +0000 Received: from CY5PR12MB6252.namprd12.prod.outlook.com ([fe80::ab00:d77:6014:64a2]) by CY5PR12MB6252.namprd12.prod.outlook.com ([fe80::ab00:d77:6014:64a2%4]) with mapi id 15.21.0688.009; Thu, 3 Dec 2026 11:34:59 +0000 Message-ID: Date: Thu, 3 Dec 2026 17:03:43 +0530 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] soundwire: bus: use pm_runtime_get_if_active() in sdw_handle_slave_alerts() To: Pierre-Louis Bossart , vkoul@kernel.org Cc: broonie@kernel.org, yung-chuan.liao@linux.intel.com, Sunil-kumar.Dommati@amd.com, venkataprasad.potturu@amd.com, Syed.SabaKareem@amd.com, Mario.Limonciello@amd.com, Richard.Gong@amd.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261201082651.3700713-1-Vijendar.Mukunda@amd.com> <89ff4a51-4346-4013-b645-4bcc8643509c@linux.dev> <89d18c0d-b19b-435c-aebd-e11c2793cb24@linux.dev> Content-Language: en-US From: "Mukunda,Vijendar" In-Reply-To: <89d18c0d-b19b-435c-aebd-e11c2793cb24@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: MA5P287CA0174.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:1af::8) To CY5PR12MB6252.namprd12.prod.outlook.com (2603:10b6:930:20::17) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY5PR12MB6252:EE_|IA1PR12MB8264:EE_ X-MS-Office365-Filtering-Correlation-Id: 75527a5d-541d-4619-e503-08df513176bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016|23010399003|5023799004|11063799006|4143699003|6133799003|261009223027099003|261009221227099003|22082099003|18002099003|260925021911599003|260925021311599003|260925022911599003|56012099006|10067099003|261102123227099003|261022075727099003|261021123027099003|261021121427099003|261028144727099003|261022105027099003|261026140227099003|261026121527099003; X-Microsoft-Antispam-Message-Info: xVEudLH+tV9hNNfuPr6YVh6NSeR9+4zLBUyF713aGZupVCrpoZJJUKqkTMzqklmenipLYfVB6Cao0m0hI6IAzUPfPlm/6N0mTeOZl3LKHSybYzWVyxRqoIQBdueiI6RBW4McsaNL0Jbf1teyB6vDd3tP2BSt3s6O5JQU4VmYzF4n+lW6XVeHE/67x2anHG/EFoHjmgOtdzbUOi8JZe8IHbFp9K6lbosqbdyul3areNGekm1D8FfVowpW8PduWRHsp9aJHR/nn0DCNJpmjeHII4cfcL9jMuTkFArpqJzAcaaU+UPzjpcO2Nxa+tcLtxtYlzeAcQba1DvHxkagh3fGme7uyESHSUA9MDGX0Z1iUkKggnBN0okor0OcqQRY440e2L3TiW6H1Zxqhmv+sQ2XUCTXg+Xk1BHoE9x4fJ7ZmhH19PoEZkh1IG7OKk476N5LzNUXPpWp++euO8sZxM9YugWlyz6AQll4LQIl0EDxzX/GRCb43ZtuxI7Ip0jn0kUst8Zq8Q3Exn2C9dCdQFutBMnuI9ohyh2t8zTXbdxvXrubg7wUad40Z847k1yKVsu7Mah2yA2Svtz9OvymGH8oGmbdmuECs6r9mGBlwHGvIx0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY5PR12MB6252.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016)(23010399003)(5023799004)(11063799006)(4143699003)(6133799003)(261009223027099003)(261009221227099003)(22082099003)(18002099003)(260925021911599003)(260925021311599003)(260925022911599003)(56012099006)(10067099003)(261102123227099003)(261022075727099003)(261021123027099003)(261021121427099003)(261028144727099003)(261022105027099003)(261026140227099003)(261026121527099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?QU4xT2lSc2x5WFF4NmRUdW1qN1pKeTVlcndRckRKbHJNVjRlOFlsUHVNdWZu?= =?utf-8?B?Z2RGSStSTUR1UFVBeTRDc1BtTXFidkYzK24zM1JOcjdoRy8vS1I2Q3dtcUxo?= =?utf-8?B?L21aa010U3VLaVNVbGdBR2lVWjdyUjU5QXFSaUIwdGZCYlp5cUs1M3E1OWsx?= =?utf-8?B?UUIwVkc0eFI2S09WcVRCTWhIa0dxVjBLMTBOYkgvWjhaWGhjbkhHMUdKZDZE?= =?utf-8?B?YXJsd0ZsSUpzK3M3bFA1ZlNLS2VIUDlka1dnNVpkMURGVHlOanR3M0JoUU5j?= =?utf-8?B?bDVYTTdmUmxnOGg0eWY0dW44MmJ4dCtLMGQzYzN4UC9hWFVlQ3ZidUJXVGtj?= =?utf-8?B?REl2alBmbVdNWDdwZjNQMmpmUThEeU5QdFJuZ3NBa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f-8?B?M01NUWpDNGtLOGx6TDRjQkc1YmJkcjNUMnBXZS92WU9McVZseDlSOEdITTlO?= =?utf-8?B?bjlScVd0OWFpWFZRTDF2dkx2by9hWEVwMW1IK0VnNHNZYU1SVTh6ckZ6OUtZ?= =?utf-8?B?cWN1cDl3SVpMRDhuMXpRcExxNWtnTG5oU3FZM3QrMWtKZit0ZHUxQT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75527a5d-541d-4619-e503-08df513176bd X-MS-Exchange-CrossTenant-AuthSource: CY5PR12MB6252.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 11:34:59.8494 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6triWPg8dNEeBg2QK6RAN7mCrYeS7B6QIi3LA0UlZgVSxohhvpTCkaKGz4ZVhwA5pv4QMp5j2Ny3UU6o3EwE9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8264 On 12/2/26 20:58, Pierre-Louis Bossart wrote: > > > On 12/2/26 7:43 AM, Mukunda,Vijendar wrote: >> >> >> On 12/1/26 22:44, Pierre-Louis Bossart wrote: >>> >>> >>> On 12/1/26 9:26 AM, Vijendar Mukunda wrote: >>>> 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. >>> >>> Can I ask why the manager doesn't disable the interrupts before >>> initiating a runtime pm_suspend and presumably stopping the clock? >>> >>> It's a known design feature btw with the clock stop, once you start >>> the transition you want to go all the way. If there is indeed a jack >>> or something, the device can keep the data line high to resume. >>> >>> I am not sure if there's any merit is requesting a resume that could >>> be done with the regular wake from clock stop? >> >> The fix in bus.c is generic and applies to all SoundWire managers. >> Even when a manager disables interrupts early in its suspend sequence, >> there is still a timing window where: >> >> 1. The slave asserts ALERT; the IRQ fires and the alert work is queued. >> 2. The manager transitions to RPM_SUSPENDING and runtime_suspend calls >>     cancel_work_sync() to drain the work. >> 3. The in-flight alert work reaches pm_runtime_get_sync(&slave->dev), >>     which propagates rpm_resume() up to the manager — blocking on >>     dev->power.wait_queue because the manager is in RPM_SUSPENDING. >> >> cancel_work_sync() and pm_runtime_get_sync() deadlock on each other. >> In theory this can occur on any SoundWire manager that calls >> cancel_work_sync() inside runtime_suspend. >> >> As per our understanding, the fix returns early from >> sdw_handle_slave_alerts() in that window to break the deadlock and >> calls pm_request_resume() so the alert is re-serviced after the >> manager reaches RPM_ACTIVE. >> >> This was originally identified during the AMD SoundWire driver series >> review and the bus.c fix was proposed as the resolution: >> >> https://sashiko.dev/#/ >> message/9466c3c5-50f7-4566-9ff4-3d7d8aa4491f%40amd.com >> >> The issue has not been observed in practice on AMD platforms. >> Intel's cdns_update_slave_status_work() follows the same pattern, >> so the exposure is not AMD-specific. >> >> @Vinod, @Pierre-Louis: given that this has not been observed in >> practice and the clock-stop wake mechanism handles most scenarios, >> would you prefer to keep this fix or revert to the original >> pm_runtime_get_sync() path?  We are happy to defer to your guidance. > > my understanding is: > - if the manager is already suspended, then the interrupt handling was > disabled a long time ago. > - if the manager resumes, there's no deadlock. > > So it'd really only be in the case of the manager starting to suspend > with a peripheral already suspended but able to generate interrupts. > Those interrupts would most likely be related to jack insert/removal > or a catastrophic issue like reporting an amplifier catching on fire... > > I believe the solution suggested would cover this corner case, but > it'd need to be documented as a paranoia check based on code analysis, > with an additional dev_warn() or dev_err(). > >>> we've gone back and forth on the use of pm_runtime_resume_and_get(), >>> it was great until we reverted most of my changes. >>> >>> see e9537962519e ("soundwire: bus: Fix unbalanced pm_runtime_put() >>> causing usage count underflow") >> >> Acknowledged.  The revert `e9537962519e` notes that the previous >> use of pm_runtime_resume_and_get() caused a usage count underflow >> because pm_runtime_put() was called unconditionally even when >> pm_runtime_resume_and_get() returned -EACCES (which does not >> increment the counter). >> >> The current implementation addresses this explicitly: have_pm_ref is >> set to true only when pm_runtime_resume_and_get() returns >= 0, and >> pm_runtime_put_autosuspend() at io_err: is guarded by have_pm_ref. >> The put is never called on an error path where no reference was >> taken.  This is precisely the conditional-put pattern that the >> revert commit described as the requirement for safe use of >> pm_runtime_resume_and_get(). > > ok, I must admit I didn't trace all the branches, if you've looked > into this I'll give you the benefit of doubt. > >>>> 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. > > I would reword this paragraph to say that the suggested fix only > improved functionality for the RPM_SUSPENDING case, and is harmless in > all other cases. > >>>> +         * 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; >>> >>> that statement isn't quite right, in theory for runtime_pm you *do* >>> want the ability to exit from clock stop. It's only in the system >>> suspend that it's ok to lose an alert and request the peripheral >>> state when the user restarts the device. >> >> Agreed, the comment is imprecise.  For runtime PM the peripheral >> retains its state via the clock-stop wake mechanism and the alert is >> re-asserted after the manager resumes; pm_request_resume() is >> therefore actively useful, not merely harmless.  Losing alert state >> without recovery is acceptable only in system suspend (S3/S4) where >> the peripheral may be fully powered off.  We will update the comment >> to make this distinction explicit. >>> >>>> +         * pm_request_resume() is unnecessary but harmless. >>>> +         */ >>>> +        pm_request_resume(mgr_dev); >>> >>> what happens if you don't do this? My take is that the clock stop >>> wake will be used. >>> >> For wake-capable CLK_STOP_MODE peripherals, agreed — the wake >> mechanism triggers a resume and the alert is re-serviced. >> >> The gap is non-wake-capable CLK_STOP_MODE peripherals.  Without >> pm_request_resume(), the manager completes its suspend, the clock >> stops, and nothing triggers a resume — the manager stays in >> RPM_SUSPENDED and the alert goes unserviced indefinitely. >> pm_request_resume() sets deferred_resume=true so the manager >> resumes immediately after runtime_suspend returns, restarts the >> clock, and the peripheral re-asserts the alert in the first PING. > > I am not sure we need to care about those 'non-wake-capable > CLK_STOP_MODE peripherals' since they would not work reliably anyway > for regular pm_runtime. Adding support for this narrow window where > this race condition happens doesn't fundamentally make those devices > work well.. > >> For POWER_OFF_MODE and CLK_STOP_BUS_RESET the bus reset on resume >> clears the peripheral's SCP state, so the alert is lost regardless; >> pm_request_resume() is harmless but not needed in that path. > > agreed. All comments will be addressed in v2.