From: Cezary Rojewski <cezary.rojewski@intel.com>
To: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
Takashi Iwai <tiwai@suse.com>, Mark Brown <broonie@kernel.org>,
Jaroslav Kysela <perex@perex.cz>
Cc: "Kai Vehmanen" <kai.vehmanen@linux.intel.com>,
"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ranjani Sridharan" <ranjani.sridharan@linux.intel.com>,
"Amadeusz Sławiński" <amadeuszx.slawinski@linux.intel.com>,
"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
Subject: Re: Question regarding delayed trigger in dpcm_set_fe_update_state()
Date: Thu, 27 Oct 2022 10:23:54 +0200 [thread overview]
Message-ID: <d1cfd094-0bf3-da6f-655b-863133df570c@intel.com> (raw)
In-Reply-To: <73e6425f-8e51-e26f-ad83-ccc5df517a43@intel.com>
On 2022-10-12 4:07 PM, Cezary Rojewski wrote:
> Hello,
>
> Writing with question regarding dpcm_set_fe_update_state() function
> which is part of sound/soc/soc-pcm.c file and has been introduced with
> commit "ASoC: dpcm: Fix race between FE/BE updates and trigger" [1].
>
> The part that concerns me is the invocation of dpcm_fe_dai_do_trigger()
> regardless of the actual state given DPCM is in (actual state, not the
> DPCM_UPDATE_XX). The conditional invocation of said _trigger() and
> addition of .trigger_pending field are here to address a race where PCM
> state is being modified from multiple locations simultaneously, at least
> judging by the commit's description.
>
> Note that the dpcm_set_fe_update_state() is called from all the dai-ops
> i.e.: startup, shutdown, hw_params, prepare and hw_free.
> Now, given that knowledge, we could end up in scenario where
> dpcm_fe_dai_do_trigger() is invoked as a part of dpcm_fe_dai_hw_free().
> dpcm_set_fe_update_state() is called there twice, once with
> DPCM_UPDATE_FE and once with DPCM_UPDATE_NO. The second case is the more
> interesting one since it's called **after** ->hw_free() callback is
> invoked for all the DAIs.
>
> dpcm_fe_dai_hw_free()
> dpcm_set_fe_update_state(DPCM_UPDATE_FE) // fine
> (...)
> dpcm_be_dai_hw_free() // data allocated in hw_params
> // is freed here
> (...)
> dpcm_set_fe_update_state(DPCM_UPDATE_NO) // not fine
>
>
> The last is *not fine* if the .trigger_pending is not a zero, and can
> lead to panic as code used during ->trigger() is often manipulating data
> allocated during ->hw_params() but that data has just been freed with
> ->hw_free().
>
> Is what I'm looking at a bug? Or, perhaps there's something I'm missing
> in the picture. From my study, it seems that only dpcm_fe_dai_prepare()
> is a safe place for calling dpcm_fe_dai_do_trigger() - once
> .trigger_pending is taken into account. Any input is much appreciated.
Given no responses, perhaps there's something in my message to be improved?
next prev parent reply other threads:[~2022-10-27 8:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-12 14:07 Question regarding delayed trigger in dpcm_set_fe_update_state() Cezary Rojewski
2022-10-27 8:23 ` Cezary Rojewski [this message]
2022-10-28 13:38 ` Takashi Iwai
2022-11-07 9:44 ` Cezary Rojewski
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=d1cfd094-0bf3-da6f-655b-863133df570c@intel.com \
--to=cezary.rojewski@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=amadeuszx.slawinski@linux.intel.com \
--cc=broonie@kernel.org \
--cc=hdegoede@redhat.com \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=perex@perex.cz \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=ranjani.sridharan@linux.intel.com \
--cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox