linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock
@ 2019-06-24  5:33 Christophe JAILLET
  2019-06-24  6:37 ` Nicholas Mc Guire
  2019-06-24  8:13 ` Stefan Wahren
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2019-06-24  5:33 UTC (permalink / raw)
  To: eric, stefan.wahren, gregkh, f.fainelli, rjui, sbranden,
	bcm-kernel-feedback-list, tuomas.tynkkynen, inf.braun,
	tobias.buettner, hofrat
  Cc: devel, kernel-janitors, linux-kernel, Christophe JAILLET,
	linux-rpi-kernel, linux-arm-kernel

Do not allocate memory with GFP_KERNEL when holding a spin_lock, it may
sleep. Use GFP_NOWAIT instead.

Fixes: 950fd867c635 ("staging: bcm2835-camera: Replace open-coded idr with a struct idr.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
index 16af735af5c3..438d548c6e24 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
@@ -186,7 +186,7 @@ get_msg_context(struct vchiq_mmal_instance *instance)
 	 */
 	spin_lock(&instance->context_map_lock);
 	handle = idr_alloc(&instance->context_map, msg_context,
-			   0, 0, GFP_KERNEL);
+			   0, 0, GFP_NOWAIT);
 	spin_unlock(&instance->context_map_lock);
 
 	if (handle < 0) {
-- 
2.20.1


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

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

* Re: [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock
  2019-06-24  5:33 [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock Christophe JAILLET
@ 2019-06-24  6:37 ` Nicholas Mc Guire
  2019-06-24  8:13 ` Stefan Wahren
  1 sibling, 0 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2019-06-24  6:37 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: stefan.wahren, devel, f.fainelli, sbranden, tuomas.tynkkynen,
	rjui, hofrat, kernel-janitors, linux-kernel, tobias.buettner,
	eric, bcm-kernel-feedback-list, linux-rpi-kernel, gregkh,
	inf.braun, linux-arm-kernel

On Mon, Jun 24, 2019 at 07:33:51AM +0200, Christophe JAILLET wrote:
> Do not allocate memory with GFP_KERNEL when holding a spin_lock, it may
> sleep. Use GFP_NOWAIT instead.
>

checking for this in the rest of the kernel with a cocci spatch
<snip>
virtual report

@nonatomic@
position p;
identifier var;
@@

  spin_lock(...)
  ... when != spin_unlock(...)
* var = idr_alloc@p(...,GFP_KERNEL);
  ... when != spin_unlock(...)
  spin_unlock(...);
<snip>
this seems to be the only instance of this specific problem.

> Fixes: 950fd867c635 ("staging: bcm2835-camera: Replace open-coded idr with a struct idr.")

The GFP_KERNEL actually was there befor this patch so not sure if this Fixes
ref is correct - I think the GFP_KERNEL was introduced in:
4e6bafdfb9f3 ("staging: bcm2835_camera: Use a mapping table for context field of mmal_msg_header")

> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Nicholas Mc Guire <hofrat@osadl.org>

> ---
>  drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> index 16af735af5c3..438d548c6e24 100644
> --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> +++ b/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
> @@ -186,7 +186,7 @@ get_msg_context(struct vchiq_mmal_instance *instance)
>  	 */
>  	spin_lock(&instance->context_map_lock);
>  	handle = idr_alloc(&instance->context_map, msg_context,
> -			   0, 0, GFP_KERNEL);
> +			   0, 0, GFP_NOWAIT);
>  	spin_unlock(&instance->context_map_lock);
>  
>  	if (handle < 0) {
> -- 
> 2.20.1
> 

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

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

* Re: [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock
  2019-06-24  5:33 [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock Christophe JAILLET
  2019-06-24  6:37 ` Nicholas Mc Guire
@ 2019-06-24  8:13 ` Stefan Wahren
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Wahren @ 2019-06-24  8:13 UTC (permalink / raw)
  To: Christophe JAILLET, eric, gregkh, f.fainelli, rjui, sbranden,
	bcm-kernel-feedback-list, tuomas.tynkkynen, inf.braun,
	tobias.buettner, hofrat
  Cc: devel, kernel-janitors, linux-kernel, linux-rpi-kernel,
	Dave Stevenson, linux-arm-kernel

Hi Christophe,

Am 24.06.2019 um 07:33 schrieb Christophe JAILLET:
> Do not allocate memory with GFP_KERNEL when holding a spin_lock, it may
> sleep. Use GFP_NOWAIT instead.
>
> Fixes: 950fd867c635 ("staging: bcm2835-camera: Replace open-coded idr with a struct idr.")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

there has been a fix for this, which isn't upstreamed yet. The preferred 
solution is to replace the spin_lock with a mutex. Since i'm currently 
working on this i would take care of this.

Sorry about this.

Stefan


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

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

end of thread, other threads:[~2019-06-24  8:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24  5:33 [PATCH] staging: bcm2835-camera: Avoid apotential sleep while holding a spin_lock Christophe JAILLET
2019-06-24  6:37 ` Nicholas Mc Guire
2019-06-24  8:13 ` Stefan Wahren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).