Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp952808ybj; Tue, 5 May 2020 10:15:19 -0700 (PDT) X-Google-Smtp-Source: APiQypIkjYZVa+jlWuZhf2pHDgbz/9XFhnk11DTnmhRYgIDEe6vQdBKGsnkksJT4eOzTNsLYbG11 X-Received: by 2002:a17:906:f90e:: with SMTP id lc14mr3625676ejb.156.1588698919645; Tue, 05 May 2020 10:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588698919; cv=none; d=google.com; s=arc-20160816; b=zfWe5+s+YzfODUyTtqsfTFLu/dMiPCyv47Sn+CW8UjgLkJP9Gkm0vonqQdj8TXosBg HLCj0BZjY8aYFdrKURsIlESrG7985DbVWG3R55PN4/fEUzAOeuOmX8e1+y+vdxedOYtr 8TOgnuhIKLcDM6Kz80a46ZKT0RYMBA/5Pp4qUe+XkhEpRJM0o/Id+Gn5H4idv2npJvoJ FAzZbopkVKlqlERiXRwm9xiSczVkVqp7V0zZEApLGTePCK4yBxemPR0MGAv2lbXVQUdi r82lUK4J/4kXbtpK5sXad+Xu5qrjq/nduKxw2aHsRH1A721RQp102S8PsL1E3d2YK94o GyZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=Dukm2lONyZGM3jH6Zqk0uVOmFYp2c9u684qv9nSoTw0=; b=GfdBXaaUJjPzoC/vsF+KxaWoAWTPZuEvxD9OIsekfchU5cnJ1l6JPXtBq3us2t92jo leYbHcfYsFa1d9FaomkHOEQA3k91oeWn1u6khHL/ZAx25jfdfmkAPN+zynljZJ5FZOfS kBSNmat6/HfXB+XJGweMUYmdbEJNneaI2Nc/tKQvKmE3+3mf7/USphD2dQ0RwyaWhV23 7/hn8Ry02OlYmb7iOi7V4pIBEzLAkVe7SAVIlpUWKQ7jKohahVWXhPBBML6+59nL2RxX Dn7hAteluwYzX5TeduQV8m5YaP0RYki0bVzM29IkcD54dD0G8D4MFH9iCsb4ypBUsgcx TPIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=bncziU2b; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qn4si1440792ejb.209.2020.05.05.10.14.43; Tue, 05 May 2020 10:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=bncziU2b; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729488AbgEERMJ (ORCPT + 99 others); Tue, 5 May 2020 13:12:09 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:35974 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728804AbgEERMJ (ORCPT ); Tue, 5 May 2020 13:12:09 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1588698727; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=Dukm2lONyZGM3jH6Zqk0uVOmFYp2c9u684qv9nSoTw0=; b=bncziU2bS4iJzOefd19YrH08Yk2/uxFjTcRZ+LqXRP9+1lk2vqCEWnk7siO9Ki0bQ8QOF8oA zZ431aX60fhGFCOx/Zwxl4N34C5tBf5iWIKSOZmmDggRuo+gNwJ2PS7/O34Z5QdVNGb7W40k jgpIcU1q9qhzKlgQPt53iOOPnCo= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI3YTAwOSIsICJsaW51eC13aXJlbGVzc0B2Z2VyLmtlcm5lbC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5eb19e5b.7f221ceb4810-smtp-out-n01; Tue, 05 May 2020 17:11:55 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 0502FC433BA; Tue, 5 May 2020 17:11:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=ham autolearn_force=no version=3.4.0 Received: from pradeepc-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: pradeepc) by smtp.codeaurora.org (Postfix) with ESMTPSA id 53998C433CB; Tue, 5 May 2020 17:11:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 53998C433CB Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=pradeepc@codeaurora.org From: Pradeep Kumar Chitrapu To: ath11k@lists.infradead.org Cc: linux-wireless@vger.kernel.org, Pradeep Kumar Chitrapu , Miles Hu Subject: [PATCH] ath11k: fix htt stats module not handle multiple skbs Date: Tue, 5 May 2020 10:11:33 -0700 Message-Id: <1588698693-6218-1-git-send-email-pradeepc@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org HTT EXT stats comes in stream of TLVs spanning over multiple messages. Currently completion is being sent for each message which is creating a race where stats_req is being accessed for filling in second message after the memory is already freed in release operation. Fix this by issuing completion once all the messages are received and processed. Driver knows this info from DONE bit set in htt msg. Also fix locking required for htt stats. Co-developed-by: Miles Hu Signed-off-by: Miles Hu Signed-off-by: Pradeep Kumar Chitrapu --- drivers/net/wireless/ath/ath11k/debug_htt_stats.c | 49 ++++++++++++++++++----- drivers/net/wireless/ath/ath11k/dp.h | 1 + 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/debug_htt_stats.c b/drivers/net/wireless/ath/ath11k/debug_htt_stats.c index 5db0c27de475..9722dc431173 100644 --- a/drivers/net/wireless/ath/ath11k/debug_htt_stats.c +++ b/drivers/net/wireless/ath/ath11k/debug_htt_stats.c @@ -4306,6 +4306,7 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab, u32 len; u64 cookie; int ret; + bool send_completion = false; u8 pdev_id; msg = (struct ath11k_htt_extd_stats_msg *)skb->data; @@ -4330,11 +4331,11 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab, return; spin_lock_bh(&ar->debug.htt_stats.lock); - if (stats_req->done) { - spin_unlock_bh(&ar->debug.htt_stats.lock); - return; - } - stats_req->done = true; + + stats_req->done = FIELD_GET(HTT_T2H_EXT_STATS_INFO1_DONE, msg->info1); + if (stats_req->done) + send_completion = true; + spin_unlock_bh(&ar->debug.htt_stats.lock); len = FIELD_GET(HTT_T2H_EXT_STATS_INFO1_LENGTH, msg->info1); @@ -4344,7 +4345,8 @@ void ath11k_dbg_htt_ext_stats_handler(struct ath11k_base *ab, if (ret) ath11k_warn(ab, "Failed to parse tlv %d\n", ret); - complete(&stats_req->cmpln); + if (send_completion) + complete(&stats_req->cmpln); } static ssize_t ath11k_read_htt_stats_type(struct file *file, @@ -4497,28 +4499,54 @@ static int ath11k_open_htt_stats(struct inode *inode, struct file *file) if (type == ATH11K_DBG_HTT_EXT_STATS_RESET) return -EPERM; + mutex_lock(&ar->conf_mutex); + + if (ar->state != ATH11K_STATE_ON) { + ret = -ENETDOWN; + goto err_unlock; + } + + if (ar->debug.htt_stats.stats_req) { + ret = -EAGAIN; + goto err_unlock; + } + stats_req = vzalloc(sizeof(*stats_req) + ATH11K_HTT_STATS_BUF_SIZE); - if (!stats_req) - return -ENOMEM; + if (!stats_req) { + ret = -ENOMEM; + goto err_unlock; + } - mutex_lock(&ar->conf_mutex); ar->debug.htt_stats.stats_req = stats_req; stats_req->type = type; + ret = ath11k_dbg_htt_stats_req(ar); - mutex_unlock(&ar->conf_mutex); if (ret < 0) goto out; file->private_data = stats_req; + + mutex_unlock(&ar->conf_mutex); + return 0; out: vfree(stats_req); + ar->debug.htt_stats.stats_req = NULL; +err_unlock: + mutex_unlock(&ar->conf_mutex); + return ret; } static int ath11k_release_htt_stats(struct inode *inode, struct file *file) { + struct ath11k *ar = inode->i_private; + + mutex_lock(&ar->conf_mutex); vfree(file->private_data); + ar->debug.htt_stats.stats_req = NULL; + mutex_unlock(&ar->conf_mutex); + return 0; } @@ -4582,7 +4610,6 @@ static ssize_t ath11k_write_htt_stats_reset(struct file *file, 0ULL); if (ret) { ath11k_warn(ar->ab, "failed to send htt stats request: %d\n", ret); - mutex_unlock(&ar->conf_mutex); return ret; } diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h index 222de10e4b93..058a5c1d86ff 100644 --- a/drivers/net/wireless/ath/ath11k/dp.h +++ b/drivers/net/wireless/ath/ath11k/dp.h @@ -1517,6 +1517,7 @@ struct htt_ext_stats_cfg_params { * 4 bytes. */ +#define HTT_T2H_EXT_STATS_INFO1_DONE BIT(11) #define HTT_T2H_EXT_STATS_INFO1_LENGTH GENMASK(31, 16) struct ath11k_htt_extd_stats_msg { -- 1.9.1