Skip to content

Commit

Permalink
net: wwan: mhi_wwan_ctrl: Fix possible deadlock
Browse files Browse the repository at this point in the history
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: fa588eb ("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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Loic Poulain authored and David S. Miller committed Aug 7, 2021
1 parent 47fac45 commit 34737e1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/net/wwan/mhi_wwan_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ 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 */
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--;
if (test_bit(MHI_WWAN_RX_REFILL, &mhiwwan->flags))
ret = true;
}

spin_unlock(&mhiwwan->rx_lock);
spin_unlock_bh(&mhiwwan->rx_lock);

return ret;
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 34737e1

Please sign in to comment.