From patchwork Tue Jul 25 01:13:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 9860967 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 581436038C for ; Tue, 25 Jul 2017 01:16:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A8CE283BF for ; Tue, 25 Jul 2017 01:16:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F47C2842E; Tue, 25 Jul 2017 01:16:51 +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=ham 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 44C37285A2 for ; Tue, 25 Jul 2017 01:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756962AbdGYBQL (ORCPT ); Mon, 24 Jul 2017 21:16:11 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:36899 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756801AbdGYBO2 (ORCPT ); Mon, 24 Jul 2017 21:14:28 -0400 Received: by mail-pg0-f44.google.com with SMTP id y129so63969736pgy.4 for ; Mon, 24 Jul 2017 18:14:28 -0700 (PDT) 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=xI1m0KRiEYfRRsL93ah/ZuJVjvPjR0VYtRGg5SJAms4=; b=j0WtieTknEd/r3S6u9dMEYMpNR146HRAmUcc1W4YFVHiEKnvOuVtQ03qolS4jcIJ3m 53LVScfyx41OaG1LrQ0+cUcPNOixjcxW1RxzvaxDffj0WTBbsDLn/z3rrAaU5IxwysaZ VWKik9dXYmluHPuYur+TV0KCkVxkixAzcdzr4= 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=xI1m0KRiEYfRRsL93ah/ZuJVjvPjR0VYtRGg5SJAms4=; b=n1dh/yI/s78KCjZgKovagGO8ZH5I7rAYcua9dlhf1mUVPigTstzzv7lo/J8TR3e9aq dOYXTM/EpYACkqh7vnlD7S0dTDemsVoZopzCnH5pjnrZKgk7wiyXhvBKA2hN2apwZNFg 9JlIpglpDtAInhQ4257cNj6bg1Zr9zsWX6Tv53C+pV7xVeLJ2S5azoEzLgn9Uv64kC03 w4ebpxG8aH6ucuTZWIohTaaw1U9MEqRPElE/1q/Z+rJuMJ9PWrX72f3fZetgY2WSsAZx P5/vdWmN1JMcA/zizto2AHR/UwRW5mbGfukn96AcSF3Rtj0DQu7ZHVAzy4OlIMIKUPHJ VCpw== X-Gm-Message-State: AIVw113yLK6N99QcQ+AiyihV8FQw4gGC5JT0UrwqWb/CogS2+hQ6y0/u koY6VkpQ8JQTjm0T X-Received: by 10.98.204.10 with SMTP id a10mr18183638pfg.332.1500945266385; Mon, 24 Jul 2017 18:14:26 -0700 (PDT) Received: from ban.mtv.corp.google.com ([172.22.113.17]) by smtp.gmail.com with ESMTPSA id h123sm21497036pgc.36.2017.07.24.18.14.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Jul 2017 18:14:25 -0700 (PDT) From: Brian Norris To: Ganapathi Bhat , Nishant Sarmukadam Cc: , Dmitry Torokhov , Amitkumar Karwar , Kalle Valo , linux-wireless@vger.kernel.org, Brian Norris Subject: [PATCH v2 17/20] mwifiex: pcie: disable device DMA before unmapping/freeing buffers Date: Mon, 24 Jul 2017 18:13:33 -0700 Message-Id: <20170725011336.99993-18-briannorris@chromium.org> X-Mailer: git-send-email 2.14.0.rc0.284.gd933b75aa4-goog In-Reply-To: <20170725011336.99993-1-briannorris@chromium.org> References: <20170725011336.99993-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 In testing the mwifiex reset code path, I've noticed KASAN complaining about some "overwritten poison values" in our RX buffer descriptors. Because KASAN didn't notice this at the time of a CPU write, this seems to suggest that the device is writing to this memory. This makes a little sense, because when resetting, we don't necessarily expect the device to be responsive, so we don't have a chance to disable everything cleanly. We can at least take the precaution of disabling DMA for the device though, and in my testing that seems to clear up this particular issue. This patch reorders the removal path so that we disable the device *before* releasing our last PCIe buffers, and it clears/sets the bus master feature from the PCI device when resetting. Along the way, remove the insufficient (and confusing) error path in mwifiex_pcie_up_dev() (it doesn't unwind things well enough, and it doesn't propagate its errors upward anyway). Signed-off-by: Brian Norris --- new in v2 --- drivers/net/wireless/marvell/mwifiex/pcie.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c index c08ebb55a7e8..a1907e8e620f 100644 --- a/drivers/net/wireless/marvell/mwifiex/pcie.c +++ b/drivers/net/wireless/marvell/mwifiex/pcie.c @@ -2958,15 +2958,17 @@ static void mwifiex_cleanup_pcie(struct mwifiex_adapter *adapter) "Failed to write driver not-ready signature\n"); } - mwifiex_pcie_free_buffers(adapter); - if (pdev) { + pci_disable_device(pdev); + pci_iounmap(pdev, card->pci_mmap); pci_iounmap(pdev, card->pci_mmap1); pci_disable_device(pdev); pci_release_region(pdev, 2); pci_release_region(pdev, 0); } + + mwifiex_pcie_free_buffers(adapter); } static int mwifiex_pcie_request_irq(struct mwifiex_adapter *adapter) @@ -3142,7 +3144,6 @@ static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter) static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter) { struct pcie_service_card *card = adapter->card; - int ret; struct pci_dev *pdev = card->dev; /* tx_buf_size might be changed to 3584 by firmware during @@ -3150,11 +3151,9 @@ static void mwifiex_pcie_up_dev(struct mwifiex_adapter *adapter) */ adapter->tx_buf_size = card->pcie.tx_buf_size; - ret = mwifiex_pcie_alloc_buffers(adapter); - if (!ret) - return; + mwifiex_pcie_alloc_buffers(adapter); - pci_iounmap(pdev, card->pci_mmap1); + pci_set_master(pdev); } /* This function cleans up the PCI-E host memory space. */ @@ -3162,10 +3161,13 @@ static void mwifiex_pcie_down_dev(struct mwifiex_adapter *adapter) { struct pcie_service_card *card = adapter->card; const struct mwifiex_pcie_card_reg *reg = card->pcie.reg; + struct pci_dev *pdev = card->dev; if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000)) mwifiex_dbg(adapter, ERROR, "Failed to write driver not-ready signature\n"); + pci_clear_master(pdev); + adapter->seq_num = 0; mwifiex_pcie_free_buffers(adapter);