Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp5556148pxb; Mon, 28 Mar 2022 14:10:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5uInOKDppGjqhwikZUgHVS3uUZvIm/GDHn1j6jalzyXrTWBvmfZineiJEKYldInhUzDtF X-Received: by 2002:a63:254:0:b0:386:1d94:2dfb with SMTP id 81-20020a630254000000b003861d942dfbmr11523178pgc.6.1648501821663; Mon, 28 Mar 2022 14:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648501821; cv=none; d=google.com; s=arc-20160816; b=hLSbBcd3SQlqtor0UGByj31/N0PtnKLA1hZi8e36mcCD6uMdGuEMAGBrdX1SToIYnE JolCTLoDe9udLDMGgbTKdke1eCEW0bEEGZKxjOGLHBF1i9MG2k29sEWS/0GTErzCQscu ki+dygB8nhmbUi0HuWmLwlcl2ZtZZaIFItKr8pHUo9bvtAkGdLrRtQhWvk9wZykU1jWm ZZzX3vKMyxMqPdHro8U+H6sr+ZhnKQfLLYB3VJKd0ZW/wlSqfv1fLmfO3luu27Yezas8 I1n1OmwlpvnQonZ51DcKO6i1iMBoCy5uOtVnBGprMY0F589Nhwe0j0OSP5lNdZqLL9U3 MHwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=q4Xt99w9xbYhH0KUJ1KGjk1nQO3I91qbWeC7RgiTOTM=; b=01oliZ+kcSiMkFBj6/1JITx8mW8quVAjJ9Ho0sSZ78X6pD5RumLgCiitdQSrh3gcCF 5kMiz+JZ01x+/MTlJ9Mb9/UeMZbLXzi5+UjLnb729ju2Q7zHksddCQ0zXmFdHB4oFPs6 REAySGzeYx7w8VHeRNHqEs0bjVK5Xuc2PVVnbwpi24ZPjJFfEdjAYY+ZL9CmZ1+J/IS9 S8QJ5uwDy/IeP2jVQ7Imq0lmvyymfdYtUhOZ5YpGf0RbvLhLpKbp8Woo9wn8JEfxU9W5 +/XSCHCJd+9bFGDczdWKknw7ZnS/GJOvywvZqRJ7Uz7K+vPEI9I2gNXNq3glijdSCjkS UZIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aui3z9lU; dkim=neutral (no key) header.i=@suse.de header.b=bskkfPk2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s6-20020a170902ea0600b00153b2d1663asi12094643plg.578.2022.03.28.14.10.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:10:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=aui3z9lU; dkim=neutral (no key) header.i=@suse.de header.b=bskkfPk2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E57326CA76; Mon, 28 Mar 2022 14:03:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241240AbiC1QRg (ORCPT + 99 others); Mon, 28 Mar 2022 12:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239988AbiC1QRf (ORCPT ); Mon, 28 Mar 2022 12:17:35 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D68625EBF for ; Mon, 28 Mar 2022 09:15:54 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 43FA4210EE; Mon, 28 Mar 2022 16:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1648484153; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q4Xt99w9xbYhH0KUJ1KGjk1nQO3I91qbWeC7RgiTOTM=; b=aui3z9lUJWoZzWioOA8gh+7KdVc2GhaSTiJZeV/8K/6sR11p+AbaHSYw/F37iTj2PmKMpH OfD7F/F/FV9ox1gfV6AO3I8z5Hq5M8/PCmY4mj251JXBns0TSvyfwdf9atJudq0BD7aWJf XTPbQY3ekdaRKj1DhcgYMM3z5mp9ylM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1648484153; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=q4Xt99w9xbYhH0KUJ1KGjk1nQO3I91qbWeC7RgiTOTM=; b=bskkfPk2ufk9FbJgwzGfb4xiY/0rkelwLXX7jkO+0rUVN/6D+4WWR0agYzQzWZhNquLwaz 7YscciewtgELbSCA== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 2DF91A3B82; Mon, 28 Mar 2022 16:15:53 +0000 (UTC) Date: Mon, 28 Mar 2022 18:15:53 +0200 Message-ID: From: Takashi Iwai To: Mohan Kumar D Cc: tiwai@suse.com, kai.vehmanen@linux.intel.com, perex@perex.cz, ville.syrjala@linux.intel.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com Subject: Re: [PATCH] ALSA: hda: Avoid unsol event during RPM suspending In-Reply-To: <7cbfca20-bd1a-9ca0-f0e2-2ecf5fa74f45@nvidia.com> References: <20220328091411.31488-1-mkumard@nvidia.com> <7f7934e6-137c-4d8d-049b-0ed5e57cf00b@nvidia.com> <7cbfca20-bd1a-9ca0-f0e2-2ecf5fa74f45@nvidia.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 28 Mar 2022 15:51:17 +0200, Mohan Kumar D wrote: > > > On 3/28/2022 4:27 PM, Takashi Iwai wrote: > > External email: Use caution opening links or attachments > > > > > > On Mon, 28 Mar 2022 12:19:03 +0200, > > Mohan Kumar D wrote: > >> > >> On 3/28/2022 3:12 PM, Takashi Iwai wrote: > >>> External email: Use caution opening links or attachments > >>> > >>> > >>> On Mon, 28 Mar 2022 11:14:11 +0200, > >>> Mohan Kumar wrote: > >>>> There is a corner case with unsol event handling during codec runtime > >>>> suspending state. When the codec runtime suspend call initiated, the > >>>> codec->in_pm atomic variable would be 0, currently the codec runtime > >>>> suspend function calls snd_hdac_enter_pm() which will just increments > >>>> the codec->in_pm atomic variable. Consider unsol event happened just > >>>> after this step and before snd_hdac_leave_pm() in the codec runtime > >>>> suspend function. The snd_hdac_power_up_pm() in the unsol event > >>>> flow in hdmi_present_sense_via_verbs() function would just increment > >>>> the codec->in_pm atomic variable without calling pm_runtime_get_sync > >>>> function. > >>>> > >>>> As codec runtime suspend flow is already in progress and in parallel > >>>> unsol event is also accessing the codec verbs, as soon as codec > >>>> suspend flow completes and clocks are switched off before completing > >>>> the unsol event handling as both functions doesn't wait for each other. > >>>> This will result in below errors > >>>> > >>>> [ 589.428020] tegra-hda 3510000.hda: azx_get_response timeout, switching > >>>> to polling mode: last cmd=0x505f2f57 > >>>> [ 589.428344] tegra-hda 3510000.hda: spurious response 0x80000074:0x5, > >>>> last cmd=0x505f2f57 > >>>> [ 589.428547] tegra-hda 3510000.hda: spurious response 0x80000065:0x5, > >>>> last cmd=0x505f2f57 > >>>> > >>>> To avoid this, the unsol event flow should not perform any codec verb > >>>> related operations during RPM_SUSPENDING state. > >>>> > >>>> Signed-off-by: Mohan Kumar > >>> Thanks, that's a hairy problem... > >>> > >>> The logic sounds good, but can we check the PM state before calling > >>> snd_hda_power_up_pm()? > >> If am not wrong, PM apis exposed either provide RPM_ACTIVE or > >> RPM_SUSPENDED status. Don't see anything which provides info on > >> RPM_SUSPENDING. We might need to exactly know this state to fix this > >> issue. > > Well, maybe my question wasn't clear. What I meant was that your > > change below > > > >> ret = snd_hda_power_up_pm(codec); > >> - if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) > >> + if ((ret < 0 && pm_runtime_suspended(dev)) || > >> + (dev->power.runtime_status == RPM_SUSPENDING)) > >> goto out; > > can be rather like: > > > >> + if (dev->power.runtime_status == RPM_SUSPENDING) > >> + return; > >> ret = snd_hda_power_up_pm(codec); > >> if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) > > so that it skips unneeded power up/down calls. > > > > Basically the state is set at drivers/base/power/runtime.c > > rpm_suspend() just before calling the device's runtime_suspend > > callback. So the state is supposed to be same before and after > > snd_hda_power_up_pm() in that case. > Thanks!, Make sense, will push the updated patch after testing with > latest suggestion. Thanks. Also don't forget to cover a case the test bot complained: the reference to power.runtime_status needs #ifdef CONFIG_PM. Takashi