diff mbox series

[net-next] net: wwan: mhi_wwan_ctrl: Fix possible deadlock

Message ID 1628246109-27425-1-git-send-email-loic.poulain@linaro.org (mailing list archive)
State Accepted
Commit 34737e1320db6d51f0d140d5c684b9eb32f0da76
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: wwan: mhi_wwan_ctrl: Fix possible deadlock | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: johannes@sipsolutions.net
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 43 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Loic Poulain Aug. 6, 2021, 10:35 a.m. UTC
Lockdep detected possible interrupt unsafe locking scenario:

        CPU0                    CPU1
        ----                    ----
   lock(&mhiwwan->rx_lock);
                               local_irq_disable();
                               lock(&mhi_cntrl->pm_lock);
                               lock(&mhiwwan->rx_lock);
   <Interrupt>
     lock(&mhi_cntrl->pm_lock);

  *** DEADLOCK ***

To prevent this we need to disable the soft-interrupts when taking
the rx_lock.

Cc: stable@vger.kernel.org
Fixes: fa588eba632d ("net: Add Qcom WWAN control driver")
Reported-by: Thomas Perrot <thomas.perrot@bootlin.com>
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
---
 drivers/net/wwan/mhi_wwan_ctrl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Sergey Ryazanov Aug. 6, 2021, 10:38 a.m. UTC | #1
On Fri, Aug 6, 2021 at 1:24 PM Loic Poulain <loic.poulain@linaro.org> wrote:
> Lockdep detected possible interrupt unsafe locking scenario:
>
>         CPU0                    CPU1
>         ----                    ----
>    lock(&mhiwwan->rx_lock);
>                                local_irq_disable();
>                                lock(&mhi_cntrl->pm_lock);
>                                lock(&mhiwwan->rx_lock);
>    <Interrupt>
>      lock(&mhi_cntrl->pm_lock);
>
>   *** DEADLOCK ***
>
> To prevent this we need to disable the soft-interrupts when taking
> the rx_lock.
>
> Cc: stable@vger.kernel.org
> Fixes: fa588eba632d ("net: Add Qcom WWAN control driver")
> Reported-by: Thomas Perrot <thomas.perrot@bootlin.com>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

Reviewed-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Jakub Kicinski Aug. 6, 2021, 10:47 p.m. UTC | #2
On Fri,  6 Aug 2021 12:35:09 +0200 Loic Poulain wrote:
> Lockdep detected possible interrupt unsafe locking scenario:
> 
>         CPU0                    CPU1
>         ----                    ----
>    lock(&mhiwwan->rx_lock);
>                                local_irq_disable();
>                                lock(&mhi_cntrl->pm_lock);
>                                lock(&mhiwwan->rx_lock);
>    <Interrupt>
>      lock(&mhi_cntrl->pm_lock);
> 
>   *** DEADLOCK ***
> 
> To prevent this we need to disable the soft-interrupts when taking
> the rx_lock.
> 
> Cc: stable@vger.kernel.org
> Fixes: fa588eba632d ("net: Add Qcom WWAN control driver")
> Reported-by: Thomas Perrot <thomas.perrot@bootlin.com>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

This is for net, right? Despite it's subject annotation?
patchwork-bot+netdevbpf@kernel.org Aug. 7, 2021, 8:40 a.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Fri,  6 Aug 2021 12:35:09 +0200 you wrote:
> Lockdep detected possible interrupt unsafe locking scenario:
> 
>         CPU0                    CPU1
>         ----                    ----
>    lock(&mhiwwan->rx_lock);
>                                local_irq_disable();
>                                lock(&mhi_cntrl->pm_lock);
>                                lock(&mhiwwan->rx_lock);
>    <Interrupt>
>      lock(&mhi_cntrl->pm_lock);
> 
> [...]

Here is the summary with links:
  - [net-next] net: wwan: mhi_wwan_ctrl: Fix possible deadlock
    https://git.kernel.org/netdev/net/c/34737e1320db

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/wwan/mhi_wwan_ctrl.c b/drivers/net/wwan/mhi_wwan_ctrl.c
index 1e18420..d0a98f3 100644
--- a/drivers/net/wwan/mhi_wwan_ctrl.c
+++ b/drivers/net/wwan/mhi_wwan_ctrl.c
@@ -41,14 +41,14 @@  struct mhi_wwan_dev {
 /* Increment RX budget and schedule RX refill if necessary */
 static void mhi_wwan_rx_budget_inc(struct mhi_wwan_dev *mhiwwan)
 {
-	spin_lock(&mhiwwan->rx_lock);
+	spin_lock_bh(&mhiwwan->rx_lock);
 
 	mhiwwan->rx_budget++;
 
 	if (test_bit(MHI_WWAN_RX_REFILL, &mhiwwan->flags))
 		schedule_work(&mhiwwan->rx_refill);
 
-	spin_unlock(&mhiwwan->rx_lock);
+	spin_unlock_bh(&mhiwwan->rx_lock);
 }
 
 /* Decrement RX budget if non-zero and return true on success */
@@ -56,7 +56,7 @@  static bool mhi_wwan_rx_budget_dec(struct mhi_wwan_dev *mhiwwan)
 {
 	bool ret = false;
 
-	spin_lock(&mhiwwan->rx_lock);
+	spin_lock_bh(&mhiwwan->rx_lock);
 
 	if (mhiwwan->rx_budget) {
 		mhiwwan->rx_budget--;
@@ -64,7 +64,7 @@  static bool mhi_wwan_rx_budget_dec(struct mhi_wwan_dev *mhiwwan)
 			ret = true;
 	}
 
-	spin_unlock(&mhiwwan->rx_lock);
+	spin_unlock_bh(&mhiwwan->rx_lock);
 
 	return ret;
 }
@@ -130,9 +130,9 @@  static void mhi_wwan_ctrl_stop(struct wwan_port *port)
 {
 	struct mhi_wwan_dev *mhiwwan = wwan_port_get_drvdata(port);
 
-	spin_lock(&mhiwwan->rx_lock);
+	spin_lock_bh(&mhiwwan->rx_lock);
 	clear_bit(MHI_WWAN_RX_REFILL, &mhiwwan->flags);
-	spin_unlock(&mhiwwan->rx_lock);
+	spin_unlock_bh(&mhiwwan->rx_lock);
 
 	cancel_work_sync(&mhiwwan->rx_refill);