From patchwork Fri Aug 6 10:35:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 492822 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp169252jap; Fri, 6 Aug 2021 03:24:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziVfuYbkcJiGvIvD5DHHg5ocZwsPQGrU4pimjmkPC4R6mFsPUMgAhfrSz09zM7mLqtVplt X-Received: by 2002:a05:6402:408:: with SMTP id q8mr12045884edv.13.1628245499414; Fri, 06 Aug 2021 03:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628245499; cv=none; d=google.com; s=arc-20160816; b=od3ObEWx25/g/TC1AllPSIjras3IYK9bpZxQWZhF1bLBxUwKp29KAXaJagNbIO6nzg QrnAl1sWbwB7GQtqGmLuBaXkbKs88z5huHwitDcBItD0ms4ci6dYSFmyzQ5sIt4zR1tL OH2nJSMDK8G3Xh5nFfVbjk0MFfaeYt8A8W8wwItSzfybhVhFbhu47rFrv9nzdTx6hiIW D703QA6wiqzLibUM/HRVHGAXuwbrSBD/id+H3Ku5MbmknctVVQ2chSGxJywMjxilcWuB OVg2cGCTq/E8DckojB+Yl2ASzcFdUdrtLR8+a/9+lmuvOCq3k9Jlo+v2294G1bZuxIGM 8pLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=1M+kjBe5LJfHMKPYebEvjyNaiKWDMDU0Hnt7bpr7e5A=; b=u2yJCIZCGwFWJYabx9ANrePxVxH8/neVsncdBkXHB1bI++5v3IwuhI30BbH+I7+J8Q LydoGSavr+BSDqEi7m8RFu8lZATCDwvrSGNVhvW8d/z8GmqfUWS5fozJUfXhCEilOb94 Z4KQrnRbw+5xE3VaI+fZgN47ZMBA/EOnN7uvTlL39lcIyZ97IDE7j3xrKLqXV2F3xvTu um/4jqisv04OvPS/01O4Lse52Wx/sVbIrFp9j76aVlVI9NkCt4gLj57dvH7a1Dns5UuM 487UzEeWP7XDDWEu33dJjiYanFWZG6fcJZidPm/JwJoxuwUcN52Dj6SjRInaTjasj9kA DpFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SyY5P3/3"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gz12si7967697ejc.256.2021.08.06.03.24.58; Fri, 06 Aug 2021 03:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="SyY5P3/3"; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244990AbhHFKZM (ORCPT + 12 others); Fri, 6 Aug 2021 06:25:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244970AbhHFKZM (ORCPT ); Fri, 6 Aug 2021 06:25:12 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992F5C061799 for ; Fri, 6 Aug 2021 03:24:56 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id z4so10408903wrv.11 for ; Fri, 06 Aug 2021 03:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=1M+kjBe5LJfHMKPYebEvjyNaiKWDMDU0Hnt7bpr7e5A=; b=SyY5P3/3fn3OPSGo81KmIl2K9Y502cNWmKbU9aTw7C+3CMdbgYAMOdrU0sphIJVJaf A4qkFfiU+075rWAkUPF3xkwV0v2K2kvwD+XgvgHliCYW5CBMvwzm4nf0TwECQvZMVV10 LvGbpOrinF4IpxYj6+F9M69H0Gm5I0JD81bhT+SeiEXkqUUbAZwP0alzGz/76+D1vv0/ 8QvQA7FyThN88MOFBp8GCCfY9iuTZMPRCaxyQR6Ro6b+Je1y96jRbrdn2rcKG5cXUaxx Iq3cSXTbP7T75vjY22yR7POqfg2iumeMN8q3svM7RijFlkg134qZKrZQ/kRs3+IWsXi9 g2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1M+kjBe5LJfHMKPYebEvjyNaiKWDMDU0Hnt7bpr7e5A=; b=k8nW0XRDbUiPEWGyXMhEC1xzk6w5dLhKSGL5MepFYvUU5QdWFLim7JmjEfURtt5c6N YMYy0YiU4JtwmuoJkQUVYuSEVlhvWfl3Njo0jCny7NhjHgdEYUAsWtdkAQP7cS1Cljbu KsKrGOs69VCakKoZXgjUmEcKDryFxs+zaMstvCtF6VeWHrsYbpUx6mW8BDXSQoOYTx3r /Ba9ojybmwj808xvXwGhrexM7MCZsYW3yF/9SDk0NoaVxspI6wjWrbVrSjSitApGQUNT C/Q8ORzneP+K3I1h58fL2P+M6YlhxdZdM6C/ohrnBTodRqWccQPItoSwEQaSeg3TfA3O +6eA== X-Gm-Message-State: AOAM533HvihSm1MHUfcDDD8QP/cxJgNjYH1vaFxx2j7/Rta5o13P4uPN s4vwnWc0/l/7CyWo3AHUzFQh0A== X-Received: by 2002:a5d:4a84:: with SMTP id o4mr9729993wrq.273.1628245495152; Fri, 06 Aug 2021 03:24:55 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:69b5:b274:5cfc:ef2]) by smtp.gmail.com with ESMTPSA id k17sm9046540wrw.53.2021.08.06.03.24.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Aug 2021 03:24:54 -0700 (PDT) From: Loic Poulain To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, ryazanov.s.a@gmail.com, Loic Poulain , stable@vger.kernel.org Subject: [PATCH net-next] net: wwan: mhi_wwan_ctrl: Fix possible deadlock Date: Fri, 6 Aug 2021 12:35:09 +0200 Message-Id: <1628246109-27425-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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); 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 Signed-off-by: Loic Poulain --- drivers/net/wwan/mhi_wwan_ctrl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.7.4 Reviewed-by: Sergey Ryazanov 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);