Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2989330pxj; Mon, 17 May 2021 15:02:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5jXyrPT/1Kc5c/aaHJYWgJC2evwuPqQbzLbNwhaszE5HLFpkjMlGT2whhTy9Uk0btPm+J X-Received: by 2002:a05:6402:20f:: with SMTP id t15mr2608147edv.370.1621288959524; Mon, 17 May 2021 15:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621288959; cv=none; d=google.com; s=arc-20160816; b=HCO36zRym8AasLbizCGzq/p2m6pD/d1NH8+8QmGoq0omDrufPl51DUfZ9IULQR/H6f WeH1x47VCv05fPxXthl0mhIvD3nMDHnKlTe8gFpBgaG0j2FehYrUWqQEgkdlsUflRea+ ULDTRP167kwM6+oV2DGmm9kI4NDiR8jN0NToSyGfC8XbeWHJYtLxYQZajQl8WRY6ihf0 TO5T0qMN3zQtaluE1l9ElhCVwmrQkUPjuUvLnBW6Q6pfQKRMMsDiuW4HsWQ8NdCctKlG orZlbkgZIj98yf3JgZjgy+Zv4qz2lwc64Kz3WUNy1XHh8EYomKSpo4/99rBi6PwXgZbe teZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FKw6Iy5snw9Zx4ts2DaxQR2fAk+Vn9KurUec7/rR4KU=; b=j3uRIC5mApXWelHRy7AsKrP/8/lfKpCCnTyj8FL9k+QybTd7dzK+4FT6pVJyGVujRK 6wGI7CStHls4Gv34M2CeCkZw3xAMEk8ftnkQQmXn73bAKbYhiqmhTUrpT1IyN6AS3yCw gMIK6YBqygFnVmZ/b84RmneGagvbVNZ2OUp01joEXjD7MEcK2lRzba5dyVbUhYasDcq2 IFsJd0lCCi139Vw9EMxjrwZ6GvPFjDOB4L45i2K9xhkgJpm4ozQjVQ4dBTgJFibveO8b OAfbtaz2GhCX4vzww3XoIgjD8ZG3nry/1ZbZbX1C0C/M2S5UT6Gjca+3LcuHDO0XVgab vC9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=deYepTfu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a22si9276210edv.404.2021.05.17.15.02.12; Mon, 17 May 2021 15:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=deYepTfu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238701AbhEQOMD (ORCPT + 99 others); Mon, 17 May 2021 10:12:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:58830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238275AbhEQOJ5 (ORCPT ); Mon, 17 May 2021 10:09:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 751506135C; Mon, 17 May 2021 14:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260426; bh=rvik31wNCtC9gMOzvh2YCdENR358Ai1yNdp2L2ZWotY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=deYepTfuRY5YAqzYN0ZObmTZDEENJT8aegIz0I4U96f7RD/m5WAFTOLppel/i/Qfr joKcYQCYE2nLWbcmF1PpTVndfOD/JHHq1tlR47HUdw0/57asSdaMvf1Jam7atTBYD7 9iL7P45LKwA+is4Kwjs1pB5vUsupQYfX9UzjG2J8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mordechay Goodstein , Luca Coelho , Sasha Levin Subject: [PATCH 5.12 077/363] iwlwifi: queue: avoid memory leak in reset flow Date: Mon, 17 May 2021 15:59:03 +0200 Message-Id: <20210517140305.196019382@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mordechay Goodstein [ Upstream commit 4cf2f5904d971a461f67825434ae3c31900ff84b ] In case the device is stopped any usage of hw queues needs to be reallocated in fw due to fw reset after device stop, so all driver internal queue should also be freed, and if we don't free the next usage would leak the old memory and get in recover flows "iwlwifi 0000:00:03.0: dma_pool_destroy iwlwifi:bc" warning. Also warn about trying to reuse an internal allocated queue. Signed-off-by: Mordechay Goodstein Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20210411124417.c72d2f0355c4.Ia3baff633b9b9109f88ab379ef0303aa152c16bf@changeid Signed-off-by: Luca Coelho Signed-off-by: Sasha Levin --- .../wireless/intel/iwlwifi/pcie/trans-gen2.c | 4 +-- drivers/net/wireless/intel/iwlwifi/queue/tx.c | 30 ++++--------------- drivers/net/wireless/intel/iwlwifi/queue/tx.h | 3 +- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c index 94ffc1ae484d..af9412bd697e 100644 --- a/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c +++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* * Copyright (C) 2017 Intel Deutschland GmbH - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation */ #include "iwl-trans.h" #include "iwl-prph.h" @@ -143,7 +143,7 @@ void _iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans) if (test_and_clear_bit(STATUS_DEVICE_ENABLED, &trans->status)) { IWL_DEBUG_INFO(trans, "DEVICE_ENABLED bit was set and is now cleared\n"); - iwl_txq_gen2_tx_stop(trans); + iwl_txq_gen2_tx_free(trans); iwl_pcie_rx_stop(trans); } diff --git a/drivers/net/wireless/intel/iwlwifi/queue/tx.c b/drivers/net/wireless/intel/iwlwifi/queue/tx.c index 833f43d1ca7a..810dcb3df242 100644 --- a/drivers/net/wireless/intel/iwlwifi/queue/tx.c +++ b/drivers/net/wireless/intel/iwlwifi/queue/tx.c @@ -13,30 +13,6 @@ #include "iwl-scd.h" #include -/* - * iwl_txq_gen2_tx_stop - Stop all Tx DMA channels - */ -void iwl_txq_gen2_tx_stop(struct iwl_trans *trans) -{ - int txq_id; - - /* - * This function can be called before the op_mode disabled the - * queues. This happens when we have an rfkill interrupt. - * Since we stop Tx altogether - mark the queues as stopped. - */ - memset(trans->txqs.queue_stopped, 0, - sizeof(trans->txqs.queue_stopped)); - memset(trans->txqs.queue_used, 0, sizeof(trans->txqs.queue_used)); - - /* Unmap DMA from host system and free skb's */ - for (txq_id = 0; txq_id < ARRAY_SIZE(trans->txqs.txq); txq_id++) { - if (!trans->txqs.txq[txq_id]) - continue; - iwl_txq_gen2_unmap(trans, txq_id); - } -} - /* * iwl_txq_update_byte_tbl - Set up entry in Tx byte-count array */ @@ -1189,6 +1165,12 @@ static int iwl_txq_alloc_response(struct iwl_trans *trans, struct iwl_txq *txq, goto error_free_resp; } + if (WARN_ONCE(trans->txqs.txq[qid], + "queue %d already allocated\n", qid)) { + ret = -EIO; + goto error_free_resp; + } + txq->id = qid; trans->txqs.txq[qid] = txq; wr_ptr &= (trans->trans_cfg->base_params->max_tfd_queue_size - 1); diff --git a/drivers/net/wireless/intel/iwlwifi/queue/tx.h b/drivers/net/wireless/intel/iwlwifi/queue/tx.h index af1dbdf5617a..20efc62acf13 100644 --- a/drivers/net/wireless/intel/iwlwifi/queue/tx.h +++ b/drivers/net/wireless/intel/iwlwifi/queue/tx.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation */ #ifndef __iwl_trans_queue_tx_h__ #define __iwl_trans_queue_tx_h__ @@ -123,7 +123,6 @@ int iwl_txq_gen2_tx(struct iwl_trans *trans, struct sk_buff *skb, void iwl_txq_dyn_free(struct iwl_trans *trans, int queue); void iwl_txq_gen2_free_tfd(struct iwl_trans *trans, struct iwl_txq *txq); void iwl_txq_inc_wr_ptr(struct iwl_trans *trans, struct iwl_txq *txq); -void iwl_txq_gen2_tx_stop(struct iwl_trans *trans); void iwl_txq_gen2_tx_free(struct iwl_trans *trans); int iwl_txq_init(struct iwl_trans *trans, struct iwl_txq *txq, int slots_num, bool cmd_queue); -- 2.30.2