All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume
@ 2021-04-16 13:11 Kai Vehmanen
  2021-04-16 14:03 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Vehmanen @ 2021-04-16 13:11 UTC (permalink / raw)
  To: alsa-devel, tiwai; +Cc: pierre-louis.bossart, kai.vehmanen

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.

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 use "dev.power.power_state.event"
instead of ALSA specific card power state variable.

BugLink: https://github.com/thesofproject/linux/issues/2825
Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
---
 sound/pci/hda/patch_hdmi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Changes for V2:
 - use codec->core.dev.power.power_state.event instead of card state
 - verified on multiple systems and confirmed that checking for
   PM_EVENT_ON is not sufficient -- when resuming from S3, 
   state can be PM_EVENT_RESUME at eld_notify, and if notification is 
   ignored in this case, the original bugis hit (monitor state upon resume
   is lost)

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 5de3666a7101..4b2cc8cb55c4 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 (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
 		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 (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
 		return;
 	/* ditto during suspend/resume process itself */
 	if (snd_hdac_is_in_pm(&codec->core))

base-commit: 1867068c322ea7a627fde8d947a9e40db32816a4
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume
  2021-04-16 13:11 [PATCH v2] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume Kai Vehmanen
@ 2021-04-16 14:03 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2021-04-16 14:03 UTC (permalink / raw)
  To: Kai Vehmanen; +Cc: alsa-devel, pierre-louis.bossart

On Fri, 16 Apr 2021 15:11:57 +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.
> 
> 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 use "dev.power.power_state.event"
> instead of ALSA specific card power state variable.
> 
> BugLink: https://github.com/thesofproject/linux/issues/2825
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>

Thanks, applied now.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-16 14:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 13:11 [PATCH v2] ALSA: hda/hdmi: fix race in handling acomp ELD notification at resume Kai Vehmanen
2021-04-16 14:03 ` Takashi Iwai

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.