From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82EA0C433B4 for ; Thu, 8 Apr 2021 08:34:58 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A6B3D61164 for ; Thu, 8 Apr 2021 08:34:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A6B3D61164 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id DF9441686; Thu, 8 Apr 2021 10:34:05 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DF9441686 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1617870896; bh=nSL5tNuJfKjRXnnv9hZZw+Oaj2IRZ6UVJpJGtmk7ZE4=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iATCpH++bWiG1xKcAmpWxgX62AV9zz+uKrTBQY4ZSYnO6Lzyc4kI2V9wvkHCTTLpT /z9zQ7azRV16AdXrJ9mb0bTyEPTAd22P7KELBcBY6aEmOKKqivtbXrRA1kL4r+5iXT 8AeCRSebqXrxhPIY4zQ990jO8xqWJGWPP6kCWHBY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D347DF80274; Thu, 8 Apr 2021 10:33:32 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CF1B0F80423; Thu, 8 Apr 2021 10:33:30 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 280DFF80274 for ; Thu, 8 Apr 2021 10:33:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 280DFF80274 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 67568B023; Thu, 8 Apr 2021 08:33:21 +0000 (UTC) Date: Thu, 08 Apr 2021 10:33:21 +0200 Message-ID: From: Takashi Iwai To: Kai Vehmanen Subject: Re: [RFC PATCH] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume In-Reply-To: References: <20210407154727.589017-1-kai.vehmanen@linux.intel.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 Cc: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Wed, 07 Apr 2021 18:40:29 +0200, Kai Vehmanen wrote: > > Hey, > > On Wed, 7 Apr 2021, Takashi Iwai wrote: > > > On Wed, 07 Apr 2021 17:47:27 +0200, Kai Vehmanen wrote: > > > > > > When snd-hda-codec-hdmi is used with ASoC HDA controller like SOF (acomp > > > used for ELD notifications), display connection change done during suspend, > > > can be lost due to following sequence of events: > > > > > > 1. system in S3 suspend > > > 2. DP/HDMI receiver connected > > > 3. system resumed > > > 4. HDA controller resumed, but card->deferred_resume_work not complete > > > 5. acomp eld_notify callback > > > 6. eld_notify ignored as power state is not CTL_POWER_D0 > > > 7. HDA resume deferred work completed, power state set to CTL_POWER_D0 > > > > > > This results in losing the notification, and the jack state reported to > > > user-space is not correct. > > > > Hrm, that's odd. The logic there is: there is a manual call of > > hdmi_present_sense() for each pin in the resume call back of HDMI > > codec driver, so at the point 7, update_eld() is invoked from > > hdmi_present_sense(), which notifies the state to user-space. > > In the bug case, the codec resume is completed in step (4). i915 is up and > running but no HDMI/DP receiver is yet found/setup at this point. So HDA > codec driver resumes and concludes no HDMI/DP receivers are available. > > A bit later, the HDMI/DP receiver is found and i915 calls eld_notify. But > as HDA controller's soc_resume_deferred() is still running, > card->power_state==D2 still at this point. patch_hdmi.c:*pin_eld_notify() > checks power_state, figures card is not in D0 and ignores the > notification. > > Then another moment later, HDA controller's deferred resume work completes > and card power state is set to D0, but at this point there are no actions > left that would trigger reprocessing the ELD nodification. > > I now changed this so that if card is in D2, that's good enough and we > process the notification in patch_hdmi.c:*pin_eld_notify(). > > > So I don't see what's missing there. Could you check whether the > > scenario above is correct? The state is updated in > > snd_hdac_acomp_get_eld() call in sync_eld_via_acomp(). We can see > > what state is returned there at which timing. > > At this point, state for the ports is still disconnected (monitor was > connected while system was in suspend). OK, that's a messy problem, indeed. It's partly because of ASoC referred resume that is completely independent from the rest resume via HD-audio bus. More badly, this can't be managed via the device link because the resume callback itself has been processed. And, IIUC, another part of the problem is that i915 notifies the HPD *after* the resume completion, right? Then indeed it can be racy. > > The only possible case I can think of now is that the graphics driver > > isn't ready for returning the right value at the HDMI codec resume. > > But this should have been covered by the device link... > > Yes, this seems to be the case. The device link seems to be honoured, > but the fact that 1) monitor/receiver is not immediately found, and 2) > ASoC core does some of the resume work in a work-queue, opens this race > still. > > Seems quite odd indeed, but I've now got reports of systems where this is > hit, and unfortunately it's very systematic on these systems. By adding > some arbitrary delay to soc_resume_deferred(), I could easily hit this > myself as well on the systems I have at hand. Judging from the above, I see no problem to merge the patch as is. It's no intrusive changes and cover practically ASoC cases (mostly). Another possible fix would be to check dev->power.power_state instead of the global card state. This is set in each PM callback in hda_codec.c to indicate the current PM state of the codec. Something like below. Let me know if this works, too. thanks, Takashi --- --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -2658,7 +2658,7 @@ static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) /* skip notification during system suspend (but not in runtime PM); * the state will be updated at resume */ - if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0) + if (codec->core.dev.power.power_state.event != PM_EVENT_ON) return; /* ditto during suspend/resume process itself */ if (snd_hdac_is_in_pm(&codec->core))