From patchwork Wed Feb 28 01:22:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Greear X-Patchwork-Id: 10246493 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8845F60212 for ; Wed, 28 Feb 2018 01:25:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75BC928B38 for ; Wed, 28 Feb 2018 01:25:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 685D628B44; Wed, 28 Feb 2018 01:25:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C426F28B3C for ; Wed, 28 Feb 2018 01:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=4YOE8fX7AC8Nu9mu6JQ7HG0Jj5UBJFSLeOcgkwMVA+Q=; b=gog 5CfCmDhUI6MzFHlw2O32gX+XO+PlxOsTMqyv7+cdviK5c1zp+n4qWDE7mlMKmvG2PVVXbmowi4gf1 OppoSB9fWaIV59zUbP/1OCY3GaQiuSf913LLqZv65KHvfNpSqRhsl0QKVznNfO2WoGBmbGWpM8drz Z+kRoovdwhnQWSyx6SMTjxdW6dFcfY7SM4kUYT47YTdsnJXOAhOZGd3a2m/jz0MNTlKWCV/yVOV94 zYzvGvJUR0Ws2BnkiTsarvziqavmQMbU2+j6mOwj+ZgvYQ4NNgKjADmlRN4GdiEM2JK26EIYVnY6m feQpBd+SaC9QXuE9RP93ttNNXB49+3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqqUJ-0006gx-82; Wed, 28 Feb 2018 01:24:55 +0000 Received: from mail2.candelatech.com ([208.74.158.173]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqqSX-0005WO-9z for ath10k@lists.infradead.org; Wed, 28 Feb 2018 01:23:15 +0000 Received: from ben-dt3.candelatech.com (firewall.candelatech.com [50.251.239.81]) by mail2.candelatech.com (Postfix) with ESMTP id 860C940A30A; Tue, 27 Feb 2018 17:22:50 -0800 (PST) From: greearb@candelatech.com To: linux-wireless@vger.kernel.org Subject: [RFC] ath10k: Attempt to work around napi_synchronize hang. Date: Tue, 27 Feb 2018 17:22:45 -0800 Message-Id: <1519780965-15292-1-git-send-email-greearb@candelatech.com> X-Mailer: git-send-email 2.4.11 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180227_172305_912138_12191E66 X-CRM114-Status: GOOD ( 10.47 ) X-BeenThere: ath10k@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Greear , ath10k@lists.infradead.org MIME-Version: 1.0 Sender: "ath10k" Errors-To: ath10k-bounces+patchwork-ath10k=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ben Greear Calling napi_disable twice in a row (w/out starting it and/or without having NAPI active leads to deadlock because napi_disable sets NAPI_STATE_SCHED and NAPI_STATE_NPSVC when it returns, as far as I can tell. So, guard this call to napi_disable. I believe the failure case is something like this: rmmod ath10k_pci ath10k_core Firmware crashes before hif_stop is called by the rmmod path The crash handling logic calls hif_stop Then rmmod gets around to calling hif_stop, but spins endlessly in napi_synchronize. I think one way this could happen is that ath10k_stop checks for state != ATH10K_STATE_OFF, but STATE_RESTARTING is also a possibility. That might be how we can have hif_stop called twice without a hif_start in between. --Ben Signed-off-by: Ben Greear --- drivers/net/wireless/ath/ath10k/core.h | 1 + drivers/net/wireless/ath/ath10k/pci.c | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index 72b4495..c7ba49f 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -1205,6 +1205,7 @@ struct ath10k { /* NAPI */ struct net_device napi_dev; struct napi_struct napi; + bool napi_enabled; struct work_struct stop_scan_work; diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index 398e413..9131e15 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -1956,6 +1956,7 @@ static int ath10k_pci_hif_start(struct ath10k *ar) ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n"); napi_enable(&ar->napi); + ar->napi_enabled = true; ath10k_pci_irq_enable(ar); ath10k_pci_rx_post(ar); @@ -2086,8 +2087,28 @@ static void ath10k_pci_hif_stop(struct ath10k *ar) ath10k_pci_irq_disable(ar); ath10k_pci_irq_sync(ar); ath10k_pci_flush(ar); - napi_synchronize(&ar->napi); - napi_disable(&ar->napi); + + /* Calling napi_disable twice in a row (w/out starting it and/or without + * having NAPI active leads to deadlock because napi_disable sets + * NAPI_STATE_SCHED and NAPI_STATE_NPSVC when it returns, as far as I + * can tell. So, guard this call to napi_disable. I believe the + * failure case is something like this: + * rmmod ath10k_pci ath10k_core + * Firmware crashes before hif_stop is called by the rmmod path + * The crash handling logic calls hif_stop + * Then rmmod gets around to calling hif_stop, but spins endlessly + * in napi_synchronize. + * + * I think one way this could happen is that ath10k_stop checks + * for state != ATH10K_STATE_OFF, but STATE_RESTARTING is also + * a possibility. That might be how we can have hif_stop called twice + * without a hif_start in between. --Ben + */ + if (ar->napi_enabled) { + napi_synchronize(&ar->napi); + napi_disable(&ar->napi); + ar->napi_enabled = false; + } spin_lock_irqsave(&ar_pci->ps_lock, flags); WARN_ON(ar_pci->ps_wake_refcount > 0);