Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1980082pxb; Fri, 5 Mar 2021 04:40:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvLMBX1ATU5X5sf0GFmaQMNLs+ftdAaDXp4fNP50UdGljOIZ3FP7i+k0lj4W5aStLG5R5r X-Received: by 2002:a17:906:58d6:: with SMTP id e22mr2011651ejs.112.1614948049754; Fri, 05 Mar 2021 04:40:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614948049; cv=none; d=google.com; s=arc-20160816; b=kfedCdPTPpvSxmmtSX0ghzAuYPK1STfKMhUAsO91W4+IvarFcva/w2cO7cBxcvJOU/ 1zjRp6g86kT67M1d9TF5vw+pXFppFBY6gWGJiKDg9vYIJ3fGHTDgJDFtSCvvYX5WGBNi 3YoLE+NxXS+NLfgiTShNoGoDDpOwYe0NyPvjD0NPI5o3jC3v/RG6UO1Of6YEZlTAoQlR HJXNrkN2Nuj2fR4GOlzSWQGyb2UIDlQs3eFD/Pb/pSDIywACo0LWyDh8P3Zwc1PJgbyv rO1EEpBBPkNdz/s9aL3chtBWUt94NJ2IWCxcMfR9jW5RDiib/Jujjt/zH0tdL5h/Mky/ +38Q== 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=OTzCBvg+Wv56H+rL8Cb7WswZb7c2Ql4QfA75IvQ0/LY=; b=yFfsIttFiqnyHKk7+0df9SQB86yAJQoblJjOFguA0p6FGXJOAgmGFMVI57lCPpdPAP c/aoNUb2Gk60x6eEsF2LPvT3MHPgGoQOf9UZ64VP5mkLt0IPE4QG1W9FNSAJGT4pfvZL PfgSohuZJDkuLMpr2ho6Fnor9+Dmup3iuUIc3plkB+DsEl4CrQels0WMbhyjjt3tvWjD QN2DK6oNKjfDAzB5JDat3Hqb/z4fRK35zHLdcURERGQaPcwGIc0MKwXhP97MGXHjbLjA fd6Nkuqnw6efHAblqioESQg8gusgyR3fGxLPLTYY3lZcF/feOuz6Mn6bXanGPC9wXls0 xTkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=u7fJRoqB; 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 r20si1479566edw.406.2021.03.05.04.40.24; Fri, 05 Mar 2021 04:40:49 -0800 (PST) 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=u7fJRoqB; 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 S233019AbhCEMj0 (ORCPT + 99 others); Fri, 5 Mar 2021 07:39:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:52468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbhCEMip (ORCPT ); Fri, 5 Mar 2021 07:38:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6E576503A; Fri, 5 Mar 2021 12:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947925; bh=d+q80kQSMRpcRLO1N4ipTPIJYZsU/cjDy/rQFHpnJHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u7fJRoqBWm6JMtE5dOy16YMcJYdOZBge+BCZ6MjEZLvykJxL+j0nPkBU5gmTE6lFC 8oMsE+I3NN8tDlLOEmkrHIZG3fB3pufP6cMBo7jP23a2VSEv1wr7rJdglJH6FKNF4g Mp+T2iKeiYyw/9tls5kuN8wUexncBDtOLyoTemCk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaoqing Pan , Brian Norris , Kalle Valo , Sasha Levin Subject: [PATCH 4.19 27/52] ath10k: fix wmi mgmt tx queue full due to race condition Date: Fri, 5 Mar 2021 13:21:58 +0100 Message-Id: <20210305120855.008497719@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120853.659441428@linuxfoundation.org> References: <20210305120853.659441428@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: Miaoqing Pan [ Upstream commit b55379e343a3472c35f4a1245906db5158cab453 ] Failed to transmit wmi management frames: [84977.840894] ath10k_snoc a000000.wifi: wmi mgmt tx queue is full [84977.840913] ath10k_snoc a000000.wifi: failed to transmit packet, dropping: -28 [84977.840924] ath10k_snoc a000000.wifi: failed to submit frame: -28 [84977.840932] ath10k_snoc a000000.wifi: failed to transmit frame: -28 This issue is caused by race condition between skb_dequeue and __skb_queue_tail. The queue of ‘wmi_mgmt_tx_queue’ is protected by a different lock: ar->data_lock vs list->lock, the result is no protection. So when ath10k_mgmt_over_wmi_tx_work() and ath10k_mac_tx_wmi_mgmt() running concurrently on different CPUs, there appear to be a rare corner cases when the queue length is 1, CPUx (skb_deuque) CPUy (__skb_queue_tail) next=list prev=list struct sk_buff *skb = skb_peek(list); WRITE_ONCE(newsk->next, next); WRITE_ONCE(list->qlen, list->qlen - 1);WRITE_ONCE(newsk->prev, prev); next = skb->next; WRITE_ONCE(next->prev, newsk); prev = skb->prev; WRITE_ONCE(prev->next, newsk); skb->next = skb->prev = NULL; list->qlen++; WRITE_ONCE(next->prev, prev); WRITE_ONCE(prev->next, next); If the instruction ‘next = skb->next’ is executed before ‘WRITE_ONCE(prev->next, newsk)’, newsk will be lost, as CPUx get the old ‘next’ pointer, but the length is still added by one. The final result is the length of the queue will reach the maximum value but the queue is empty. So remove ar->data_lock, and use 'skb_queue_tail' instead of '__skb_queue_tail' to prevent the potential race condition. Also switch to use skb_queue_len_lockless, in case we queue a few SKBs simultaneously. Tested-on: WCN3990 hw1.0 SNOC WLAN.HL.3.1.c2-00033-QCAHLSWMTPLZ-1 Signed-off-by: Miaoqing Pan Reviewed-by: Brian Norris Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/1608618887-8857-1-git-send-email-miaoqing@codeaurora.org Signed-off-by: Sasha Levin --- drivers/net/wireless/ath/ath10k/mac.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c index faaca7fe9ad1..f32d35e03708 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -3567,23 +3567,16 @@ bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar) static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb) { struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; - int ret = 0; - - spin_lock_bh(&ar->data_lock); - if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) { + if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) { ath10k_warn(ar, "wmi mgmt tx queue is full\n"); - ret = -ENOSPC; - goto unlock; + return -ENOSPC; } - __skb_queue_tail(q, skb); + skb_queue_tail(q, skb); ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); -unlock: - spin_unlock_bh(&ar->data_lock); - - return ret; + return 0; } static enum ath10k_mac_tx_path -- 2.30.1