Received: by 10.223.185.116 with SMTP id b49csp751383wrg; Wed, 21 Feb 2018 06:23:56 -0800 (PST) X-Google-Smtp-Source: AH8x224F+lm7+G8IZKJY34q97w+W2ITmfAalEfss6bVw0PujvzXExBvSvNSNz72/7nz6MacAgUwK X-Received: by 2002:a17:902:bcc1:: with SMTP id o1-v6mr3404838pls.218.1519223035960; Wed, 21 Feb 2018 06:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519223035; cv=none; d=google.com; s=arc-20160816; b=HODujr3/EXO2o7hJAbh2FDyn+K5EasMvmw9cJ6oN4Y+T9hIyytu+RJC66f0DHAXtbN 5TAWHJeKLbXQfj53350cl1S4jP4uOkpTWdb7JCnw+/VDayZGBv5t5sZvFgAZ8hGOPtPZ PSkE1eDsT608Sb7o/e1B2/IzOQiP8aBE/E1Jryqz3E8hmb29JYzxiuvqqBALlLcA4iTR QDvk0ckF4larmB4hKRqyFz19An5Ko+cyr3D8mUkUS9aaXWBvOkfMaWfPfjqekqF/w4V/ RiLdc7by1mjD7MeuDDbkIAiNLbqJ+HSdDAKwoWvx+FMEryI2SascTaZWTAjtvR4PiCJc cenw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=tHI60DHSl2mdorovP1x8B1vBfYgC8NZyS6KI8EZ7KrQ=; b=o6VwrlqzAswqri7V836pjkhAF9coYp54c09IOzGsIMBqZjvS3TSFajWrr4hRr3EURI ta4NZgb5BOKDF5+j5FMonjeikpUuVM2SObzAzt9g+dF7wJUqTTsdhjWqqpuJsvDWQS76 HGwZ1GFPOg5f+afq9m2Cvq6WbMq9ACtqoAb1Oon2AkpMYfRx6vTFCPgMmakzRR+JLm3y sqBJvFSRbrUO7F6yyWK8WhZ7h+puKLxr5/of/Sn7euj4gec0GmoqV+ktmfww8LQoSo9D d2xD/Qtjifjxj42RoVgIUJYwHgH/2eR37MY++5NMJMVQW24Z5Un1ny47FkdrKm2hyVPI FZkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 101-v6si1713008ple.263.2018.02.21.06.23.41; Wed, 21 Feb 2018 06:23:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935057AbeBUOWf (ORCPT + 99 others); Wed, 21 Feb 2018 09:22:35 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36080 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934867AbeBUM6Q (ORCPT ); Wed, 21 Feb 2018 07:58:16 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 86452F5A; Wed, 21 Feb 2018 12:58:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xinming Hu , Brian Norris , Kalle Valo Subject: [PATCH 4.14 017/167] mwifiex: resolve reset vs. remove()/shutdown() deadlocks Date: Wed, 21 Feb 2018 13:47:08 +0100 Message-Id: <20180221124525.562795649@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124524.639039577@linuxfoundation.org> References: <20180221124524.639039577@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brian Norris commit a64e7a79dd6030479caad603c8d78e6c9c14904f upstream. 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 Signed-off-by: Kalle Valo Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/marvell/mwifiex/pcie.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -2781,7 +2781,10 @@ static void mwifiex_pcie_card_reset_work { 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)