Linux-ARM-MSM Archive on lore.kernel.org
 help / color / Atom feed
* [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs
@ 2020-09-29 20:30 Evan Green
  2020-10-16 16:48 ` Stephen Boyd
  2020-10-16 17:13 ` Bjorn Andersson
  0 siblings, 2 replies; 3+ messages in thread
From: Evan Green @ 2020-09-29 20:30 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Markus Elfring, Evan Green, Andy Gross, linux-arm-msm, linux-kernel

smp2p_update_bits() should disable interrupts when it acquires its
spinlock. This is important because without the _irqsave, a priority
inversion can occur.

This function is called both with interrupts enabled in
qcom_q6v5_request_stop(), and with interrupts disabled in
ipa_smp2p_panic_notifier(). IRQ handling of spinlocks should be
consistent to avoid the panic notifier deadlocking because it's
sitting on the thread that's already got the lock via _request_stop().

Found via lockdep.

Fixes: 50e99641413e7 ("soc: qcom: smp2p: Qualcomm Shared Memory Point to Point")
Signed-off-by: Evan Green <evgreen@chromium.org>
---

 drivers/soc/qcom/smp2p.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c
index 07183d731d747..a9709aae54abb 100644
--- a/drivers/soc/qcom/smp2p.c
+++ b/drivers/soc/qcom/smp2p.c
@@ -318,15 +318,16 @@ static int qcom_smp2p_inbound_entry(struct qcom_smp2p *smp2p,
 static int smp2p_update_bits(void *data, u32 mask, u32 value)
 {
 	struct smp2p_entry *entry = data;
+	unsigned long flags;
 	u32 orig;
 	u32 val;
 
-	spin_lock(&entry->lock);
+	spin_lock_irqsave(&entry->lock, flags);
 	val = orig = readl(entry->value);
 	val &= ~mask;
 	val |= value;
 	writel(val, entry->value);
-	spin_unlock(&entry->lock);
+	spin_unlock_irqrestore(&entry->lock, flags);
 
 	if (val != orig)
 		qcom_smp2p_kick(entry->smp2p);
-- 
2.26.2


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

* Re: [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs
  2020-09-29 20:30 [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs Evan Green
@ 2020-10-16 16:48 ` Stephen Boyd
  2020-10-16 17:13 ` Bjorn Andersson
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-10-16 16:48 UTC (permalink / raw)
  To: Bjorn Andersson, Evan Green
  Cc: Markus Elfring, Evan Green, Andy Gross, linux-arm-msm, linux-kernel

Quoting Evan Green (2020-09-29 13:30:57)
> smp2p_update_bits() should disable interrupts when it acquires its
> spinlock. This is important because without the _irqsave, a priority
> inversion can occur.
> 
> This function is called both with interrupts enabled in
> qcom_q6v5_request_stop(), and with interrupts disabled in
> ipa_smp2p_panic_notifier(). IRQ handling of spinlocks should be
> consistent to avoid the panic notifier deadlocking because it's
> sitting on the thread that's already got the lock via _request_stop().
> 
> Found via lockdep.
> 
> Fixes: 50e99641413e7 ("soc: qcom: smp2p: Qualcomm Shared Memory Point to Point")
> Signed-off-by: Evan Green <evgreen@chromium.org>
> ---

Reviewed-by: Stephen Boyd <swboyd@chromium.org>

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

* Re: [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs
  2020-09-29 20:30 [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs Evan Green
  2020-10-16 16:48 ` Stephen Boyd
@ 2020-10-16 17:13 ` Bjorn Andersson
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Andersson @ 2020-10-16 17:13 UTC (permalink / raw)
  To: Evan Green; +Cc: Markus Elfring, Andy Gross, linux-arm-msm, linux-kernel

On Tue 29 Sep 15:30 CDT 2020, Evan Green wrote:

> smp2p_update_bits() should disable interrupts when it acquires its
> spinlock. This is important because without the _irqsave, a priority
> inversion can occur.
> 
> This function is called both with interrupts enabled in
> qcom_q6v5_request_stop(), and with interrupts disabled in
> ipa_smp2p_panic_notifier(). IRQ handling of spinlocks should be
> consistent to avoid the panic notifier deadlocking because it's
> sitting on the thread that's already got the lock via _request_stop().
> 
> Found via lockdep.
> 
> Fixes: 50e99641413e7 ("soc: qcom: smp2p: Qualcomm Shared Memory Point to Point")
> Signed-off-by: Evan Green <evgreen@chromium.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
> 
>  drivers/soc/qcom/smp2p.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c
> index 07183d731d747..a9709aae54abb 100644
> --- a/drivers/soc/qcom/smp2p.c
> +++ b/drivers/soc/qcom/smp2p.c
> @@ -318,15 +318,16 @@ static int qcom_smp2p_inbound_entry(struct qcom_smp2p *smp2p,
>  static int smp2p_update_bits(void *data, u32 mask, u32 value)
>  {
>  	struct smp2p_entry *entry = data;
> +	unsigned long flags;
>  	u32 orig;
>  	u32 val;
>  
> -	spin_lock(&entry->lock);
> +	spin_lock_irqsave(&entry->lock, flags);
>  	val = orig = readl(entry->value);
>  	val &= ~mask;
>  	val |= value;
>  	writel(val, entry->value);
> -	spin_unlock(&entry->lock);
> +	spin_unlock_irqrestore(&entry->lock, flags);
>  
>  	if (val != orig)
>  		qcom_smp2p_kick(entry->smp2p);
> -- 
> 2.26.2
> 

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 20:30 [RESEND PATCH] soc: qcom: smp2p: Safely acquire spinlock without IRQs Evan Green
2020-10-16 16:48 ` Stephen Boyd
2020-10-16 17:13 ` Bjorn Andersson

Linux-ARM-MSM Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-msm/0 linux-arm-msm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-msm linux-arm-msm/ https://lore.kernel.org/linux-arm-msm \
		linux-arm-msm@vger.kernel.org
	public-inbox-index linux-arm-msm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-arm-msm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git