All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Cc: alsa-devel@alsa-project.org, pierre-louis.bossart@linux.intel.com
Subject: Re: [RFC PATCH] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume
Date: Wed, 07 Apr 2021 18:10:31 +0200	[thread overview]
Message-ID: <s5hr1jm8494.wl-tiwai@suse.de> (raw)
In-Reply-To: <20210407154727.589017-1-kai.vehmanen@linux.intel.com>

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.

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.

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...


thanks,

Takashi

> The check on step 6 was added in commit 8ae743e82f0b ("ALSA: hda - Skip
> ELD notification during system suspend"). It would seem with the deferred
> resume logic in ASoC core, this check is not safe.
> 
> Fix the issue by modifying the check to only skip ELD notification
> processing if power state is D3 or deeper. This helps in the ASoC
> controller case as card power state is set to D2 at start of
> soc_resume_deferred().
> 
> BugLink: https://github.com/thesofproject/linux/issues/2825
> Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
> ---
>  sound/pci/hda/patch_hdmi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> NOTES:
>  - I wonder if there is a better way to check for system suspend
>    case than looking at snd_power_get_state()
>  - 'chip->pm_prepared' is one option, but this is not directly available
>    to codec drivers
>  - storing PM target is hda_codec_pm_prepare() is perhaps one option
> 
> diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
> index 5de3666a7101..a43df036db1d 100644
> --- a/sound/pci/hda/patch_hdmi.c
> +++ b/sound/pci/hda/patch_hdmi.c
> @@ -2654,7 +2654,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 (snd_power_get_state(codec->card) >= SNDRV_CTL_POWER_D3)
>  		return;
>  	/* ditto during suspend/resume process itself */
>  	if (snd_hdac_is_in_pm(&codec->core))
> @@ -2840,7 +2840,7 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
>  	/* 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 (snd_power_get_state(codec->card) >= SNDRV_CTL_POWER_D3)
>  		return;
>  	/* ditto during suspend/resume process itself */
>  	if (snd_hdac_is_in_pm(&codec->core))
> 
> base-commit: 7dc53a38e4ac00d68943bab91deadc67f07d4a0b
> -- 
> 2.31.0
> 

  reply	other threads:[~2021-04-07 16:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 15:47 [RFC PATCH] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume Kai Vehmanen
2021-04-07 16:10 ` Takashi Iwai [this message]
2021-04-07 16:40   ` Kai Vehmanen
2021-04-08  8:33     ` Takashi Iwai
2021-04-08 10:49       ` Kai Vehmanen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hr1jm8494.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.