diff mbox

[v2] spi: fix possible deadlock between internal bus locks and bus_lock_flag

Message ID 1603558.KZbpLAQA15@diego (mailing list archive)
State New, archived
Headers show

Commit Message

Heiko Stuebner March 18, 2016, 10:15 a.m. UTC
External users may use spi_bus_lock to get exclusive access. This will
also grab the bus_lock_mutex and may therefore result in a deadlock if
__spi_pump_messages also tries to get the mutex.

Therefore adapt spi_pump_messages as well as spi_sync to preset the
bus_locked parameter according to the master->bus_lock_flag.

Fixes: 49023d2e4ead ("spi: core: Fix deadlock when sending messages")
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
changes in v2:
- move the second check from __spi_pump_messages to its calling functions
  spi_pump_messages and __spi_sync as suggested by Vignesh

 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jon Hunter March 18, 2016, 10:40 a.m. UTC | #1
On 18/03/16 10:15, Heiko Stübner wrote:
> External users may use spi_bus_lock to get exclusive access. This will
> also grab the bus_lock_mutex and may therefore result in a deadlock if
> __spi_pump_messages also tries to get the mutex.
> 
> Therefore adapt spi_pump_messages as well as spi_sync to preset the
> bus_locked parameter according to the master->bus_lock_flag.
> 
> Fixes: 49023d2e4ead ("spi: core: Fix deadlock when sending messages")
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
> changes in v2:
> - move the second check from __spi_pump_messages to its calling functions
>   spi_pump_messages and __spi_sync as suggested by Vignesh
> 
>  drivers/spi/spi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index de2f2f9..0239b45 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1209,7 +1209,7 @@ static void spi_pump_messages(struct kthread_work *work)
>  	struct spi_master *master =
>  		container_of(work, struct spi_master, pump_messages);
>  
> -	__spi_pump_messages(master, true, false);
> +	__spi_pump_messages(master, true, master->bus_lock_flag);
>  }
>  
>  static int spi_init_queue(struct spi_master *master)
> @@ -2853,7 +2853,7 @@ static int __spi_sync(struct spi_device *spi, struct spi_message *message,
>   */
>  int spi_sync(struct spi_device *spi, struct spi_message *message)
>  {
> -	return __spi_sync(spi, message, 0);
> +	return __spi_sync(spi, message, spi->master->bus_lock_flag);
>  }
>  EXPORT_SYMBOL_GPL(spi_sync);

Acked-by: Jon Hunter <jonathanh@nvidia.com>

Thanks for the report and fixing this!

Jon
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
Kevin Hilman March 18, 2016, 4:22 p.m. UTC | #2
Heiko Stübner <heiko@sntech.de> writes:

> External users may use spi_bus_lock to get exclusive access. This will
> also grab the bus_lock_mutex and may therefore result in a deadlock if
> __spi_pump_messages also tries to get the mutex.
>
> Therefore adapt spi_pump_messages as well as spi_sync to preset the
> bus_locked parameter according to the master->bus_lock_flag.
>
> Fixes: 49023d2e4ead ("spi: core: Fix deadlock when sending messages")
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>

Tested on rk3288-veyron-jerry and verified that it fixes the boot
failure I reported.

Tested-by: Kevin Hilman <khilman@baylibre.com>

Kevin
diff mbox

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index de2f2f9..0239b45 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1209,7 +1209,7 @@  static void spi_pump_messages(struct kthread_work *work)
 	struct spi_master *master =
 		container_of(work, struct spi_master, pump_messages);
 
-	__spi_pump_messages(master, true, false);
+	__spi_pump_messages(master, true, master->bus_lock_flag);
 }
 
 static int spi_init_queue(struct spi_master *master)
@@ -2853,7 +2853,7 @@  static int __spi_sync(struct spi_device *spi, struct spi_message *message,
  */
 int spi_sync(struct spi_device *spi, struct spi_message *message)
 {
-	return __spi_sync(spi, message, 0);
+	return __spi_sync(spi, message, spi->master->bus_lock_flag);
 }
 EXPORT_SYMBOL_GPL(spi_sync);