From patchwork Fri Jan 12 21:08:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 10161677 X-Patchwork-Delegate: kvalo@adurom.com 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 4377460327 for ; Fri, 12 Jan 2018 21:10:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 366AF28AA1 for ; Fri, 12 Jan 2018 21:10:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ADF028ABD; Fri, 12 Jan 2018 21:10:03 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BB8528A18 for ; Fri, 12 Jan 2018 21:10:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965289AbeALVIr (ORCPT ); Fri, 12 Jan 2018 16:08:47 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:35464 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965287AbeALVIo (ORCPT ); Fri, 12 Jan 2018 16:08:44 -0500 Received: by mail-pg0-f65.google.com with SMTP id d6so5356691pgv.2 for ; Fri, 12 Jan 2018 13:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MTkPuUB9FwHau9vCnxx3/MtD4zXVUtfdKRayfVFIw/Q=; b=dOt/QfNfhF3rvg7uVDMBkMMcsMNBp1FD6iVJx/MtvO3p0MDC3Mk5/0cJem/DY7Djbe hLyNXQyqi2N5+gKsy3p+gkx8TmYTrXwU0Jh70eoCUqvHEjbT+/5XADAyQ6qweCNDE5tk FIpyoJGW1Vwm/rYyye79LP6F3isVN9OuPOB7o= 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:in-reply-to :references; bh=MTkPuUB9FwHau9vCnxx3/MtD4zXVUtfdKRayfVFIw/Q=; b=d4KwKJStnGHqTz1M5RIeGA8fdMSO0TuYsAlpU8Bzb0HyreDZbt3oLcNTBC7tj0WYdV +BkmQD42HOsrMPLt57Nmhuxns0gS42bsjfFEn3dUk/YQZp+68ypVe7UPpWyftZ0rd5UD Kc+PJ2gQuiQa2uO1aQ0JpVggNQnLJxKVd6FFvyM6+NN2d7+B+DiuusEa0j2iynCFRV+c 4fV9hK9oVgjBKEpaJg5OGdfNFaH+m6RDl+fAm07tpjNVPCaJ1ePXI5wW7A9iE2MLSty5 /FkmNzHyrIRo0e276zJ+DcUSP38b7XVLTjEtOT4Xw7pTXNr390qkFAwYocFN1wgc+pCw odqA== X-Gm-Message-State: AKGB3mKNRqQb83dr/BCxm+aWL2ZoyXKjRQqyQTb5FvagYWgOiynWdN2N mS7XhSxs1umsRvunvdHE8bRJAg== X-Google-Smtp-Source: ACJfBot4DsWHZH8I4uNdG85HDlBvTAumE8BsMv3nN4BXnLTEFoo432IWN8bXMzq20QCGkkGx/FbBnw== X-Received: by 10.101.100.198 with SMTP id t6mr20969971pgv.99.1515791324390; Fri, 12 Jan 2018 13:08:44 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.113.17]) by smtp.gmail.com with ESMTPSA id o7sm15217313pgp.18.2018.01.12.13.08.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 13:08:43 -0800 (PST) From: Brian Norris To: Ganapathi Bhat , Nishant Sarmukadam , Kalle Valo , Amitkumar Karwar Cc: , linux-wireless@vger.kernel.org, Ellie Reeves , Christoph Hellwig , Dmitry Torokhov , Zhiyuan Yang , Tim Song , Cathy Luo , James Cao , Brian Norris , stable@vger.kernel.org, Xinming Hu Subject: [PATCH 2/2] mwifiex: resolve reset vs. remove()/shutdown() deadlocks Date: Fri, 12 Jan 2018 13:08:37 -0800 Message-Id: <20180112210837.112628-2-briannorris@chromium.org> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog In-Reply-To: <20180112210837.112628-1-briannorris@chromium.org> References: <20180112210837.112628-1-briannorris@chromium.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit b014e96d1abb ("PCI: Protect pci_error_handlers->reset_notify() usage with device_lock()") resolves races between driver reset and removal, but it introduces some new deadlock problems. If we see a timeout while we've already started suspending, removing, or shutting down the driver, we might see: (a) a worker thread, running mwifiex_pcie_work() -> mwifiex_pcie_card_reset_work() -> pci_reset_function() (b) a removal thread, running mwifiex_pcie_remove() -> mwifiex_free_adapter() -> mwifiex_unregister() -> mwifiex_cleanup_pcie() -> cancel_work_sync(&card->work) Unfortunately, mwifiex_pcie_remove() already holds the device lock that pci_reset_function() is now requesting, and so we see a deadlock. It's necessary to cancel and synchronize our outstanding work before tearing down the driver, so we can't have this work wait indefinitely for the lock. It's reasonable to only "try" to reset here, since this will mostly happen for cases where it's already difficult to reset the firmware anyway (e.g., while we're suspending or powering off the system). And if reset *really* needs to happen, we can always try again later. Fixes: b014e96d1abb ("PCI: Protect pci_error_handlers->reset_notify() usage with device_lock()") Cc: Cc: Xinming Hu Signed-off-by: Brian Norris --- drivers/net/wireless/marvell/mwifiex/pcie.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index f666cb2ea7e0..97a6199692ab 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -2786,7 +2786,10 @@ static void mwifiex_pcie_card_reset_work(struct mwifiex_adapter *adapter) { struct pcie_service_card *card = adapter->card; - pci_reset_function(card->dev); + /* We can't afford to wait here; remove() might be waiting on us. If we + * can't grab the device lock, maybe we'll get another chance later. + */ + pci_try_reset_function(card->dev); } static void mwifiex_pcie_work(struct work_struct *work)