Skip to content

ASoC: rt5682: Fix deadlock on resume - #3390

Closed
ujfalusi wants to merge 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/rt5682_locking_fix_01
Closed

ujfalusi wants to merge 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/rt5682_locking_fix_01

Conversation

@ujfalusi

Copy link
Copy Markdown
Collaborator

On resume from suspend the following chain of events can happen:
A rt5682_resume() -> mod_delayed_work() for jack_detect_work
B DAPM sequence starts ( DAPM is locked now)

A1. rt5682_jack_detect_handler() scheduled

  • Takes both jdet_mutex and calibrate_mutex
  • Calls in to rt5682_headset_detect() which tries to take DAPM lock, it
    starts to wait for it as B path took it already.
    B1. DAPM sequence reaches the "HP Amp", rt5682_hp_event() tries to take
    the jdet_mutex, but it is locked in A1, so it waits.

Deadlock.

In order to solve the lock while keeping similar level of protection we
need to drop the jdet_mutex and the jd_check_work altogether and widen the
DAPM lock to rt5682_jack_detect_handler().

The jd_check_work was used to check for jack removal as presumably the
codec is not generating interrupt for that event.
We can do the same thing with the jack_detect_work and report the jack only
if it is changed.

Fixes: 8deb34a ("ASoC: rt5682: fix the wrong jack type detected")

Signed-off-by: Peter Ujfalusi peter.ujfalusi@linux.intel.com

@ujfalusi
ujfalusi force-pushed the peter/sof/pr/rt5682_locking_fix_01 branch 2 times, most recently from 7aa43e9 to 18c0903 Compare January 24, 2022 10:32
This reverts commit 8deb34a.

On resume from suspend the following chain of events can happen:
A rt5682_resume() -> mod_delayed_work() for jack_detect_work
B DAPM sequence starts ( DAPM is locked now)

A1. rt5682_jack_detect_handler() scheduled
 - Takes both jdet_mutex and calibrate_mutex
 - Calls in to rt5682_headset_detect() which tries to take DAPM lock, it
   starts to wait for it as B path took it already.
B1. DAPM sequence reaches the "HP Amp", rt5682_hp_event() tries to take
    the jdet_mutex, but it is locked in A1, so it waits.

Deadlock.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi ujfalusi closed this Jan 25, 2022
@ujfalusi
ujfalusi deleted the peter/sof/pr/rt5682_locking_fix_01 branch November 18, 2022 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant