All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	Mark Brown <broonie@kernel.org>,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [alsa-devel] [PATCH] ASoC: atmel_ssc_dai: Remove wrong spinlock usage
Date: Wed, 18 Sep 2019 11:48:00 +0200	[thread overview]
Message-ID: <20190918094800.GJ21254@piout.net> (raw)
In-Reply-To: <20190918094114.15867-1-gregory.clement@bootlin.com>

On 18/09/2019 11:41:14+0200, Gregory CLEMENT wrote:
> A potential bug was reported in the email "[BUG] atmel_ssc_dai: a
> possible sleep-in-atomic bug in atmel_ssc_shutdown"[1]
> 
> Indeed in the function atmel_ssc_shutdown() free_irq() was called in a
> critical section protected by spinlock.
> 
> However this spinlock is only used in atmel_ssc_shutdown() and
> atmel_ssc_startup() functions. After further analysis, it occurred that
> the call to these function are already protected by mutex used on the
> calling functions.
> 
> Then we can remove the spinlock which will fix this bug as a side
> effect. Thanks to this patch the following message disappears:
> 
> "BUG: sleeping function called from invalid context at
> kernel/locking/mutex.c:909"
> 
> [1]: https://www.spinics.net/lists/alsa-devel/msg71286.html
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
> ---
>  sound/soc/atmel/atmel_ssc_dai.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
> index 6f89483ac88c..365957e86419 100644
> --- a/sound/soc/atmel/atmel_ssc_dai.c
> +++ b/sound/soc/atmel/atmel_ssc_dai.c
> @@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
>  static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
>  	{
>  	.name		= "ssc0",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),

This member is now unused and can be removed from the struct.

Once fixed, Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc1",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc2",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
> @@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
>  
>  	snd_soc_dai_set_dma_data(dai, substream, dma_params);
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	if (ssc_p->dir_mask & dir_mask) {
>  		spin_unlock_irq(&ssc_p->lock);
>  		return -EBUSY;
>  	}
>  	ssc_p->dir_mask |= dir_mask;
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	return 0;
>  }
> @@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  
>  	dir_mask = 1 << dir;
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	ssc_p->dir_mask &= ~dir_mask;
>  	if (!ssc_p->dir_mask) {
>  		if (ssc_p->initialized) {
> @@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  		ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
>  		ssc_p->forced_divider = 0;
>  	}
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	/* Shutdown the SSC clock. */
>  	pr_debug("atmel_ssc_dai: Stopping clock\n");
> -- 
> 2.23.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Liam Girdwood <lgirdwood@gmail.com>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	Mark Brown <broonie@kernel.org>,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] ASoC: atmel_ssc_dai: Remove wrong spinlock usage
Date: Wed, 18 Sep 2019 11:48:00 +0200	[thread overview]
Message-ID: <20190918094800.GJ21254@piout.net> (raw)
In-Reply-To: <20190918094114.15867-1-gregory.clement@bootlin.com>

On 18/09/2019 11:41:14+0200, Gregory CLEMENT wrote:
> A potential bug was reported in the email "[BUG] atmel_ssc_dai: a
> possible sleep-in-atomic bug in atmel_ssc_shutdown"[1]
> 
> Indeed in the function atmel_ssc_shutdown() free_irq() was called in a
> critical section protected by spinlock.
> 
> However this spinlock is only used in atmel_ssc_shutdown() and
> atmel_ssc_startup() functions. After further analysis, it occurred that
> the call to these function are already protected by mutex used on the
> calling functions.
> 
> Then we can remove the spinlock which will fix this bug as a side
> effect. Thanks to this patch the following message disappears:
> 
> "BUG: sleeping function called from invalid context at
> kernel/locking/mutex.c:909"
> 
> [1]: https://www.spinics.net/lists/alsa-devel/msg71286.html
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
> ---
>  sound/soc/atmel/atmel_ssc_dai.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
> index 6f89483ac88c..365957e86419 100644
> --- a/sound/soc/atmel/atmel_ssc_dai.c
> +++ b/sound/soc/atmel/atmel_ssc_dai.c
> @@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
>  static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
>  	{
>  	.name		= "ssc0",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),

This member is now unused and can be removed from the struct.

Once fixed, Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc1",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc2",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
> @@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
>  
>  	snd_soc_dai_set_dma_data(dai, substream, dma_params);
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	if (ssc_p->dir_mask & dir_mask) {
>  		spin_unlock_irq(&ssc_p->lock);
>  		return -EBUSY;
>  	}
>  	ssc_p->dir_mask |= dir_mask;
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	return 0;
>  }
> @@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  
>  	dir_mask = 1 << dir;
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	ssc_p->dir_mask &= ~dir_mask;
>  	if (!ssc_p->dir_mask) {
>  		if (ssc_p->initialized) {
> @@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  		ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
>  		ssc_p->forced_divider = 0;
>  	}
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	/* Shutdown the SSC clock. */
>  	pr_debug("atmel_ssc_dai: Stopping clock\n");
> -- 
> 2.23.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] ASoC: atmel_ssc_dai: Remove wrong spinlock usage
Date: Wed, 18 Sep 2019 11:48:00 +0200	[thread overview]
Message-ID: <20190918094800.GJ21254@piout.net> (raw)
In-Reply-To: <20190918094114.15867-1-gregory.clement@bootlin.com>

On 18/09/2019 11:41:14+0200, Gregory CLEMENT wrote:
> A potential bug was reported in the email "[BUG] atmel_ssc_dai: a
> possible sleep-in-atomic bug in atmel_ssc_shutdown"[1]
> 
> Indeed in the function atmel_ssc_shutdown() free_irq() was called in a
> critical section protected by spinlock.
> 
> However this spinlock is only used in atmel_ssc_shutdown() and
> atmel_ssc_startup() functions. After further analysis, it occurred that
> the call to these function are already protected by mutex used on the
> calling functions.
> 
> Then we can remove the spinlock which will fix this bug as a side
> effect. Thanks to this patch the following message disappears:
> 
> "BUG: sleeping function called from invalid context at
> kernel/locking/mutex.c:909"
> 
> [1]: https://www.spinics.net/lists/alsa-devel/msg71286.html
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
> ---
>  sound/soc/atmel/atmel_ssc_dai.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
> index 6f89483ac88c..365957e86419 100644
> --- a/sound/soc/atmel/atmel_ssc_dai.c
> +++ b/sound/soc/atmel/atmel_ssc_dai.c
> @@ -116,19 +116,16 @@ static struct atmel_pcm_dma_params ssc_dma_params[NUM_SSC_DEVICES][2] = {
>  static struct atmel_ssc_info ssc_info[NUM_SSC_DEVICES] = {
>  	{
>  	.name		= "ssc0",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[0].lock),

This member is now unused and can be removed from the struct.

Once fixed, Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc1",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[1].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
>  	{
>  	.name		= "ssc2",
> -	.lock		= __SPIN_LOCK_UNLOCKED(ssc_info[2].lock),
>  	.dir_mask	= SSC_DIR_MASK_UNUSED,
>  	.initialized	= 0,
>  	},
> @@ -317,13 +314,11 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
>  
>  	snd_soc_dai_set_dma_data(dai, substream, dma_params);
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	if (ssc_p->dir_mask & dir_mask) {
>  		spin_unlock_irq(&ssc_p->lock);
>  		return -EBUSY;
>  	}
>  	ssc_p->dir_mask |= dir_mask;
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	return 0;
>  }
> @@ -355,7 +350,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  
>  	dir_mask = 1 << dir;
>  
> -	spin_lock_irq(&ssc_p->lock);
>  	ssc_p->dir_mask &= ~dir_mask;
>  	if (!ssc_p->dir_mask) {
>  		if (ssc_p->initialized) {
> @@ -369,7 +363,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
>  		ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
>  		ssc_p->forced_divider = 0;
>  	}
> -	spin_unlock_irq(&ssc_p->lock);
>  
>  	/* Shutdown the SSC clock. */
>  	pr_debug("atmel_ssc_dai: Stopping clock\n");
> -- 
> 2.23.0
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2019-09-18  9:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18  9:41 [alsa-devel] [PATCH] ASoC: atmel_ssc_dai: Remove wrong spinlock usage Gregory CLEMENT
2019-09-18  9:41 ` Gregory CLEMENT
2019-09-18  9:41 ` Gregory CLEMENT
2019-09-18  9:48 ` Alexandre Belloni [this message]
2019-09-18  9:48   ` Alexandre Belloni
2019-09-18  9:48   ` Alexandre Belloni
2019-09-18  9:59   ` [alsa-devel] " Gregory CLEMENT
2019-09-18  9:59     ` Gregory CLEMENT
2019-09-18  9:59     ` Gregory CLEMENT

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=20190918094800.GJ21254@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=codrin.ciubotariu@microchip.com \
    --cc=gregory.clement@bootlin.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=nicolas.ferre@microchip.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.