All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe
@ 2024-04-17 18:41 Joao Paulo Goncalves
  2024-04-18  6:44 ` Jai Luthra
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Joao Paulo Goncalves @ 2024-04-17 18:41 UTC (permalink / raw)
  To: Peter Ujfalusi, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
  Cc: Joao Paulo Goncalves, Jai Luthra, alsa-devel, linux-sound,
	linux-kernel, stable

From: Joao Paulo Goncalves <joao.goncalves@toradex.com>

When using davinci-mcasp as CPU DAI with simple-card, there are some
conditions that cause simple-card to finish registering a sound card before
davinci-mcasp finishes registering all sound components. This creates a
non-working sound card from userspace with no problem indication apart
from not being able to play/record audio on a PCM stream. The issue
arises during simultaneous probe execution of both drivers. Specifically,
the simple-card driver, awaiting a CPU DAI, proceeds as soon as
davinci-mcasp registers its DAI. However, this process can lead to the
client mutex lock (client_mutex in soc-core.c) being held or davinci-mcasp
being preempted before PCM DMA registration on davinci-mcasp finishes.
This situation occurs when the probes of both drivers run concurrently.
Below is the code path for this condition. To solve the issue, defer
davinci-mcasp CPU DAI registration to the last step in the audio part of
it. This way, simple-card CPU DAI parsing will be deferred until all
audio components are registered.

Fail Code Path:

simple-card.c: probe starts
simple-card.c: simple_dai_link_of: simple_parse_node(..,cpu,..) returns EPROBE_DEFER, no CPU DAI yet
davinci-mcasp.c: probe starts
davinci-mcasp.c: devm_snd_soc_register_component() register CPU DAI
simple-card.c: probes again, finish CPU DAI parsing and call devm_snd_soc_register_card()
simple-card.c: finish probe
davinci-mcasp.c: *dma_pcm_platform_register() register PCM  DMA
davinci-mcasp.c: probe finish

Cc: stable@vger.kernel.org
Fixes: 9fbd58cf4ab0 ("ASoC: davinci-mcasp: Choose PCM driver based on configured DMA controller")
Signed-off-by: Joao Paulo Goncalves <joao.goncalves@toradex.com>
---
 sound/soc/ti/davinci-mcasp.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c
index b892d66f78470..1e760c3155213 100644
--- a/sound/soc/ti/davinci-mcasp.c
+++ b/sound/soc/ti/davinci-mcasp.c
@@ -2417,12 +2417,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 
 	mcasp_reparent_fck(pdev);
 
-	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
-					      &davinci_mcasp_dai[mcasp->op_mode], 1);
-
-	if (ret != 0)
-		goto err;
-
 	ret = davinci_mcasp_get_dma_type(mcasp);
 	switch (ret) {
 	case PCM_EDMA:
@@ -2449,6 +2443,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 		goto err;
 	}
 
+	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
+					      &davinci_mcasp_dai[mcasp->op_mode], 1);
+
+	if (ret != 0)
+		goto err;
+
 no_audio:
 	ret = davinci_mcasp_init_gpiochip(mcasp);
 	if (ret) {
-- 
2.34.1


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

* Re: [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe
  2024-04-17 18:41 [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe Joao Paulo Goncalves
@ 2024-04-18  6:44 ` Jai Luthra
  2024-04-18 17:49 ` Péter Ujfalusi
  2024-04-19 10:03 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Jai Luthra @ 2024-04-18  6:44 UTC (permalink / raw)
  To: Joao Paulo Goncalves
  Cc: Peter Ujfalusi, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Joao Paulo Goncalves, alsa-devel, linux-sound,
	linux-kernel, stable

[-- Attachment #1: Type: text/plain, Size: 3177 bytes --]

Hi Joao,

On Apr 17, 2024 at 15:41:38 -0300, Joao Paulo Goncalves wrote:
> From: Joao Paulo Goncalves <joao.goncalves@toradex.com>
> 
> When using davinci-mcasp as CPU DAI with simple-card, there are some
> conditions that cause simple-card to finish registering a sound card before
> davinci-mcasp finishes registering all sound components. This creates a
> non-working sound card from userspace with no problem indication apart
> from not being able to play/record audio on a PCM stream. The issue
> arises during simultaneous probe execution of both drivers. Specifically,
> the simple-card driver, awaiting a CPU DAI, proceeds as soon as
> davinci-mcasp registers its DAI. However, this process can lead to the
> client mutex lock (client_mutex in soc-core.c) being held or davinci-mcasp
> being preempted before PCM DMA registration on davinci-mcasp finishes.
> This situation occurs when the probes of both drivers run concurrently.
> Below is the code path for this condition. To solve the issue, defer
> davinci-mcasp CPU DAI registration to the last step in the audio part of
> it. This way, simple-card CPU DAI parsing will be deferred until all
> audio components are registered.

Good catch, thanks for the fix.

Reviewed-by: Jai Luthra <j-luthra@ti.com>

> 
> Fail Code Path:
> 
> simple-card.c: probe starts
> simple-card.c: simple_dai_link_of: simple_parse_node(..,cpu,..) returns EPROBE_DEFER, no CPU DAI yet
> davinci-mcasp.c: probe starts
> davinci-mcasp.c: devm_snd_soc_register_component() register CPU DAI
> simple-card.c: probes again, finish CPU DAI parsing and call devm_snd_soc_register_card()
> simple-card.c: finish probe
> davinci-mcasp.c: *dma_pcm_platform_register() register PCM  DMA
> davinci-mcasp.c: probe finish
> 
> Cc: stable@vger.kernel.org
> Fixes: 9fbd58cf4ab0 ("ASoC: davinci-mcasp: Choose PCM driver based on configured DMA controller")
> Signed-off-by: Joao Paulo Goncalves <joao.goncalves@toradex.com>
> ---
>  sound/soc/ti/davinci-mcasp.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c
> index b892d66f78470..1e760c3155213 100644
> --- a/sound/soc/ti/davinci-mcasp.c
> +++ b/sound/soc/ti/davinci-mcasp.c
> @@ -2417,12 +2417,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
>  
>  	mcasp_reparent_fck(pdev);
>  
> -	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
> -					      &davinci_mcasp_dai[mcasp->op_mode], 1);
> -
> -	if (ret != 0)
> -		goto err;
> -
>  	ret = davinci_mcasp_get_dma_type(mcasp);
>  	switch (ret) {
>  	case PCM_EDMA:
> @@ -2449,6 +2443,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
>  		goto err;
>  	}
>  
> +	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
> +					      &davinci_mcasp_dai[mcasp->op_mode], 1);
> +
> +	if (ret != 0)
> +		goto err;
> +
>  no_audio:
>  	ret = davinci_mcasp_init_gpiochip(mcasp);
>  	if (ret) {
> -- 
> 2.34.1
> 

-- 
Thanks,
Jai

GPG Fingerprint: 4DE0 D818 E5D5 75E8 D45A AFC5 43DE 91F9 249A 7145

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe
  2024-04-17 18:41 [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe Joao Paulo Goncalves
  2024-04-18  6:44 ` Jai Luthra
@ 2024-04-18 17:49 ` Péter Ujfalusi
  2024-04-19 10:03 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Péter Ujfalusi @ 2024-04-18 17:49 UTC (permalink / raw)
  To: Joao Paulo Goncalves, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai
  Cc: Joao Paulo Goncalves, Jai Luthra, alsa-devel, linux-sound,
	linux-kernel, stable



On 17/04/2024 21:41, Joao Paulo Goncalves wrote:
> From: Joao Paulo Goncalves <joao.goncalves@toradex.com>
> 
> When using davinci-mcasp as CPU DAI with simple-card, there are some
> conditions that cause simple-card to finish registering a sound card before
> davinci-mcasp finishes registering all sound components. This creates a
> non-working sound card from userspace with no problem indication apart
> from not being able to play/record audio on a PCM stream. The issue
> arises during simultaneous probe execution of both drivers. Specifically,
> the simple-card driver, awaiting a CPU DAI, proceeds as soon as
> davinci-mcasp registers its DAI. However, this process can lead to the
> client mutex lock (client_mutex in soc-core.c) being held or davinci-mcasp
> being preempted before PCM DMA registration on davinci-mcasp finishes.
> This situation occurs when the probes of both drivers run concurrently.
> Below is the code path for this condition. To solve the issue, defer
> davinci-mcasp CPU DAI registration to the last step in the audio part of
> it. This way, simple-card CPU DAI parsing will be deferred until all
> audio components are registered.
> 
> Fail Code Path:
> 
> simple-card.c: probe starts
> simple-card.c: simple_dai_link_of: simple_parse_node(..,cpu,..) returns EPROBE_DEFER, no CPU DAI yet
> davinci-mcasp.c: probe starts
> davinci-mcasp.c: devm_snd_soc_register_component() register CPU DAI
> simple-card.c: probes again, finish CPU DAI parsing and call devm_snd_soc_register_card()
> simple-card.c: finish probe
> davinci-mcasp.c: *dma_pcm_platform_register() register PCM  DMA
> davinci-mcasp.c: probe finish

Interesting... Thanks for the details.
Acked-by: Peter Ujfalusi <peter.ujfalusi@gmail.com>

> 
> Cc: stable@vger.kernel.org
> Fixes: 9fbd58cf4ab0 ("ASoC: davinci-mcasp: Choose PCM driver based on configured DMA controller")

Just to note that the DAI registration was always before the platform
registration (ever since the DAI driver started to register the
platform) and I think most TI (and probably other vendor's) driver does
things this way. McASP does a bit of lifting by requesting a DMA channel
to figure out the type of DMA...

> Signed-off-by: Joao Paulo Goncalves <joao.goncalves@toradex.com>
> ---
>  sound/soc/ti/davinci-mcasp.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/sound/soc/ti/davinci-mcasp.c b/sound/soc/ti/davinci-mcasp.c
> index b892d66f78470..1e760c3155213 100644
> --- a/sound/soc/ti/davinci-mcasp.c
> +++ b/sound/soc/ti/davinci-mcasp.c
> @@ -2417,12 +2417,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
>  
>  	mcasp_reparent_fck(pdev);
>  
> -	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
> -					      &davinci_mcasp_dai[mcasp->op_mode], 1);
> -
> -	if (ret != 0)
> -		goto err;
> -
>  	ret = davinci_mcasp_get_dma_type(mcasp);
>  	switch (ret) {
>  	case PCM_EDMA:
> @@ -2449,6 +2443,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
>  		goto err;
>  	}
>  
> +	ret = devm_snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
> +					      &davinci_mcasp_dai[mcasp->op_mode], 1);
> +
> +	if (ret != 0)
> +		goto err;
> +
>  no_audio:
>  	ret = davinci_mcasp_init_gpiochip(mcasp);
>  	if (ret) {

-- 
Péter

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

* Re: [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe
  2024-04-17 18:41 [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe Joao Paulo Goncalves
  2024-04-18  6:44 ` Jai Luthra
  2024-04-18 17:49 ` Péter Ujfalusi
@ 2024-04-19 10:03 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2024-04-19 10:03 UTC (permalink / raw)
  To: Peter Ujfalusi, Liam Girdwood, Jaroslav Kysela, Takashi Iwai,
	Joao Paulo Goncalves
  Cc: Joao Paulo Goncalves, Jai Luthra, alsa-devel, linux-sound,
	linux-kernel, stable

On Wed, 17 Apr 2024 15:41:38 -0300, Joao Paulo Goncalves wrote:
> When using davinci-mcasp as CPU DAI with simple-card, there are some
> conditions that cause simple-card to finish registering a sound card before
> davinci-mcasp finishes registering all sound components. This creates a
> non-working sound card from userspace with no problem indication apart
> from not being able to play/record audio on a PCM stream. The issue
> arises during simultaneous probe execution of both drivers. Specifically,
> the simple-card driver, awaiting a CPU DAI, proceeds as soon as
> davinci-mcasp registers its DAI. However, this process can lead to the
> client mutex lock (client_mutex in soc-core.c) being held or davinci-mcasp
> being preempted before PCM DMA registration on davinci-mcasp finishes.
> This situation occurs when the probes of both drivers run concurrently.
> Below is the code path for this condition. To solve the issue, defer
> davinci-mcasp CPU DAI registration to the last step in the audio part of
> it. This way, simple-card CPU DAI parsing will be deferred until all
> audio components are registered.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: ti: davinci-mcasp: Fix race condition during probe
      commit: d18ca8635db2f88c17acbdf6412f26d4f6aff414

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


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

end of thread, other threads:[~2024-04-19 10:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 18:41 [PATCH] ASoC: ti: davinci-mcasp: Fix race condition during probe Joao Paulo Goncalves
2024-04-18  6:44 ` Jai Luthra
2024-04-18 17:49 ` Péter Ujfalusi
2024-04-19 10:03 ` Mark Brown

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.