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.43.66 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796297655; b=5AXUGBx76XcyGPzthPDksyQn90qiV3kIePiJzOM4VZVuBhVEHZt1hAV+xQ8yd7XqiRDM j1+MuKn7J8PWcwgu4Xs0yeZec+1IutjaXhlIJI/0Z5eUDsikEPSJeMEr5AnTH+Upop+pL A+UFoaRmf/wxQrV0yMFLwaVeJ2EC79LSSQOQuypjzq7ozYUt/BTCVuhYujd456yVYmBwC UcaV1BvquI+ZxHn1t1ybBmvUfP2rUZ8uRl1RvDwMNBvS7ZPuW+o6mccajzW4k5Fk6ZO+x FCFfrjTrOj96Fxo4OekanWPBv614W597XaRq7ODEcE5cxFeXcFTU8ZUcVz4OYWZnOSw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796297655; 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=bAy02Bnz+PPfMrMm8bkb3Kg/OEy/xBF2JcoFPeeIm6RqOCZxgmHQOuIxjwXWaOJN4BKA 7+bthnx+/2hrz8ZeLHfX33f5TIBQc9pILT44oa88ugFxYWnwSjxYoYJiUTE0pJNVCe3Dj 6w76MzYBsXhD0fW3io8bWGrWMULzSDwb1kcg0DdodRYDlq5FYwfVV+7BGl0R033M0SrWy bl1z6pvzNRcpYDUQ1Hfn3MDWY8tpPklHDhp+rwX+/7k4aPubtmOgjEpUVhwdTAzE80tG9 08RCJ8q5frYa6CT/lOfoElaurLWoAMtPGIu2m7syWKGYOZBJAFn/cj+Z6GdRDlCDGlA== 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=VsBI3dwL; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.43.66 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012066.outbound.protection.outlook.com [52.101.43.66]) (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 249F9606A32C; Thu, 3 Dec 2026 11:34:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 249F9606A32C 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=VsBI3dwL ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KUAFW1b+MDOc3PigP2lVnpkxnllcvrsP9GZN80zJDfe/63PdYacy6itlW3YewS2TI9NUh/IU3gqhbtwxIZHRKQ0Z8cLpe9zQP9X+NDPvcQVplqhxCE1VW4Hw9tOzM4jAl6xiW0Rz9WCO2Bri+pxRaMTv68Y4SYAaDqxMXAqw50PmImUBOPnjgzPuScISXGvlYn9w+FxGK8V5lMFimzZxDNmrpXjFiVs1gfhnZ9ObkEHjAhxNnIlMhtMF+crcCU+ZHlTSLkCStM4VcNKzeZewBCFEv/zMRzx0BXp4yjyrzXVp8WV1XLRbtnHChc66cmAKcy1rbWkxTSWjuinNzydvEA== 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=JvgFRMcUSWbqSdEUiHfoposNPH+O5qVD7vCzqPzBqRZPGVPP6sOFaIBBYAj5/hes5HuUmw/KODlEzm/kiBsFBGTzzcdNWAbJuC1P8MWP3Tw1z5uZwwyPzeUB0n1aqZC7TkDvvsjU8E8h8Yjowff1OGhcIUr2Xtz6YwbDn6V3/VQ3jHnUVirVAk3bentH4tA5MJoMb/9/2ipOzw49U3PO1559KsC2MOsO9oHkC8eGLJKMUq+zIVPQnESte/z4DTw/fZulifIzhTT/JpGWpGn5GoLTKVBm+HBff4kFEf/GtNib7oHSDShVdteQnEaz8MJQAMCojdnke2KrZqbg0dl2gg== 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=VsBI3dwLzuIUvtAltuyRu1YDEViECoacWp3I+ozODkR7GOxpcecBMWZQiIxBwsvQF3mnY8KZhQLfI2NW7VYuF3kdubeeeDXFdIIGv14zNEUlaWkK4FU3RGa1TK0HJNF1QhNYorYO5rfB/HyOxo6TLYSmRVB00tVADRbXFRlIt48= 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 PH7PR12MB8054.namprd12.prod.outlook.com (2603:10b6:510:27f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Thu, 3 Dec 2026 11:34:09 +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:09 +0000 Message-ID: <17f00eb3-8345-41e7-8d6c-68d7c7c63026@amd.com> Date: Thu, 3 Dec 2026 17:02:53 +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: MA5P287CA0177.INDP287.PROD.OUTLOOK.COM (2603:1096:a01:1af::10) 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_|PH7PR12MB8054:EE_ X-MS-Office365-Filtering-Correlation-Id: bc1e8787-fc53-446b-ba66-08df51315878 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|23010399003|11063799006|4143699003|5023799004|6133799003|18002099003|22082099003|10067099003|260925021311599003|260925021911599003|56012099006|260925022911599003|261102123227099003|261021123027099003|261021121427099003|261022075727099003|261026140227099003|261026121527099003|261009221227099003|261022105027099003|261009223027099003|261028144727099003; X-Microsoft-Antispam-Message-Info: aPAqREOg0cMWNRLl6gku5E5gjPuoFgDzQRFa/hjN3DQXgMcl9R+HNCvKQEK7OGjPxMsEXKp1gaSlD9mz6uA5YFgTJhz3Vhhi4JimQKOWPCrKROfXxGglJixO3/OH/Bo9MDvKRGNr81REKOjOwIx1aaPCj0yaPjiBXTKXUSbJqgQLEyTX4XgM5UhFdBNt1w6/obLV78u7tKzXkDC5piI+GSH6OrrlgS/mcwx9NB+ePjMXW5T4akWIPSPkgque+rmSmtZAvLnl6rc0+Qgmpn8rXZdMrmPZ/AIN4bA6eY0LYoalnsPMd9ZnadMPxY3UDZOqA8bTSjH3gC/4leLrGLsmzcZd9tgUtJkrktrHvQPt5eiNWe+J1DTs54G8dpz/QrqTy+RuCx8xmjSqBpTo4kxW8eHNgMffOjnxozRtX8L+tN9YHY1rXKaUmfKETFzA+3WwlcFawN+UFZaALgIDlfMGTdASKiSm1wX/goQ3WvWgufvT+LOS7yn8mwkE6s+6CCG6um9De9KlmWVbWGoWbDdJTAyCqknmbYd+IOG6kNr+Qbwz5+Oqp+sN/x6ELVn/8DIl3R0bw2kDCSK4y/nFEInHciewoYp76yqOYKbvYFDIeNc= 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)(1800799024)(376014)(366016)(23010399003)(11063799006)(4143699003)(5023799004)(6133799003)(18002099003)(22082099003)(10067099003)(260925021311599003)(260925021911599003)(56012099006)(260925022911599003)(261102123227099003)(261021123027099003)(261021121427099003)(261022075727099003)(261026140227099003)(261026121527099003)(261009221227099003)(261022105027099003)(261009223027099003)(261028144727099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SEIvRGZmZlhpeThDaEZxVUVQbXdrUFhyQmhNbzliWlNoa01tRnZIWkxoRVoy?= =?utf-8?B?T0FaMUI4dWlhd1RGMzBHL29ydWwrUTNUUlFjRW1kVDkrNUJHclN2OVc2cVht?= =?utf-8?B?bTVvUlBGeURNdEl6LzdaSEtnakVrazRkd2w1QVV2MkxMVnhEUER1NmFzSFJy?= =?utf-8?B?RnREclNvMFp4dE9IS3ZmdVpmbFNOb2JJRisrTmNiYzlwV3Y3R0dvZmxzdXdP?= =?utf-8?B?ZG5qUkZTQjJrU0duUjJ4VFArZUtzOStGejlZU29USzBqMlVrUS9wV0xGblJJ?= =?utf-8?B?UVdFV0dwMm1meC9xaThrMkZwVW1yUm1yTitTZFQvYzRUZy8wYmJUcFN1ODh4?= =?utf-8?B?ZUlLNll4RDRWazNWOXltK3NYaWdsdS9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f-8?B?ajR5aFJmY1JUNkZ0SnUzTXBUS2E1UkJ0bDJtbnp6aGVtVmJ6RWc2L21wekpj?= =?utf-8?B?UEgwOXFyb1F2bVBxWjZsZW0wSU1CbVJwVThhZ2gvZzllQVg3TVAxSUF0WGtm?= =?utf-8?B?Y1lveWNTSlZ2aDg1YTZ6cXUweE9EWG9SNDhGam51WWFuRTNmcVdNZz09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc1e8787-fc53-446b-ba66-08df51315878 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:09.3214 (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: zFqvPFcJpRGfq1sYhIZSny2JlgFuhL1TRJLoIQ+DAx/R0Qlq0XU51lwKUCrEnugmz6cg/ZCK3bT8tFWUTbS5XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8054 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.